1
|
|
|
<?php declare(strict_types = 1); |
2
|
|
|
|
3
|
|
|
namespace Suilven\FreeTextSearch\Tests\Factory; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use Suilven\FreeTextSearch\Factory\IndexerFactory; |
8
|
|
|
use Suilven\FreeTextSearch\Tests\Mock\Indexer; |
9
|
|
|
|
10
|
|
|
class IndexerFactoryTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
protected static $fixture_file = ['tests/fixtures/sitetree.yml']; |
13
|
|
|
|
14
|
|
|
public function testFactory(): void |
15
|
|
|
{ |
16
|
|
|
Indexer::resetIndexedPayload(); |
17
|
|
|
|
18
|
|
|
$factory = new IndexerFactory(); |
19
|
|
|
|
20
|
|
|
/** @var \Suilven\FreeTextSearch\Tests\Mock\Indexer $indexer */ |
21
|
|
|
$indexer = $factory->getIndexer(); |
22
|
|
|
$this->assertInstanceOf('Suilven\FreeTextSearch\Interfaces\Indexer', $indexer); |
23
|
|
|
$this->assertInstanceOf('Suilven\FreeTextSearch\Tests\Mock\Indexer', $indexer); |
24
|
|
|
|
25
|
|
|
$indexer->setIndexName('sitetree'); |
26
|
|
|
$page = $this->objFromFixture(SiteTree::class, 'sitetree_20'); |
27
|
|
|
$indexer->index($page); |
28
|
|
|
|
29
|
|
|
// the mock stores the indexed content. Firstly check that members and flickrphotos have no updates |
30
|
|
|
$allDocumentsPayload = Indexer::getIndexedPayload(); |
31
|
|
|
$this->assertEquals(1, \sizeof($allDocumentsPayload)); |
|
|
|
|
32
|
|
|
$indexedDocumentPayload = $allDocumentsPayload[0]; |
33
|
|
|
|
34
|
|
|
$this->assertEquals([], $indexedDocumentPayload['members']); |
35
|
|
|
$this->assertEquals([], $indexedDocumentPayload['flickrphotos']); |
36
|
|
|
|
37
|
|
|
// check non timestamped data for the page in question |
38
|
|
|
$siteTreePayload = $indexedDocumentPayload['sitetree']; |
39
|
|
|
$this->assertEquals('The None In San Marino Is Full', $siteTreePayload['Title']); |
40
|
|
|
$this->assertEquals('The None In San Marino Is Full', $siteTreePayload['MenuTitle']); |
41
|
|
|
$this->assertEquals( |
42
|
|
|
'Ella opened the good and found that it led into a big close, not much larger than a might.', |
43
|
|
|
$siteTreePayload['Content'] |
44
|
|
|
); |
45
|
|
|
$this->assertEquals(21, $siteTreePayload['Sort']); |
46
|
|
|
$this->assertEquals(0, $siteTreePayload['ParentID']); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|