Passed
Push — sheepy/introspection ( 9a33c8...7d1300 )
by Marco
05:54
created

SolrCoreServiceTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
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\Dev\SapphireTest;
11
use SilverStripe\ORM\ArrayList;
12
13
class SolrCoreServiceTest extends SapphireTest
14
{
15
    /**
16
     * @var SolrCoreService
17
     */
18
    protected $service;
19
20
    public function testIndexes()
21
    {
22
        $service = new SolrCoreService();
23
24
        $expected = [
25
            CircleCITestIndex::class,
26
            TestIndex::class,
27
            TestIndexTwo::class,
28
        ];
29
30
        $this->assertEquals($expected, $service->getValidIndexes());
31
        $this->assertEquals([\CircleCITestIndex::class], $service->getValidIndexes(\CircleCITestIndex::class));
32
    }
33
34
35
    /**
36
     * @expectedException \LogicException
37
     */
38
    public function testUpdateItemsFail()
39
    {
40
        $this->service->updateItems(null, SolrCoreService::CREATE_TYPE);
41
    }
42
43
    /**
44
     * @expectedException \LogicException
45
     */
46
    public function testUpdateItemsFailWrongCall()
47
    {
48
        $this->service->updateItems(['test'], SolrCoreService::DELETE_TYPE_ALL);
49
    }
50
51
    public function testUpdateItems()
52
    {
53
        $index = new CircleCITestIndex();
54
        $query = new BaseQuery();
55
        $query->addTerm('*:*');
56
        $items = SiteTree::get();
57
58
        $result = $this->service->updateItems($items, SolrCoreService::UPDATE_TYPE, CircleCITestIndex::class);
59
        $this->assertEquals(200, $result->getResponse()->getStatusCode());
60
61
        $this->service->updateItems($items, SolrCoreService::DELETE_TYPE, CircleCITestIndex::class);
62
        $this->assertEquals(0, $index->doSearch($query)->getTotalItems());
63
    }
64
65
    public function testUpdateItemsEmptyArray()
66
    {
67
        $index = new CircleCITestIndex();
68
        $query = new BaseQuery();
69
        $this->service->doManipulate(ArrayList::create(), SolrCoreService::DELETE_TYPE_ALL, $index);
70
        $this->assertEquals(0, $index->doSearch($query)->getTotalItems());
71
    }
72
73
    /**
74
     * @expectedException \LogicException
75
     */
76
    public function testWrongUpdateItems()
77
    {
78
        $items = SiteTree::get();
79
80
        $this->service->updateItems($items, SolrCoreService::UPDATE_TYPE, 'NonExisting');
81
    }
82
83
    protected function setUp()
84
    {
85
        $this->service = new SolrCoreService();
86
        return parent::setUp(); // TODO: Change the autogenerated stub
87
    }
88
}
89