1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Firesphere\SolrSearch\Tests; |
5
|
|
|
|
6
|
|
|
use CircleCITestIndex; |
7
|
|
|
use Firesphere\SolrSearch\Queries\BaseQuery; |
8
|
|
|
use Firesphere\SolrSearch\Services\SolrCoreService; |
9
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
10
|
|
|
use SilverStripe\Control\HTTPRequestBuilder; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
use SilverStripe\ORM\ArrayList; |
13
|
|
|
use SilverStripe\ORM\DatabaseAdmin; |
14
|
|
|
use SilverStripe\ORM\DB; |
15
|
|
|
|
16
|
|
|
class SolrCoreServiceTest extends SapphireTest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var SolrCoreService |
20
|
|
|
*/ |
21
|
|
|
protected $service; |
22
|
|
|
|
23
|
|
|
public static function setUpBeforeClass() |
24
|
|
|
{ |
25
|
|
|
parent::setUpBeforeClass(); |
26
|
|
|
// This is a hack on my local dev to make fixtures populate temporary database |
27
|
|
|
$conn = DB::get_conn(); |
28
|
|
|
$dbName = self::tempDB()->build(); |
29
|
|
|
$conn->selectDatabase($dbName); |
30
|
|
|
$dbAdmin = new DatabaseAdmin(); |
31
|
|
|
$dbAdmin->setRequest(HTTPRequestBuilder::createFromEnvironment()); |
32
|
|
|
$dbAdmin->doBuild(true, true, true); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testIndexes() |
36
|
|
|
{ |
37
|
|
|
$service = new SolrCoreService(); |
38
|
|
|
|
39
|
|
|
$expected = [ |
40
|
|
|
CircleCITestIndex::class, |
41
|
|
|
TestIndex::class, |
42
|
|
|
TestIndexTwo::class, |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
$this->assertEquals($expected, $service->getValidIndexes()); |
46
|
|
|
$this->assertEquals([\CircleCITestIndex::class], $service->getValidIndexes(\CircleCITestIndex::class)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @expectedException \LogicException |
52
|
|
|
*/ |
53
|
|
|
public function testUpdateItemsFail() |
54
|
|
|
{ |
55
|
|
|
$this->service->updateItems(null, SolrCoreService::CREATE_TYPE); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @expectedException \LogicException |
60
|
|
|
*/ |
61
|
|
|
public function testUpdateItemsFailWrongCall() |
62
|
|
|
{ |
63
|
|
|
$this->service->updateItems(['test'], SolrCoreService::DELETE_TYPE_ALL); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testUpdateItems() |
67
|
|
|
{ |
68
|
|
|
$index = new CircleCITestIndex(); |
69
|
|
|
$query = new BaseQuery(); |
70
|
|
|
$query->addTerm('*:*'); |
71
|
|
|
$items = SiteTree::get(); |
72
|
|
|
|
73
|
|
|
$result = $this->service->updateItems($items, SolrCoreService::UPDATE_TYPE, CircleCITestIndex::class); |
74
|
|
|
$this->assertEquals(200, $result->getResponse()->getStatusCode()); |
75
|
|
|
|
76
|
|
|
$this->service->updateItems($items, SolrCoreService::DELETE_TYPE, CircleCITestIndex::class); |
77
|
|
|
$this->assertEquals(0, $index->doSearch($query)->getTotalItems()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testUpdateItemsEmptyArray() |
81
|
|
|
{ |
82
|
|
|
$index = new CircleCITestIndex(); |
83
|
|
|
$query = new BaseQuery(); |
84
|
|
|
$this->service->doManipulate(ArrayList::create(), SolrCoreService::DELETE_TYPE_ALL, $index); |
85
|
|
|
$this->assertEquals(0, $index->doSearch($query)->getTotalItems()); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @expectedException \LogicException |
90
|
|
|
*/ |
91
|
|
|
public function testWrongUpdateItems() |
92
|
|
|
{ |
93
|
|
|
$items = SiteTree::get(); |
94
|
|
|
|
95
|
|
|
$this->service->updateItems($items, SolrCoreService::UPDATE_TYPE, 'NonExisting'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function setUp() |
99
|
|
|
{ |
100
|
|
|
$this->service = new SolrCoreService(); |
101
|
|
|
return parent::setUp(); // TODO: Change the autogenerated stub |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|