First setup: module registry, switchable modules, permissions

This commit is contained in:
Matthijs Iriks committed 2026-12-04 01:18:14 +01:00
commit 936c794597
52 files changed
+1304

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
<?php
use Illuminate\Support\Facades\Schema;
use IriksIT\Manager\Facades\Manager;
use IriksIT\Manager\Models\Group;
use IriksIT\Manager\Tests\Fixtures\User;
use IriksIT\Manager\Tests\TestCase;
uses(TestCase::class);
it('has users and media on and reviews off by default', function () {
expect(Manager::enabled('users'))->toBeTrue()
->and(Manager::enabled('media'))->toBeTrue()
->and(Manager::enabled('reviews'))->toBeFalse();
});
it('adds no routes, tables or permissions for a module that is off', function () {
expect(Route::has('manager.reviews.index'))->toBeFalse()
->and(Schema::hasTable('manager_reviews'))->toBeFalse()
->and(Manager::permissions())->not->toHaveKey('reviews.manage')
->and(collect(Manager::navigation())->pluck('label'))->not->toContain('Reviews');
});
it('adds all of it for a module that is on', function () {
expect(Route::has('manager.posts.index'))->toBeTrue()
->and(Schema::hasTable('manager_posts'))->toBeTrue()
->and(Manager::permissions())->toHaveKey('posts.publish');
});
it('lets a super admin in and keeps others out without the permission', function () {
$admin = User::create(['name' => 'a', 'email' => '[email protected]', 'password' => 'x', 'manager_super_admin' => true]);
$other = User::create(['name' => 'b', 'email' => '[email protected]', 'password' => 'x']);
$this->actingAs($admin)->getJson('/manager/posts')->assertOk();
$this->actingAs($other)->getJson('/manager/posts')->assertForbidden();
});
it('gives a group member the permissions of the group', function () {
$user = User::create(['name' => 'c', 'email' => '[email protected]', 'password' => 'x']);
$group = Group::create(['name' => 'Editors', 'permissions' => ['posts.view']]);
$user->managerGroups()->attach($group);
$this->actingAs($user)->getJson('/manager/posts')->assertOk();
$this->actingAs($user)->getJson('/manager/pages')->assertForbidden();
});