ComboBoxTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Dojo
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_Dojo_Form_Element_ComboBoxTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_Element_ComboBoxTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_Form_Element_ComboBox */
  28. require_once 'Zend/Dojo/Form/Element/ComboBox.php';
  29. /** Zend_View */
  30. require_once 'Zend/View.php';
  31. /** Zend_Registry */
  32. require_once 'Zend/Registry.php';
  33. /** Zend_Dojo_View_Helper_Dojo */
  34. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  35. /**
  36. * Test class for Zend_Dojo_Form_Element_ComboBox.
  37. *
  38. * @category Zend
  39. * @package Zend_Dojo
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. * @group Zend_Dojo
  44. * @group Zend_Dojo_Form
  45. */
  46. class Zend_Dojo_Form_Element_ComboBoxTest extends PHPUnit_Framework_TestCase
  47. {
  48. /**
  49. * Runs the test methods of this class.
  50. *
  51. * @return void
  52. */
  53. public static function main()
  54. {
  55. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_Element_ComboBoxTest");
  56. $result = PHPUnit_TextUI_TestRunner::run($suite);
  57. }
  58. /**
  59. * Sets up the fixture, for example, open a network connection.
  60. * This method is called before a test is executed.
  61. *
  62. * @return void
  63. */
  64. public function setUp()
  65. {
  66. Zend_Registry::_unsetInstance();
  67. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  68. $this->view = $this->getView();
  69. $this->element = $this->getElement();
  70. $this->element->setView($this->view);
  71. }
  72. /**
  73. * Tears down the fixture, for example, close a network connection.
  74. * This method is called after a test is executed.
  75. *
  76. * @return void
  77. */
  78. public function tearDown()
  79. {
  80. }
  81. public function getView()
  82. {
  83. require_once 'Zend/View.php';
  84. $view = new Zend_View();
  85. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  86. return $view;
  87. }
  88. public function getElement()
  89. {
  90. $element = new Zend_Dojo_Form_Element_ComboBox(
  91. 'foo',
  92. array(
  93. 'label' => 'ComboBox',
  94. )
  95. );
  96. return $element;
  97. }
  98. public function testSettingStoreIdShouldProxyToStoreDijitParam()
  99. {
  100. $this->element->setStoreId('someStore');
  101. $this->assertTrue($this->element->hasDijitParam('store'));
  102. $store = $this->element->getDijitParam('store');
  103. $this->assertTrue(array_key_exists('store', $store));
  104. $this->assertEquals('someStore', $store['store']);
  105. $this->assertEquals($this->element->getStoreId(), $store['store']);
  106. }
  107. public function testSettingStoreTypeShouldProxyToStoreDijitParam()
  108. {
  109. $this->element->setStoreType('dojo.data.ItemFileReadStore');
  110. $this->assertTrue($this->element->hasDijitParam('store'));
  111. $store = $this->element->getDijitParam('store');
  112. $this->assertTrue(array_key_exists('type', $store));
  113. $this->assertEquals('dojo.data.ItemFileReadStore', $store['type']);
  114. $this->assertEquals($this->element->getStoreType(), $store['type']);
  115. }
  116. public function testSettingStoreParamsShouldProxyToStoreDijitParam()
  117. {
  118. $this->element->setStoreParams(array('url' => '/js/foo.json'));
  119. $this->assertTrue($this->element->hasDijitParam('store'));
  120. $store = $this->element->getDijitParam('store');
  121. $this->assertTrue(array_key_exists('params', $store));
  122. $this->assertEquals(array('url' => '/js/foo.json'), $store['params']);
  123. $this->assertEquals($this->element->getStoreParams(), $store['params']);
  124. }
  125. public function testAutocompleteAccessorsShouldProxyToDijitParams()
  126. {
  127. $this->assertFalse($this->element->getAutocomplete());
  128. $this->assertFalse(array_key_exists('autocomplete', $this->element->dijitParams));
  129. $this->element->setAutocomplete(true);
  130. $this->assertTrue($this->element->getAutocomplete());
  131. $this->assertTrue(array_key_exists('autocomplete', $this->element->dijitParams));
  132. }
  133. /**#@+
  134. * @see ZF-3286
  135. */
  136. public function testShouldNeverRegisterInArrayValidatorAutomatically()
  137. {
  138. $options = array(
  139. 'foo' => 'Foo Value',
  140. 'bar' => 'Bar Value',
  141. 'baz' => 'Baz Value',
  142. );
  143. $this->element->setMultiOptions($options);
  144. $this->assertFalse($this->element->getValidator('InArray'));
  145. $this->element->isValid('test');
  146. $this->assertFalse($this->element->getValidator('InArray'));
  147. }
  148. /**#@-*/
  149. public function testShouldRenderComboBoxDijit()
  150. {
  151. $html = $this->element->render();
  152. $this->assertContains('dojoType="dijit.form.ComboBox"', $html);
  153. }
  154. /**
  155. * @group ZF-7134
  156. * @group ZF-7266
  157. */
  158. public function testComboBoxInSubFormShouldCreateJsonStoreBasedOnQualifiedId()
  159. {
  160. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  161. $this->element->setStoreId('foo')
  162. ->setStoreType('dojo.data.ItemFileReadStore')
  163. ->setStoreParams(array(
  164. 'url' => '/foo',
  165. ));
  166. include_once 'Zend/Form/SubForm.php';
  167. $subform = new Zend_Form_SubForm(array('name' => 'bar'));
  168. $subform->addElement($this->element);
  169. $html = $this->element->render();
  170. $dojo = $this->view->dojo()->__toString();
  171. $this->assertContains('"store":"foo"', $dojo, $dojo);
  172. }
  173. }
  174. // Call Zend_Dojo_Form_Element_ComboBoxTest::main() if this source file is executed directly.
  175. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_Element_ComboBoxTest::main") {
  176. Zend_Dojo_Form_Element_ComboBoxTest::main();
  177. }