public function testHasEmptyDefault() { $source = array(1 => 'one'); // Test getSource with empty $field = new DropdownField('Field', null, $source); $field->setHasEmptyDefault(true); $this->assertEquals($field->getSource(), array(1 => 'one')); // Test that an empty option comes through in the markup however $options = $this->findOptionElements($field->Field()); $this->assertEquals(2, count($options), 'Two options exist in the markup, one for the source, one for empty'); // the default value should be first $first = array_shift($options); $attrs = $first->attributes(); $this->assertNotEquals(1, $attrs['value'], 'First value is the not value (not the source value)'); // Test Field Without Empty $FieldWithoutEmpty = new DropdownField('Field', null, $source); $this->assertEquals($FieldWithoutEmpty->getSource(), array(1 => 'one')); $this->assertEquals(1, count($options), 'As hasEmptyDefault is not provided, then no default option.'); }