dimanche 31 janvier 2016

Test Not Passing From Redirection

I'm wanting to test to see if a user is NOT authenticated and the user tries to access the dashboard then they are are taken to the login page to submit the form.

<?php

use Illuminate\Foundation\Testing\DatabaseTransactions;

class AuthTest extends TestCase {

    use DatabaseTransactions;

    protected $user;
    protected $password = 'testpass123';


    /** @before */
    public function setupUserObjectBeforeAnyTest() {
        $this->app->make('db')->beginTransaction();
        $this->beforeApplicationDestroyed(function () {
            $this->app->make('db')->rollBack();
        });
        $this->user = factory(App\User::class)->create([
            'email' => 'john@example.com',
            'password' => bcrypt($this->password),
        ]);
    }

    /** @test */
    public function a_user_is_redirected_to_dashboard_if_authenticated_and_tries_to_access_login_page()
    {
        $this->actingAs($this->user)
            ->visit(route('login'))
            ->seePageIs(route('dashboard'));
    }

    /** @test */
    public function a_user_is_redirected_to_login_page_if_not_authenticated_and_tries_to_access_dashboard()
    {
        $this->visit(route('dashboard'))
            ->seePageIs(route('login'));
    }
}

In the results from the test below it fails. The word app is a route group prefix.

    1) AuthTest::a_user_is_redirected_to_login_page_if_not_authenticated_and_tries_to_access_dashboard
Did not land on expected page [http://localhost/app/login].

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/app/login'
+'http://localhost/app/dashboard'



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Vz60KR
via IFTTT

Aucun commentaire:

Enregistrer un commentaire