DojoTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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-2015 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_FormTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_DojoTest::main");
  25. }
  26. /** Zend_Dojo */
  27. require_once 'Zend/Dojo.php';
  28. /** Zend_Form */
  29. require_once 'Zend/Form.php';
  30. /** Zend_Form_Element */
  31. require_once 'Zend/Form/Element.php';
  32. /** Zend_Form_SubForm */
  33. require_once 'Zend/Form/SubForm.php';
  34. /** Zend_View */
  35. require_once 'Zend/View.php';
  36. /**
  37. * Test class for Zend_Dojo
  38. *
  39. * @category Zend
  40. * @package Zend_Date
  41. * @subpackage UnitTests
  42. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  43. * @license http://framework.zend.com/license/new-bsd New BSD License
  44. * @group Zend_Dojo
  45. */
  46. class Zend_Dojo_DojoTest 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_DojoTest");
  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. }
  67. /**
  68. * Tears down the fixture, for example, close a network connection.
  69. * This method is called after a test is executed.
  70. *
  71. * @return void
  72. */
  73. public function tearDown()
  74. {
  75. }
  76. public function getForm()
  77. {
  78. $form = new Zend_Form();
  79. $form->addElement('text', 'foo')
  80. ->addElement('text', 'bar')
  81. ->addElement('text', 'baz')
  82. ->addElement('text', 'bat');
  83. $subForm = new Zend_Form_SubForm();
  84. $subForm->addElement('text', 'foo')
  85. ->addElement('text', 'bar')
  86. ->addElement('text', 'baz')
  87. ->addElement('text', 'bat');
  88. $form->addDisplayGroup(array('foo', 'bar'), 'foobar')
  89. ->addSubForm($subForm, 'sub')
  90. ->setView(new Zend_View);
  91. return $form;
  92. }
  93. public function testEnableFormShouldSetAppropriateDecoratorAndElementPaths()
  94. {
  95. $form = $this->getForm();
  96. Zend_Dojo::enableForm($form);
  97. $decPluginLoader = $form->getPluginLoader('decorator');
  98. $paths = $decPluginLoader->getPaths('Zend_Dojo_Form_Decorator');
  99. $this->assertTrue(is_array($paths));
  100. $elPluginLoader = $form->getPluginLoader('element');
  101. $paths = $elPluginLoader->getPaths('Zend_Dojo_Form_Element');
  102. $this->assertTrue(is_array($paths));
  103. $decPluginLoader = $form->baz->getPluginLoader('decorator');
  104. $paths = $decPluginLoader->getPaths('Zend_Dojo_Form_Decorator');
  105. $this->assertTrue(is_array($paths));
  106. $decPluginLoader = $form->foobar->getPluginLoader();
  107. $paths = $decPluginLoader->getPaths('Zend_Dojo_Form_Decorator');
  108. $this->assertTrue(is_array($paths));
  109. $decPluginLoader = $form->sub->getPluginLoader('decorator');
  110. $paths = $decPluginLoader->getPaths('Zend_Dojo_Form_Decorator');
  111. $this->assertTrue(is_array($paths));
  112. $elPluginLoader = $form->sub->getPluginLoader('element');
  113. $paths = $elPluginLoader->getPaths('Zend_Dojo_Form_Element');
  114. $this->assertTrue(is_array($paths));
  115. }
  116. public function testEnableFormShouldSetAppropriateDefaultDisplayGroup()
  117. {
  118. $form = $this->getForm();
  119. Zend_Dojo::enableForm($form);
  120. $this->assertEquals('Zend_Dojo_Form_DisplayGroup', $form->getDefaultDisplayGroupClass());
  121. }
  122. public function testEnableFormShouldSetAppropriateViewHelperPaths()
  123. {
  124. $form = $this->getForm();
  125. Zend_Dojo::enableForm($form);
  126. $view = $form->getView();
  127. $helperLoader = $view->getPluginLoader('helper');
  128. $paths = $helperLoader->getPaths('Zend_Dojo_View_Helper');
  129. $this->assertTrue(is_array($paths));
  130. }
  131. public function testEnableViewShouldSetAppropriateViewHelperPaths()
  132. {
  133. $view = new Zend_View;
  134. Zend_Dojo::enableView($view);
  135. $helperLoader = $view->getPluginLoader('helper');
  136. $paths = $helperLoader->getPaths('Zend_Dojo_View_Helper');
  137. $this->assertTrue(is_array($paths));
  138. }
  139. }
  140. // Call Zend_Dojo_DojoTest::main() if this source file is executed directly.
  141. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_DojoTest::main") {
  142. Zend_Dojo_DojoTest::main();
  143. }