CrawlerTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testRemoveExtremityStopWords() 0 5 1
A testStripTags() 0 12 1
A testremoveStopWords() 0 3 1
A testRemoveExtremityStopWords2() 0 3 1
A testSimpleSentences() 0 5 1
1
<?php
2
namespace rOpenDev\Crawler\Test;
3
4
use rOpenDev\ExtractExpression\CleanText;
5
6
class CrawlerTest extends \PHPUnit\Framework\TestCase
7
{
8
    public function testSimpleSentences()
9
    {
10
        $loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
11
12
        $this->assertSame(4, count(CleanText::getSentences($loremIpsum)));
13
    }
14
15
    public function testRemoveExtremityStopWords()
16
    {
17
        $this->assertSame('ferme', CleanText::removeStopWordsAtExtremity('la ferme'));
18
        $this->assertSame('ferme', CleanText::removeStopWordsAtExtremity('la ferme de'));
19
        $this->assertSame('ferme', CleanText::removeStopWordsAtExtremity('ferme de'));
20
    }
21
22
    public function testRemoveExtremityStopWords2()
23
    {
24
        $this->assertSame('savoir', CleanText::removeStopWordsAtExtremity('savoir plus '));
25
    }
26
27
    public function testremoveStopWords()
28
    {
29
        $this->assertSame('', CleanText::removeStopWords(' http//www '));
30
    }
31
32
    public function testStripTags()
33
    {
34
        $text = '<label class="u-block" for="js-toggler-menu"><svg aria-labelledby="title" role="img" class="u-icon u-icon-burger" viewbox="0 0 18 18" width="18" height="18"><title lang="fr">Icone menu burger</title><span class="u-visually-hidden" aria-hidden="true">Menu</span></label>';
35
36
        $this->assertSame('Icone menu burger Menu', CleanText::stripHtmlTags($text));
37
        $this->assertSame('Icone menu burger Menu', CleanText::stripHtmlTagsOldWay(str_replace('<', ' <', $text)));
38
39
40
        $text = '<label class="u-block" for="js-toggler-menu"><svg aria-labelledby="title" role="img" class="u-icon u-icon-burger" viewbox="0 0 18 18" width="18" height="18"><title lang="fr">Icone menu burger</title>'."\n".'<span class="u-visually-hidden" aria-hidden="true">Menu</span></label>';
41
42
        $this->assertSame('Icone menu burger Menu', CleanText::stripHtmlTags($text));
43
        $this->assertSame('Icone menu burger Menu', CleanText::stripHtmlTagsOldWay(str_replace('<', ' <', $text)));
44
45
    }
46
}
47