1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BenManu\SimpleStyleguide; |
4
|
|
|
|
5
|
|
|
use BenManu\SimpleStyleguide\SimpleStyleguideController; |
6
|
|
|
use SilverStripe\Dev\SapphireTest; |
7
|
|
|
use SilverStripe\Core\Config\Config; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @package simple-styleguide |
11
|
|
|
* @subpackage tests |
12
|
|
|
*/ |
13
|
|
|
class SimpleStyleguideControllerTest extends SapphireTest |
14
|
|
|
{ |
15
|
|
|
protected static $fixture_file = 'SimpleStyleguideControllerTest.yml'; |
16
|
|
|
|
17
|
|
|
protected $requiredExtensions = [ |
18
|
|
|
SimpleStyleguideController::class => [ |
19
|
|
|
SimpleStyleguideControllerTest_data::class |
20
|
|
|
], |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
public function testGetStyleguideData() |
24
|
|
|
{ |
25
|
|
|
$controller = SimpleStyleguideController::create(); |
26
|
|
|
$data = $controller->getStyleguideData(); |
27
|
|
|
|
28
|
|
|
$this->assertInstanceOf('SilverStripe\View\ArrayData', $data); |
29
|
|
|
$this->assertEquals('Styleguide', $data->Title); |
30
|
|
|
$this->assertEquals( |
31
|
|
|
'<p>This controller is only accessible to developers and admin users.</p>', |
32
|
|
|
$data->Message->getValue() |
33
|
|
|
); |
34
|
|
|
$this->assertInstanceOf('SilverStripe\Forms\Form', $data->TestForm); |
35
|
|
|
$this->assertInstanceOf('SilverStripe\ORM\FieldType\DBHTMLText', $data->Content); |
36
|
|
|
$this->assertInstanceOf('SilverStripe\ORM\ArrayList', $data->ColorSwatches); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetStyleguideDataExtension() |
40
|
|
|
{ |
41
|
|
|
SimpleStyleguideController::add_extension( |
42
|
|
|
SimpleStyleguideControllerTest_data::class |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$controller = SimpleStyleguideController::create(); |
46
|
|
|
|
47
|
|
|
$data = $controller->getStyleguideData(); |
48
|
|
|
$this->assertTrue($data->hasField('CustomData')); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetTestForm() |
52
|
|
|
{ |
53
|
|
|
$controller = SimpleStyleguideController::create(); |
54
|
|
|
$form = $controller->getTestForm(); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf('SilverStripe\Forms\Form', $form); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetContent() |
60
|
|
|
{ |
61
|
|
|
$controller = SimpleStyleguideController::create(); |
62
|
|
|
$content = $controller->getContent(); |
63
|
|
|
|
64
|
|
|
$this->assertInstanceOf('SilverStripe\ORM\FieldType\DBHTMLText', $content); |
65
|
|
|
$this->assertNotNull($content->getValue()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testGetColorSwatches() |
69
|
|
|
{ |
70
|
|
|
$controller = SimpleStyleguideController::create(); |
71
|
|
|
$swatchesFixture = [ |
72
|
|
|
[ |
73
|
|
|
'Name' => 'Black', |
74
|
|
|
'Description' => 'This color is rather dark', |
75
|
|
|
'CSSColor' => '#000000', |
76
|
|
|
'TextColor' => '#ffffff', |
77
|
|
|
], |
78
|
|
|
[ |
79
|
|
|
'Name' => 'Grey', |
80
|
|
|
'Description' => 'This color is grey', |
81
|
|
|
'CSSColor' => '#666666', |
82
|
|
|
'TextColor' => '#000000', |
83
|
|
|
], |
84
|
|
|
]; |
85
|
|
|
|
86
|
|
|
SimpleStyleguideController::config()->remove('color_swatches'); |
87
|
|
|
SimpleStyleguideController::config()->update('color_swatches', $swatchesFixture); |
88
|
|
|
|
89
|
|
|
$swatches = $controller->getColorSwatches(); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf('SilverStripe\ORM\ArrayList', $swatches); |
92
|
|
|
$this->assertEquals(count($swatchesFixture), $swatches->count()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|