IndexTest::testGetTokenizer()   A
last analyzed

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
        $relationshipArray = [
30
            'relationship' => 'Photographer',
31
            'field' => 'PathAlias',
32
            'class' => 'Suilven\FreeTextSearch\Tests\Models\FlickrAuthor',
33
        ];
34
35
        $index = new Index();
36
        $this->assertEquals([], $index->getHasOneFields());
37
        $index->addHasOneField('first', $relationshipArray);
38
        $this->assertEquals(['first' => $relationshipArray], $index->getHasOneFields());
39
        $index->addHasOneField('second', $relationshipArray);
40
        $this->assertEquals(['first' => $relationshipArray, 'second' => $relationshipArray], $index->getHasOneFields());
41
        $index->addHasOneField('third', $relationshipArray);
42
        $this->assertEquals(
43
            ['first' => $relationshipArray, 'second' => $relationshipArray, 'third' => $relationshipArray],
44
            $index->getHasOneFields()
45
        );
46
        $index->addHasOneField('fourth', $relationshipArray);
47
        $this->assertEquals(['first' => $relationshipArray, 'second' => $relationshipArray,
48
            'third' => $relationshipArray, 'fourth' => $relationshipArray], $index->getHasOneFields());
49
    }
50
51
52
    public function testHasManyields(): void
53
    {
54
        $payload = [
55
            'name' => 'tags',
56
            'relationship' => 'FlickrTags',
57
            'field' => 'RawValue',
58
        ];
59
        $index = new Index();
60
        $this->assertEquals([], $index->getHasManyFields());
61
        $index->addHasManyField('first', $payload);
62
        $this->assertEquals(['first' => $payload], $index->getHasManyFields());
63
        $index->addHasManyField('second', $payload);
64
        $this->assertEquals(['first' => $payload, 'second' => $payload], $index->getHasManyFields());
65
        $index->addHasManyField('third', $payload);
66
        $this->assertEquals(
67
            ['first' => $payload, 'second' => $payload, 'third' => $payload],
68
            $index->getHasManyFields()
69
        );
70
        $index->addHasManyField('fourth', $payload);
71
        $this->assertEquals(
72
            ['first' => $payload, 'second' => $payload, 'third' => $payload, 'fourth' => $payload],
73
            $index->getHasManyFields()
74
        );
75
    }
76
77
78
    public function testAddTokens(): void
79
    {
80
        $index = new Index();
81
        $this->assertEquals([], $index->getTokens());
82
        $index->addToken('first');
83
        $this->assertEquals(['first'], $index->getTokens());
84
        $index->addToken('second');
85
        $this->assertEquals(['first', 'second'], $index->getTokens());
86
        $index->addToken('third');
87
        $this->assertEquals(['first', 'second', 'third'], $index->getTokens());
88
        $index->addToken('fourth');
89
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getTokens());
90
    }
91
92
93
    public function testAddFields(): void
94
    {
95
        $index = new Index();
96
        $this->assertEquals([], $index->getFields());
97
        $index->addField('first');
98
        $this->assertEquals(['first'], $index->getFields());
99
        $index->addField('second');
100
        $this->assertEquals(['first', 'second'], $index->getFields());
101
        $index->addField('third');
102
        $this->assertEquals(['first', 'second', 'third'], $index->getFields());
103
        $index->addField('fourth');
104
        $this->assertEquals(['first', 'second', 'third', 'fourth'], $index->getFields());
105
    }
106
107
108
    public function testGetTokenizer(): void
109
    {
110
        $index = new Index();
111
        $index->setTokenizer(TokenizerTypes::PORTER);
112
        $this->assertEquals(TokenizerTypes::PORTER, $index->getTokenizer());
113
    }
114
115
116
    public function testGetLanguage(): void
117
    {
118
        $index = new Index();
119
        $this->assertEquals('en', $index->getLanguage());
120
    }
121
}
122