|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Firesphere\SolrSearch\Tests; |
|
5
|
|
|
|
|
6
|
|
|
use CircleCITestIndex; |
|
7
|
|
|
use Firesphere\SolrSearch\Extensions\DataObjectExtension; |
|
8
|
|
|
use Firesphere\SolrSearch\Indexes\BaseIndex; |
|
9
|
|
|
use Firesphere\SolrSearch\Jobs\SolrConfigureJob; |
|
10
|
|
|
use Firesphere\SolrSearch\Jobs\SolrIndexJob; |
|
11
|
|
|
use Page; |
|
12
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
|
13
|
|
|
use SilverStripe\Core\Config\Config; |
|
14
|
|
|
use SilverStripe\Core\Injector\Injector; |
|
15
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
16
|
|
|
use stdClass; |
|
17
|
|
|
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; |
|
18
|
|
|
|
|
19
|
|
|
class SolrIndexJobTest extends SapphireTest |
|
20
|
|
|
{ |
|
21
|
|
|
protected static $fixture_file = '../fixtures/DataResolver.yml'; |
|
22
|
|
|
protected static $extra_dataobjects = [ |
|
23
|
|
|
TestObject::class, |
|
24
|
|
|
TestPage::class, |
|
25
|
|
|
TestRelationObject::class, |
|
26
|
|
|
]; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var SolrConfigureJob |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $job; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var SolrIndexJob |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $indexJob; |
|
37
|
|
|
|
|
38
|
|
|
public function testGetTitle() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertEquals('Index groups to Solr search', $this->indexJob->getTitle()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testProcess() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->job->process(); |
|
46
|
|
|
$result = $this->indexJob->process(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertNotContains(BaseIndex::class, $this->indexJob->getIndexes(), 'Test index removed'); |
|
49
|
|
|
$this->assertEquals(0, $result->totalSteps, 'Test reset total count'); |
|
50
|
|
|
|
|
51
|
|
|
$job = new SolrIndexJob(); |
|
52
|
|
|
$data = new stdClass(); |
|
53
|
|
|
|
|
54
|
|
|
$data->indexes = [CircleCITestIndex::class]; |
|
55
|
|
|
$data->classToIndex = []; |
|
56
|
|
|
|
|
57
|
|
|
$job->setJobData(0, 0, false, $data, []); |
|
58
|
|
|
|
|
59
|
|
|
$job->process(); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertCount(1, $job->getIndexes(), 'Test index count'); |
|
62
|
|
|
$this->assertCount(1, $job->getClassToIndex(), 'Test class count'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testAfterComplete() |
|
66
|
|
|
{ |
|
67
|
|
|
$job = new SolrIndexJob(); |
|
68
|
|
|
$job->setIndexes(['Index1', 'Index2']); |
|
69
|
|
|
$job->setClassToIndex(['Test']); |
|
70
|
|
|
$job->afterComplete(); |
|
71
|
|
|
|
|
72
|
|
|
$newJob = QueuedJobDescriptor::get()->filter(['Implementation' => SolrIndexJob::class])->first(); |
|
73
|
|
|
$jobData = unserialize($newJob->SavedJobData); |
|
74
|
|
|
$this->assertCount(1, $jobData->indexes, 'Should have one index after complete'); |
|
75
|
|
|
$this->assertCount(0, $jobData->classToIndex, 'Set to default count as the index is shifted'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testGettersSetters() |
|
79
|
|
|
{ |
|
80
|
|
|
$this->indexJob->setIndexes([CircleCITestIndex::class]); |
|
81
|
|
|
$this->assertEquals([CircleCITestIndex::class], $this->indexJob->getIndexes()); |
|
82
|
|
|
$this->indexJob->setClassToIndex([SiteTree::class]); |
|
83
|
|
|
$this->assertEquals([SiteTree::class], $this->indexJob->getClassToIndex()); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
protected function setUp() |
|
87
|
|
|
{ |
|
88
|
|
|
parent::setUp(); |
|
89
|
|
|
Injector::inst()->get(Page::class)->requireDefaultRecords(); |
|
90
|
|
|
foreach (self::$extra_dataobjects as $className) { |
|
91
|
|
|
Config::modify()->merge($className, 'extensions', [DataObjectExtension::class]); |
|
92
|
|
|
} |
|
93
|
|
|
$this->indexJob = Injector::inst()->get(SolrIndexJob::class); |
|
94
|
|
|
$this->job = Injector::inst()->get(SolrConfigureJob::class); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|