view = $this->getView();
$this->helper = new Zend_Dojo_View_Helper_CheckBox();
$this->helper->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()
{
return $this->helper->checkBox(
'elementId',
'foo',
array(),
array(),
array(
'checked' => 'foo',
'unChecked' => 'bar',
)
);
}
public function testShouldAllowDeclarativeDijitCreation()
{
$html = $this->getElement();
$this->assertRegexp('/]*(dojoType="dijit.form.CheckBox")/', $html, $html);
}
public function testShouldAllowProgrammaticDijitCreation()
{
Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
$html = $this->getElement();
$this->assertNotRegexp('/]*(dojoType="dijit.form.CheckBox")/', $html);
$this->assertNotNull($this->view->dojo()->getDijit('elementId'));
}
public function testShouldCreateHiddenElementWithUncheckedValue()
{
$html = $this->getElement();
if (!preg_match('/(]*(type="hidden")[^>]*>)/s', $html, $m)) {
$this->fail('Missing hidden element with unchecked value');
}
$this->assertContains('value="bar"', $m[1]);
}
public function testShouldCheckElementWhenValueMatchesCheckedValue()
{
$html = $this->getElement();
if (!preg_match('/(]*(type="checkbox")[^>]*>)/s', $html, $m)) {
$this->fail('Missing checkbox element: ' . $html);
}
$this->assertContains('checked="checked"', $m[1]);
}
/**
* @see ZF-4006
* @group ZF-4006
*/
public function testElementShouldUseCheckedValueForCheckboxInput()
{
$html = $this->helper->checkBox('foo', '0', array(), array(), array(
'checkedValue' => '1',
'unCheckedValue' => '0',
));
if (!preg_match('#(]*(?:type="checkbox")[^>]*>)#s', $html, $matches)) {
$this->fail('Did not find checkbox in html: ' . $html);
}
$this->assertContains('value="1"', $matches[1]);
$this->assertNotContains('checked', $matches[1]);
}
/**
* @group ZF-3878
*/
public function testElementShouldCreateAppropriateIdWhenNameIncludesArrayNotation()
{
$html = $this->helper->checkBox('foo[bar]', '0');
$this->assertContains('id="foo-bar"', $html);
}
}
// Call Zend_Dojo_View_Helper_CheckBoxTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_CheckBoxTest::main") {
Zend_Dojo_View_Helper_CheckBoxTest::main();
}