1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Firesphere\SolrSearch\Tests; |
4
|
|
|
|
5
|
|
|
use Firesphere\SolrSearch\Helpers\Columnar; |
6
|
|
|
use SilverStripe\CMS\Model\SiteTree; |
7
|
|
|
use SilverStripe\Control\HTTPRequestBuilder; |
8
|
|
|
use SilverStripe\Core\Injector\Injector; |
9
|
|
|
use SilverStripe\Dev\Debug; |
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
use SilverStripe\ORM\DatabaseAdmin; |
12
|
|
|
use SilverStripe\ORM\DB; |
13
|
|
|
|
14
|
|
|
class ColumnarTest extends SapphireTest |
15
|
|
|
{ |
16
|
|
|
protected static $fixture_file = 'tests/fixtures/Columnar.yml'; |
17
|
|
|
|
18
|
|
|
public function assertEqualsDump() |
19
|
|
|
{ |
20
|
|
|
Debug::dump(func_get_args()); |
21
|
|
|
} |
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 test_DataObjectEmptyColumnIsToMap() |
36
|
|
|
{ |
37
|
|
|
$objectOne = $this->objFromFixture(TestObject::class, 'objectOne'); |
38
|
|
|
$this->assertEquals($objectOne->toMap(), Columnar::identify($objectOne, '')); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function test_DataListEmptyColumnIsToNestedArray() |
42
|
|
|
{ |
43
|
|
|
$objectOne = $this->objFromFixture(TestObject::class, 'objectOne'); |
44
|
|
|
$dataList = $objectOne->TestPages(); |
45
|
|
|
$this->assertEquals($dataList->toNestedArray(), Columnar::identify($dataList, '')); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function test_DataObjectGetMethod() |
49
|
|
|
{ |
50
|
|
|
$pageOne = $this->objFromFixture(TestPage::class, 'pageOne'); |
51
|
|
|
$this->assertEquals($pageOne->getSalutation(), Columnar::identify($pageOne, 'Salutation')); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function test_DataObjectAttributes() |
55
|
|
|
{ |
56
|
|
|
$mockDate = '2019-07-04 22:01:00'; |
57
|
|
|
$pageOne = $this->objFromFixture(TestPage::class, 'pageOne'); |
58
|
|
|
$pageOne->Created = $mockDate; |
59
|
|
|
$pageOne->write(); |
60
|
|
|
$this->assertEquals($pageOne->Title, Columnar::identify($pageOne, 'Title')); |
|
|
|
|
61
|
|
|
$this->assertEquals($mockDate, $pageOne->Created); |
62
|
|
|
$this->assertEquals($mockDate, Columnar::identify($pageOne, 'Created')); |
|
|
|
|
63
|
|
|
$this->assertEquals('Jul 4, 2019, 10:01 PM', Columnar::identify($pageOne, 'Created.Nice')); |
|
|
|
|
64
|
|
|
$this->assertEquals('2019-07-04T22:01:00+00:00', Columnar::identify($pageOne, 'Created.Rfc3339')); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function test_DataTraversal() |
68
|
|
|
{ |
69
|
|
|
$mockDate = '2019-07-04 22:01:00'; |
70
|
|
|
$objectOne = $this->objFromFixture(TestObject::class, 'objectOne'); |
71
|
|
|
$pageOne = $this->objFromFixture(TestPage::class, 'pageOne'); |
72
|
|
|
$relationOne = $this->objFromFixture(TestRelationObject::class, 'relationOne'); |
73
|
|
|
$relationOne->Created = $mockDate; |
74
|
|
|
$relationOne->write(); |
75
|
|
|
$this->assertEquals($objectOne->toMap(), Columnar::identify($pageOne, 'TestObject')); |
|
|
|
|
76
|
|
|
$this->assertEquals($objectOne->Title, Columnar::identify($pageOne, 'TestObject.Title')); |
|
|
|
|
77
|
|
|
$this->assertEquals(0, Columnar::identify($pageOne, 'TestObject.ShowInSearch')); |
|
|
|
|
78
|
|
|
$this->assertEquals('No', Columnar::identify($pageOne, 'TestObject.ShowInSearch.Nice')); |
|
|
|
|
79
|
|
|
$this->assertEquals($objectOne->TestRelation()->toNestedArray(), Columnar::identify($pageOne, 'TestObject.TestRelation')); |
|
|
|
|
80
|
|
|
$this->assertEquals($objectOne->TestRelation()->First()->toMap(), Columnar::identify($pageOne, 'TestObject.TestRelation.First')); |
|
|
|
|
81
|
|
|
$this->assertEquals($relationOne->Title, Columnar::identify($pageOne, 'TestObject.TestRelation.First.Title')); |
|
|
|
|
82
|
|
|
$this->assertEquals($mockDate, Columnar::identify($pageOne, 'TestObject.TestRelation.First.Created')); |
|
|
|
|
83
|
|
|
$this->assertEquals($mockDate, $relationOne->Created); |
84
|
|
|
$this->assertEquals('Jul 4, 2019, 10:01 PM', Columnar::identify($pageOne, 'TestObject.TestRelation.First.Created.Nice')); |
|
|
|
|
85
|
|
|
$this->assertEquals('2019-07-04T22:01:00+00:00', Columnar::identify($pageOne, 'TestObject.TestRelation.First.Created.Rfc3339')); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.