Provided Test Cases For Inactive Check
This commit is contained in:
parent
687e13d49f
commit
0f0512562e
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\User\Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class AdminFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = \Webkul\User\Models\Admin::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
'name' => $this->faker->name(),
|
||||
'email' => $this->faker->unique()->email,
|
||||
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
|
||||
'role_id' => 1,
|
||||
'status' => 1
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
namespace Webkul\User\Models;
|
||||
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Webkul\User\Models\Role;
|
||||
use Webkul\User\Notifications\AdminResetPassword;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Webkul\User\Contracts\Admin as AdminContract;
|
||||
|
||||
use Webkul\User\Database\Factories\AdminFactory;
|
||||
use Webkul\User\Notifications\AdminResetPassword;
|
||||
|
||||
class Admin extends Authenticatable implements AdminContract
|
||||
{
|
||||
use Notifiable;
|
||||
use Notifiable, HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -40,23 +40,14 @@ class Admin extends Authenticatable implements AdminContract
|
|||
|
||||
/**
|
||||
* Get the role that owns the admin.
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function role()
|
||||
{
|
||||
return $this->belongsTo(RoleProxy::modelClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
*
|
||||
* @param string $token
|
||||
* @return void
|
||||
*/
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new AdminResetPassword($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if admin has permission to perform certain action.
|
||||
*
|
||||
|
|
@ -71,4 +62,25 @@ class Admin extends Authenticatable implements AdminContract
|
|||
|
||||
return in_array($permission, $this->role->permissions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send the password reset notification.
|
||||
*
|
||||
* @param string $token
|
||||
* @return void
|
||||
*/
|
||||
public function sendPasswordResetNotification($token)
|
||||
{
|
||||
$this->notify(new AdminResetPassword($token));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new factory instance for the model.
|
||||
*
|
||||
* @return AdminFactory
|
||||
*/
|
||||
protected static function newFactory(): AdminFactory
|
||||
{
|
||||
return AdminFactory::new();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,14 +6,20 @@ use FunctionalTester;
|
|||
|
||||
class ExchangeRatesCest
|
||||
{
|
||||
/**
|
||||
* Index page test.
|
||||
*
|
||||
* @param FunctionalTester $I
|
||||
* @return void
|
||||
*/
|
||||
public function testIndex(FunctionalTester $I): void
|
||||
{
|
||||
$I->loginAsAdmin();
|
||||
$I->amOnAdminRoute('admin.dashboard.index');
|
||||
|
||||
$I->click(__('admin::app.layouts.settings'), '//*[contains(@class, "navbar-left")]');
|
||||
$I->click(__('admin::app.layouts.exchange-rates'), '//*[contains(@class, "aside-nav")]');
|
||||
|
||||
$I->click(__('admin::app.layouts.exchange-rates'), '//*[contains(@class, "aside-nav")]');
|
||||
$I->seeCurrentRouteIs('admin.exchange_rates.index');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
<?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();
|
||||
$I->amOnAdminRoute('admin.dashboard.index');
|
||||
|
||||
$I->click(__('admin::app.layouts.settings'), '//*[contains(@class, "navbar-left")]');
|
||||
|
||||
$I->click(__('admin::app.layouts.users'), '//*[contains(@class, "aside-nav")]');
|
||||
$I->seeCurrentRouteIs('admin.users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test inactive status when there is single admin present.
|
||||
*
|
||||
* @param FunctionalTester $I
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminInactiveStatusWithSingleAdmin(FunctionalTester $I): void
|
||||
{
|
||||
/**
|
||||
* Change the status.
|
||||
*/
|
||||
$this->proceedToChangeStatus($I);
|
||||
|
||||
/**
|
||||
* Current route should be user listing page with error.
|
||||
*/
|
||||
$I->seeCurrentRouteIs('admin.users.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test inactive status when there are more admins present.
|
||||
*
|
||||
* @param FunctionalTester $I
|
||||
* @return void
|
||||
*/
|
||||
public function testAdminInactiveStatusWhenMoreAdminsPresent(FunctionalTester $I): void
|
||||
{
|
||||
/**
|
||||
* Created one more admin so that status get changed.
|
||||
*/
|
||||
$I->have(Admin::class);
|
||||
|
||||
/**
|
||||
* Change the status.
|
||||
*/
|
||||
$this->proceedToChangeStatus($I);
|
||||
|
||||
/**
|
||||
* Admin should be logged out.
|
||||
*/
|
||||
$I->seeCurrentRouteIs('admin.session.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the status of the admin.
|
||||
*
|
||||
* @param FunctionalTester $I
|
||||
* @return void
|
||||
*/
|
||||
private function proceedToChangeStatus(FunctionalTester $I): void
|
||||
{
|
||||
$I->loginAsAdmin();
|
||||
$I->amOnAdminRoute('admin.users.edit', ['id' => 1], true);
|
||||
|
||||
$I->seeElement('#status', ['value' => '1']);
|
||||
$I->uncheckOption('#status');
|
||||
|
||||
$I->click(__('admin::app.users.users.save-btn-title'));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue