uri.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Part of the Fuel framework.
  4. *
  5. * @package Fuel
  6. * @version 1.5
  7. * @author Fuel Development Team
  8. * @license MIT License
  9. * @copyright 2010 - 2013 Fuel Development Team
  10. * @link http://fuelphp.com
  11. */
  12. namespace Fuel\Core;
  13. /**
  14. * Html class tests
  15. *
  16. * @group Core
  17. * @group Uri
  18. */
  19. class Test_Uri extends TestCase
  20. {
  21. /**
  22. * Tests Uri::create()
  23. *
  24. * @test
  25. */
  26. public function test_create()
  27. {
  28. Config::set('url_suffix', '');
  29. $prefix = Uri::create('');
  30. Config::set('index_file', 'index.php');
  31. $output = Uri::create('controller/method');
  32. $expected = $prefix."index.php/controller/method";
  33. $this->assertEquals($expected, $output);
  34. Config::set('index_file', '');
  35. $output = Uri::create('controller/method');
  36. $expected = $prefix."controller/method";
  37. $this->assertEquals($expected, $output);
  38. $output = Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
  39. $expected = $prefix."controller/thing?what=more";
  40. $this->assertEquals($expected, $output);
  41. Config::set('url_suffix', '.html');
  42. $output = Uri::create('controller/method');
  43. $expected = $prefix."controller/method.html";
  44. $this->assertEquals($expected, $output);
  45. $output = Uri::create('controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
  46. $expected = $prefix."controller/thing.html?what=more";
  47. $this->assertEquals($expected, $output);
  48. $output = Uri::create('http://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'));
  49. $expected = "http://example.com/controller/thing.html?what=more";
  50. $this->assertEquals($expected, $output);
  51. $output = Uri::create('http://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), true);
  52. $expected = "https://example.com/controller/thing.html?what=more";
  53. $this->assertEquals($expected, $output);
  54. $output = Uri::create('https://example.com/controller/:some', array('some' => 'thing', 'and' => 'more'), array('what' => ':and'), false);
  55. $expected = "http://example.com/controller/thing.html?what=more";
  56. $this->assertEquals($expected, $output);
  57. }
  58. /**
  59. * Tests Uri::base()
  60. *
  61. * @test
  62. */
  63. public function test_base()
  64. {
  65. Config::set('base_url', null);
  66. Config::set('index_file', false);
  67. $output = Uri::base();
  68. $expected = null;
  69. $this->assertEquals($expected, $output);
  70. Config::set('base_url', 'http://example.com/');
  71. Config::set('index_file', 'index.php');
  72. $output = Uri::base();
  73. $expected = 'http://example.com/index.php/';
  74. $this->assertEquals($expected, $output);
  75. $output = Uri::base(false);
  76. $expected = 'http://example.com/';
  77. $this->assertEquals($expected, $output);
  78. }
  79. /**
  80. * Tests Uri::current()
  81. *
  82. * @test
  83. */
  84. public function test_current()
  85. {
  86. $output = Uri::current();
  87. $expected = Uri::create();
  88. $this->assertEquals($expected, $output);
  89. }
  90. }