TabContainerTest.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ZendX
  16. * @package ZendX_JQuery
  17. * @subpackage View
  18. * @copyright Copyright (c) 2005-2010 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. require_once "jQueryTestCase.php";
  23. require_once "ZendX/JQuery/View/Helper/TabContainer.php";
  24. class ZendX_JQuery_View_TabContainerTest extends ZendX_JQuery_View_jQueryTestCase
  25. {
  26. public function testCallingInViewEnablesJQueryHelper()
  27. {
  28. $element = $this->view->tabContainer();
  29. $this->assertTrue($this->jquery->isEnabled());
  30. $this->assertTrue($this->jquery->uiIsEnabled());
  31. }
  32. public function testShouldAppendToJqueryHelper()
  33. {
  34. $this->view->tabContainer()->addPane("elem1", "test1", "test1");
  35. $element = $this->view->tabContainer("elem1", array('option' => 'true'), array());
  36. $jquery = $this->view->jQuery()->__toString();
  37. $this->assertContains('tabs(', $jquery);
  38. $this->assertContains('"option":"true"', $jquery);
  39. }
  40. public function testShouldAllowAddingTabs()
  41. {
  42. $tabs = $this->view->tabContainer()->addPane("container1", "elem1", "Text1")
  43. ->addPane("container1", "elem2", "Text2")
  44. ->tabContainer("container1", array(), array());
  45. $this->assertEquals(array('$("#container1").tabs({});'), $this->jquery->getOnLoadActions());
  46. $this->assertContains("elem1", $tabs);
  47. $this->assertContains("Text1", $tabs);
  48. $this->assertContains("elem2", $tabs);
  49. $this->assertContains("Text2", $tabs);
  50. $this->assertContains('href="#container1-frag-1"', $tabs);
  51. $this->assertContains('href="#container1-frag-2"', $tabs);
  52. }
  53. public function testShoudAllowAddingTabsFromUrls()
  54. {
  55. $tabs = $this->view->tabContainer()->addPane("container1", "elem1", '', array('contentUrl' => 'blub.html'))
  56. ->addPane("container1", "elem2", '', array('contentUrl' => 'cookie.html'))
  57. ->tabContainer("container1", array(), array());
  58. $this->assertEquals(array('$("#container1").tabs({});'), $this->jquery->getOnLoadActions());
  59. $this->assertContains("elem1", $tabs);
  60. $this->assertContains("elem2", $tabs);
  61. $this->assertContains('href="blub.html"', $tabs);
  62. $this->assertContains('href="cookie.html"', $tabs);
  63. }
  64. public function testShouldAllowCaptureTabContent()
  65. {
  66. $this->view->tabPane()->captureStart("container1", "elem1");
  67. echo "Lorem Ipsum!";
  68. $this->view->tabPane()->captureEnd("container1");
  69. $this->view->tabPane()->captureStart("container1", "elem2", array('contentUrl' => 'foo.html'));
  70. echo "This is captured, but not displayed: contentUrl overrides this output.";
  71. $this->view->tabPane()->captureEnd("container1");
  72. $tabs = $this->view->tabContainer("container1", array(), array());
  73. $this->assertEquals(array('$("#container1").tabs({});'), $this->jquery->getOnLoadActions());
  74. $this->assertContains('elem1', $tabs);
  75. $this->assertContains('elem2', $tabs);
  76. $this->assertContains('Lorem Ipsum!', $tabs);
  77. $this->assertContains('href="foo.html"', $tabs);
  78. $this->assertNotContains('This is captured, but not displayed: contentUrl overrides this output.', $tabs);
  79. }
  80. public function testShouldAllowUsingTabPane()
  81. {
  82. $this->view->tabPane("container1", "Lorem Ipsum!", array('title' => 'elem1'));
  83. $this->view->tabPane("container1", '', array('title' => 'elem2', 'contentUrl' => 'foo.html'));
  84. $tabs = $this->view->tabContainer("container1", array(), array());
  85. $this->assertEquals(array('$("#container1").tabs({});'), $this->jquery->getOnLoadActions());
  86. $this->assertContains('elem1', $tabs);
  87. $this->assertContains('elem2', $tabs);
  88. $this->assertContains('Lorem Ipsum!', $tabs);
  89. $this->assertContains('href="foo.html"', $tabs);
  90. $this->assertNotContains('This is captured, but not displayed: contentUrl overrides this output.', $tabs);
  91. }
  92. public function testPaneCaptureLockExceptionNoNestingAllowed()
  93. {
  94. $this->view->tabPane()->captureStart('pane1', 'Label1');
  95. try {
  96. $this->view->tabPane()->captureStart('pane1', 'Label1');
  97. $this->fail();
  98. } catch(ZendX_JQuery_View_Exception $e) {
  99. }
  100. }
  101. public function testPaneCaptureLockExceptionNoEndWithoutStartPossible()
  102. {
  103. try {
  104. $this->view->tabPane()->captureEnd('pane3');
  105. $this->fail();
  106. } catch(ZendX_JQuery_View_Exception $e) {
  107. }
  108. }
  109. }