jeudi 21 mars 2019

Laravel voyager with phpunit

I'm trying to write some tests for my admin panel using laravel voyager however there seems to be some issues doing some research i found that the problem may be have something to do with permissions

 public function A_admin_user_can_visit_the_admin_page()
    {
        \DB::table('permissions')->insert(
            ['key' => 'browse_admin', 'id' => 1]
        );

        \DB::table('roles')->insert(
            ['name' => 'admin', 'display_name' => 'Administrator']
        );

        \DB::table('permission_role')->insert(
            ['permission_id' => 1, 'role_id' => 1]
        );

        $user = factory('App\User')->create(['role_id' => 1]);
        $this->actingAs($user);
        $this->get('/admin')->assertStatus(200);
    }

This tests works fine given i have the correct permissions

    public function A_admin_can_browse_users_data()
    {
       $this->admin();
        $this->adminPermissions();
        $this->adminRoles();
        $user = factory('App\User')->create(['role_id' => 1]);
        $this->actingAs($user);
        $this->get('/admin')->assertStatus(200);
//      dd(\Voyager::canOrFail('browse_bread'));
        $this->get('/admin/users')->assertStatus(200);

    }

Here this tests fails but I assure the functions admin adminRoles and adminPermissions have created the necessary db entries that give my user full access even when i die and dump the permissions i get true so it can't be the permissions is the problem something else is going wrong and I don't what it is any help would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire