|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SixtyNine\Cloud\Tests\Builder; |
|
4
|
|
|
|
|
5
|
|
|
use SixtyNine\Cloud\Builder\FiltersBuilder; |
|
6
|
|
|
use SixtyNine\Cloud\Builder\WordsListBuilder; |
|
7
|
|
|
use SixtyNine\Cloud\Model\Word; |
|
8
|
|
|
use SixtyNine\Cloud\Model\WordsList; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class WordsListBuilderTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testConstructor() |
|
14
|
|
|
{ |
|
15
|
|
|
$list = WordsListBuilder::create()->build('foobar'); |
|
16
|
|
|
$this->assertInstanceOf(WordsList::class, $list); |
|
17
|
|
|
$this->assertEquals('foobar', $list->getName()); |
|
18
|
|
|
$this->assertEmpty($list->getWords()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testImportWords() |
|
22
|
|
|
{ |
|
23
|
|
|
$list = WordsListBuilder::create()->importWords('foobar foo foo bar')->build('foobar'); |
|
24
|
|
|
$this->assertInstanceOf(WordsList::class, $list); |
|
25
|
|
|
$this->assertEquals('foobar', $list->getName()); |
|
26
|
|
|
$this->assertCount(3, $list->getWords()); |
|
27
|
|
|
|
|
28
|
|
|
$word = $list->getWords()->first(); |
|
29
|
|
|
$this->assertInstanceOf(Word::class, $word); |
|
30
|
|
|
$this->assertEquals('foobar', $word->getText()); |
|
31
|
|
|
$this->assertEquals(1, $word->getCount()); |
|
32
|
|
|
|
|
33
|
|
|
$word = $list->getWords()->next(); |
|
34
|
|
|
$this->assertInstanceOf(Word::class, $word); |
|
35
|
|
|
$this->assertEquals('foo', $word->getText()); |
|
36
|
|
|
$this->assertEquals(2, $word->getCount()); |
|
37
|
|
|
|
|
38
|
|
|
$word = $list->getWords()->next(); |
|
39
|
|
|
$this->assertInstanceOf(Word::class, $word); |
|
40
|
|
|
$this->assertEquals('bar', $word->getText()); |
|
41
|
|
|
$this->assertEquals(1, $word->getCount()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testImportUrl() |
|
45
|
|
|
{ |
|
46
|
|
|
$min = 5; |
|
47
|
|
|
$max = 8; |
|
48
|
|
|
$list = WordsListBuilder::create() |
|
49
|
|
|
->setFilters(FiltersBuilder::create()->setMinLength($min)->setMaxLength($max)->build()) |
|
50
|
|
|
->importUrl('https://en.wikipedia.org/wiki/Tag_cloud') |
|
51
|
|
|
->build('foobar') |
|
52
|
|
|
; |
|
53
|
|
|
$this->assertInstanceOf(WordsList::class, $list); |
|
54
|
|
|
$this->assertEquals('foobar', $list->getName()); |
|
55
|
|
|
$this->assertNotEmpty($list->getWords()); |
|
56
|
|
|
|
|
57
|
|
|
foreach ($list->getWords() as $word) { |
|
58
|
|
|
$len = strlen($word->getText()); |
|
59
|
|
|
$this->assertTrue($len > $min); |
|
60
|
|
|
$this->assertTrue($len < $max); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|