mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-21 10:15:01 -04:00
- Rename `ConfigTest` to `ConfigControllerTest` and add bootstrap logic for child tests. - Introduce `StockLocationsControllerTest` to validate stock location API behavior, including payload validation, creation, renaming, deletion, reordering, and default location assignment. - Implement `AdminAuthTrait` for streamlined test authentication with customizable permissions and session setup. Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Support;
|
|
|
|
use App\Models\Employee;
|
|
use CodeIgniter\Config\Services;
|
|
|
|
trait AdminAuthTrait
|
|
{
|
|
protected function loginAsAdminWithGrants(array $permissionIds, string $menuGroup = 'office'): int
|
|
{
|
|
$personData = [
|
|
'first_name' => 'Test',
|
|
'last_name' => 'Admin',
|
|
'email' => 'admin-' . uniqid() . '@test.com',
|
|
'phone_number' => '555-0100',
|
|
];
|
|
|
|
$employeeData = [
|
|
'username' => 'admin_' . uniqid(),
|
|
'password' => password_hash('password123', PASSWORD_DEFAULT),
|
|
'hash_version' => 2,
|
|
'language_code' => 'en',
|
|
'language' => 'english',
|
|
];
|
|
|
|
$grantsData = array_map(
|
|
static fn (string $permissionId) => ['permission_id' => $permissionId, 'menu_group' => $menuGroup],
|
|
$permissionIds
|
|
);
|
|
|
|
$employeeModel = model(Employee::class);
|
|
$employeeModel->save_employee($personData, $employeeData, $grantsData, NEW_ENTRY);
|
|
|
|
$personId = $personData['person_id'];
|
|
|
|
$session = Services::session();
|
|
$session->destroy();
|
|
$session->set('person_id', $personId);
|
|
$session->set('menu_group', $menuGroup);
|
|
|
|
$this->withSession($session->get());
|
|
|
|
return $personId;
|
|
}
|
|
}
|