File: D:/HostingSpaces/SBogers10/werkenbij.komma.pro/tests/Browser/AuthorisationTest.php
<?php declare(strict_types=1);
namespace Tests\Browser;
use App\Komma\Kms\QualityAssurance\ExtraDuskTools;
use App\Komma\Users\Models\KmsUser;
use Laravel\Dusk\Browser;
use Tests\Browser\Pages\KmsUsersSectionTestPage;
use Tests\DuskTestCase;
class AuthorisationTest extends DuskTestCase
{
/**
* @test
* @group Authorisation
* @throws \Throwable
* @see ExtraDuskTools
*/
public function testUserSectionAuthorisationForAdmins()
{
$newUser = factory(KmsUser::class)->make();
$adminUser = KmsUser::where('email', '=',\KmsUserTableSeeder::getAdminDefaultCredentials()['email'])->first();
//Test that the Admin user can create another user.
$this->browse(function (Browser $browser) use($adminUser, $newUser) {
$browser->loginAs($adminUser, 'kms')
->visit(new KmsUsersSectionTestPage()) //When the user visits this page it means that is Authorized to view it. See App\Komma\Base\Policy::index(). Triggered by the controller's index method.
->assertVisible('@add_button') //When the users sees this button it means that he is Authorized to see it. See App\Komma\Base\Policy::index(). Triggered by the call in entities/index.blade.php
->click('@add_button')
->assertVisible('@save_button')
->pause(1000);
$browser->type('@TextField-first_name', $newUser->first_name)
->type('@TextField-last_name', $newUser->last_name)
->type('@TextField-email', $newUser->email)
->type('@Password-password-1', 'Test123')
->type('@Password-password-2', 'Test123')
->click('@save_button')
->assertSee(__('kms/global.saved'));
$newUser = KmsUser::where('email', '=', $newUser->email)->first();
$browser->assertSee(__('kms/kms_users.section.title'))
->type('@entity_search_input', $newUser->first_name.' '.$newUser->last_name)
->pause(5000)
->assertSeeIn('@search-result-counter', '1'); //The adminUser which we used to login must now see the just created other admin user. Because the list must show users that have the same role level or lower.
});
}
}