PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/Zap/FrameTest.php

https://github.com/cmhudson/zap
PHP | 201 lines | 151 code | 50 blank | 0 comment | 0 complexity | a35635083eb81d187678655ac414d643 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. require_once 'PHPUnit/Autoload.php';
  3. require_once dirname(dirname(__FILE__)) . '/bootstrap.php';
  4. class Zap_FrameTest extends PHPUnit_Framework_TestCase
  5. {
  6. protected $_frame;
  7. public function setUp()
  8. {
  9. $this->_frame = new Zap_Frame();
  10. }
  11. public function tearDown()
  12. {
  13. unset($this->_frame);
  14. }
  15. public function testSetTitle()
  16. {
  17. $this->_frame->setTitle('Test');
  18. $this->assertEquals('Test', $this->_frame->getTitle());
  19. }
  20. public function testSetSubtitle()
  21. {
  22. $this->_frame->setSubtitle('Test');
  23. $this->assertEquals('Test', $this->_frame->getSubtitle());
  24. }
  25. public function testSetTitleSeparator()
  26. {
  27. $this->_frame->setTitleSeparator('%');
  28. $this->assertEquals('%', $this->_frame->getTitleSeparator());
  29. }
  30. public function testSetTitleContentType()
  31. {
  32. $this->_frame->setTitleContentType('text/xml');
  33. $this->assertEquals('text/xml', $this->_frame->getTitleContentType());
  34. }
  35. public function testSetHeaderLevel()
  36. {
  37. $this->_frame->setHeaderLevel(6);
  38. $this->assertEquals(6, $this->_frame->getHeaderLevel());
  39. }
  40. public function testDisplayInvisible()
  41. {
  42. $this->_frame->setVisible(false);
  43. ob_start();
  44. $this->_frame->display();
  45. $out = trim(ob_get_clean());
  46. $this->assertEmpty($out);
  47. }
  48. public function testDisplayNoSubtitle()
  49. {
  50. $this->_frame->setTitle('Foo')
  51. ->setTitleSeparator('%%%');
  52. ob_start();
  53. $this->_frame->display();
  54. $out = ob_get_clean();
  55. $this->assertNotContains(
  56. $this->_frame->getTitleSeparator(),
  57. $out
  58. );
  59. }
  60. public function testDisplayWithSubtitle()
  61. {
  62. $this->_frame->setTitle('Foo')
  63. ->setTitleSeparator('%%%')
  64. ->setSubtitle('Bar');
  65. ob_start();
  66. $this->_frame->display();
  67. $out = ob_get_clean();
  68. $this->assertContains(
  69. $this->_frame->getTitleSeparator(),
  70. $out
  71. );
  72. }
  73. public function testDefaultHeaderLevel()
  74. {
  75. $this->_frame->setTitle('Foo');
  76. ob_start();
  77. $this->_frame->display();
  78. $out = ob_get_clean();
  79. $this->assertContains(
  80. '</h2>',
  81. $out
  82. );
  83. }
  84. public function testCustomHeaderLevel()
  85. {
  86. $this->_frame->setTitle('Foo')
  87. ->setHeaderLevel(5);
  88. ob_start();
  89. $this->_frame->display();
  90. $out = ob_get_clean();
  91. $this->assertContains(
  92. '</h5>',
  93. $out
  94. );
  95. }
  96. public function testShallowNestedHeaderLevel()
  97. {
  98. $outer = new Zap_Frame();
  99. $outer->setTitle('Foo')
  100. ->addChild($this->_frame);
  101. $this->_frame->setTitle('Bar');
  102. ob_start();
  103. $this->_frame->display();
  104. $out = ob_get_clean();
  105. $this->assertContains('</h3>', $out);
  106. }
  107. public function testDeepNestedHeaderLevel()
  108. {
  109. $inner = new Zap_Frame();
  110. $inner->setTitle('Bar')
  111. ->addChild($this->_frame);
  112. $outer = new Zap_Frame();
  113. $outer->setTitle('Foo')
  114. ->addChild($inner);
  115. $this->_frame->setTitle('Baz');
  116. ob_start();
  117. $this->_frame->display();
  118. $out = ob_get_clean();
  119. $this->assertContains('</h4>', $out);
  120. }
  121. public function testDeepNestedHeaderLevelWithContainer()
  122. {
  123. $inner = new Zap_Container();
  124. $inner->addChild($this->_frame);
  125. $outer = new Zap_Frame();
  126. $outer->setTitle('Foo')
  127. ->addChild($inner);
  128. $this->_frame->setTitle('Baz');
  129. ob_start();
  130. $this->_frame->display();
  131. $out = ob_get_clean();
  132. $this->assertContains('</h3>', $out);
  133. }
  134. public function testDeeperNestedHeaderLevel()
  135. {
  136. $inner = new Zap_Frame();
  137. $inner->setTitle('Bar')
  138. ->addChild($this->_frame);
  139. $mid = new Zap_Frame();
  140. $mid->setTitle('Gah')
  141. ->addChild($inner);
  142. $outer = new Zap_Frame();
  143. $outer->setTitle('Foo')
  144. ->addChild($mid);
  145. $this->_frame->setTitle('Baz');
  146. ob_start();
  147. $this->_frame->display();
  148. $out = ob_get_clean();
  149. $this->assertContains('</h5>', $out);
  150. }
  151. }