DojoTest.php 5.2 KB

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