add tests batch 20

This commit is contained in:
root
2026-06-09 01:03:53 -04:00
parent 95efb9652e
commit 6be4875c5e
1502 changed files with 13797 additions and 11313 deletions
+41 -47
View File
@@ -3,6 +3,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use App\Models\BaseModel;
class Role extends BaseModel
{
@@ -18,12 +19,11 @@ class Role extends BaseModel
'created_at',
'updated_at',
];
public $timestamps = true;
protected $casts = [
'priority' => 'integer',
'is_active' => 'boolean',
'priority' => 'integer',
'is_active' => 'boolean',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
@@ -52,47 +52,43 @@ class Role extends BaseModel
* Find roles by names or slugs (case-insensitive), active only, ordered by priority ASC.
*/
// Put these INSIDE the Role model, replacing the current implementations
// Put these INSIDE the Role model, replacing the current implementations
public static function findByNamesOrSlugs(array $keys): array
{
$keys = array_values(array_filter(array_map('strval', $keys)));
if (empty($keys)) {
return [];
}
public static function findByNamesOrSlugs(array $keys): array
{
$keys = array_values(array_filter(array_map('strval', $keys)));
if (empty($keys)) return [];
$lower = array_map('mb_strtolower', $keys);
$placeholders = implode(',', array_fill(0, count($lower), '?'));
$lower = array_map('mb_strtolower', $keys);
$placeholders = implode(',', array_fill(0, count($lower), '?'));
return static::query()
->active()
->where(function (Builder $q) use ($lower, $placeholders) {
$q->whereRaw("LOWER(name) IN ($placeholders)", $lower)
->orWhereRaw("LOWER(slug) IN ($placeholders)", $lower);
})
->orderBy('priority', 'asc')
->get()
->all();
}
return static::query()
->active()
->where(function (Builder $q) use ($lower, $placeholders) {
$q->whereRaw("LOWER(name) IN ($placeholders)", $lower)
->orWhereRaw("LOWER(slug) IN ($placeholders)", $lower);
})
->orderBy('priority', 'asc')
->get()
->all();
}
public static function getIdsByNames(array $names): array
{
$names = array_values(array_filter(array_map('strval', $names)));
if (empty($names)) {
return [];
}
public static function getIdsByNames(array $names): array
{
$names = array_values(array_filter(array_map('strval', $names)));
if (empty($names)) return [];
$lower = array_map('mb_strtolower', $names);
$placeholders = implode(',', array_fill(0, count($lower), '?'));
$lower = array_map('mb_strtolower', $names);
$placeholders = implode(',', array_fill(0, count($lower), '?'));
$ids = static::query()
->select('id')
->whereRaw("LOWER(name) IN ($placeholders)", $lower)
->pluck('id')
->all();
$ids = static::query()
->select('id')
->whereRaw("LOWER(name) IN ($placeholders)", $lower)
->pluck('id')
->all();
return array_map('intval', $ids);
}
return array_map('intval', $ids);
}
/**
* Get dashboard_route by name or slug (case-insensitive), active only.
@@ -100,9 +96,7 @@ class Role extends BaseModel
public static function getRouteByNameOrSlug(string $key): ?string
{
$key = trim((string) $key);
if ($key === '') {
return null;
}
if ($key === '') return null;
$lower = mb_strtolower($key);
@@ -110,7 +104,7 @@ class Role extends BaseModel
->active()
->where(function (Builder $q) use ($lower) {
$q->whereRaw('LOWER(name) = ?', [$lower])
->orWhereRaw('LOWER(slug) = ?', [$lower]);
->orWhereRaw('LOWER(slug) = ?', [$lower]);
})
->first();
@@ -147,12 +141,12 @@ class Role extends BaseModel
public static function rules(?int $id = null): array
{
return [
'name' => ['required', 'string', 'max:255'],
'slug' => ['required', 'string', 'max:255', 'unique:roles,slug,'.($id ?? 'NULL').',id'],
'description' => ['nullable', 'string', 'max:2000'],
'name' => ['required', 'string', 'max:255'],
'slug' => ['required', 'string', 'max:255', 'unique:roles,slug,' . ($id ?? 'NULL') . ',id'],
'description' => ['nullable', 'string', 'max:2000'],
'dashboard_route' => ['nullable', 'string', 'max:255'],
'priority' => ['nullable', 'integer', 'min:0'],
'is_active' => ['nullable', 'boolean'],
'priority' => ['nullable', 'integer', 'min:0'],
'is_active' => ['nullable', 'boolean'],
];
}
}
}