Files
laravel-manager/tests/Feature/ModulesTest.php

52 lines
2.0 KiB
PHP

<?php
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use IriksIT\Manager\Facades\Manager;
use IriksIT\Manager\Models\Group;
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 () {
$this->actingAs(makeUser(superAdmin: true))->getJson('/manager/posts')->assertOk();
$this->actingAs(makeUser())->getJson('/manager/posts')->assertForbidden();
});
it('gives a group member the permissions of the group, with what they need', function () {
$user = makeUser(['posts.publish']);
expect($user->managerPermissions())->toBe(['posts.view', 'posts.write', 'posts.publish']);
$this->actingAs($user)->getJson('/manager/posts')->assertOk();
$this->actingAs($user)->getJson('/manager/pages')->assertForbidden();
});
it('forgets what a switched-off module allowed', function () {
$group = Group::create(['name' => 'Old', 'permissions' => ['posts.view', 'reviews.manage']]);
expect($group->allowed())->toBe(['posts.view']);
});
it('does not answer for abilities of the host app', function () {
expect(Gate::forUser(makeUser(superAdmin: true))->allows('host.something'))->toBeFalse();
});