This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlopfileTest.php
384 lines (311 loc) · 20 KB
/
PlopfileTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
<?php
require_once __DIR__ . '/vendor/autoload.php';
use PHPUnit\Framework\TestCase;
final class PlopfileTest extends TestCase
{
public $root;
public function setUp(): void
{
file_put_contents(__DIR__ . '/.env', "PLOP_CLIPBOARD=false");
$this->root = __DIR__ . '/tests';
$this->assertTrue(empty(shell_exec('composer reset')));
}
public function tearDown(): void
{
$this->assertTrue(empty(shell_exec('composer reset')));
}
public function testBlueprint()
{
$file = $this->root . '/site/blueprints/pages/blogpost.yml';
$this->assertTrue(empty(shell_exec('plop blueprint $ pages blogpost .yml {}')));
$this->assertFileExists($file);
$file = $this->root . '/site/blueprints/files/download.php';
$this->assertTrue(empty(shell_exec('plop blueprint $ files download .php {}')));
$this->assertFileExists($file);
$file = $this->root . '/site/blueprints/fields/subfolder/blogpost.yml';
$this->assertTrue(empty(shell_exec('plop blueprint $ fields subfolder/blogpost .yml {}')));
$this->assertFileExists($file);
}
public function testConfig()
{
$file = $this->root . '/site/config/config.php';
$this->assertTrue(empty(shell_exec('plop config config all {}')));
$this->assertFileExists($file);
$this->assertTrue(empty(shell_exec('plop config-hook config page.update:before hooktodo')));
$this->assertStringContainsString('page.update:before', file_get_contents($file));
$this->assertStringContainsString('hooktodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop config-option config confkey confvalue')));
$this->assertStringContainsString('confkey', file_get_contents($file));
$this->assertStringContainsString('confvalue', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop config-route config confpat confpar confmeth confrouodo')));
$this->assertStringContainsString('confpat', file_get_contents($file));
$this->assertStringContainsString('confpar', file_get_contents($file));
$this->assertStringContainsString('confmeth', file_get_contents($file));
$this->assertStringContainsString('confrouodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop language en n ltr en_EN English en {}')));
$this->assertTrue(empty(shell_exec('plop config-route config confenpat confenpar confenmeth confenrouodo en')));
$this->assertStringContainsString('confenpat', file_get_contents($file));
$this->assertStringContainsString('confenpar', file_get_contents($file));
$this->assertStringContainsString('confenmeth', file_get_contents($file));
$this->assertStringContainsString('confenrouodo', file_get_contents($file));
}
public function testContent()
{
$file = $this->root . '/content/blog/consistency-made-simple/blogpost.txt';
$this->assertTrue(empty(shell_exec('plop content "Consistency made simple!" blog blogpost \'{"Date":"2020-08-03"}\'')));
$this->assertFileExists($file);
$this->assertStringContainsString('Date: 2020-08-03', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop language jp n rtl jp_JP Japanese jp {}')));
$file = $this->root . '/content/blog/consistency-made-great/blogpost.jp.txt';
$this->assertTrue(empty(shell_exec('plop content "Consistency made great!" blog blogpost \'{"Show":"2020-08-03"}\' jp arigatou')));
$this->assertFileExists($file);
$this->assertStringContainsString('Slug: arigatou', file_get_contents($file));
$this->assertStringContainsString('Show: 2020-08-03', file_get_contents($file));
}
public function testController()
{
$file = $this->root . '/site/controllers/blogpost.php';
$this->assertTrue(empty(shell_exec('plop controller $ blogpost .php all')));
$this->assertFileExists($file);
$file = $this->root . '/site/controllers/blogpost.qr.php';
$this->assertTrue(empty(shell_exec('plop controller $ blogpost .qr.php all')));
$this->assertFileExists($file);
}
public function testFile()
{
$file = $this->root . '/content/blog/consitency-made-easy/image.png.txt';
$this->assertTrue(empty(shell_exec('plop file tests/image.png blog/consitency-made-easy hero \'{"sort": 4}\'')));
$this->assertFileExists($file);
$this->assertFileExists(str_replace('.txt', '', $file));
$this->assertStringContainsString('Template: hero', file_get_contents($file));
$this->assertStringContainsString('Sort: 4', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop language jp n rtl jp_JP Japanese jp {}')));
$file = $this->root . '/content/blog/something-else/image.png.jp.txt';
$this->assertTrue(empty(shell_exec('plop file tests/image.png blog/something-else "" {} jp')));
$this->assertFileExists($file);
$this->assertFileExists(str_replace('.jp.txt', '', $file));
}
public function testLanguage()
{
$file = $this->root . '/site/languages/de.php';
$this->assertTrue(empty(shell_exec('plop language de n ltr de_DE Deutsch de \'{"a": "Ad_e", "b": "Bd_e"}\'')));
$this->assertFileExists($file);
$this->assertStringContainsString('ltr', file_get_contents($file));
$this->assertStringContainsString('de_DE', file_get_contents($file));
$this->assertStringContainsString('Deutsch', file_get_contents($file));
$this->assertStringContainsString('Ad_e', file_get_contents($file));
}
public function testModel()
{
$file = $this->root . '/site/models/blogpost.php';
$this->assertTrue(empty(shell_exec('plop model $ blogpost all')));
$this->assertFileExists($file);
}
public function testPluginWithExtensions()
{
$file = $this->root . '/site/plugins/myplug/index.php';
$this->assertTrue(empty(shell_exec('plop plugin myname myplug "" all all')));
$this->assertFileExists($file);
$this->assertFileExists(str_replace('index.php', 'composer.json', $file));
$this->assertStringContainsString('myname/myplug', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-auth-challenge myplug authkey authvalue')));
$this->assertStringContainsString('authkey', file_get_contents($file));
$this->assertStringContainsString('authvalue', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-api-data myplug adkey adparams adtodo')));
$this->assertStringContainsString('adkey', file_get_contents($file));
$this->assertStringContainsString('adparams', file_get_contents($file));
$this->assertStringContainsString('adtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-api-route myplug arparams arpattern armethod artodo')));
$this->assertStringContainsString('arparams', file_get_contents($file));
$this->assertStringContainsString('arpattern', file_get_contents($file));
$this->assertStringContainsString('armethod', file_get_contents($file));
$this->assertStringContainsString('artodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop blueprint myplug pages hello .yml {}')));
$this->assertTrue(empty(shell_exec('plop ext-blueprint myplug pages/hello')));
$this->assertStringContainsString('/blueprints/pages/hello.yml', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-cache-type myplug ctkey ctvalue')));
$this->assertStringContainsString('ctkey', file_get_contents($file));
$this->assertStringContainsString('Ctvalue::class', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-class-alias myplug cakey cavalue')));
$this->assertStringContainsString('class_alias(\'cakey', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-class-loader myplug clkey clvalue')));
$this->assertStringContainsString('Clkey', file_get_contents($file));
$this->assertStringContainsString('clvalue.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-collection-filter myplug cfkey cftodo')));
$this->assertStringContainsString('cfkey', file_get_contents($file));
$this->assertStringContainsString('cftodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-collection-method myplug cmkey cmparams cmtodo')));
$this->assertStringContainsString('cmkey', file_get_contents($file));
$this->assertStringContainsString('cmparams', file_get_contents($file));
$this->assertStringContainsString('cmtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-collection myplug clkey clparams cltodo')));
$this->assertStringContainsString('clkey', file_get_contents($file));
$this->assertStringContainsString('clparams', file_get_contents($file));
$this->assertStringContainsString('cltodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop controller myplug cooni .php defaults')));
$this->assertTrue(empty(shell_exec('plop ext-controller myplug cooni')));
$this->assertStringContainsString('require \'controllers/cooni.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop command $ comman all')));
$this->assertTrue(empty(shell_exec('plop ext-command myplug cdkey cdparams cdtodo')));
$this->assertStringContainsString('cdkey', file_get_contents($file));
$this->assertStringContainsString('cdparams', file_get_contents($file));
$this->assertStringContainsString('cdtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-field-method myplug fmkey fmparams fmtodo')));
$this->assertStringContainsString('fmkey', file_get_contents($file));
$this->assertStringContainsString('fmparams', file_get_contents($file));
$this->assertStringContainsString('fmtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-field myplug fikey fitodo')));
$this->assertStringContainsString('fikey', file_get_contents($file));
$this->assertStringContainsString('fitodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-file-method myplug fimkey fimparams fimtodo')));
$this->assertStringContainsString('fimkey', file_get_contents($file));
$this->assertStringContainsString('fimparams', file_get_contents($file));
$this->assertStringContainsString('fimtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-files-method myplug fiskey fisparams fistodo')));
$this->assertStringContainsString('fiskey', file_get_contents($file));
$this->assertStringContainsString('fisparams', file_get_contents($file));
$this->assertStringContainsString('fistodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-hook myplug page.delete:after hotodo')));
$this->assertStringContainsString('page.delete:after', file_get_contents($file));
$this->assertStringContainsString('$status, $page', file_get_contents($file));
$this->assertStringContainsString('hotodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-kirbytag myplug ktkey "ktattr1, ktattr2" ktparams kttodo')));
$this->assertStringContainsString('ktkey', file_get_contents($file));
$this->assertStringContainsString('\'ktattr1\'', file_get_contents($file));
$this->assertStringContainsString('\'ktattr2\'', file_get_contents($file));
$this->assertStringContainsString('ktparams', file_get_contents($file));
$this->assertStringContainsString('kttodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-option myplug opkey opvalue')));
$this->assertStringContainsString('opkey', file_get_contents($file));
$this->assertStringContainsString('opvalue', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-page-method myplug pmkey pmparams pmtodo')));
$this->assertStringContainsString('pmkey', file_get_contents($file));
$this->assertStringContainsString('pmparams', file_get_contents($file));
$this->assertStringContainsString('pmtodo', file_get_contents($file));
// $this->assertTrue(empty(shell_exec('plop model myplug idefix all')));
// + class alias
$this->assertTrue(empty(shell_exec('plop ext-page-model myplug idefix IdefixPage')));
$this->assertStringContainsString('idefix', file_get_contents($file));
$this->assertStringContainsString('IdefixPage', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-pages-method myplug pasmkey pasmparams pasmtodo')));
$this->assertStringContainsString('pasmkey', file_get_contents($file));
$this->assertStringContainsString('pasmparams', file_get_contents($file));
$this->assertStringContainsString('pasmtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-pages myplug "Wei rdo!" magician {}')));
$this->assertStringContainsString('magician', file_get_contents($file));
$this->assertStringContainsString('Wei rdo!', file_get_contents($file));
$this->assertStringContainsString('wei-rdo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-permission myplug pekey pevalue')));
$this->assertStringContainsString('pekey', file_get_contents($file));
$this->assertStringContainsString('pevalue', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-route myplug ropattern romethod roparams rotodo')));
$this->assertStringContainsString('ropattern', file_get_contents($file));
$this->assertStringContainsString('romethod', file_get_contents($file));
$this->assertStringContainsString('ropattern', file_get_contents($file));
$this->assertStringContainsString('rotodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-section myplug sekey setodo')));
$this->assertStringContainsString('sekey', file_get_contents($file));
$this->assertStringContainsString('setodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-site-method myplug simkey simparams simtodo')));
$this->assertStringContainsString('simkey', file_get_contents($file));
$this->assertStringContainsString('simparams', file_get_contents($file));
$this->assertStringContainsString('simtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop snippet myplug asterix all {}')));
$this->assertTrue(empty(shell_exec('plop ext-snippet myplug asterix')));
$this->assertStringContainsString('/snippets/asterix.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop template myplug obelix .php all')));
$this->assertTrue(empty(shell_exec('plop ext-template myplug obelix')));
$this->assertStringContainsString('/templates/obelix.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-user-method myplug umkey umparams umtodo')));
$this->assertStringContainsString('umkey', file_get_contents($file));
$this->assertStringContainsString('umparams', file_get_contents($file));
$this->assertStringContainsString('umtodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-user-model myplug umokey umovalue')));
$this->assertStringContainsString('umokey', file_get_contents($file));
$this->assertStringContainsString('Umovalue', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-users-method myplug umekey umeparams umetodo')));
$this->assertStringContainsString('umekey', file_get_contents($file));
$this->assertStringContainsString('umeparams', file_get_contents($file));
$this->assertStringContainsString('umetodo', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop ext-validator myplug vakey vatodo')));
$this->assertStringContainsString('vakey', file_get_contents($file));
$this->assertStringContainsString('vatodo', file_get_contents($file));
}
public function testRightReferncesInFullMtcButSameNames() {
$file = $this->root . '/site/plugins/myplug/index.php';
$this->assertTrue(empty(shell_exec('plop plugin myname myplug "" all all')));
$this->assertFileExists($file);
$this->assertTrue(empty(shell_exec('plop blueprint myplug pages hello .yml {}')));
$this->assertTrue(empty(shell_exec('plop ext-blueprint myplug pages/hello')));
$this->assertStringContainsString('/blueprints/pages/hello.yml', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop blueprint myplug fields hello .yml {}')));
$this->assertTrue(empty(shell_exec('plop ext-blueprint myplug fields/hello')));
$this->assertStringContainsString('/blueprints/fields/hello.yml', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop model myplug hello all')));
$this->assertTrue(empty(shell_exec('plop ext-page-model myplug hello helloPage')));
$this->assertStringContainsString('HelloPage', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop template myplug hello .php all')));
$this->assertTrue(empty(shell_exec('plop ext-template myplug hello')));
$this->assertStringContainsString('/templates/hello.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop controller myplug hello .php defaults')));
$this->assertTrue(empty(shell_exec('plop ext-controller myplug hello')));
$this->assertStringContainsString('require \'controllers/hello.php', file_get_contents($file));
$this->assertTrue(empty(shell_exec('plop snippet myplug hello all {}')));
$this->assertTrue(empty(shell_exec('plop ext-snippet myplug hello')));
$this->assertStringContainsString('/snippets/hello.php', file_get_contents($file));
}
public function testSnippet()
{
$file = $this->root . '/site/snippets/slideshow.php';
$this->assertTrue(empty(shell_exec('plop snippet $ slideshow all {}')));
$this->assertFileExists($file);
}
public function testTemplate()
{
$file = $this->root . '/site/templates/blogpost.php';
$this->assertTrue(empty(shell_exec('plop template $ blogpost .php all')));
$this->assertFileExists($file);
$file = $this->root . '/site/templates/blogpost.qr.php';
$this->assertTrue(empty(shell_exec('plop template $ blogpost .qr.php all')));
$this->assertFileExists($file);
}
public function testUser()
{
$this->assertTrue(empty(shell_exec('plop user t@test.com myname pw admin en')));
foreach(glob(__DIR__.'/site/accounts/*/index.php') as $file) {
$this->assertStringContainsString('myname', file_get_contents($file));
$this->assertStringContainsString('admin', file_get_contents($file));
$this->assertStringContainsString('en', file_get_contents($file));
$this->assertStringStartsWith('$2y', file_get_contents(str_replace('index.php', '.htaccess', $file)));
}
}
public function testTDD()
{
$this->markTestSkipped();
}
public function testSetup()
{
$this->markTestSkipped();
}
public function testRobotstxt()
{
$this->markTestSkipped();
}
public function testHtaccess()
{
$this->markTestSkipped();
}
public function testDockercompose()
{
$this->markTestSkipped();
}
public function xtestReadmeExamples()
{
$examples = file_get_contents(__DIR__ . '/fixtures.md');
foreach(explode("\n", $examples) as $ex) {
if ($ex[0] != '#') {
$this->assertTrue(empty(shell_exec($ex)));
}
}
}
}