1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\CKANRegistry\Tests\Page; |
4
|
|
|
|
5
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
6
|
|
|
use SilverStripe\CKANRegistry\Page\CKANRegistryPage; |
7
|
|
|
use SilverStripe\CKANRegistry\Page\CKANRegistryPageController; |
8
|
|
|
use SilverStripe\CKANRegistry\Service\ResourcePopulatorInterface; |
9
|
|
|
use SilverStripe\Core\Injector\Injector; |
10
|
|
|
use SilverStripe\Dev\SapphireTest; |
11
|
|
|
|
12
|
|
|
class CKANRegistryPageControllerTest extends SapphireTest |
13
|
|
|
{ |
14
|
|
|
protected static $fixture_file = 'CKANRegistryPageControllerTest.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 testGetCKANClientConfig() |
27
|
|
|
{ |
28
|
|
|
/** @var CKANRegistryPage $page */ |
29
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
30
|
|
|
|
31
|
|
|
$controller = new CKANRegistryPageController($page); |
32
|
|
|
$config = $controller->getCKANClientConfig($page); |
33
|
|
|
|
34
|
|
|
$this->assertSame([ |
35
|
|
|
'endpoint' => 'https://example.com/ckan', |
36
|
|
|
'dataset' => 'animal-centers', |
37
|
|
|
'identifier' => '123-456', |
38
|
|
|
], $config['spec'], 'CKAN endpoint specification should be provided'); |
39
|
|
|
$this->assertSame('Animal Centers', $config['name'], 'Name should be provided'); |
40
|
|
|
$this->assertSame('Vet Clinics', $config['resourceName'], 'Resource name should be provided'); |
41
|
|
|
$this->assertSame('/animal-centers', $config['basePath'], 'Without a page, basePath should be root'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $relativeLink |
46
|
|
|
* @param string $expected |
47
|
|
|
* @dataProvider basePathProvider |
48
|
|
|
*/ |
49
|
|
|
public function testGetBasePath($relativeLink, $expected) |
50
|
|
|
{ |
51
|
|
|
/** @var CKANRegistryPage|PHPUnit_Framework_MockObject_MockObject $page */ |
52
|
|
|
$page = $this->createMock(CKANRegistryPage::class); |
53
|
|
|
$page->expects($this->once())->method('RelativeLink')->willReturn($relativeLink); |
54
|
|
|
|
55
|
|
|
$controller = new CKANRegistryPageController($page); |
56
|
|
|
|
57
|
|
|
$this->assertSame($expected, $controller->getBasePath($page)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return array[] |
62
|
|
|
*/ |
63
|
|
|
public function basePathProvider() |
64
|
|
|
{ |
65
|
|
|
return [ |
66
|
|
|
['/', '/'], |
67
|
|
|
['/my-page', '/my-page'], |
68
|
|
|
['my-page', '/my-page'], |
69
|
|
|
['my-page/', '/my-page'], |
70
|
|
|
['/my-page/', '/my-page'], |
71
|
|
|
['/my-page/my-resources/', '/my-page/my-resources'], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetBasePathWithNoArgument() |
76
|
|
|
{ |
77
|
|
|
/** @var CKANRegistryPage $page */ |
78
|
|
|
$page = $this->objFromFixture(CKANRegistryPage::class, 'animal_centers'); |
79
|
|
|
|
80
|
|
|
$controller = new CKANRegistryPageController($page); |
81
|
|
|
|
82
|
|
|
$this->assertSame('/', $controller->getBasePath()); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|