1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CKANRegistry\Tests\Page; |
4
|
|
|
|
5
|
|
|
use SilverStripe\CKANRegistry\Page\CKANRegistryPage; |
6
|
|
|
use SilverStripe\CKANRegistry\Service\ResourcePopulatorInterface; |
7
|
|
|
use SilverStripe\Core\Injector\Injector; |
8
|
|
|
use SilverStripe\Dev\SapphireTest; |
9
|
|
|
use SilverStripe\Forms\GridField\GridField; |
10
|
|
|
use Symbiote\GridFieldExtensions\GridFieldEditableColumns; |
11
|
|
|
|
12
|
|
|
class CKANRegistryPageTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = 'CKANRegistryPageTest.yml'; |
15
|
|
|
|
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
// Mock the field populator, in case an action we perform in a unit test tries to contact the mock API. |
19
|
|
|
// Done before parent::setUp() so write hooks don't run during fixture population. |
20
|
|
|
$populator = $this->createMock(ResourcePopulatorInterface::class); |
21
|
|
|
Injector::inst()->registerService($populator, ResourcePopulatorInterface::class); |
22
|
|
|
|
23
|
|
|
parent::setUp(); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testHasItemsPerPageSetting() |
27
|
|
|
{ |
28
|
|
|
/** @var CKANRegistryPage $page */ |
29
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
30
|
|
|
|
31
|
|
|
$this->assertNotNull($page->getSettingsFields()->fieldByName('Root.Settings.ItemsPerPage')); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testColumnsGridFieldHasUniqueClassName() |
35
|
|
|
{ |
36
|
|
|
/** @var CKANRegistryPage $page */ |
37
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
38
|
|
|
|
39
|
|
|
$field = $page->getCMSFields()->dataFieldByName('DataColumns'); |
40
|
|
|
$this->assertInstanceOf(GridField::class, $field, 'Columns GridField was not found in fields'); |
41
|
|
|
$this->assertTrue($field->hasClass('ckan-columns'), 'Columns GridField should have unique class'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testFiltersGridFieldHasUniqueClassName() |
45
|
|
|
{ |
46
|
|
|
/** @var CKANRegistryPage $page */ |
47
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
48
|
|
|
|
49
|
|
|
$field = $page->getCMSFields()->dataFieldByName('DataFilters'); |
50
|
|
|
$this->assertInstanceOf(GridField::class, $field, 'Filters GridField was not found in fields'); |
51
|
|
|
$this->assertTrue($field->hasClass('ckan-filters'), 'Filters GridField should have unique class'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testNoDataColumnsGridFieldGetsAddedWhenNoResourceIsDefined() |
55
|
|
|
{ |
56
|
|
|
$page = new CKANRegistryPage(); |
57
|
|
|
$page->write(); |
58
|
|
|
|
59
|
|
|
$field = $page->getCMSFields()->fieldByName('Root.Data.DataColumns'); |
60
|
|
|
$this->assertNull($field, 'Columns should not be added until a resource is defined'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testHasEditableColumnsComponent() |
64
|
|
|
{ |
65
|
|
|
/** @var CKANRegistryPage $page */ |
66
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
67
|
|
|
|
68
|
|
|
/** @var GridField $field */ |
69
|
|
|
$field = $page->getCMSFields()->fieldByName('Root.Data.DataColumns'); |
70
|
|
|
$this->assertInstanceOf(GridField::class, $field, 'Columns GridField was not found in fields'); |
71
|
|
|
$this->assertNotNull($field->getConfig()->getComponentByType(GridFieldEditableColumns::class)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testEditableColumnsHaveCorrectDisplayFields() |
75
|
|
|
{ |
76
|
|
|
/** @var CKANRegistryPage $page */ |
77
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
78
|
|
|
|
79
|
|
|
/** @var GridField $field */ |
80
|
|
|
$field = $page->getCMSFields()->fieldByName('Root.Data.DataColumns'); |
81
|
|
|
$this->assertInstanceOf(GridField::class, $field, 'Columns GridField was not found in fields'); |
82
|
|
|
|
83
|
|
|
/** @var GridFieldEditableColumns $component */ |
84
|
|
|
$component = $field->getConfig()->getComponentByType(GridFieldEditableColumns::class); |
85
|
|
|
$this->assertNotNull($component, 'Component was not found in the GridField'); |
86
|
|
|
|
87
|
|
|
$displayFields = $component->getDisplayFields($field); |
88
|
|
|
$this->assertEquals([ |
89
|
|
|
'ShowInResultsView' => _t('SilverStripe\\CKANRegistry\\Page\\CKANRegistryPage.IN_RESULTS', 'In Results'), |
90
|
|
|
'ShowInDetailView' => _t('SilverStripe\\CKANRegistry\\Page\\CKANRegistryPage.IN_DETAIL', 'In Detail'), |
91
|
|
|
], $displayFields, 'Correct display fields were not found'); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|