Passed
Push — sheepy/introspection ( 000d40...b6b869 )
by Marco
02:43
created

BaseQueryTest::testAddClassError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Firesphere\SolrSearch\Tests;
5
6
use Firesphere\SolrSearch\Queries\BaseQuery;
7
use SilverStripe\Core\Injector\Injector;
8
use SilverStripe\Dev\SapphireTest;
9
10
class BaseQueryTest extends SapphireTest
11
{
12
    /**
13
     * @var BaseQuery
14
     */
15
    protected $query;
16
17
    public function testGetSet()
18
    {
19
        $this->assertEquals(0, $this->query->getStart());
20
        $this->query->setStart(1);
21
        $this->assertEquals(1, $this->query->getStart());
22
        $this->assertEquals(10, $this->query->getRows());
23
        $this->query->setRows(20);
24
        $this->assertEquals(20, $this->query->getRows());
25
        $this->assertEmpty($this->query->getClasses());
26
        $this->query->addClass('test');
27
        $this->assertCount(1, $this->query->getClasses());
28
        $this->query->setClasses([]);
29
        $this->assertCount(0, $this->query->getClasses());
30
        $this->assertEmpty($this->query->getExclude());
31
        $this->query->setExclude(['test']);
32
        $this->assertEquals(['test'], $this->query->getExclude());
33
        $this->query->addExclude('test', 'test');
34
        $this->assertEquals(['test', 'test' => 'test'], $this->query->getExclude());
35
        $this->query->addField('test');
36
        $this->assertEquals(['test'], $this->query->getFields());
37
        $this->assertEquals(0, $this->query->getFacetsMinCount());
38
        $this->query->setFacetsMinCount(15);
39
        $this->assertEquals(15, $this->query->getFacetsMinCount());
40
        $this->query->setFields(['Field1', 'Field2']);
41
        $this->assertCount(2, $this->query->getFields());
42
        $this->query->setSort(['Field1']);
43
        $this->assertCount(1, $this->query->getSort());
44
        $this->query->setTerms(['Term' => 'Test']);
45
        $this->assertCount(1, $this->query->getTerms());
46
        $this->query->addTerm('String', ['Field1'], 2);
47
        $this->assertCount(2, $this->query->getTerms());
48
        $this->query->addFilter('Field1', 'test');
49
        $this->assertCount(1, $this->query->getFilter());
50
        $this->query->setFields([['Field1' => 'testing']]);
51
        $this->assertCount(1, $this->query->getFilter());
52
        $this->query->setFilter([['Field1' => 'Test']]);
53
        $this->assertCount(1, $this->query->getFilter());
54
        $this->query->setSpellcheck(false);
55
        $this->assertFalse($this->query->hasSpellcheck());
56
        $this->query->addBoostedField('Field1', 2);
57
        $this->assertEquals(2, $this->query->getBoostedFields()['Field1']);
58
        $this->query->setBoostedFields(['Field' => 2]);
59
        $this->assertEquals(2, $this->query->getBoostedFields()['Field']);
60
        $this->query->setHighlight(['test']);
61
        $this->assertEquals(['test'], $this->query->getHighlight());
62
        $this->query->addHighlight('test');
63
        $this->assertEquals(['test', 'test'], $this->query->getHighlight());
64
    }
65
66
    /**
67
     * @expectedException \PHPUnit_Framework_Error
68
     */
69
    public function testAddClassError()
70
    {
71
        $this->query->addClass('test', ['test']);
72
    }
73
74
    protected function setUp()
75
    {
76
        $this->query = Injector::inst()->get(BaseQuery::class);
77
        parent::setUp();
78
    }
79
}
80