1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Firesphere\SolrSearch\Tests; |
5
|
|
|
|
6
|
|
|
use Firesphere\SolrSearch\Extensions\DataObjectExtension; |
7
|
|
|
use Firesphere\SolrSearch\Queries\BaseQuery; |
8
|
|
|
use Page; |
9
|
|
|
use SilverStripe\Core\Config\Config; |
10
|
|
|
use SilverStripe\Core\Injector\Injector; |
11
|
|
|
use SilverStripe\Dev\SapphireTest; |
12
|
|
|
|
13
|
|
|
class BaseQueryTest extends SapphireTest |
14
|
|
|
{ |
15
|
|
|
protected static $fixture_file = '../fixtures/DataResolver.yml'; |
16
|
|
|
protected static $extra_dataobjects = [ |
17
|
|
|
TestObject::class, |
18
|
|
|
TestPage::class, |
19
|
|
|
TestRelationObject::class, |
20
|
|
|
]; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var BaseQuery |
24
|
|
|
*/ |
25
|
|
|
protected $query; |
26
|
|
|
|
27
|
|
|
public function testGetSet() |
28
|
|
|
{ |
29
|
|
|
$this->assertEquals(0, $this->query->getStart()); |
30
|
|
|
$this->query->setStart(1); |
31
|
|
|
$this->assertEquals(1, $this->query->getStart()); |
32
|
|
|
$this->assertEquals(10, $this->query->getRows()); |
33
|
|
|
$this->query->setRows(20); |
34
|
|
|
$this->assertEquals(20, $this->query->getRows()); |
35
|
|
|
$this->assertEmpty($this->query->getClasses()); |
36
|
|
|
$this->query->addClass('test'); |
37
|
|
|
$this->assertCount(1, $this->query->getClasses()); |
38
|
|
|
$this->query->setClasses([]); |
39
|
|
|
$this->assertCount(0, $this->query->getClasses()); |
40
|
|
|
$this->assertEmpty($this->query->getExclude()); |
41
|
|
|
$this->query->setExclude(['test']); |
42
|
|
|
$this->assertEquals(['test'], $this->query->getExclude()); |
43
|
|
|
$this->query->addExclude('test', 'test'); |
44
|
|
|
$this->assertEquals(['test', 'test' => 'test'], $this->query->getExclude()); |
45
|
|
|
$this->query->addField('test'); |
46
|
|
|
$this->assertEquals(['test'], $this->query->getFields()); |
47
|
|
|
$this->assertEquals(0, $this->query->getFacetsMinCount()); |
48
|
|
|
$this->query->setFacetsMinCount(15); |
49
|
|
|
$this->assertEquals(15, $this->query->getFacetsMinCount()); |
50
|
|
|
$this->query->setFields(['Field1', 'Field2']); |
51
|
|
|
$this->assertCount(2, $this->query->getFields()); |
52
|
|
|
$this->query->setSort(['Field1']); |
53
|
|
|
$this->assertCount(1, $this->query->getSort()); |
54
|
|
|
$this->query->setTerms(['Term' => 'Test']); |
55
|
|
|
$this->assertCount(1, $this->query->getTerms()); |
56
|
|
|
$this->query->addTerm('String', ['Field1'], 2); |
57
|
|
|
$this->assertCount(2, $this->query->getTerms()); |
58
|
|
|
$this->query->addFilter('Field1', 'test'); |
59
|
|
|
$this->assertCount(1, $this->query->getFilter()); |
60
|
|
|
$this->query->setFields([['Field1' => 'testing']]); |
61
|
|
|
$this->assertCount(1, $this->query->getFilter()); |
62
|
|
|
$this->query->setFilter([['Field1' => 'Test']]); |
63
|
|
|
$this->assertCount(1, $this->query->getFilter()); |
64
|
|
|
$this->query->setSpellcheck(false); |
65
|
|
|
$this->assertFalse($this->query->hasSpellcheck()); |
66
|
|
|
$this->query->addBoostedField('Field1', 2); |
67
|
|
|
$this->assertEquals(2, $this->query->getBoostedFields()['Field1']); |
68
|
|
|
$this->query->setBoostedFields(['Field' => 2]); |
69
|
|
|
$this->assertEquals(2, $this->query->getBoostedFields()['Field']); |
70
|
|
|
$this->query->setHighlight(['test']); |
71
|
|
|
$this->assertEquals(['test'], $this->query->getHighlight()); |
72
|
|
|
$this->query->addHighlight('test'); |
73
|
|
|
$this->assertEquals(['test', 'test'], $this->query->getHighlight()); |
74
|
|
|
$this->assertFalse($this->query->shouldFollowSpellcheck()); |
75
|
|
|
$this->query->setFollowSpellcheck(true); |
76
|
|
|
$this->assertTrue($this->query->shouldFollowSpellcheck()); |
77
|
|
|
$this->query->addFacetFilter('Test', 'test'); |
78
|
|
|
$this->assertEquals(['Test' => ['test']], $this->query->getFacetFilter()); |
79
|
|
|
$this->query->setFacetFilter(['Testing' => [1, 2]]); |
80
|
|
|
$this->assertEquals(['Testing' => [1, 2]], $this->query->getFacetFilter()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
protected function setUp() |
84
|
|
|
{ |
85
|
|
|
$this->query = Injector::inst()->get(BaseQuery::class); |
86
|
|
|
parent::setUp(); |
87
|
|
|
Injector::inst()->get(Page::class)->requireDefaultRecords(); |
88
|
|
|
foreach (self::$extra_dataobjects as $className) { |
89
|
|
|
Config::modify()->merge($className, 'extensions', [DataObjectExtension::class]); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|