From ba54a4789f1f9e6bde0f4de5b7f746e9a43a6444 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 6 Jan 2014 23:09:33 -0500 Subject: [PATCH] Add tests for selecting multiple values at a time. --- Test/TestCase/View/Input/SelectBoxTest.php | 51 ++++++++++++++++++++-- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/Test/TestCase/View/Input/SelectBoxTest.php b/Test/TestCase/View/Input/SelectBoxTest.php index 10e51614901..7edda3c492b 100644 --- a/Test/TestCase/View/Input/SelectBoxTest.php +++ b/Test/TestCase/View/Input/SelectBoxTest.php @@ -26,8 +26,7 @@ class SelectBoxTest extends TestCase { public function setUp() { parent::setUp(); $templates = [ - 'select' => '', - 'selectMultiple' => '', + 'select' => '', 'option' => '', 'optionSelected' => '', 'optgroup' => '{{content}}', @@ -126,7 +125,25 @@ public function testRenderSelected() { * @return void */ public function testRenderMultipleSelect() { - $this->markTestIncomplete('Not done'); + $select = new SelectBox($this->templates); + $data = [ + 'id' => 'BirdName', + 'name' => 'Birds[name]', + 'multiple' => true, + 'options' => ['a' => 'Albatross', 'b' => 'Budgie'] + ]; + $result = $select->render($data); + $expected = [ + 'select' => [ + 'name' => 'Birds[name]', + 'id' => 'BirdName', + 'multiple' => 'multiple', + ], + ['option' => ['value' => 'a']], 'Albatross', '/option', + ['option' => ['value' => 'b']], 'Budgie', '/option', + '/select' + ]; + $this->assertTags($result, $expected); } /** @@ -135,7 +152,33 @@ public function testRenderMultipleSelect() { * @return void */ public function testRenderMultipleSelected() { - $this->markTestIncomplete('Not done'); + $select = new SelectBox($this->templates); + $data = [ + 'multiple' => true, + 'id' => 'BirdName', + 'name' => 'Birds[name]', + 'value' => ['1', '2', 'burp'], + 'options' => [ + 1 => 'one', + '1x' => 'one x', + '2' => 'two', + '2x' => 'two x', + ] + ]; + $result = $select->render($data); + $expected = [ + 'select' => [ + 'name' => 'Birds[name]', + 'multiple' => 'multiple', + 'id' => 'BirdName' + ], + ['option' => ['value' => '1', 'selected' => 'selected']], 'one', '/option', + ['option' => ['value' => '1x']], 'one x', '/option', + ['option' => ['value' => '2', 'selected' => 'selected']], 'two', '/option', + ['option' => ['value' => '2x']], 'two x', '/option', + '/select' + ]; + $this->assertTags($result, $expected); } /**