Browse Source

Add templateVars tests for button, checkbox, file and label widgets.

Add tests to ensure the templateVars option is wired up.
Mark Story 10 years ago
parent
commit
5b98a4ca1d

+ 28 - 0
tests/TestCase/View/Widget/ButtonWidgetTest.php

@@ -128,4 +128,32 @@ class ButtonWidgetTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
+
+    /**
+     * Ensure templateVars option is hooked up.
+     *
+     * @return void
+     */
+    public function testRenderTemplateVars()
+    {
+        $this->templates->add([
+            'button' => '<button {{attrs}} custom="{{custom}}">{{text}}</button>',
+        ]);
+
+        $button = new ButtonWidget($this->templates);
+        $data = [
+            'templateVars' => ['custom' => 'value'],
+            'text' => 'Go',
+        ];
+        $result = $button->render($data, $this->context);
+        $expected = [
+            'button' => [
+                'type' => 'submit',
+                'custom' => 'value'
+            ],
+            'Go',
+            '/button'
+        ];
+        $this->assertHtml($expected, $result);
+    }
 }

+ 29 - 0
tests/TestCase/View/Widget/CheckboxWidgetTest.php

@@ -233,4 +233,33 @@ class CheckboxWidgetTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
+
+    /**
+     * Ensure templateVars option is hooked up.
+     *
+     * @return void
+     */
+    public function testRenderTemplateVars()
+    {
+        $this->templates->add([
+            'checkbox' => '<input type="checkbox" custom="{{custom}}" name="{{name}}" value="{{value}}"{{attrs}}>',
+        ]);
+
+        $checkbox = new CheckboxWidget($this->templates);
+        $data = [
+            'templateVars' => ['custom' => 'value'],
+            'name' => 'Comment[spam]',
+            'value' => 1,
+        ];
+        $result = $checkbox->render($data, $this->context);
+        $expected = [
+            'input' => [
+                'type' => 'checkbox',
+                'custom' => 'value',
+                'name' => 'Comment[spam]',
+                'value' => 1,
+            ]
+        ];
+        $this->assertHtml($expected, $result);
+    }
 }

+ 27 - 0
tests/TestCase/View/Widget/FileWidgetTest.php

@@ -69,4 +69,31 @@ class FileWidgetTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
+
+    /**
+     * Ensure templateVars option is hooked up.
+     *
+     * @return void
+     */
+    public function testRenderTemplateVars()
+    {
+        $this->templates->add([
+            'file' => '<input custom="{{custom}}" type="file" name="{{name}}"{{attrs}}>',
+        ]);
+
+        $input = new FileWidget($this->templates);
+        $data = [
+            'templateVars' => ['custom' => 'value'],
+            'name' => 'files',
+        ];
+        $result = $input->render($data, $this->context);
+        $expected = [
+            'input' => [
+                'type' => 'file',
+                'name' => 'files',
+                'custom' => 'value'
+            ],
+        ];
+        $this->assertHtml($expected, $result);
+    }
 }

+ 25 - 0
tests/TestCase/View/Widget/LabelWidgetTest.php

@@ -103,4 +103,29 @@ class LabelWidgetTest extends TestCase
         ];
         $this->assertHtml($expected, $result);
     }
+
+    /**
+     * Ensure templateVars option is hooked up.
+     *
+     * @return void
+     */
+    public function testRenderTemplateVars()
+    {
+        $this->templates->add([
+            'label' => '<label custom="{{custom}}" {{attrs}}>{{text}}</label>',
+        ]);
+
+        $label = new LabelWidget($this->templates);
+        $data = [
+            'templateVars' => ['custom' => 'value'],
+            'text' => 'Label Text',
+        ];
+        $result = $label->render($data, $this->context);
+        $expected = [
+            'label' => ['custom' => 'value'],
+            'Label Text',
+            '/label'
+        ];
+        $this->assertHtml($expected, $result);
+    }
 }