Laravel PHPUnit: Check form submit redirection


I just made a Laravel  UnitTest to test and make sure that my create function is working and redirects user to the right url after form post submitted , this is how I make it work:


public function testSurveysCreateSuccess()
    {
        $form = [
            'name' => 'New Survey',
            'type' => 'Lecturer',
            'description' => 'It\'s a text'
        ];

        $url =  '/admin/courses/'.$this->course->id.'/surveys';

        $response = $this->actingAs($this->user)->call('POST', $url, $form);
        $this->assertEquals(302, $response->status());
        $redirect_to = $response->getTargetUrl();

        $this->assertEquals($redirect_to, $this->baseUrl.$url);
    }

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s