HTTPTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php defined('SYSPATH') OR die('Kohana bootstrap needs to be included before tests run');
  2. /**
  3. * Tests HTTP
  4. *
  5. * @group kohana
  6. * @group kohana.core
  7. * @group kohana.core.http
  8. *
  9. * @package Kohana
  10. * @category Tests
  11. * @author Kohana Team
  12. * @copyright (c) 2008-2012 Kohana Team
  13. * @license http://kohanaframework.org/license
  14. */
  15. class Kohana_HTTPTest extends Unittest_TestCase {
  16. /**
  17. * Defaults for this test
  18. * @var array
  19. */
  20. // @codingStandardsIgnoreStart
  21. protected $environmentDefault = array(
  22. 'Kohana::$base_url' => '/kohana/',
  23. 'Kohana::$index_file' => 'index.php',
  24. 'HTTP_HOST' => 'www.example.com',
  25. );
  26. // @codingStandardsIgnoreEnd
  27. /**
  28. * Provides test data for test_attributes()
  29. *
  30. * @return array
  31. */
  32. public function provider_redirect()
  33. {
  34. return array(
  35. array(
  36. 'http://www.example.org/',
  37. 301,
  38. 'HTTP_Exception_301',
  39. 'http://www.example.org/'
  40. ),
  41. array(
  42. '/page_one',
  43. 302,
  44. 'HTTP_Exception_302',
  45. 'http://www.example.com/kohana/index.php/page_one'
  46. ),
  47. array(
  48. 'page_two',
  49. 303,
  50. 'HTTP_Exception_303',
  51. 'http://www.example.com/kohana/index.php/page_two'
  52. ),
  53. );
  54. }
  55. /**
  56. * Tests HTTP::redirect()
  57. *
  58. * @test
  59. * @dataProvider provider_redirect
  60. * @param array $location Location to redirect to
  61. * @param array $code HTTP Code to use for the redirect
  62. * @param string $expected_exception Expected exception
  63. * @param string $expected_location Expected exception
  64. */
  65. public function test_redirect($location, $code, $expected_exception, $expected_location)
  66. {
  67. try
  68. {
  69. HTTP::redirect($location, $code);
  70. }
  71. catch (HTTP_Exception_Redirect $e)
  72. {
  73. $response = $e->get_response();
  74. $this->assertInstanceOf($expected_exception, $e);
  75. $this->assertEquals($expected_location, $response->headers('Location'));
  76. return;
  77. }
  78. $this->fail('HTTP_Exception_Redirect not thrown');
  79. }
  80. }