2
0

PageFactoryTest.php 5.0 KB

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