PageFactoryTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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_Navigation
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2012 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 'Zend/Navigation/Page.php';
  23. /**
  24. * Tests Zend_Navigation_Page::factory()
  25. *
  26. /**
  27. * @category Zend
  28. * @package Zend_Navigation
  29. * @subpackage UnitTests
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. * @group Zend_Navigation
  33. */
  34. class Zend_Navigation_PageFactoryTest extends PHPUnit_Framework_TestCase
  35. {
  36. protected $_oldIncludePath;
  37. protected function setUp()
  38. {
  39. // store old include path
  40. $this->_oldIncludePath = get_include_path();
  41. // add _files dir to include path
  42. $addToPath = dirname(__FILE__) . '/_files';
  43. set_include_path($addToPath . PATH_SEPARATOR . $this->_oldIncludePath);
  44. }
  45. protected function tearDown()
  46. {
  47. // reset include path
  48. set_include_path($this->_oldIncludePath);
  49. }
  50. public function testDetectMvcPage()
  51. {
  52. $pages = array(
  53. Zend_Navigation_Page::factory(array(
  54. 'label' => 'MVC Page',
  55. 'action' => 'index'
  56. )),
  57. Zend_Navigation_Page::factory(array(
  58. 'label' => 'MVC Page',
  59. 'controller' => 'index'
  60. )),
  61. Zend_Navigation_Page::factory(array(
  62. 'label' => 'MVC Page',
  63. 'module' => 'index'
  64. )),
  65. Zend_Navigation_Page::factory(array(
  66. 'label' => 'MVC Page',
  67. 'route' => 'home'
  68. ))
  69. );
  70. $this->assertContainsOnly('Zend_Navigation_Page_Mvc', $pages);
  71. }
  72. public function testDetectUriPage()
  73. {
  74. $page = Zend_Navigation_Page::factory(array(
  75. 'label' => 'URI Page',
  76. 'uri' => '#'
  77. ));
  78. $this->assertType('Zend_Navigation_Page_Uri', $page);
  79. }
  80. public function testMvcShouldHaveDetectionPrecedence()
  81. {
  82. $page = Zend_Navigation_Page::factory(array(
  83. 'label' => 'MVC Page',
  84. 'action' => 'index',
  85. 'controller' => 'index',
  86. 'uri' => '#'
  87. ));
  88. $this->assertType('Zend_Navigation_Page_Mvc', $page);
  89. }
  90. public function testSupportsMvcShorthand()
  91. {
  92. $mvcPage = Zend_Navigation_Page::factory(array(
  93. 'type' => 'mvc',
  94. 'label' => 'MVC Page',
  95. 'action' => 'index',
  96. 'controller' => 'index'
  97. ));
  98. $this->assertType('Zend_Navigation_Page_Mvc', $mvcPage);
  99. }
  100. public function testSupportsUriShorthand()
  101. {
  102. $uriPage = Zend_Navigation_Page::factory(array(
  103. 'type' => 'uri',
  104. 'label' => 'URI Page',
  105. 'uri' => 'http://www.example.com/'
  106. ));
  107. $this->assertType('Zend_Navigation_Page_Uri', $uriPage);
  108. }
  109. public function testSupportsCustomPageTypes()
  110. {
  111. $page = Zend_Navigation_Page::factory(array(
  112. 'type' => 'My_Page',
  113. 'label' => 'My Custom Page'
  114. ));
  115. return $this->assertType('My_Page', $page);
  116. }
  117. public function testShouldFailForInvalidType()
  118. {
  119. try {
  120. $page = Zend_Navigation_Page::factory(array(
  121. 'type' => 'My_InvalidPage',
  122. 'label' => 'My Invalid Page'
  123. ));
  124. } catch(Zend_Navigation_Exception $e) {
  125. return;
  126. }
  127. $this->fail('An exception has not been thrown for invalid page type');
  128. }
  129. public function testShouldFailForNonExistantType()
  130. {
  131. $pageConfig = array(
  132. 'type' => 'My_NonExistant_Page',
  133. 'label' => 'My non-existant Page'
  134. );
  135. try {
  136. $page = Zend_Navigation_Page::factory($pageConfig);
  137. } catch(Zend_Exception $e) {
  138. return;
  139. }
  140. $msg = 'A Zend_Exception has not been thrown for non-existant class';
  141. $this->fail($msg);
  142. }
  143. public function testShouldFailIfUnableToDetermineType()
  144. {
  145. try {
  146. $page = Zend_Navigation_Page::factory(array(
  147. 'label' => 'My Invalid Page'
  148. ));
  149. } catch(Zend_Navigation_Exception $e) {
  150. return;
  151. }
  152. $this->fail('An exception has not been thrown for invalid page type');
  153. }
  154. }