|
14 | 14 | expect($engine->getFileExtension())->toBe('phtml'); |
15 | 15 | }); |
16 | 16 |
|
17 | | -test('Let\'s try to add and then get several folders', function () use ($engine) { |
18 | | - $engine->addPath('folder1', 'ns1') |
19 | | - ->addPath('folder2', 'ns1') |
20 | | - ->addPath(M_PATH_ROOT); |
21 | | - expect($engine->getPath('ns1'))->toContain('folder1') |
22 | | - ->and($engine->getPath('ns1'))->toContain('folder2') |
23 | | - ->and($engine->getPath('main'))->toContain(rtrim(M_PATH_ROOT, '/\\')); |
24 | | -}); |
| 17 | +describe('addPath()', function () { |
| 18 | + $engine = new Engine(); |
| 19 | + |
| 20 | + test('let\'s try to add and then get several folders', function () use ($engine) { |
| 21 | + $engine->addPath('folder1', 'ns1') |
| 22 | + ->addPath('folder2', 'ns1') |
| 23 | + ->addPath(M_PATH_ROOT); |
| 24 | + expect($engine->getPath('ns1'))->toContain('folder1') |
| 25 | + ->and($engine->getPath('ns1'))->toContain('folder2') |
| 26 | + ->and($engine->getPath('main'))->toContain(rtrim(M_PATH_ROOT, '/\\')); |
| 27 | + }); |
| 28 | + |
| 29 | + it('throws an exception on adding a folder with an empty namespace', function () use ($engine) { |
| 30 | + $engine->addPath('folder', ''); |
| 31 | + })->throws(InvalidArgumentException::class, 'Namespace cannot be empty.'); |
25 | 32 |
|
26 | | -test('Ability to pass data to a template', function () use ($engine) { |
27 | | - // Share data with all templates |
28 | | - $engine->addData(['all' => 'AllTemplatesData']); |
| 33 | + it('throws an exception on adding a folder with an empty path', function () use ($engine) { |
| 34 | + $engine->addPath(''); |
| 35 | + })->throws(InvalidArgumentException::class, 'You must specify folder.'); |
| 36 | +}); |
29 | 37 |
|
30 | | - // Passing data to a specific template |
31 | | - $engine->addData(['tpl1' => 'Tpl1Data'], ['template1']); |
32 | | - $engine->addData(['tpl2' => 'Tpl2Data'], ['template2']); |
| 38 | +describe('addData()', function () { |
| 39 | + $engine = new Engine(); |
33 | 40 |
|
34 | | - expect($engine->getTemplateData()['all'])->toBe('AllTemplatesData') |
35 | | - ->and($engine->getTemplateData('template1')['tpl1'])->toBe('Tpl1Data') |
36 | | - ->and($engine->getTemplateData('template2')['tpl2'])->toBe('Tpl2Data'); |
| 41 | + test('share data with all templates', function () use ($engine) { |
| 42 | + $engine->addData(['all' => 'AllTemplatesData']); |
| 43 | + expect($engine->getTemplateData()['all'])->toBe('AllTemplatesData'); |
| 44 | + }); |
| 45 | + |
| 46 | + test('passing data to a specific template', function () use ($engine) { |
| 47 | + $engine->addData(['tpl1' => 'Tpl1Data'], ['template1']); |
| 48 | + $engine->addData(['tpl2' => 'Tpl2Data'], ['template2']); |
| 49 | + expect($engine->getTemplateData('template1')['tpl1'])->toBe('Tpl1Data') |
| 50 | + ->and($engine->getTemplateData('template2')['tpl2'])->toBe('Tpl2Data'); |
| 51 | + }); |
37 | 52 | }); |
38 | 53 |
|
39 | 54 | test('Can render template', function () use ($engine) { |
|
71 | 86 | describe('Exception handling:', function () { |
72 | 87 | $engine = new Engine(); |
73 | 88 |
|
74 | | - test('adding a folder with an empty namespace', function () use ($engine) { |
75 | | - $engine->addPath('folder', ''); |
76 | | - })->throws(InvalidArgumentException::class, 'Namespace cannot be empty.'); |
77 | | - |
78 | | - test('adding a folder with an empty path', function () use ($engine) { |
79 | | - $engine->addPath(''); |
80 | | - })->throws(InvalidArgumentException::class, 'You must specify folder.'); |
81 | | - |
82 | 89 | test('accessing a nonexistent namespace', function () use ($engine) { |
83 | 90 | $engine->getPath('name'); |
84 | 91 | })->throws(InvalidArgumentException::class, 'The template namespace "name" was not found.'); |
|
0 commit comments