/tests/Zend/Dojo/View/Helper/BorderContainerTest.php

https://github.com/devilsansclue/ZendFramework · PHP · 139 lines · 67 code · 15 blank · 57 comment · 3 complexity · c9b9be83fd720ce77e05c8000d33595b MD5 · raw file

  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-2011 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_BorderContainerTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Dojo_View_Helper_BorderContainerTest::main");
  25. }
  26. /** Zend_Dojo_View_Helper_BorderContainer */
  27. require_once 'Zend/Dojo/View/Helper/BorderContainer.php';
  28. /** Zend_View */
  29. require_once 'Zend/View.php';
  30. /** Zend_Registry */
  31. require_once 'Zend/Registry.php';
  32. /** Zend_Dojo_View_Helper_Dojo */
  33. require_once 'Zend/Dojo/View/Helper/Dojo.php';
  34. /**
  35. * Test class for Zend_Dojo_View_Helper_BorderContainer.
  36. *
  37. * @category Zend
  38. * @package Zend_Dojo
  39. * @subpackage UnitTests
  40. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  41. * @license http://framework.zend.com/license/new-bsd New BSD License
  42. * @group Zend_Dojo
  43. * @group Zend_Dojo_View
  44. */
  45. class Zend_Dojo_View_Helper_BorderContainerTest extends PHPUnit_Framework_TestCase
  46. {
  47. /**
  48. * Runs the test methods of this class.
  49. *
  50. * @return void
  51. */
  52. public static function main()
  53. {
  54. $suite = new PHPUnit_Framework_TestSuite("Zend_Dojo_View_Helper_BorderContainerTest");
  55. $result = PHPUnit_TextUI_TestRunner::run($suite);
  56. }
  57. /**
  58. * Sets up the fixture, for example, open a network connection.
  59. * This method is called before a test is executed.
  60. *
  61. * @return void
  62. */
  63. public function setUp()
  64. {
  65. Zend_Registry::_unsetInstance();
  66. Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
  67. $this->view = $this->getView();
  68. $this->helper = new Zend_Dojo_View_Helper_BorderContainer();
  69. $this->helper->setView($this->view);
  70. }
  71. /**
  72. * Tears down the fixture, for example, close a network connection.
  73. * This method is called after a test is executed.
  74. *
  75. * @return void
  76. */
  77. public function tearDown()
  78. {
  79. }
  80. public function getView()
  81. {
  82. require_once 'Zend/View.php';
  83. $view = new Zend_View();
  84. $view->addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper');
  85. return $view;
  86. }
  87. public function getContainer()
  88. {
  89. $html = '';
  90. foreach (array('top', 'bottom', 'center', 'left', 'right') as $pane) {
  91. $id = $pane . 'Pane';
  92. $content = 'This is the content of pane ' . $pane;
  93. $html .= $this->view->contentPane($id, $content, array('region' => $pane));
  94. }
  95. return $this->helper->borderContainer('container', $html, array('design' => 'headline'));
  96. }
  97. public function testShouldAllowDeclarativeDijitCreation()
  98. {
  99. $html = $this->getContainer();
  100. $this->assertRegexp('/<div[^>]*(dojoType="dijit.layout.BorderContainer")/', $html, $html);
  101. }
  102. public function testShouldAllowProgrammaticDijitCreation()
  103. {
  104. Zend_Dojo_View_Helper_Dojo::setUseProgrammatic();
  105. $html = $this->getContainer();
  106. $this->assertNotRegexp('/<div[^>]*(dojoType="dijit.layout.BorderContainer")/', $html);
  107. $this->assertNotNull($this->view->dojo()->getDijit('container'));
  108. }
  109. /**
  110. * @group ZF-4664
  111. */
  112. public function testMultipleCallsToBorderContainerShouldNotCreateMultipleStyleEntries()
  113. {
  114. $this->getContainer();
  115. $this->getContainer();
  116. $style = 'html, body { height: 100%; width: 100%; margin: 0; padding: 0; }';
  117. $styles = $this->helper->view->headStyle()->toString();
  118. $this->assertEquals(1, substr_count($styles, $style), $styles);
  119. }
  120. }
  121. // Call Zend_Dojo_View_Helper_BorderContainerTest::main() if this source file is executed directly.
  122. if (PHPUnit_MAIN_METHOD == "Zend_Dojo_View_Helper_BorderContainerTest::main") {
  123. Zend_Dojo_View_Helper_BorderContainerTest::main();
  124. }