|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @package simple-styleguide |
|
4
|
|
|
* @subpackage tests |
|
5
|
|
|
*/ |
|
6
|
|
|
class SimpleStyleguideControllerTest extends SapphireTest |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
protected static $fixture_file = 'SimpleStyleguideControllerTest.yml'; |
|
9
|
|
|
|
|
10
|
|
|
protected $requiredExtensions = [ |
|
11
|
|
|
'SimpleStyleguideController' => ['SimpleStyleguideControllerTest_data'], |
|
12
|
|
|
]; |
|
13
|
|
|
|
|
14
|
|
|
public function testGetStyleguideData() |
|
15
|
|
|
{ |
|
16
|
|
|
$controller = SimpleStyleguideController::create(); |
|
17
|
|
|
$data = $controller->getStyleguideData(); |
|
18
|
|
|
|
|
19
|
|
|
$this->assertInstanceOf('ArrayData', $data); |
|
|
|
|
|
|
20
|
|
|
$this->assertEquals('Styleguide', $data->Title); |
|
|
|
|
|
|
21
|
|
|
$this->assertEquals( |
|
|
|
|
|
|
22
|
|
|
'<p>This controller is only accessible to developers and admin users.</p>', |
|
23
|
|
|
$data->Message->getValue() |
|
24
|
|
|
); |
|
25
|
|
|
$this->assertInstanceOf('Form', $data->TestForm); |
|
|
|
|
|
|
26
|
|
|
$this->assertInstanceOf('HTMLText', $data->Content); |
|
|
|
|
|
|
27
|
|
|
$this->assertInstanceOf('ArrayList', $data->ColorSwatches); |
|
|
|
|
|
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGetStyleguideDataExtension() |
|
31
|
|
|
{ |
|
32
|
|
|
$controller = SimpleStyleguideController::create(); |
|
33
|
|
|
$data = $controller->getStyleguideData(); |
|
34
|
|
|
$this->assertTrue($data->hasField('CustomData')); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function testGetTestForm() |
|
38
|
|
|
{ |
|
39
|
|
|
$controller = SimpleStyleguideController::create(); |
|
40
|
|
|
$form = $controller->getTestForm(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertInstanceOf('Form', $form); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGetContent() |
|
46
|
|
|
{ |
|
47
|
|
|
$controller = SimpleStyleguideController::create(); |
|
48
|
|
|
$content = $controller->getContent(); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertInstanceOf('HTMLText', $content); |
|
|
|
|
|
|
51
|
|
|
$this->assertNotNull($content->getValue()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testGetColorSwatches() |
|
55
|
|
|
{ |
|
56
|
|
|
$controller = SimpleStyleguideController::create(); |
|
57
|
|
|
$swatchesFixture = [ |
|
58
|
|
|
[ |
|
59
|
|
|
'Name' => 'Black', |
|
60
|
|
|
'Description' => 'This color is rather dark', |
|
61
|
|
|
'CSSColor' => '#000000', |
|
62
|
|
|
'TextColor' => '#ffffff', |
|
63
|
|
|
], |
|
64
|
|
|
[ |
|
65
|
|
|
'Name' => 'Grey', |
|
66
|
|
|
'Description' => 'This color is grey', |
|
67
|
|
|
'CSSColor' => '#666666', |
|
68
|
|
|
'TextColor' => '#000000', |
|
69
|
|
|
], |
|
70
|
|
|
]; |
|
71
|
|
|
|
|
72
|
|
|
Config::inst()->remove('SimpleStyleguideController', 'color_swatches'); |
|
73
|
|
|
Config::inst()->update('SimpleStyleguideController', 'color_swatches', $swatchesFixture); |
|
74
|
|
|
|
|
75
|
|
|
$swatches = $controller->getColorSwatches(); |
|
76
|
|
|
|
|
77
|
|
|
$this->assertInstanceOf('ArrayList', $swatches); |
|
|
|
|
|
|
78
|
|
|
$this->assertEquals(count($swatchesFixture), $swatches->count()); |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
class SimpleStyleguideControllerTest_data extends DataExtension implements TestOnly { |
|
|
|
|
|
|
83
|
|
|
public function updateStyleguideData($data) |
|
84
|
|
|
{ |
|
85
|
|
|
$data->setField('CustomData', 'Test'); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.