UriTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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-2015 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/Uri.php';
  23. /**
  24. * Tests the class Zend_Navigation_Page_Uri
  25. *
  26. * @category Zend
  27. * @package Zend_Navigation
  28. * @subpackage UnitTests
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. * @group Zend_Navigation
  32. */
  33. class Zend_Navigation_Page_UriTest extends PHPUnit_Framework_TestCase
  34. {
  35. public function testUriOptionAsString()
  36. {
  37. $page = new Zend_Navigation_Page_Uri(array(
  38. 'label' => 'foo',
  39. 'uri' => '#'
  40. ));
  41. $this->assertEquals('#', $page->getUri());
  42. }
  43. public function testUriOptionAsNull()
  44. {
  45. $page = new Zend_Navigation_Page_Uri(array(
  46. 'label' => 'foo',
  47. 'uri' => null
  48. ));
  49. $this->assertNull($page->getUri(), 'getUri() should return null');
  50. }
  51. public function testUriOptionAsInteger()
  52. {
  53. try {
  54. $page = new Zend_Navigation_Page_Uri(array('uri' => 1337));
  55. $this->fail('An invalid \'uri\' was given, but ' .
  56. 'a Zend_Navigation_Exception was not thrown');
  57. } catch (Zend_Navigation_Exception $e) {
  58. }
  59. }
  60. public function testUriOptionAsObject()
  61. {
  62. try {
  63. $uri = new stdClass();
  64. $uri->foo = 'bar';
  65. $page = new Zend_Navigation_Page_Uri(array('uri' => $uri));
  66. $this->fail('An invalid \'uri\' was given, but ' .
  67. 'a Zend_Navigation_Exception was not thrown');
  68. } catch (Zend_Navigation_Exception $e) {
  69. }
  70. }
  71. public function testSetAndGetUri()
  72. {
  73. $page = new Zend_Navigation_Page_Uri(array(
  74. 'label' => 'foo',
  75. 'uri' => '#'
  76. ));
  77. $page->setUri('http://www.example.com/')->setUri('about:blank');
  78. $this->assertEquals('about:blank', $page->getUri());
  79. }
  80. public function testGetHref()
  81. {
  82. $uri = 'spotify:album:4YzcWwBUSzibRsqD9Sgu4A';
  83. $page = new Zend_Navigation_Page_Uri();
  84. $page->setUri($uri);
  85. $this->assertEquals($uri, $page->getHref());
  86. }
  87. /**
  88. * @group ZF-8922
  89. */
  90. public function testGetHrefWithFragmentIdentifier()
  91. {
  92. $uri = 'http://www.example.com/foo.html';
  93. $page = new Zend_Navigation_Page_Uri();
  94. $page->setUri($uri);
  95. $page->setFragment('bar');
  96. $this->assertEquals($uri . '#bar', $page->getHref());
  97. $page->setUri('#');
  98. $this->assertEquals('#bar', $page->getHref());
  99. }
  100. }