Skip to content

Commit 45d6989

Browse files
author
Mikaël Capelle
committed
Add test files.
1 parent 3177b84 commit 45d6989

File tree

4 files changed

+913
-0
lines changed

4 files changed

+913
-0
lines changed

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,19 @@
77
"require": {
88
"cakephp/cakephp": "~3.0"
99
},
10+
"require-dev": {
11+
"phpunit/phpunit": "*"
12+
}
1013
"autoload": {
1114
"psr-4": {
1215
"Bootstrap\\": "src"
1316
}
1417
},
18+
"autoload-dev": {
19+
"psr-4": {
20+
"Bootstrap\\Test\\": "tests"
21+
}
22+
},
1523
"extra": {
1624
"installer-name": "Bootstrap"
1725
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
namespace Bootstrap\Test\TestCase\View;
4+
5+
use Bootstrap\View\BootstrapStringTemplate;
6+
use Cake\TestSuite\TestCase;
7+
use Cake\View\View;
8+
9+
class BootstrapStringTemplateTest extends TestCase {
10+
11+
/**
12+
* Setup
13+
*
14+
* @return void
15+
*/
16+
public function setUp () {
17+
parent::setUp();
18+
$this->templater = new BootstrapStringTemplate () ;
19+
}
20+
21+
22+
/**
23+
* Tear Down
24+
*
25+
* @return void
26+
*/
27+
public function tearDown()
28+
{
29+
parent::tearDown();
30+
unset($this->templater);
31+
}
32+
33+
public function test () {
34+
$this->templater->add([
35+
'test_default' => '<p{{attrs}}>{{content}}</p>',
36+
'test_attrs_class' => '<p class="test-class {{attrs.class}}"{{attrs}}>{{content}}</p>'
37+
]) ;
38+
// Standard test
39+
$result = $this->templater->format ('test_default', [
40+
'attrs' => ' id="test-id" class="test-class"',
41+
'content' => 'Hello World!'
42+
]);
43+
$this->assertHtml([
44+
['p' => [
45+
'id' => 'test-id',
46+
'class' => 'test-class'
47+
]],
48+
'Hello World!',
49+
'/p'
50+
], $result) ;
51+
// Test with class test
52+
$result = $this->templater->format ('test_attrs_class', [
53+
'attrs' => ' id="test-id" class="test-class-2"',
54+
'content' => 'Hello World!'
55+
]);
56+
$this->assertHtml([
57+
['p' => [
58+
'id' => 'test-id',
59+
'class' => 'test-class test-class-2'
60+
]],
61+
'Hello World!',
62+
'/p'
63+
], $result) ;
64+
// Test with class test
65+
$result = $this->templater->format ('test_attrs_class', [
66+
'attrs' => 'class="test-class-2" id="test-id"',
67+
'content' => 'Hello World!'
68+
]);
69+
$this->assertHtml([
70+
['p' => [
71+
'id' => 'test-id',
72+
'class' => 'test-class test-class-2'
73+
]],
74+
'Hello World!',
75+
'/p'
76+
], $result) ;
77+
}
78+
79+
}

0 commit comments

Comments
 (0)