sarga/tests/functional/Admin/Settings/UsersCest.php

122 lines
2.8 KiB
PHP
Raw Normal View History

2021-10-28 09:29:17 +00:00
<?php
namespace Tests\Functional\Admin\Settings;
use FunctionalTester;
use Webkul\User\Models\Admin;
class UsersCest
{
/**
* Index page test.
*
* @param FunctionalTester $I
* @return void
*/
public function testIndex(FunctionalTester $I): void
{
$I->loginAsAdmin();
2022-01-05 12:50:27 +00:00
2021-10-28 09:29:17 +00:00
$I->amOnAdminRoute('admin.dashboard.index');
2022-01-05 12:50:27 +00:00
$I->seeCurrentRouteIs('admin.dashboard.index');
2021-10-28 09:29:17 +00:00
}
/**
* Test inactive status when there is single admin present.
*
* @param FunctionalTester $I
* @return void
*/
public function testAdminInactiveStatusWithSingleAdmin(FunctionalTester $I): void
{
2022-01-05 12:50:27 +00:00
/**
* Logged in user.
*/
$admin = $I->loginAsAdmin();
2021-10-28 09:29:17 +00:00
/**
* Change the status.
*/
2022-01-05 12:50:27 +00:00
$this->proceedToChangeStatus($I, $admin);
2021-10-28 09:29:17 +00:00
/**
2022-01-05 12:50:27 +00:00
* Current route should be user listing page.
2021-10-28 09:29:17 +00:00
*/
$I->seeCurrentRouteIs('admin.users.index');
2022-01-05 12:50:27 +00:00
/**
* Grabbed latest record.
*/
$latestRecord = $I->grabRecord(Admin::class, [
'id' => $admin->id,
]);
/**
* Assertion.
*/
$I->assertEquals(1, $latestRecord->status);
2021-10-28 09:29:17 +00:00
}
/**
* Test inactive status when there are more admins present.
*
* @param FunctionalTester $I
* @return void
*/
public function testAdminInactiveStatusWhenMoreAdminsPresent(FunctionalTester $I): void
{
2022-01-05 12:50:27 +00:00
/**
* Logged in user.
*/
$I->loginAsAdmin();
2021-10-28 09:29:17 +00:00
/**
* Created one more admin so that status get changed.
*/
2022-01-05 12:50:27 +00:00
$anotherAdmin = $I->have(Admin::class);
2021-10-28 09:29:17 +00:00
/**
* Change the status.
*/
2022-01-05 12:50:27 +00:00
$this->proceedToChangeStatus($I, $anotherAdmin);
2021-10-28 09:29:17 +00:00
/**
2022-01-05 12:50:27 +00:00
* Current route should be user listing page.
2021-10-28 09:29:17 +00:00
*/
2022-01-05 12:50:27 +00:00
$I->seeCurrentRouteIs('admin.users.index');
/**
* Grabbed latest record.
*/
$latestRecord = $I->grabRecord(Admin::class, [
'id' => $anotherAdmin->id,
]);
/**
* Assertion.
*/
$I->assertEquals(0, $latestRecord->status);
2021-10-28 09:29:17 +00:00
}
/**
* Change the status of the admin.
*
* @param FunctionalTester $I
* @return void
*/
2022-01-05 12:50:27 +00:00
private function proceedToChangeStatus(FunctionalTester $I, $editableAdmin = null): void
2021-10-28 09:29:17 +00:00
{
2022-01-05 12:50:27 +00:00
$I->amOnAdminRoute('admin.users.edit', ['id' => $editableAdmin->id], true);
2021-10-28 09:29:17 +00:00
2022-01-05 12:50:27 +00:00
if (auth()->guard('admin')->user()->id !== $editableAdmin->id) {
$I->seeElement('#status', ['value' => '1']);
$I->uncheckOption('#status');
} else {
$I->dontSeeElement('#status');
}
2021-10-28 09:29:17 +00:00
$I->click(__('admin::app.users.users.save-btn-title'));
}
}