@@ -360,6 +360,56 @@ public function testRunRedirectionWithURINotSet()
360360 $ this ->assertEquals ('http://example.com/pages/notset ' , $ response ->getHeader ('Location ' )->getValue ());
361361 }
362362
363+ public function testRunRedirectionWithHTTPCode303 ()
364+ {
365+ $ _SERVER ['argv ' ] = [
366+ 'index.php ' ,
367+ 'example ' ,
368+ ];
369+ $ _SERVER ['argc ' ] = 2 ;
370+ $ _SERVER ['REQUEST_URI ' ] = '/example ' ;
371+ $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
372+ $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
373+
374+ // Inject mock router.
375+ $ routes = Services::routes ();
376+ $ routes ->addRedirect ('example ' , 'pages/notset ' , 301 );
377+
378+ $ router = Services::router ($ routes , Services::request ());
379+ Services::injectMock ('router ' , $ router );
380+
381+ ob_start ();
382+ $ this ->codeigniter ->useSafeOutput (true )->run ();
383+ ob_get_clean ();
384+ $ response = $ this ->getPrivateProperty ($ this ->codeigniter , 'response ' );
385+ $ this ->assertEquals ('303 ' , $ response ->getStatusCode ());
386+ }
387+
388+ public function testRunRedirectionWithHTTPCode301 ()
389+ {
390+ $ _SERVER ['argv ' ] = [
391+ 'index.php ' ,
392+ 'example ' ,
393+ ];
394+ $ _SERVER ['argc ' ] = 2 ;
395+ $ _SERVER ['REQUEST_URI ' ] = '/example ' ;
396+ $ _SERVER ['SERVER_PROTOCOL ' ] = 'HTTP/1.1 ' ;
397+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
398+
399+ // Inject mock router.
400+ $ routes = Services::routes ();
401+ $ routes ->addRedirect ('example ' , 'pages/notset ' , 301 );
402+
403+ $ router = Services::router ($ routes , Services::request ());
404+ Services::injectMock ('router ' , $ router );
405+
406+ ob_start ();
407+ $ this ->codeigniter ->useSafeOutput (true )->run ();
408+ ob_get_clean ();
409+ $ response = $ this ->getPrivateProperty ($ this ->codeigniter , 'response ' );
410+ $ this ->assertEquals ('301 ' , $ response ->getStatusCode ());
411+ }
412+
363413 /**
364414 * The method after all test, reset Servces:: config
365415 * Can't use static::tearDownAfterClass. This will cause a buffer exception
0 commit comments