Passed
Push — master ( 76d4cd...f9d9de )
by Gordon
03:35
created

IndexTest::testSetClassNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Suilven\FreeTextSearch\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use Suilven\FreeTextSearch\Index;
7
use Suilven\FreeTextSearch\Types\TokenizerTypes;
8
9
class IndexTest extends SapphireTest
10
{
11
    public function testSetGetName(): void
12
    {
13
        $index = new Index();
14
        $index->setName('testname');
15
        $this->assertEquals('testname', $index->getName());
16
    }
17
18
19
    public function testSetClass(): void
20
    {
21
        $index = new Index();
22
        $index->setClass('\Page');
23
        $this->assertEquals('\Page', $index->getClass());
24
    }
25
26
27
    public function testHasOneFields(): void
28
    {
29
        $index = new Index();
30
        $this->assertEquals([], $index->getHasOneFields());
31
        $index->addHasOneField('first');
32
        $this->assertEquals(['first'], $index->getHasOneFields());
33
        $index->addHasOneField('second');
34
        $this->assertEquals(['first', 'second'], $index->getHasOneFields());
35
        $index->addHasOneField('third');
36
        $this->assertEquals(['first', 'second', 'third'], $index->getHasOneFields());
37
        $index->addHasOneField('fourth');
38
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getHasOneFields());
39
    }
40
41
42
    public function testHasManyields(): void
43
    {
44
        $payload = [
45
            'name' => 'tags',
46
            'relationship' => 'FlickrTags',
47
            'field' => 'RawValue',
48
        ];
49
        $index = new Index();
50
        $this->assertEquals([], $index->getHasManyFields());
51
        $index->addHasManyField('first', $payload);
52
        $this->assertEquals(['first' => $payload], $index->getHasManyFields());
53
        $index->addHasManyField('second', $payload);
54
        $this->assertEquals(['first' => $payload, 'second' => $payload], $index->getHasManyFields());
55
        $index->addHasManyField('third', $payload);
56
        $this->assertEquals(
57
            ['first' => $payload, 'second' => $payload, 'third' => $payload],
58
            $index->getHasManyFields()
59
        );
60
        $index->addHasManyField('fourth', $payload);
61
        $this->assertEquals(
62
            ['first' => $payload, 'second' => $payload, 'third' => $payload, 'fourth' => $payload],
63
            $index->getHasManyFields()
64
        );
65
    }
66
67
68
    public function testAddTokens(): void
69
    {
70
        $index = new Index();
71
        $this->assertEquals([], $index->getTokens());
72
        $index->addToken('first');
73
        $this->assertEquals(['first'], $index->getTokens());
74
        $index->addToken('second');
75
        $this->assertEquals(['first', 'second'], $index->getTokens());
76
        $index->addToken('third');
77
        $this->assertEquals(['first', 'second', 'third'], $index->getTokens());
78
        $index->addToken('fourth');
79
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getTokens());
80
    }
81
82
83
    public function testAddFields(): void
84
    {
85
        $index = new Index();
86
        $this->assertEquals([], $index->getFields());
87
        $index->addField('first');
88
        $this->assertEquals(['first'], $index->getFields());
89
        $index->addField('second');
90
        $this->assertEquals(['first', 'second'], $index->getFields());
91
        $index->addField('third');
92
        $this->assertEquals(['first', 'second', 'third'], $index->getFields());
93
        $index->addField('fourth');
94
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getFields());
95
    }
96
97
98
    public function testGetTokenizer(): void
99
    {
100
        $index = new Index();
101
        $index->setTokenizer(TokenizerTypes::PORTER);
102
        $this->assertEquals(TokenizerTypes::PORTER, $index->getTokenizer());
103
    }
104
105
106
    public function testGetLanguage(): void
107
    {
108
        $index = new Index();
109
        $this->assertEquals('en', $index->getLanguage());
110
    }
111
}
112