-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestCase.php
104 lines (92 loc) · 3.76 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace EscolaLms\Courses\Tests;
use EscolaLms\Auth\EscolaLmsAuthServiceProvider;
use EscolaLms\Auth\Tests\Models\Client;
use EscolaLms\Categories\EscolaLmsCategoriesServiceProvider;
use EscolaLms\Courses\AuthServiceProvider;
use EscolaLms\Courses\EscolaLmsCourseServiceProvider;
use EscolaLms\Courses\Facades\Topic;
use EscolaLms\Courses\Tests\Models\TopicContent\SecondExampleTopicType;
use EscolaLms\Courses\Tests\Http\Resources\TopicType\Admin\ExampleTopicTypeResource;
use EscolaLms\Courses\Tests\Models\TopicContent\ExampleTopicType;
use EscolaLms\Courses\Tests\Models\User as UserTest;
use EscolaLms\Files\EscolaLmsFilesServiceProvider;
use EscolaLms\ModelFields\ModelFieldsServiceProvider;
use EscolaLms\Scorm\EscolaLmsScormServiceProvider;
use EscolaLms\Settings\EscolaLmsSettingsServiceProvider;
use EscolaLms\Tags\EscolaLmsTagsServiceProvider;
use Illuminate\Testing\TestResponse;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use Spatie\Permission\PermissionServiceProvider;
use Spatie\ResponseCache\ResponseCacheServiceProvider;
class TestCase extends \EscolaLms\Core\Tests\TestCase
{
protected ?TestResponse $response;
protected function setUp(): void
{
parent::setUp();
Passport::useClientModel(Client::class);
Topic::registerContentClasses([ExampleTopicType::class]);
Topic::registerContentClasses([SecondExampleTopicType::class]);
Topic::registerResourceClasses(ExampleTopicType::class, [
'admin' => ExampleTopicTypeResource::class,
]);
}
protected function getPackageProviders($app)
{
return [
...parent::getPackageProviders($app),
EscolaLmsAuthServiceProvider::class,
PermissionServiceProvider::class,
PassportServiceProvider::class,
EscolaLmsCategoriesServiceProvider::class,
EscolaLmsCourseServiceProvider::class,
AuthServiceProvider::class,
EscolaLmsSettingsServiceProvider::class,
EscolaLmsTopicTypeTestServiceProvider::class,
EscolaLmsFilesServiceProvider::class,
ResponseCacheServiceProvider::class,
ModelFieldsServiceProvider::class,
];
}
protected function getEnvironmentSetUp($app)
{
$app['config']->set('auth.providers.users.model', UserTest::class);
$app['config']->set('passport.client_uuids', true);
$app['config']->set('database.connections.mysql.strict', false);
$app['config']->set('app.debug', (bool) env('APP_DEBUG', true));
$app['config']->set('escolalms.tags.ignore_migrations', false);
$app['config']->set('scorm', [
'table_names' => [
'user_table' => 'users',
'scorm_table' => 'scorm',
'scorm_sco_table' => 'scorm_sco',
'scorm_sco_tracking_table' => 'scorm_sco_tracking',
],
// Scorm directory. You may create a custom path in file system
'disk' => 'local',
]);
}
public function assertApiResponse(array $actualData)
{
$this->assertApiSuccess();
$response = json_decode($this->response->getContent(), true);
$responseData = $response['data'];
$this->assertNotEmpty($responseData['id']);
$this->assertModelData($actualData, $responseData);
}
public function assertApiSuccess()
{
$this->response->assertJson(['success' => true]);
}
public function assertModelData(array $actualData, array $expectedData)
{
foreach ($actualData as $key => $value) {
if (in_array($key, ['created_at', 'updated_at'])) {
continue;
}
$this->assertEquals($actualData[$key], $expectedData[$key]);
}
}
}