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
|
|
|
|