|
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
|
|
|
public function testGetIndex(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$indexes = new Indexes(); |
|
13
|
|
|
$index = $indexes->getIndex('sitetree'); |
|
14
|
|
|
$this->assertEquals('sitetree', $index->getName()); |
|
15
|
|
|
$this->assertEquals([ |
|
16
|
|
|
'Title', |
|
17
|
|
|
'Content', |
|
18
|
|
|
'ParentID', |
|
19
|
|
|
'MenuTitle', |
|
20
|
|
|
'Sort', |
|
21
|
|
|
'Created', |
|
22
|
|
|
'LastEdited', |
|
23
|
|
|
], $index->getFields()); |
|
24
|
|
|
$this->assertEquals([], $index->getHasOneFields()); |
|
25
|
|
|
$this->assertEquals([], $index->getHasManyFields()); |
|
26
|
|
|
$this->assertEquals([], $index->getTokens()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Assert that index objects are create correctly from the configuration file |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testGetIndexes(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$indexes = new Indexes(); |
|
36
|
|
|
$indices = $indexes->getIndexes(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertEquals('sitetree', $indices[0]->getName()); |
|
39
|
|
|
$this->assertEquals([ |
|
40
|
|
|
'Title', |
|
41
|
|
|
'Content', |
|
42
|
|
|
'ParentID', |
|
43
|
|
|
'MenuTitle', |
|
44
|
|
|
'Sort', |
|
45
|
|
|
'Created', |
|
46
|
|
|
'LastEdited', |
|
47
|
|
|
], $indices[0]->getFields()); |
|
48
|
|
|
$this->assertEquals([], $indices[0]->getHasOneFields()); |
|
49
|
|
|
$this->assertEquals([], $indices[0]->getHasManyFields()); |
|
50
|
|
|
$this->assertEquals([], $indices[0]->getTokens()); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertEquals('members', $indices[1]->getName()); |
|
53
|
|
|
$this->assertEquals([ |
|
54
|
|
|
'FirstName', |
|
55
|
|
|
'Surname', |
|
56
|
|
|
'Email', |
|
57
|
|
|
], $indices[1]->getFields()); |
|
58
|
|
|
$this->assertEquals([], $indices[1]->getHasOneFields()); |
|
59
|
|
|
$this->assertEquals([], $indices[1]->getHasManyFields()); |
|
60
|
|
|
$this->assertEquals([], $indices[1]->getTokens()); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals('flickrphotos', $indices[2]->getName()); |
|
63
|
|
|
$this->assertEquals([ |
|
64
|
|
|
'Title', |
|
65
|
|
|
'Description', |
|
66
|
|
|
], $indices[2]->getFields()); |
|
67
|
|
|
$this->assertEquals(['Suilven\FreeTextSearch\Tests\Models\FlickrAuthor'], $indices[2]->getHasOneFields()); |
|
68
|
|
|
$this->assertEquals(['Suilven\FreeTextSearch\Tests\Models\FlickrTag'], $indices[2]->getHasManyFields()); |
|
69
|
|
|
$this->assertEquals([ |
|
70
|
|
|
'Aperture', |
|
71
|
|
|
'ShutterSpeed', |
|
72
|
|
|
'ISO', |
|
73
|
|
|
], $indices[2]->getTokens()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
public function testGetFacetFields(): void |
|
78
|
|
|
{ |
|
79
|
|
|
$indexes = new Indexes(); |
|
80
|
|
|
|
|
81
|
|
|
// @todo Why is this being lowercased |
|
82
|
|
|
$this->assertEquals([ |
|
83
|
|
|
'aperture', |
|
84
|
|
|
'shutterspeed', |
|
85
|
|
|
'iso', |
|
86
|
|
|
], $indexes->getFacetFields('flickrphotos')); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
public function testGetHasOneFields(): void |
|
91
|
|
|
{ |
|
92
|
|
|
$indexes = new Indexes(); |
|
93
|
|
|
|
|
94
|
|
|
// @todo Why is this being lowercased |
|
95
|
|
|
$this->assertEquals( |
|
96
|
|
|
['suilven\freetextsearch\tests\models\flickrauthor'], |
|
97
|
|
|
$indexes->getHasOneFields('flickrphotos') |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
public function testGetHasManyFields(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$indexes = new Indexes(); |
|
105
|
|
|
|
|
106
|
|
|
// @todo Why is this being lowercased |
|
107
|
|
|
$this->assertEquals( |
|
108
|
|
|
['suilven\freetextsearch\tests\models\flickrtag'], |
|
109
|
|
|
$indexes->getHasManyFields('flickrphotos') |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|