Lance Pioch f8ad9a1805
Use PestPHP (#962)
* Install Pest

* Don’t use bootstrap file anymore

* Fix comment

* Think this is needed

* Reset this

* Switch dataproviders to attributes

* Fix these

* Support in memory databases

* Fix this migration

* Switch this back for now

* Add missing import

* Truncate and reseed database

* These are replaced now

* Switch ci to use pest
2025-01-30 16:39:17 -05:00

50 lines
1.5 KiB
PHP

<?php
namespace App\Tests\Unit\Services\Acl\Api;
use App\Models\ApiKey;
use App\Tests\TestCase;
use App\Services\Acl\Api\AdminAcl;
use App\Models\Server;
use PHPUnit\Framework\Attributes\DataProvider;
class AdminAclTest extends TestCase
{
/**
* Test that permissions return the expects values.
*/
#[DataProvider('permissionsDataProvider')]
public function testPermissions(int $permission, int $check, bool $outcome): void
{
$this->assertSame($outcome, AdminAcl::can($permission, $check));
}
/**
* Test that checking against a model works as expected.
*/
public function testCheck(): void
{
$model = ApiKey::factory()->make(['permissions' => [
Server::RESOURCE_NAME => AdminAcl::READ | AdminAcl::WRITE,
]]);
$this->assertTrue(AdminAcl::check($model, Server::RESOURCE_NAME, AdminAcl::WRITE));
}
/**
* Provide valid and invalid permissions combos for testing.
*/
public static function permissionsDataProvider(): array
{
return [
[AdminAcl::READ, AdminAcl::READ, true],
[AdminAcl::READ | AdminAcl::WRITE, AdminAcl::READ, true],
[AdminAcl::READ | AdminAcl::WRITE, AdminAcl::WRITE, true],
[AdminAcl::WRITE, AdminAcl::WRITE, true],
[AdminAcl::READ, AdminAcl::WRITE, false],
[AdminAcl::NONE, AdminAcl::READ, false],
[AdminAcl::NONE, AdminAcl::WRITE, false],
];
}
}