Skip to content

Commit 1f36064

Browse files
committed
add test cases
1 parent aa7e861 commit 1f36064

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

tests/src/Feature/Resources/ExtraResourceTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<?php
22

3+
use SolutionForest\InspireCms\InspireCmsConfig;
34
use SolutionForest\InspireCms\Tests\Fixtures\Filament\Resources\PostResource;
45
use SolutionForest\InspireCms\Tests\TestCase;
56

67
uses(TestCase::class);
78

89
beforeEach(function () {
9-
$this->panelPath = '/cms';
10-
$this->panelId = 'cms';
10+
$this->panelPath = '/' . InspireCmsConfig::get('admin.path', 'cms');
11+
$this->panelId = InspireCmsConfig::getPanelId();
1112
$this->createSuperAdminUser();
1213
});
1314

tests/src/Unit/Models/UserTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Auth;
4+
use Illuminate\Support\Facades\Hash;
5+
use Illuminate\Support\Str;
6+
use SolutionForest\InspireCms\Facades\PermissionManifest;
7+
use SolutionForest\InspireCms\Helpers\AuthHelper;
8+
use SolutionForest\InspireCms\Helpers\PermissionHelper;
9+
use SolutionForest\InspireCms\Tests\Models\User;
10+
use SolutionForest\InspireCms\Tests\TestCase;
11+
use Spatie\Permission\Models\Role;
12+
13+
uses(TestCase::class);
14+
15+
describe('user management', function () {
16+
17+
it('can create super admin user', function () {
18+
$this->createSuperAdminUser();
19+
20+
$user = User::first();
21+
22+
expect($user)->not->toBeNull();
23+
expect($user->name)->toBe('Super Admin');
24+
expect($user->email)->toBe('[email protected]');
25+
expect($user->preferred_language)->toBe('en');
26+
expect($user->uuid)->not->toBeNull();
27+
expect(Str::isUuid($user->uuid))->toBeTrue();
28+
expect(Hash::check('password', $user->password))->toBeTrue();
29+
});
30+
31+
it('assigns super admin role to created user', function () {
32+
$this->createSuperAdminUser();
33+
34+
$user = User::first();
35+
$superAdminRoleName = PermissionManifest::getSuperAdminRoleName();
36+
$superAdminRole = Role::where('name', $superAdminRoleName)->first();
37+
38+
expect($user->hasRole($superAdminRole))->toBeTrue();
39+
});
40+
41+
it('can login as super admin', function () {
42+
$this->createSuperAdminUser();
43+
44+
$response = $this->loginCmsPanelAsSuperAdmin();
45+
46+
expect(Auth::guard(AuthHelper::guardName())->check())->toBeTrue();
47+
expect(Auth::guard(AuthHelper::guardName())->user())->toBeInstanceOf(User::class);
48+
});
49+
50+
});

0 commit comments

Comments
 (0)