1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSoellinger\SilverStripe\ModelAnnotations\Test\Unit\View; |
4
|
|
|
|
5
|
|
|
// phpcs:disable |
6
|
|
|
require_once __DIR__ . '/../../mockup.php'; |
7
|
|
|
// phpcs:enable |
8
|
|
|
|
9
|
|
|
use CSoellinger\SilverStripe\ModelAnnotations\Test\PhpUnitHelper; |
10
|
|
|
use CSoellinger\SilverStripe\ModelAnnotations\Util\Util; |
11
|
|
|
use CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView; |
12
|
|
|
use Reflection; |
13
|
|
|
use SilverStripe\Core\Environment; |
14
|
|
|
use SilverStripe\Core\Injector\Injector; |
15
|
|
|
use SilverStripe\Dev\SapphireTest; |
16
|
|
|
use SilverStripe\ORM\DataObject; |
17
|
|
|
|
18
|
|
|
define('TEST_MESSAGE', 'Test Message'); |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @internal |
22
|
|
|
* |
23
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView |
24
|
|
|
*/ |
25
|
|
|
class DataClassTaskViewTest extends SapphireTest |
26
|
|
|
{ |
27
|
|
|
protected static DataClassTaskView $view; |
28
|
|
|
|
29
|
|
|
public static string $phpSapiName = 'cli'; |
30
|
|
|
|
31
|
|
|
public static function setUpBeforeClass(): void |
32
|
|
|
{ |
33
|
|
|
parent::setUpBeforeClass(); |
34
|
|
|
|
35
|
|
|
/** @var DataClassTaskView $view */ |
36
|
|
|
$view = Injector::inst()->get(DataClassTaskView::class); |
37
|
|
|
|
38
|
|
|
self::$view = $view; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function setUp(): void |
42
|
|
|
{ |
43
|
|
|
parent::setUp(); |
44
|
|
|
|
45
|
|
|
PhpUnitHelper::$phpSapiName = 'cli'; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderHeader |
50
|
|
|
* @group ExpectedOutput |
51
|
|
|
*/ |
52
|
|
|
public function testRenderHeader(): void |
53
|
|
|
{ |
54
|
|
|
$output = self::class . PHP_EOL; |
55
|
|
|
$output .= 'File: ' . __FILE__ . PHP_EOL . PHP_EOL; |
56
|
|
|
|
57
|
|
|
$this->expectOutputString($output); |
58
|
|
|
|
59
|
|
|
self::$view->renderHeader(self::class, __FILE__); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderHeader |
64
|
|
|
* @group ExpectedOutput |
65
|
|
|
*/ |
66
|
|
|
public function testRenderHeaderHtml(): void |
67
|
|
|
{ |
68
|
|
|
PhpUnitHelper::$phpSapiName = 'apache'; |
69
|
|
|
|
70
|
|
|
$output = '<div class="info">'; |
71
|
|
|
$output .= ' <h3 style="margin-bottom: 0;">' . self::class . '</h3>'; |
72
|
|
|
$output .= '</div>'; |
73
|
|
|
|
74
|
|
|
$this->expectOutputString($output); |
75
|
|
|
|
76
|
|
|
self::$view->renderHeader(self::class, __FILE__); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderMessage |
81
|
|
|
* @group ExpectedOutput |
82
|
|
|
*/ |
83
|
|
|
public function testRenderMessage(): void |
84
|
|
|
{ |
85
|
|
|
$output = TEST_MESSAGE . PHP_EOL . PHP_EOL; |
86
|
|
|
|
87
|
|
|
$this->expectOutputString($output); |
88
|
|
|
|
89
|
|
|
self::$view->renderMessage(TEST_MESSAGE); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderMessage |
94
|
|
|
* @group ExpectedOutput |
95
|
|
|
*/ |
96
|
|
|
public function testRenderMessageHtml(): void |
97
|
|
|
{ |
98
|
|
|
PhpUnitHelper::$phpSapiName = 'apache'; |
99
|
|
|
|
100
|
|
|
$output = '<div class="build" style="padding-bottom: 0;">'; |
101
|
|
|
$output .= ' <div class="success" style="font-weight: 600;">'; |
102
|
|
|
$output .= TEST_MESSAGE; |
103
|
|
|
$output .= ' </div>'; |
104
|
|
|
$output .= '</div>'; |
105
|
|
|
|
106
|
|
|
$this->expectOutputString($output); |
107
|
|
|
|
108
|
|
|
self::$view->renderMessage(TEST_MESSAGE); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderSource |
113
|
|
|
* @group ExpectedOutput |
114
|
|
|
*/ |
115
|
|
|
public function testRenderSource(): void |
116
|
|
|
{ |
117
|
|
|
$output = file_get_contents(__FILE__) . PHP_EOL . PHP_EOL; |
118
|
|
|
|
119
|
|
|
$this->expectOutputString($output); |
120
|
|
|
|
121
|
|
|
self::$view->renderSource(__FILE__, (string) file_get_contents(__FILE__)); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderSource |
126
|
|
|
* @group ExpectedOutput |
127
|
|
|
*/ |
128
|
|
|
public function testRenderSourceHtml(): void |
129
|
|
|
{ |
130
|
|
|
PhpUnitHelper::$phpSapiName = 'apache'; |
131
|
|
|
|
132
|
|
|
$output = '<div class="info">'; |
133
|
|
|
$output .= ' <small>' . __FILE__ . '</small>'; |
134
|
|
|
$output .= ' <pre><code>' . htmlentities((string) file_get_contents(__FILE__)) . '</code></pre>'; |
135
|
|
|
$output .= '</div><div> </div>'; |
136
|
|
|
|
137
|
|
|
$this->expectOutputString($output); |
138
|
|
|
|
139
|
|
|
self::$view->renderSource(__FILE__, (string) file_get_contents(__FILE__)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderHr |
144
|
|
|
* @group ExpectedOutput |
145
|
|
|
*/ |
146
|
|
|
public function testRenderHr(): void |
147
|
|
|
{ |
148
|
|
|
$output = '--- --- --- --- --- --- --- ---' . PHP_EOL . PHP_EOL; |
149
|
|
|
|
150
|
|
|
$this->expectOutputString($output); |
151
|
|
|
|
152
|
|
|
self::$view->renderHr(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @covers \CSoellinger\SilverStripe\ModelAnnotations\View\DataClassTaskView::renderHr |
157
|
|
|
* @group ExpectedOutput |
158
|
|
|
*/ |
159
|
|
|
public function testRenderHrHtml(): void |
160
|
|
|
{ |
161
|
|
|
PhpUnitHelper::$phpSapiName = 'apache'; |
162
|
|
|
|
163
|
|
|
$output = '<div class="info" style="padding: 0;"><hr /></div>'; |
164
|
|
|
|
165
|
|
|
$this->expectOutputString($output); |
166
|
|
|
|
167
|
|
|
self::$view->renderHr(); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|