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