File tree Expand file tree Collapse file tree 4 files changed +109
-0
lines changed
tests/TestCase/View/Widget Expand file tree Collapse file tree 4 files changed +109
-0
lines changed Original file line number Diff line number Diff line change @@ -128,4 +128,32 @@ public function testRenderAttributes()
128
128
];
129
129
$ this ->assertHtml ($ expected , $ result );
130
130
}
131
+
132
+ /**
133
+ * Ensure templateVars option is hooked up.
134
+ *
135
+ * @return void
136
+ */
137
+ public function testRenderTemplateVars ()
138
+ {
139
+ $ this ->templates ->add ([
140
+ 'button ' => '<button {{attrs}} custom="{{custom}}">{{text}}</button> ' ,
141
+ ]);
142
+
143
+ $ button = new ButtonWidget ($ this ->templates );
144
+ $ data = [
145
+ 'templateVars ' => ['custom ' => 'value ' ],
146
+ 'text ' => 'Go ' ,
147
+ ];
148
+ $ result = $ button ->render ($ data , $ this ->context );
149
+ $ expected = [
150
+ 'button ' => [
151
+ 'type ' => 'submit ' ,
152
+ 'custom ' => 'value '
153
+ ],
154
+ 'Go ' ,
155
+ '/button '
156
+ ];
157
+ $ this ->assertHtml ($ expected , $ result );
158
+ }
131
159
}
Original file line number Diff line number Diff line change @@ -233,4 +233,33 @@ public function testRenderUnCheckedValue($checked)
233
233
];
234
234
$ this ->assertHtml ($ expected , $ result );
235
235
}
236
+
237
+ /**
238
+ * Ensure templateVars option is hooked up.
239
+ *
240
+ * @return void
241
+ */
242
+ public function testRenderTemplateVars ()
243
+ {
244
+ $ this ->templates ->add ([
245
+ 'checkbox ' => '<input type="checkbox" custom="{{custom}}" name="{{name}}" value="{{value}}"{{attrs}}> ' ,
246
+ ]);
247
+
248
+ $ checkbox = new CheckboxWidget ($ this ->templates );
249
+ $ data = [
250
+ 'templateVars ' => ['custom ' => 'value ' ],
251
+ 'name ' => 'Comment[spam] ' ,
252
+ 'value ' => 1 ,
253
+ ];
254
+ $ result = $ checkbox ->render ($ data , $ this ->context );
255
+ $ expected = [
256
+ 'input ' => [
257
+ 'type ' => 'checkbox ' ,
258
+ 'custom ' => 'value ' ,
259
+ 'name ' => 'Comment[spam] ' ,
260
+ 'value ' => 1 ,
261
+ ]
262
+ ];
263
+ $ this ->assertHtml ($ expected , $ result );
264
+ }
236
265
}
Original file line number Diff line number Diff line change @@ -69,4 +69,31 @@ public function testRenderAttributes()
69
69
];
70
70
$ this ->assertHtml ($ expected , $ result );
71
71
}
72
+
73
+ /**
74
+ * Ensure templateVars option is hooked up.
75
+ *
76
+ * @return void
77
+ */
78
+ public function testRenderTemplateVars ()
79
+ {
80
+ $ this ->templates ->add ([
81
+ 'file ' => '<input custom="{{custom}}" type="file" name="{{name}}"{{attrs}}> ' ,
82
+ ]);
83
+
84
+ $ input = new FileWidget ($ this ->templates );
85
+ $ data = [
86
+ 'templateVars ' => ['custom ' => 'value ' ],
87
+ 'name ' => 'files ' ,
88
+ ];
89
+ $ result = $ input ->render ($ data , $ this ->context );
90
+ $ expected = [
91
+ 'input ' => [
92
+ 'type ' => 'file ' ,
93
+ 'name ' => 'files ' ,
94
+ 'custom ' => 'value '
95
+ ],
96
+ ];
97
+ $ this ->assertHtml ($ expected , $ result );
98
+ }
72
99
}
Original file line number Diff line number Diff line change @@ -103,4 +103,29 @@ public function testRenderAttributes()
103
103
];
104
104
$ this ->assertHtml ($ expected , $ result );
105
105
}
106
+
107
+ /**
108
+ * Ensure templateVars option is hooked up.
109
+ *
110
+ * @return void
111
+ */
112
+ public function testRenderTemplateVars ()
113
+ {
114
+ $ this ->templates ->add ([
115
+ 'label ' => '<label custom="{{custom}}" {{attrs}}>{{text}}</label> ' ,
116
+ ]);
117
+
118
+ $ label = new LabelWidget ($ this ->templates );
119
+ $ data = [
120
+ 'templateVars ' => ['custom ' => 'value ' ],
121
+ 'text ' => 'Label Text ' ,
122
+ ];
123
+ $ result = $ label ->render ($ data , $ this ->context );
124
+ $ expected = [
125
+ 'label ' => ['custom ' => 'value ' ],
126
+ 'Label Text ' ,
127
+ '/label '
128
+ ];
129
+ $ this ->assertHtml ($ expected , $ result );
130
+ }
106
131
}
You can’t perform that action at this time.
0 commit comments