FormTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // Call Zend_Dojo_Form_FormTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_Form_FormTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. /** Zend_Dojo_Form */
  8. require_once 'Zend/Dojo/Form.php';
  9. /** Zend_View */
  10. require_once 'Zend/View.php';
  11. /**
  12. * Test class for Zend_Dojo_Form and Zend_Dojo_Form_DisplayGroup
  13. */
  14. class Zend_Dojo_Form_FormTest extends PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * Runs the test methods of this class.
  18. *
  19. * @return void
  20. */
  21. public static function main()
  22. {
  23. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_Form_FormTest");
  24. $result = PHPUnit_TextUI_TestRunner::run($suite);
  25. }
  26. /**
  27. * Sets up the fixture, for example, open a network connection.
  28. * This method is called before a test is executed.
  29. *
  30. * @return void
  31. */
  32. public function setUp()
  33. {
  34. $this->form = new Zend_Dojo_Form();
  35. $this->form->addElement('TextBox', 'foo')
  36. ->addDisplayGroup(array('foo'), 'dg')
  37. ->setView(new Zend_View());
  38. }
  39. /**
  40. * Tears down the fixture, for example, close a network connection.
  41. * This method is called after a test is executed.
  42. *
  43. * @return void
  44. */
  45. public function tearDown()
  46. {
  47. }
  48. public function testDojoFormDecoratorPathShouldBeRegisteredByDefault()
  49. {
  50. $paths = $this->form->getPluginLoader('decorator')->getPaths('Zend_Dojo_Form_Decorator');
  51. $this->assertTrue(is_array($paths));
  52. }
  53. public function testDojoFormElementPathShouldBeRegisteredByDefault()
  54. {
  55. $paths = $this->form->getPluginLoader('element')->getPaths('Zend_Dojo_Form_Element');
  56. $this->assertTrue(is_array($paths));
  57. }
  58. public function testDojoFormElementDecoratorPathShouldBeRegisteredByDefault()
  59. {
  60. $paths = $this->form->foo->getPluginLoader('decorator')->getPaths('Zend_Dojo_Form_Decorator');
  61. $this->assertTrue(is_array($paths));
  62. }
  63. public function testDojoFormDisplayGroupDecoratorPathShouldBeRegisteredByDefault()
  64. {
  65. $paths = $this->form->dg->getPluginLoader()->getPaths('Zend_Dojo_Form_Decorator');
  66. $this->assertTrue(is_array($paths));
  67. }
  68. public function testDefaultDisplayGroupClassShouldBeDojoDisplayGroupByDefault()
  69. {
  70. $this->assertEquals('Zend_Dojo_Form_DisplayGroup', $this->form->getDefaultDisplayGroupClass());
  71. }
  72. public function testDefaultDecoratorsShouldIncludeDijitForm()
  73. {
  74. $this->assertNotNull($this->form->getDecorator('DijitForm'));
  75. }
  76. public function testShouldRegisterDojoViewHelperPath()
  77. {
  78. $view = $this->form->getView();
  79. $loader = $view->getPluginLoader('helper');
  80. $paths = $loader->getPaths('Zend_Dojo_View_Helper');
  81. $this->assertTrue(is_array($paths));
  82. }
  83. public function testDisplayGroupShouldRegisterDojoViewHelperPath()
  84. {
  85. $this->form->dg->setView(new Zend_View());
  86. $view = $this->form->dg->getView();
  87. $loader = $view->getPluginLoader('helper');
  88. $paths = $loader->getPaths('Zend_Dojo_View_Helper');
  89. $this->assertTrue(is_array($paths));
  90. }
  91. /**
  92. * @group ZF-4748
  93. */
  94. public function testHtmlTagDecoratorShouldHaveZendFormDojoClassByDefault()
  95. {
  96. $decorator = $this->form->getDecorator('HtmlTag');
  97. $this->assertEquals('zend_form_dojo', $decorator->getOption('class'));
  98. }
  99. }
  100. // Call Zend_Dojo_Form_FormTest::main() if this source file is executed directly.
  101. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_Form_FormTest::main") {
  102. Zend_Dojo_Form_FormTest::main();
  103. }