view = $this->getView();
$this->element = $this->getElement();
$this->element->setView($this->view);
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @return void
*/
public function tearDown()
{
}
public function getView()
{
require_once 'Zend/View.php';
$view = new Zend_View();
$view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
return $view;
}
public function getElement()
{
$element = new Zend_Dojo_Form_Element_RadioButton(
'foo',
array(
'value' => 'bar',
'label' => 'RadioButton',
'class' => 'someclass',
'style' => 'width: 100px;',
'multiOptions' => array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz',
),
)
);
return $element;
}
public function testShouldAllowSpecifyingSeparatorText()
{
$this->element->setSeparator('
');
$this->assertEquals('
', $this->element->getSeparator());
}
public function testAddingAnOptionShouldResetOptionsToArrayIfScalar()
{
$this->element->options = 'foo';
$this->element->addMultiOption('bar', 'baz');
$this->assertTrue(is_array($this->element->options));
}
public function testAddMultiOptionsShouldPassKeyValueArraysAsIndividualOptions()
{
$this->element->addMultiOptions(array(
array('key' => 'foo', 'value' => 'bar'),
array('key' => 'bar', 'value' => 'baz'),
));
$this->assertEquals('bar', $this->element->getMultiOption('foo'));
$this->assertEquals('baz', $this->element->getMultiOption('bar'));
}
public function testShouldAllowRemovingIndividualOptions()
{
$this->element->removeMultiOption('bar');
$this->assertNull($this->element->getMultiOption('bar'));
}
public function testOptionsShouldBeTranslatable()
{
require_once 'Zend/Translate.php';
$translations = array(
'Foo' => 'This is Foo',
'Bar' => 'This is Bar',
'Baz' => 'This is Baz',
);
$translate = new Zend_Translate('array', $translations, 'en');
$this->element->setTranslator($translate);
$this->element->setMultiOptions(array(
'foo' => 'Foo',
'bar' => 'Bar',
'baz' => 'Baz',
));
$html = $this->element->render();
foreach ($translations as $string) {
$this->assertContains($string, $html, $html);
}
}
public function testShouldRenderRadioButtonDijit()
{
$html = $this->element->render();
$this->assertContains('dojoType="dijit.form.RadioButton"', $html);
}
public function testPassingValueShouldMarkThatValueCheckedWhenRendering()
{
$html = $this->element->render();
if (!preg_match('/(]*(id="foo-bar")[^>]*>)/', $html, $matches)) {
$this->fail('Did not find radio option matching bar');
}
$this->assertContains('checked="checked"', $matches[1]);
}
/**#+
* @group ZF-3286
*/
public function testShouldRegisterInArrayValidatorByDefault()
{
$this->assertTrue($this->element->registerInArrayValidator());
}
public function testShouldAllowSpecifyingWhetherOrNotToUseInArrayValidator()
{
$this->testShouldRegisterInArrayValidatorByDefault();
$this->element->setRegisterInArrayValidator(false);
$this->assertFalse($this->element->registerInArrayValidator());
$this->element->setRegisterInArrayValidator(true);
$this->assertTrue($this->element->registerInArrayValidator());
}
public function testInArrayValidatorShouldBeRegisteredAfterValidation()
{
$options = array(
'foo' => 'Foo Value',
'bar' => 'Bar Value',
'baz' => 'Baz Value',
);
$this->element->setMultiOptions($options);
$this->assertFalse($this->element->getValidator('InArray'));
$this->element->isValid('test');
$validator = $this->element->getValidator('InArray');
$this->assertTrue($validator instanceof Zend_Validate_InArray);
}
public function testShouldNotValidateIfValueIsNotInArray()
{
$options = array(
'foo' => 'Foo Value',
'bar' => 'Bar Value',
'baz' => 'Baz Value',
);
$this->element->setMultiOptions($options);
$this->assertFalse($this->element->getValidator('InArray'));
$this->assertFalse($this->element->isValid('test'));
}
/**#@-*/
}
// Call Zend_Dojo_Form_Element_RadioButtonTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_RadioButtonTest::main") {
Zend_Dojo_Form_Element_RadioButtonTest::main();
}