Trait luya\testsuite\traits\AdminDatabaseTableTrait
Uses Traits | luya\testsuite\traits\DatabaseTableTrait |
---|---|
Implemented by | luya\testsuite\cases\NgRestTestCase, luya\testsuite\scopes\PermissionScope |
Available since version | 1.0.20 |
Source Code | https://github.com/luyadev/luya-testsuite/blob/master/src/traits/AdminDatabaseTableTrait.php |
A trait to make it easier to work with database tables and LUYA admin permission.
Public Methods
Method Details
Add permission api entry
public integer addPermissionApi ( $id, $api, $isCrud = true ) | ||
$id | ||
$api | string | |
$isCrud | boolean | |
return | integer |
Returns the "fake" id fro the given api |
---|
public function addPermissionApi($id, $api, $isCrud = true)
{
$this->insertRow('admin_auth', [
'id' => $id,
'module_name' => '@app',
'alias_name' => $api,
'is_crud' => (int) $isCrud,
'api' => $api,
]);
return $id;
}
Add permission route.
public integer addPermissionRoute ( $id, $route, $moduleName = '@app' ) | ||
$id | ||
$route | string | |
$moduleName | ||
return | integer |
Returns the fake id for the auth entry. |
---|
public function addPermissionRoute($id, $route, $moduleName = '@app')
{
$this->insertRow('admin_auth', [
'id' => $id,
'module_name' => $moduleName,
'alias_name' => $route,
'route' => $route,
]);
return $id;
}
Assigne a group to an auth entry.
public integer assignGroupAuth ( $groupId, $authId, $canCreate = true, $canUpdate = true, $canDelete = true ) | ||
$groupId | integer | |
$authId | integer | |
$canCreate | boolean | |
$canUpdate | boolean | |
$canDelete | boolean | |
return | integer |
The number of affected rows. |
---|
public function assignGroupAuth($groupId, $authId, $canCreate = true, $canUpdate = true, $canDelete = true)
{
return $this->insertRow('admin_group_auth', [
'group_id' => $groupId,
'auth_id' => $authId,
'crud_create' => (int) $canCreate,
'crud_update' => (int) $canUpdate,
'crud_delete' => (int) $canDelete,
]);
}
Create the admin auth table.
public void createAdminAuthTable ( ) |
public function createAdminAuthTable()
{
$this->createTableIfNotExists('admin_auth', [
'id' => 'INT(11) PRIMARY KEY',
'alias_name' => 'text',
'module_name' => 'text',
'is_crud' => 'int(11)',
'route' => 'text',
'api' => 'text',
'pool' => 'text',
]);
}
Create the admin group auth table.
public void createAdminGroupAuthTable ( ) |
public function createAdminGroupAuthTable()
{
$this->createTableIfNotExists('admin_group_auth', [
'id' => 'INT(11) PRIMARY KEY',
'group_id' => 'int(11)',
'auth_id' => 'int(11)',
'crud_create' => 'int(11)',
'crud_update' => 'int(11)',
'crud_delete' => 'int(11)',
]);
}
Create the Group Fixture with given ID.
public luya\testsuite\fixtures\NgRestModelFixture createAdminGroupFixture ( $id ) | ||
$id | integer |
public function createAdminGroupFixture($id)
{
return new NgRestModelFixture([
'modelClass' => Group::class,
'fixtureData' => [
'tester' => [
'id' => $id,
'name' => 'Test Group',
],
],
]);
}
Create admin language fixture
public luya\testsuite\fixtures\NgRestModelFixture createAdminLangFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminLangFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Lang::class,
'fixtureData' => $fixtureData,
]);
}
Create the NgRest Log Fixture.
public luya\testsuite\fixtures\ActiveRecordFixture createAdminNgRestLogFixture ( array $fixtureData = [] ) | ||
$fixtureData |
public function createAdminNgRestLogFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => NgrestLog::class,
'fixtureData' => $fixtureData,
]);
}
Queue Log Error
public luya\testsuite\fixtures\ActiveRecordFixture createAdminQueueLogErrorFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminQueueLogErrorFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => QueueLogError::class,
'fixtureData' => $fixtureData,
]);
}
Queue Log
public luya\testsuite\fixtures\ActiveRecordFixture createAdminQueueLogFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminQueueLogFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => QueueLog::class,
'fixtureData' => $fixtureData,
]);
}
Create the Admin Queue Table
public void createAdminQueueTable ( ) |
public function createAdminQueueTable()
{
return $this->createTableIfNotExists('admin_queue', [
'id' => 'INT(11) PRIMARY KEY',
'channel' => 'text',
'job' => 'blog',
'pushed_at' => 'int(11)',
'ttr' => 'int(11)',
'delay' => 'int(11)',
'priority' => 'int(11)',
'reserved_at' => 'int(11)',
'attempt' => 'int(11)',
'done_at' => 'int(11)',
]);
}
Storage File
public luya\testsuite\fixtures\ActiveRecordFixture createAdminStorageFileFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminStorageFileFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => StorageFile::class,
'fixtureData' => $fixtureData,
]);
}
Storage Filter Chain
public luya\testsuite\fixtures\ActiveRecordFixture createAdminStorageFilterChainFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminStorageFilterChainFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => StorageFilterChain::class,
'fixtureData' => $fixtureData,
]);
}
Storage Filter
public luya\testsuite\fixtures\ActiveRecordFixture createAdminStorageFilterFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminStorageFilterFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => StorageFilter::class,
'fixtureData' => $fixtureData,
]);
}
Storage Image
public luya\testsuite\fixtures\ActiveRecordFixture createAdminStorageImageFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminStorageImageFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => StorageImage::class,
'fixtureData' => $fixtureData,
]);
}
Create admin tag fixture
public luya\testsuite\fixtures\NgRestModelFixture createAdminTagFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminTagFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Tag::class,
'fixtureData' => $fixtureData,
]);
}
Create admin tag relation fixture
public luya\testsuite\fixtures\ActiveRecordFixture createAdminTagRelationFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminTagRelationFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => TagRelation::class,
'fixtureData' => $fixtureData,
]);
}
Create the admin user auth notification table.
public void createAdminUserAuthNotificationTable ( ) |
public function createAdminUserAuthNotificationTable()
{
$this->createTableIfNotExists('admin_user_auth_notification', [
'id' => 'INT(11) PRIMARY KEY',
'user_id' => 'int(11)',
'auth_id' => 'int(11)',
'is_muted' => 'int(11)',
'model_latest_pk_value' => 'text',
'model_class' => 'text',
'created_at' => 'int(11)',
'updated_at' => 'int(11)',
]);
}
User Device
public luya\testsuite\fixtures\ActiveRecordFixture createAdminUserDeviceFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminUserDeviceFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => UserDevice::class,
'fixtureData' => $fixtureData,
]);
}
Create the User Fixture with given fixture Data.
public luya\testsuite\fixtures\NgRestModelFixture createAdminUserFixture ( array $fixtureData = [], $defaultSchema = true ) | ||
$fixtureData | array | |
$defaultSchema |
public function createAdminUserFixture(array $fixtureData = [], $defaultSchema = true)
{
return new NgRestModelFixture([
'modelClass' => User::class,
'schema' => $defaultSchema ? [
'title' => 'int(11)',
'firstname' => 'text',
'lastname' => 'text',
'email' => 'text',
'is_deleted' => 'int(11)',
'is_api_user' => 'boolean',
'api_last_activity' => 'int(11)',
'auth_token' => 'text',
'is_request_logger_enabled' => 'boolean',
'email_verification_token_timestamp' => 'int(11)',
'login_attempt_lock_expiration' => 'int(11)',
'login_attempt' => 'int(11)',
'email_verification_token' => 'text',
'api_allowed_ips' => 'text',
'api_rate_limit' => 'int(11)',
'cookie_token' => 'text',
'settings' => 'text',
'force_reload' => 'int(11)',
'secure_token_timestamp' => 'int(11)',
'secure_token' => 'text',
'password' => 'text',
'password_salt' => 'text',
'login_2fa_enabled' => 'int(11)',
'login_2fa_secret' => 'text',
'login_2fa_backup_key' => 'text',
'password_verification_token' => 'text',
'password_verification_token_timestamp' => 'int(11)',
] : null,
'fixtureData' => $fixtureData,
]);
}
Create the admin user group table.
public void createAdminUserGroupTable ( ) |
public function createAdminUserGroupTable()
{
$this->createTableIfNotExists('admin_user_group', [
'id' => 'INT(11) PRIMARY KEY',
'user_id' => 'int(11)',
'group_id' => 'int(11)',
]);
}
Admin User Fixture
public luya\testsuite\fixtures\NgRestModelFixture createAdminUserLoginFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminUserLoginFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => UserLogin::class,
'fixtureData' => $fixtureData,
]);
}
User Login Lockout
public luya\testsuite\fixtures\ActiveRecordFixture createAdminUserLoginLockoutFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createAdminUserLoginLockoutFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => UserLoginLockout::class,
'fixtureData' => $fixtureData,
]);
}
Create the User Online Fixture.
public luya\testsuite\fixtures\ActiveRecordFixture createAdminUserOnlineFixture ( array $fixtureData = [] ) | ||
$fixtureData |
public function createAdminUserOnlineFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => UserOnline::class,
'fixtureData' => $fixtureData,
]);
}
Create the Group Fixture with given ID.
public luya\testsuite\fixtures\NgRestModelFixture createGroupFixture ( $id ) | ||
$id | integer |
public function createGroupFixture($id)
{
trigger_error('use createAdminGroupFixture() instead', E_USER_DEPRECATED);
return $this->createAdminGroupFixture($id);
}
Create the NgRest Log Fixture.
public luya\testsuite\fixtures\ActiveRecordFixture createNgRestLogFixture ( array $fixtureData = [] ) | ||
$fixtureData |
public function createNgRestLogFixture(array $fixtureData = [])
{
trigger_error('use createAdminNgRestLogFixture() instead', E_USER_DEPRECATED);
return $this->createAdminNgRestLogFixture($fixtureData);
}
Create the User Fixture with given fixture Data.
public luya\testsuite\fixtures\NgRestModelFixture createUserFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createUserFixture(array $fixtureData = [])
{
trigger_error('use createAdminUserFixture() instead', E_USER_DEPRECATED);
return $this->createAdminUserFixture($fixtureData);
}
Create the User Online Fixture.
public luya\testsuite\fixtures\ActiveRecordFixture createUserOnlineFixture ( array $fixtureData = [] ) | ||
$fixtureData |
public function createUserOnlineFixture(array $fixtureData = [])
{
trigger_error('use createAdminUserOnlineFixture() instead', E_USER_DEPRECATED);
return $this->createAdminUserOnlineFixture($fixtureData);
}
Drop the admin auth table.
public void dropAdminAuthTable ( ) |
public function dropAdminAuthTable()
{
$this->dropTableIfExists('admin_auth');
}
Drop the admin group auth table.
public void dropAdminGroupAuthTable ( ) |
public function dropAdminGroupAuthTable()
{
$this->dropTableIfExists('admin_group_auth');
}
Drop the admin user auth notification table.
public void dropAdminUserAuthNotificationTable ( ) |
public function dropAdminUserAuthNotificationTable()
{
$this->dropTableIfExists('admin_user_auth_notification');
}
Drop the admin user group table.
public void dropAdminUserGroupTable ( ) |
public function dropAdminUserGroupTable()
{
$this->dropTableIfExists('admin_user_group');
}
Remove permission api entry.
public integer removePermissionApi ( $api ) | ||
$api | string | |
return | integer |
The number of affected rows. |
---|
public function removePermissionApi($api)
{
return $this->deleteRow('admin_auth', [
'api' => $api,
]);
}
Remove permission route
public integer removePermissionRoute ( $route ) | ||
$route | string | |
return | integer |
The number of affected rows. |
---|
public function removePermissionRoute($route)
{
return $this->deleteRow('admin_auth', [
'route' => $route,
]);
}
Unassigne a group from auth
public integer unAssignGroupAuth ( $groupId, $authId ) | ||
$groupId | integer | |
$authId | integer | |
return | integer |
The number of affected rows. |
---|
public function unAssignGroupAuth($groupId, $authId)
{
return $this->deleteRow('admin_group_auth', [
'group_id' => $groupId,
'auth_id' => $authId,
]);
}