Passed
Push — master ( 7b0b69...338501 )
by Simon
17:41 queued 07:41
created

FulltextSearchExtensionTest::testSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Firesphere\SolrCompatibility\Tests;
5
6
use Firesphere\SolrSearch\Indexes\BaseIndex;
7
use Firesphere\SolrSearch\Queries\BaseQuery;
8
use Firesphere\SolrSearch\Tasks\SolrConfigureTask;
9
use Psr\Log\NullLogger;
10
use SilverStripe\Control\NullHTTPRequest;
11
use SilverStripe\Core\Injector\Injector;
12
use SilverStripe\Dev\SapphireTest;
13
use SilverStripe\View\ArrayData;
14
15
class FulltextSearchExtensionTest extends SapphireTest
16
{
17
18
    /**
19
     * @var BaseIndex
20
     */
21
    protected $index;
22
23
    public function testSearch()
24
    {
25
        $query = new BaseQuery();
26
        $query->addTerm('Test');
27
28
        $result = $this->index->search($query, 0, 10, [], true);
29
30
        $this->assertInstanceOf(ArrayData::class, $result);
31
    }
32
33
    public function testSearchWithFields()
34
    {
35
        $query = new BaseQuery();
36
        $query->addTerm('Test');
37
38
        $result = $this->index->search($query, 0, 10, ['fq' => 'Title'], true);
39
40
        $this->assertInstanceOf(ArrayData::class, $result);
41
42
        $this->assertEquals(['Title'], $query->getFields());
43
    }
44
45
    /**
46
     * @expectedException \LogicException
47
     */
48
    public function testInitToYml()
49
    {
50
        $this->index->initToYml();
51
    }
52
53
54
    protected function setUp()
55
    {
56
        $task = new SolrConfigureTask();
57
        $task->setLogger(new NullLogger());
58
        $task->run(new NullHTTPRequest());
59
60
        $this->index = Injector::inst()->get(TestIndex::class, false);
61
62
        parent::setUp();
63
    }
64
}
65