2
0

SimpleTextareaTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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_View_Helper_SimpleTextareaTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_View_Helper_SimpleTextareaTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  27. /** Zend_Dojo_View_Helper_SimpleTextarea */
  28. require_once 'Zend/Dojo/View/Helper/SimpleTextarea.php';
  29. /** Zend_View */
  30. require_once 'Zend/View.php';
  31. /** Zend_Dojo */
  32. require_once 'Zend/Dojo.php';
  33. /** Zend_Registry */
  34. require_once 'Zend/Registry.php';
  35. /** Zend_Dojo_View_Helper_Dojo */
  36. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  37. /**
  38. * Test class for Zend_Dojo_View_Helper_SimpleTextarea.
  39. *
  40. * @category Zend
  41. * @package Zend_Dojo
  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. * @group Zend_Dojo_View
  47. */
  48. class Zend_Dojo_View_Helper_SimpleTextareaTest extends PHPUnit_Framework_TestCase
  49. {
  50. /**
  51. * Runs the test methods of this class.
  52. *
  53. * @return void
  54. */
  55. public static function main()
  56. {
  57. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_View_Helper_SimpleTextareaTest");
  58. $result = PHPUnit_TextUI_TestRunner::run($suite);
  59. }
  60. /**
  61. * Sets up the fixture, for example, open a network connection.
  62. * This method is called before a test is executed.
  63. *
  64. * @return void
  65. */
  66. public function setUp()
  67. {
  68. Zend_Registry::_unsetInstance();
  69. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  70. $this->view = $this->getView();
  71. $this->helper = new Zend_Dojo_View_Helper_SimpleTextarea();
  72. $this->helper->setView($this->view);
  73. }
  74. /**
  75. * Tears down the fixture, for example, close a network connection.
  76. * This method is called after a test is executed.
  77. *
  78. * @return void
  79. */
  80. public function tearDown()
  81. {
  82. }
  83. public function getView()
  84. {
  85. require_once 'Zend/View.php';
  86. $view = new Zend_View();
  87. Zend_Dojo::enableView($view);
  88. return $view;
  89. }
  90. public function getElement()
  91. {
  92. return $this->helper->simpleTextarea(
  93. 'elementId',
  94. 'some content',
  95. array(),
  96. array()
  97. );
  98. }
  99. public function testShouldAllowDeclarativeDijitCreation()
  100. {
  101. $html = $this->getElement();
  102. $this->assertRegexp('/<textarea[^>]*(dojoType="dijit.form.SimpleTextarea")/', $html, $html);
  103. }
  104. public function testShouldAllowProgrammaticDijitCreation()
  105. {
  106. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  107. $html = $this->getElement();
  108. $this->assertNotRegexp('/<textarea[^>]*(dojoType="dijit.form.SimpleTextarea")/', $html);
  109. $this->assertNotNull($this->view->dojo()->getDijit('elementId'));
  110. }
  111. public function testPassingIdAsAttributeShouldOverrideUsingNameAsId()
  112. {
  113. $html = $this->helper->simpleTextarea('foo[bar]', '', array(), array('id' => 'foo-bar'));
  114. $this->assertContains('id="foo-bar"', $html);
  115. }
  116. }
  117. // Call Zend_Dojo_View_Helper_SimpleTextareaTest::main() if this source file is executed directly.
  118. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_SimpleTextareaTest::main") {
  119. Zend_Dojo_View_Helper_SimpleTextareaTest::main();
  120. }