ソースを参照

Add tests for activeClass template variable

Refs #10564
Mark Story 8 年 前
コミット
657973f8a2
1 ファイル変更43 行追加0 行削除
  1. 43 0
      tests/TestCase/View/Widget/RadioWidgetTest.php

+ 43 - 0
tests/TestCase/View/Widget/RadioWidgetTest.php

@@ -153,6 +153,49 @@ class RadioWidgetTest extends TestCase
     }
 
     /**
+     * Test rendering the activeClass template var
+     *
+     * @return void
+     */
+    public function testRenderSimpleActiveTemplateVar()
+    {
+        $this->templates->add([
+            'nestingLabel' => '<label class="{{activeClass}}"{{attrs}}>{{text}}</label>',
+            'radioWrapper' => '{{input}}{{label}}'
+        ]);
+        $label = new NestingLabelWidget($this->templates);
+        $radio = new RadioWidget($this->templates, $label);
+        $data = [
+            'name' => 'Crayons[color]',
+            'val' => 'r',
+            'options' => ['r' => 'Red', 'b' => 'Black']
+        ];
+        $result = $radio->render($data, $this->context);
+        $expected = [
+            ['input' => [
+                'type' => 'radio',
+                'name' => 'Crayons[color]',
+                'value' => 'r',
+                'id' => 'crayons-color-r',
+                'checked' => 'checked',
+            ]],
+            ['label' => ['class' => 'active', 'for' => 'crayons-color-r']],
+            'Red',
+            '/label',
+            ['input' => [
+                'type' => 'radio',
+                'name' => 'Crayons[color]',
+                'value' => 'b',
+                'id' => 'crayons-color-b'
+            ]],
+            ['label' => ['class' => '', 'for' => 'crayons-color-b']],
+            'Black',
+            '/label',
+        ];
+        $this->assertHtml($expected, $result);
+    }
+
+    /**
      * Test rendering inputs with the complex option form.
      *
      * @return void