PageFactoryTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Navigation/Page.php';
  4. /**
  5. * Tests Zend_Navigation_Page::factory()
  6. *
  7. */
  8. class Zend_Navigation_PageFactoryTest extends PHPUnit_Framework_TestCase
  9. {
  10. protected $_oldIncludePath;
  11. protected function setUp()
  12. {
  13. // store old include path
  14. $this->_oldIncludePath = get_include_path();
  15. // add _files dir to include path
  16. $addToPath = dirname(__FILE__) . '/_files';
  17. set_include_path($addToPath . PATH_SEPARATOR . $this->_oldIncludePath);
  18. }
  19. protected function tearDown()
  20. {
  21. // reset include path
  22. set_include_path($this->_oldIncludePath);
  23. }
  24. public function testDetectMvcPage()
  25. {
  26. $pages = array(
  27. Zend_Navigation_Page::factory(array(
  28. 'label' => 'MVC Page',
  29. 'action' => 'index'
  30. )),
  31. Zend_Navigation_Page::factory(array(
  32. 'label' => 'MVC Page',
  33. 'controller' => 'index'
  34. )),
  35. Zend_Navigation_Page::factory(array(
  36. 'label' => 'MVC Page',
  37. 'module' => 'index'
  38. )),
  39. Zend_Navigation_Page::factory(array(
  40. 'label' => 'MVC Page',
  41. 'route' => 'home'
  42. ))
  43. );
  44. $this->assertContainsOnly('Zend_Navigation_Page_Mvc', $pages);
  45. }
  46. public function testDetectUriPage()
  47. {
  48. $page = Zend_Navigation_Page::factory(array(
  49. 'label' => 'URI Page',
  50. 'uri' => '#'
  51. ));
  52. $this->assertType('Zend_Navigation_Page_Uri', $page);
  53. }
  54. public function testMvcShouldHaveDetectionPrecedence()
  55. {
  56. $page = Zend_Navigation_Page::factory(array(
  57. 'label' => 'MVC Page',
  58. 'action' => 'index',
  59. 'controller' => 'index',
  60. 'uri' => '#'
  61. ));
  62. $this->assertType('Zend_Navigation_Page_Mvc', $page);
  63. }
  64. public function testSupportsMvcShorthand()
  65. {
  66. $mvcPage = Zend_Navigation_Page::factory(array(
  67. 'type' => 'mvc',
  68. 'label' => 'MVC Page',
  69. 'action' => 'index',
  70. 'controller' => 'index'
  71. ));
  72. $this->assertType('Zend_Navigation_Page_Mvc', $mvcPage);
  73. }
  74. public function testSupportsUriShorthand()
  75. {
  76. $uriPage = Zend_Navigation_Page::factory(array(
  77. 'type' => 'uri',
  78. 'label' => 'URI Page',
  79. 'uri' => 'http://www.example.com/'
  80. ));
  81. $this->assertType('Zend_Navigation_Page_Uri', $uriPage);
  82. }
  83. public function testSupportsCustomPageTypes()
  84. {
  85. $page = Zend_Navigation_Page::factory(array(
  86. 'type' => 'My_Page',
  87. 'label' => 'My Custom Page'
  88. ));
  89. return $this->assertType('My_Page', $page);
  90. }
  91. public function testShouldFailForInvalidType()
  92. {
  93. try {
  94. $page = Zend_Navigation_Page::factory(array(
  95. 'type' => 'My_InvalidPage',
  96. 'label' => 'My Invalid Page'
  97. ));
  98. } catch(Zend_Navigation_Exception $e) {
  99. return;
  100. }
  101. $this->fail('An exception has not been thrown for invalid page type');
  102. }
  103. public function testShouldFailForNonExistantType()
  104. {
  105. $pageConfig = array(
  106. 'type' => 'My_NonExistant_Page',
  107. 'label' => 'My non-existant Page'
  108. );
  109. try {
  110. $page = Zend_Navigation_Page::factory($pageConfig);
  111. } catch(Zend_Exception $e) {
  112. return;
  113. }
  114. $msg = 'A Zend_Exception has not been thrown for non-existant class';
  115. $this->fail($msg);
  116. }
  117. public function testShouldFailIfUnableToDetermineType()
  118. {
  119. try {
  120. $page = Zend_Navigation_Page::factory(array(
  121. 'label' => 'My Invalid Page'
  122. ));
  123. } catch(Zend_Navigation_Exception $e) {
  124. return;
  125. }
  126. $this->fail('An exception has not been thrown for invalid page type');
  127. }
  128. }