public function testCanSelectMultipleElementsInMultiselects() { $select = new Select('color', array('red' => 'Red', 'blue' => 'Blue')); $expected = '<select name="color[]" multiple="multiple"><option value="red" selected>Red</option><option value="blue" selected>Blue</option></select>'; $result = $select->multiple()->select(array('red', 'blue'))->render(); $this->assertEquals($expected, $result); }
public function select($name, $options = array()) { $select = new Select($name, $options); $selected = $this->getValueFor($name); $select->select($selected); return $select; }
public function testSelectCanBeCreatedWithIntegerKeyValueOptions() { $select = new Select('color', array('0' => 'Red', '1' => 'Blue')); $expected = '<select name="color"><option value="0">Red</option><option value="1">Blue</option></select>'; $result = $select->render(); $this->assertEquals($expected, $result); $select = new Select('fruit', array('1' => 'Granny Smith', '0' => 'Blueberry')); $expected = '<select name="fruit"><option value="1">Granny Smith</option><option value="0">Blueberry</option></select>'; $result = $select->render(); $this->assertEquals($expected, $result); }
public function testSelectCanBeMultiple() { $select = new Select('people'); $expected = '<select name="people[]" multiple="multiple"></select>'; $result = $select->multiple()->render(); $this->assertEquals($expected, $result); $select = new Select('people[]'); $expected = '<select name="people[]" multiple="multiple"></select>'; $result = $select->multiple()->render(); $this->assertEquals($expected, $result); }
public function testCanMixNestedAndUnnestedOptions() { $options = array('toronto' => 'Toronto', 'london' => 'London', 'Quebec' => array('montreal' => 'Montreal', 'quebec-city' => 'Quebec City')); $select = new Select('color', $options); $expected = '<select name="color"><option value="toronto">Toronto</option><option value="london">London</option><optgroup label="Quebec"><option value="montreal">Montreal</option><option value="quebec-city">Quebec City</option></optgroup></select>'; $result = $select->render(); $this->assertEquals($expected, $result); }