|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BasicTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_templates\ATemplate; |
|
8
|
|
|
use kalanis\kw_templates\Template; |
|
9
|
|
|
use kalanis\kw_templates\TemplateException; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class TemplateTest extends CommonTestClass |
|
13
|
|
|
{ |
|
14
|
|
|
public function testSimple() |
|
15
|
|
|
{ |
|
16
|
|
|
$template = new MockTemplate1(); |
|
17
|
|
|
$this->assertEquals('Testing content for your play - it needs more than simple check', $template->render()); |
|
18
|
|
|
$template->change('e', 'x'); |
|
19
|
|
|
$this->assertEquals('Txsting contxnt for your play - it nxxds morx than simplx chxck', $template->render()); |
|
20
|
|
|
$template->reset(); |
|
21
|
|
|
$this->assertEquals(' more than s', $template->getSubstring(40, 12)); |
|
22
|
|
|
|
|
23
|
|
|
$template->paste('no less', 32, 13); |
|
24
|
|
|
$this->assertEquals('Testing content for your play - no less than simple check', $template->render()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @throws TemplateException |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testNothingFound() |
|
31
|
|
|
{ |
|
32
|
|
|
$template = new MockTemplate1(); |
|
33
|
|
|
$this->assertEquals(35, $template->position('needs')); |
|
34
|
|
|
$this->expectException(TemplateException::class); |
|
35
|
|
|
$template->position('needs', 45); // crash - nothing found |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testInputs() |
|
39
|
|
|
{ |
|
40
|
|
|
$template = new MockTemplate2(); |
|
41
|
|
|
$this->assertEquals('Another template for fun with known issues', $template->render()); |
|
42
|
|
|
$template->reset(); |
|
43
|
|
|
$template->updateFill(); |
|
44
|
|
|
$this->assertEquals('Another template for fun with lost ideas', $template->render()); |
|
45
|
|
|
$item = $template->getExisting(); |
|
46
|
|
|
$this->assertEquals('/fill/', $item->getKey()); |
|
47
|
|
|
$this->assertEquals('lost ideas', $item->getValue()); |
|
48
|
|
|
$this->assertEmpty($template->getProblematic()); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
class MockTemplate1 extends ATemplate |
|
54
|
|
|
{ |
|
55
|
|
|
use Template\TInputs; |
|
56
|
|
|
|
|
57
|
|
|
protected function loadTemplate(): string |
|
58
|
|
|
{ |
|
59
|
|
|
return 'Testing content for your play - it needs more than simple check'; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
class MockTemplate2 extends ATemplate |
|
65
|
|
|
{ |
|
66
|
|
|
protected function fillInputs(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$this->addInput('/fill/', 'known issues'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
protected function loadTemplate(): string |
|
72
|
|
|
{ |
|
73
|
|
|
return 'Another template for fun with /fill/'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function updateFill(): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->updateItem('/fill/', 'lost ideas'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function getExisting(): ?Template\Item |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getItem('/fill/'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getProblematic(): ?Template\Item |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->getItem('/none/'); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|