view = $this->getView();
$this->helper = new Zend_Dojo_View_Helper_NumberSpinner();
$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->numberSpinner(
'elementId',
'5',
array(
'smallDelta' => '10',
'min' => 9,
'max' => 1550,
'places' => 0,
'required' => true,
),
array()
);
}
public function testShouldAllowDeclarativeDijitCreation()
{
$html = $this->getElement();
$this->assertRegexp('/]*(dojoType="dijit.form.NumberSpinner")/', $html, $html);
}
public function testShouldAllowProgrammaticDijitCreation()
{
Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
$html = $this->getElement();
$this->assertNotRegexp('/]*(dojoType="dijit.form.NumberSpinner")/', $html);
$this->assertNotNull($this->view->dojo()->getDijit('elementId'));
}
public function testShouldCreateTextInput()
{
$html = $this->getElement();
$this->assertRegexp('/]*(type="text")/', $html);
}
public function testShouldJsonEncodeConstraints()
{
$html = $this->getElement();
if (!preg_match('/constraints="(.*?)(" )/', $html, $m)) {
$this->fail('Did not serialize constraints');
}
$constraints = str_replace("'", '"', $m[1]);
$constraints = Zend_Json::decode($constraints);
$this->assertTrue(is_array($constraints), var_export($m[1], 1));
$this->assertTrue(array_key_exists('min', $constraints));
$this->assertTrue(array_key_exists('max', $constraints));
$this->assertTrue(array_key_exists('places', $constraints));
}
public function testInvalidConstraintsShouldBeStrippedPriorToRendering()
{
$html = $this->helper->numberSpinner(
'foo',
5,
array (
'constraints' => 'bogus',
)
);
$this->assertNotContains('constraints="', $html);
}
}
// Call Zend_Dojo_View_Helper_NumberSpinnerTest::main() if this source file is executed directly.
if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_NumberSpinnerTest::main") {
Zend_Dojo_View_Helper_NumberSpinnerTest::main();
}