-
Notifications
You must be signed in to change notification settings - Fork 21
/
TestCase.php
69 lines (58 loc) · 2.14 KB
/
TestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace EscolaLms\HeadlessH5P\Tests;
use EscolaLms\Core\EscolaLmsServiceProvider;
use EscolaLms\Core\Models\User;
use EscolaLms\HeadlessH5P\Database\Seeders\PermissionTableSeeder;
use EscolaLms\HeadlessH5P\Tests\Models\Client;
use EscolaLms\Settings\EscolaLmsSettingsServiceProvider;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use EscolaLms\HeadlessH5P\HeadlessH5PServiceProvider;
use Spatie\Permission\PermissionServiceProvider;
class TestCase extends \EscolaLms\Core\Tests\TestCase
{
public $user;
protected MockHandler $mock;
protected $container = [];
protected function setUp(): void
{
parent::setUp();
Passport::useClientModel(Client::class);
$this->seed(PermissionTableSeeder::class);
}
protected function getPackageProviders($app)
{
return [
...parent::getPackageProviders($app),
HeadlessH5PServiceProvider::class,
PermissionServiceProvider::class,
PassportServiceProvider::class,
EscolaLmsServiceProvider::class,
EscolaLmsSettingsServiceProvider::class,
];
}
protected function getEnvironmentSetUp($app)
{
$this->mock = new MockHandler([new Response(200, [], 'Hello, World')]);
$handlerStack = HandlerStack::create($this->mock);
// Setup default database to use sqlite :memory:
$app['config']->set('auth.providers.users.model', User::class);
$app['config']->set('passport.client_uuids', true);
$app['config']->set('hh5p.guzzle', ['handler' => $handlerStack]);
$app['config']->set('hh5p.h5p_export', true);
}
protected function authenticateAsAdmin(): void
{
$this->user = config('auth.providers.users.model')::factory()->create();
$this->user->guard_name = 'api';
$this->user->assignRole('admin');
}
protected function authenticateAsUser(): void
{
$this->user = config('auth.providers.users.model')::factory()->create();
$this->user->guard_name = 'api';
}
}