From a6da9d5da8db8e08e6408ec2d20112f501fa90dd Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Tue, 24 Jan 2017 13:05:28 +0100 Subject: [PATCH] Added unit tests regarding redirection for ResponseTest (#13437) --- tests/framework/web/ResponseTest.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tests/framework/web/ResponseTest.php b/tests/framework/web/ResponseTest.php index c531068c26..d57f76d011 100644 --- a/tests/framework/web/ResponseTest.php +++ b/tests/framework/web/ResponseTest.php @@ -18,7 +18,7 @@ class ResponseTest extends \yiiunit\TestCase protected function setUp() { parent::setUp(); - $this->mockApplication(); + $this->mockWebApplication(); $this->response = new \yii\web\Response; } @@ -101,4 +101,21 @@ class ResponseTest extends \yiiunit\TestCase static::assertEquals('attachment; filename="test.txt"', $headers->get('Content-Disposition')); static::assertEquals(4, $headers->get('Content-Length')); } + + public function testRedirect() + { + $_SERVER['REQUEST_URI'] = 'http://test-domain.com/'; + $this->assertEquals($this->response->redirect('')->headers->get('location'), '/'); + $this->assertEquals($this->response->redirect('http://some-external-domain.com')->headers->get('location'), 'http://some-external-domain.com'); + $this->assertEquals($this->response->redirect('/')->headers->get('location'), '/'); + $this->assertEquals($this->response->redirect('/something-relative')->headers->get('location'), '/something-relative'); + $this->assertEquals($this->response->redirect(['/'])->headers->get('location'), '/index.php?r='); + $this->assertEquals($this->response->redirect(['view'])->headers->get('location'), '/index.php?r=view'); + $this->assertEquals($this->response->redirect(['/controller'])->headers->get('location'), '/index.php?r=controller'); + $this->assertEquals($this->response->redirect(['/controller/index'])->headers->get('location'), '/index.php?r=controller%2Findex'); + $this->assertEquals($this->response->redirect(['//controller/index'])->headers->get('location'), '/index.php?r=controller%2Findex'); + $this->assertEquals($this->response->redirect(['//controller/index', 'id' => 3])->headers->get('location'), '/index.php?r=controller%2Findex&id=3'); + $this->assertEquals($this->response->redirect(['//controller/index', 'id_1' => 3, 'id_2' => 4])->headers->get('location'), '/index.php?r=controller%2Findex&id_1=3&id_2=4'); + $this->assertEquals($this->response->redirect(['//controller/index', 'slug' => 'äöüß!"§$%&/()'])->headers->get('location'), '/index.php?r=controller%2Findex&slug=%C3%A4%C3%B6%C3%BC%C3%9F%21%22%C2%A7%24%25%26%2F%28%29'); + } }