69 lines
3.1 KiB
PHP
69 lines
3.1 KiB
PHP
<?php
|
|
|
|
use IriksIT\Manager\Models\UserSetting;
|
|
use IriksIT\Manager\Support\ModuleRegistry;
|
|
use IriksIT\Manager\Tests\SimpleViewTestCase;
|
|
|
|
uses(SimpleViewTestCase::class);
|
|
|
|
function menuOf($test, $user): array
|
|
{
|
|
return $test->actingAs($user)->getJson('/manager')->assertOk()->json('navigation');
|
|
}
|
|
|
|
it('puts sections, icons and order on the menu, and adds links of the site', function () {
|
|
config(['manager.menu.links' => [['label' => 'Leads', 'url' => '/manager/leads', 'section' => 'Content', 'order' => 6, 'new_tab' => true]]]);
|
|
config(['manager.menu.items' => [...config('manager.menu.items'), 'labels.index' => ['hidden' => true]]]);
|
|
|
|
$items = collect(app(ModuleRegistry::class)->navigation());
|
|
|
|
expect($items->first())->toMatchArray(['label' => 'Posts', 'section' => 'Content', 'icon' => 'file', 'order' => 5, 'simple' => true])
|
|
->and($items->pluck('label')->slice(0, 2)->values()->all())->toBe(['Posts', 'Leads'])
|
|
->and($items->pluck('label'))->not->toContain('Categories and tags')
|
|
->and($items->firstWhere('label', 'Leads'))->toMatchArray(['url' => '/manager/leads', 'new_tab' => true]);
|
|
});
|
|
|
|
it('keeps the old shape of a menu item working', function () {
|
|
$item = collect(app(ModuleRegistry::class)->navigation())->firstWhere('label', 'Media');
|
|
|
|
expect($item)->toMatchArray(['label' => 'Media', 'permission' => 'media.view', 'simple' => false, 'order' => 100])
|
|
->and($item['route'])->toBe('manager.media.index');
|
|
});
|
|
|
|
it('shows an account with only the switch permission the simple face first, and lets it change', function () {
|
|
$user = makeUser(['posts.view', 'media.view', 'manager.switch']);
|
|
|
|
expect(collect(menuOf($this, $user))->pluck('label')->all())->toBe(['Posts']);
|
|
|
|
$this->putJson('/manager/profile/view', ['view' => 'full'])->assertOk();
|
|
|
|
expect(collect(menuOf($this, $user))->pluck('label')->all())->toBe(['Posts', 'Media'])
|
|
->and(UserSetting::query()->where('user_id', $user->id)->value('view'))->toBe('full');
|
|
|
|
$this->putJson('/manager/profile/view', ['view' => 'nonsense'])->assertUnprocessable();
|
|
});
|
|
|
|
it('gives the full face to an account with the full permission, and the simple face to all others for good', function () {
|
|
$full = makeUser(['posts.view', 'media.view', 'manager.full']);
|
|
$plain = makeUser(['posts.view', 'media.view']);
|
|
|
|
expect(collect(menuOf($this, $full))->pluck('label')->all())->toBe(['Posts', 'Media']);
|
|
expect(collect(menuOf($this, $plain))->pluck('label')->all())->toBe(['Posts']);
|
|
|
|
$this->putJson('/manager/profile/view', ['view' => 'full'])->assertForbidden();
|
|
});
|
|
|
|
it('lets a super admin see everything and switch', function () {
|
|
$admin = makeUser(superAdmin: true);
|
|
|
|
expect(collect(menuOf($this, $admin))->pluck('label'))->toContain('Posts', 'Media');
|
|
|
|
$this->putJson('/manager/profile/view', ['view' => 'simple'])->assertOk();
|
|
|
|
expect(collect(menuOf($this, $admin))->pluck('label')->all())->toBe(['Posts']);
|
|
});
|
|
|
|
it('offers the two permissions in the group form only when the simple face is on', function () {
|
|
expect(collect(app(ModuleRegistry::class)->permissionValues()))->toContain('manager.full', 'manager.switch');
|
|
});
|