mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-09-13 13:57:34 -04:00
- Sales::getSearch now enforces reports_sales grant before running search, returns 403 with lang message when missing - Rename snake_case helpers/methods to camelCase across Sales controller, Sale model, and tabular_helper (get_sale_data_row -> getSaleDataRow, get_payments_summary -> getPaymentsSummary, sales_headers -> salesHeaders, etc.) - Config/OSPOS: reset DB data cache before checking app_config table existence to avoid stale schema cache in tests - TestDatabaseBootstrapSeeder: expose static reset() so tests can rebuild schema once per class instead of only via seeder run() - SalesControllerTest: bootstrap DB once per class, seed once, refresh app settings each setUp, add tests for search endpoint authorization (cashier denied, supervisor allowed), move createTestItem into shared ItemFixtureTrait Signed-off-by: objecttothis <17935339+objecttothis@users.noreply.github.com>
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Database\Seeds;
|
|
|
|
use CodeIgniter\Database\Seeder;
|
|
use Config\Database;
|
|
|
|
class TestDatabaseBootstrapSeeder extends Seeder
|
|
{
|
|
public static function reset(): void
|
|
{
|
|
if (ENVIRONMENT !== 'testing') {
|
|
throw new \RuntimeException('TestDatabaseBootstrapSeeder can only run in the testing environment.');
|
|
}
|
|
|
|
$config = config('Database');
|
|
$group = $config->tests;
|
|
$dbName = $group['database'];
|
|
|
|
if ($dbName === '' || !str_contains(strtolower($dbName), 'test')) {
|
|
throw new \RuntimeException("Refusing to reset non-test database: {$dbName}");
|
|
}
|
|
|
|
$serverConn = Database::connect([
|
|
'hostname' => $group['hostname'],
|
|
'username' => $group['username'],
|
|
'password' => $group['password'],
|
|
'DBDriver' => $group['DBDriver'],
|
|
'database' => null,
|
|
'charset' => $group['charset'] ?? 'utf8mb4',
|
|
'DBCollat' => $group['DBCollat'] ?? 'utf8mb4_general_ci',
|
|
], false);
|
|
|
|
$serverConn->query("DROP DATABASE IF EXISTS `{$dbName}`");
|
|
$serverConn->query("CREATE DATABASE IF NOT EXISTS `{$dbName}`");
|
|
}
|
|
|
|
public function run(): void
|
|
{
|
|
self::reset();
|
|
}
|
|
}
|