Skip to content

Commit

Permalink
Add tests for selecting multiple values at a time.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jan 7, 2014
1 parent 0cb86ec commit ba54a47
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions Test/TestCase/View/Input/SelectBoxTest.php
Expand Up @@ -26,8 +26,7 @@ class SelectBoxTest extends TestCase {
public function setUp() {
parent::setUp();
$templates = [
'select' => '<select name="{{name}}" {{attrs}}>{{content}}</select>',
'selectMultiple' => '<select name="{{name}}" multiple="multiple" {{attrs}}>{{content}}</select>',
'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
'option' => '<option value="{{name}}">{{value}}</option>',
'optionSelected' => '<option value="{{name}}" selected="selected">{{value}}</option>',
'optgroup' => '<optgroup label="{{label}}">{{content}}</optgroup>',
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit ba54a47

Please sign in to comment.