|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BasicTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_templates\GroupedTemplate; |
|
8
|
|
|
use kalanis\kw_templates\Template; |
|
9
|
|
|
use kalanis\kw_templates\TemplateException; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class GroupTemplateTest extends CommonTestClass |
|
13
|
|
|
{ |
|
14
|
|
|
public function testSimple() |
|
15
|
|
|
{ |
|
16
|
|
|
$template = new MockGroupedTemplate1(); |
|
17
|
|
|
$this->assertEmpty($template->render()); |
|
18
|
|
|
$template->useHead(); |
|
19
|
|
|
$this->assertEquals('available from every part', $template->render()); |
|
20
|
|
|
$template->useUl(); |
|
21
|
|
|
$this->assertNotEquals('available from every part', $template->render()); |
|
22
|
|
|
$this->assertEquals('unordered list: found', $template->render()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testUnknown() |
|
26
|
|
|
{ |
|
27
|
|
|
$template = new MockGroupedTemplate1(); |
|
28
|
|
|
$this->expectException(TemplateException::class); |
|
29
|
|
|
$template->useUnknown(); // crash - nothing found |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
class MockGroupedTemplate1 extends GroupedTemplate |
|
35
|
|
|
{ |
|
36
|
|
|
use Template\TInputs; |
|
37
|
|
|
|
|
38
|
|
|
protected function defineAvailableTemplates(): array |
|
39
|
|
|
{ |
|
40
|
|
|
return [ |
|
41
|
|
|
'head' => 'available from *what*', |
|
42
|
|
|
'ul' => 'unordered list: *content*', |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function useHead(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->resetItems(); |
|
49
|
|
|
$this->selectTemplate('head'); |
|
50
|
|
|
$this->addInput('*what*', 'nowhere', 'every part'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function useUl(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$this->resetItems(); |
|
56
|
|
|
$this->selectTemplate('ul'); |
|
57
|
|
|
$this->addInput('*content*', 'not found', 'found'); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function useUnknown(): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->resetItems(); |
|
63
|
|
|
$this->selectTemplate('fake'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|