1+ <?php
2+
3+ namespace Bootstrap \Test \TestCase \View \Helper ;
4+
5+ use Bootstrap \View \Helper \BootstrapTrait ;
6+ use Bootstrap \View \Helper \BootstrapFormHelper ;
7+ use Bootstrap \View \Helper \BootstrapHtmlHelper ;
8+ use Bootstrap \View \Helper \BootstrapPaginatorHelper ;
9+ use Cake \TestSuite \TestCase ;
10+ use Cake \View \View ;
11+
12+ class PublicBootstrapTrait {
13+
14+ use BootstrapTrait ;
15+
16+ public function __construct ($ View ) {
17+ $ this ->_View = $ View ;
18+ }
19+
20+ public function publicEasyIcon ($ callback , $ title , $ options ) {
21+ return $ this ->_easyIcon ($ callback , $ title , $ options );
22+ }
23+
24+ };
25+
26+ class BootstrapTraitTemplateTest extends TestCase {
27+
28+ /**
29+ * Setup
30+ *
31+ * @return void
32+ */
33+ public function setUp () {
34+ parent ::setUp ();
35+ $ this ->View = new View ();
36+ $ this ->_Trait = new PublicBootstrapTrait ($ this ->View );
37+ $ this ->View ->Html = new BootstrapHtmlHelper ($ this ->View );
38+ $ this ->Form = new BootstrapFormHelper ($ this ->View );
39+ $ this ->Paginator = new BootstrapPaginatorHelper ($ this ->View );
40+ }
41+
42+
43+ /**
44+ * Tear Down
45+ *
46+ * @return void
47+ */
48+ public function tearDown () {
49+ parent ::tearDown ();
50+ unset($ this ->View ->Html );
51+ unset($ this ->View );
52+ unset($ this ->Form );
53+ unset($ this ->Paginator );
54+ }
55+
56+ public function testEasyIcon () {
57+
58+ $ that = $ this ;
59+ $ callback = function ($ text , $ options ) use ($ that ) {
60+ $ that ->assertEquals (isset ($ options ['escape ' ]) ? $ options ['escape ' ] : true , $ options ['expected ' ]['escape ' ]);
61+ $ that ->assertHtml ($ options ['expected ' ]['result ' ], $ text );
62+ };
63+
64+ $ this ->_Trait ->publicEasyIcon ($ callback , 'i:plus ' , [
65+ 'expected ' => [
66+ 'escape ' => false ,
67+ 'result ' => [['i ' => [
68+ 'class ' => 'glyphicon glyphicon-plus '
69+ ]], '/i ' ]
70+ ]
71+ ]);
72+
73+ $ this ->_Trait ->publicEasyIcon ($ callback , 'Click Me! ' , [
74+ 'expected ' => [
75+ 'escape ' => true ,
76+ 'result ' => 'Click Me! '
77+ ]
78+ ]);
79+
80+ $ this ->_Trait ->publicEasyIcon ($ callback , 'i:plus Add ' , [
81+ 'expected ' => [
82+ 'escape ' => false ,
83+ 'result ' => [['i ' => [
84+ 'class ' => 'glyphicon glyphicon-plus '
85+ ]], '/i ' , ' Add ' ]
86+ ]
87+ ]);
88+
89+ $ this ->_Trait ->publicEasyIcon ($ callback , 'Add i:plus ' , [
90+ 'expected ' => [
91+ 'escape ' => false ,
92+ 'result ' => ['Add ' , ['i ' => [
93+ 'class ' => 'glyphicon glyphicon-plus '
94+ ]], '/i ' ]
95+ ]
96+ ]);
97+
98+ $ this ->_Trait ->easyIcon = false ;
99+ $ this ->_Trait ->publicEasyIcon ($ callback , 'i:plus ' , [
100+ 'expected ' => [
101+ 'escape ' => true ,
102+ 'result ' => 'i:plus '
103+ ]
104+ ]);
105+
106+ }
107+
108+ public function testHelperMethods () {
109+
110+ // BootstrapPaginatorHelper - TODO
111+ // BootstrapPaginatorHelper::prev($title, array $options = []);
112+ // BootstrapPaginatorHelper::next($title, array $options = []);
113+ // BootstrapPaginatorHelper::numbers(array $options = []); // For `prev` and `next` options.
114+
115+ // BootstrapFormatHelper
116+ $ result = $ this ->Form ->button ('i:plus ' ) ;
117+ $ this ->assertHtml ([
118+ ['button ' => [
119+ 'class ' => 'btn btn-default ' ,
120+ 'type ' => 'submit '
121+ ]], ['i ' => [
122+ 'class ' => 'glyphicon glyphicon-plus '
123+ ]], '/i ' , '/button '
124+ ], $ result ) ;
125+ $ result = $ this ->Form ->input ('fieldname ' , [
126+ 'prepend ' => 'i:home ' ,
127+ 'append ' => 'i:plus ' ,
128+ 'label ' => false
129+ ]) ;
130+ $ this ->assertHtml ([
131+ ['div ' => [
132+ 'class ' => 'form-group text '
133+ ]],
134+ ['div ' => [
135+ 'class ' => 'input-group '
136+ ]],
137+ ['span ' => [
138+ 'class ' => 'input-group-addon '
139+ ]],
140+ ['i ' => ['class ' => 'glyphicon glyphicon-home ' ]], '/i ' ,
141+ '/span ' ,
142+ ['input ' => [
143+ 'type ' => 'text ' ,
144+ 'class ' => 'form-control ' ,
145+ 'name ' => 'fieldname ' ,
146+ 'id ' => 'fieldname '
147+ ]],
148+ ['span ' => [
149+ 'class ' => 'input-group-addon '
150+ ]],
151+ ['i ' => ['class ' => 'glyphicon glyphicon-plus ' ]], '/i ' ,
152+ '/span ' ,
153+ '/div ' ,
154+ '/div '
155+ ], $ result ) ;
156+ //BootstrapFormHelper::prepend($input, $prepend); // For $prepend.
157+ //BootstrapFormHelper::append($input, $append); // For $append.
158+ }
159+
160+ };
0 commit comments