Passed
Pull Request — master (#4)
by Gordon
08:08
created

IndexesTest::testGetIndexes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 34
c 3
b 0
f 0
dl 0
loc 39
rs 9.376
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\Indexes;
7
8
class IndexesTest extends SapphireTest
9
{
10
    /**
11
     * Assert that index objects are create correctly from the configuration file
12
     */
13
    public function testGetIndexes(): void
14
    {
15
        $indexes = new Indexes();
16
        $indices = $indexes->getIndexes();
17
18
        $this->assertEquals('sitetree', $indices[0]->getName());
19
        $this->assertEquals([
20
            'Title',
21
            'MenuTitle',
22
            'Content',
23
            'ParentID',
24
            'Sort',
25
        ], $indices[0]->getFields());
26
        $this->assertEquals([], $indices[0]->getHasOneFields());
27
        $this->assertEquals([], $indices[0]->getHasManyFields());
28
        $this->assertEquals([], $indices[0]->getTokens());
29
30
        $this->assertEquals('members', $indices[1]->getName());
31
        $this->assertEquals([
32
            'FirstName',
33
            'Surname',
34
            'Email',
35
        ], $indices[1]->getFields());
36
        $this->assertEquals([], $indices[1]->getHasOneFields());
37
        $this->assertEquals([], $indices[1]->getHasManyFields());
38
        $this->assertEquals([], $indices[1]->getTokens());
39
40
        $this->assertEquals('flickrphotos', $indices[2]->getName());
41
        $this->assertEquals([
42
            'Title',
43
            'Description',
44
        ], $indices[2]->getFields());
45
        $this->assertEquals(['Suilven\FreeTextSearch\Tests\Models\FlickrAuthor'], $indices[2]->getHasOneFields());
46
        $this->assertEquals(['Suilven\FreeTextSearch\Tests\Models\FlickrTag'], $indices[2]->getHasManyFields());
47
        $this->assertEquals([
48
            'Aperture',
49
            'ShutterSpeed',
50
            'ISO',
51
        ], $indices[2]->getTokens());
52
    }
53
54
55
    public function testGetFacetFields(): void
56
    {
57
        $indexes = new Indexes();
58
59
        // @todo Why is this being lowercased
60
        $this->assertEquals([
61
            'aperture',
62
            'shutterspeed',
63
            'iso',
64
        ], $indexes->getFacetFields('flickrphotos'));
65
    }
66
67
68
    public function testGetHasOneFields(): void
69
    {
70
        $indexes = new Indexes();
71
72
        // @todo Why is this being lowercased
73
        $this->assertEquals(
74
            ['suilven\freetextsearch\tests\models\flickrauthor'],
75
            $indexes->getHasOneFields('flickrphotos')
76
        );
77
    }
78
79
80
    public function testGetHasManyFields(): void
81
    {
82
        $indexes = new Indexes();
83
84
        // @todo Why is this being lowercased
85
        $this->assertEquals(
86
            ['suilven\freetextsearch\tests\models\flickrtag'],
87
            $indexes->getHasManyFields('flickrphotos')
88
        );
89
    }
90
}
91