Passed
Push — master ( eff61e...76df74 )
by Gordon
02:24
created

IndexTest::testGetLanguage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
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 testSetClassNull(): void
28
    {
29
        $index = new Index();
30
        $index->setClass(null);
31
        $this->assertNull($index->getClass());
0 ignored issues
show
Bug introduced by
Are you sure the usage of $index->getClass() targeting Suilven\FreeTextSearch\Index::getClass() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

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