This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestCase.php
More file actions
152 lines (128 loc) · 4.01 KB
/
TestCase.php
File metadata and controls
152 lines (128 loc) · 4.01 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
declare(strict_types=1);
namespace Codedge\MagicLink\Tests;
use Codedge\MagicLink\ServiceProvider;
use Illuminate\Foundation\Application;
use Orchestra\Testbench\TestCase as OrchestraTestCase;
use Statamic\Extend\Manifest;
use Statamic\Facades\Role;
use Statamic\Facades\User;
use Statamic\Providers\StatamicServiceProvider;
use Statamic\Statamic;
class TestCase extends OrchestraTestCase
{
protected bool $shouldFakeVersion = true;
/**
* Setup the test environment.
*/
protected function setUp(): void
{
parent::setUp();
if ($this->shouldFakeVersion) {
/** @phpstan-ignore-next-line */
\Facades\Statamic\Version::shouldReceive('get')->andReturn('3.0.10');
$this->addToAssertionCount(-1); // Dont want to assert this
}
}
/**
* Sign in a Statamic user.
*
* @param array $permissions
* @return mixed
*/
protected function signInUser($permissions = [])
{
$role = Role::make()->handle('test')->title('Test')->addPermission($permissions)->save();
$user = User::make();
$user->id(1)->email('test@mail.de')->assignRole($role);
$this->be($user);
return $user;
}
/**
* Sign in a Statamic user as admin.
*
* @return mixed
*/
protected function signInAdmin()
{
$user = User::make();
$user->id(1)->email('test@mail.de')->makeSuper();
$this->be($user);
return $user;
}
/**
* Load package service provider.
*
* @param Application $app
* @return array
*/
protected function getPackageProviders($app)
{
return [
StatamicServiceProvider::class,
ServiceProvider::class,
];
}
/**
* Load package alias.
*
* @param Application $app
* @return array
*/
protected function getPackageAliases($app)
{
return [
'Statamic' => Statamic::class,
];
}
/**
* Load Environment.
*
* @param Application $app
*/
protected function getEnvironmentSetUp($app)
{
parent::getEnvironmentSetUp($app);
$app->make(Manifest::class)->manifest = [
'codedge/statamic-magiclink' => [
'id' => 'codedge/statamic-magiclink',
'namespace' => 'Codedge\\MagicLink\\',
],
];
}
/**
* Resolve the Application Configuration and set the Statamic configuration.
*
* @param Application $app
*/
protected function resolveApplicationConfiguration($app)
{
parent::resolveApplicationConfiguration($app);
$configs = [
'assets', 'cp', 'forms', 'routes', 'static_caching',
'sites', 'stache', 'system', 'users',
];
foreach ($configs as $config) {
$app['config']->set("statamic.$config", require(__DIR__."/../vendor/statamic/cms/config/{$config}.php"));
}
$app['config']->set('auth.providers.users.driver', 'statamic');
$app['config']->set('statamic.stache.watcher', false);
$app['config']->set('statamic.users.repository', 'file');
$app['config']->set('statamic.stache.stores.users', [
'class' => \Statamic\Stache\Stores\UsersStore::class,
'directory' => __DIR__.'/__fixtures__/users',
]);
// Setting the user repository to the default flat file system
$app['config']->set('statamic.users.repository', 'file');
// Assume the pro edition within tests
$app['config']->set('statamic.editions.pro', true);
Statamic::pushCpRoutes(function () {
return require_once realpath(__DIR__.'/../routes/cp.php');
});
Statamic::pushWebRoutes(function () {
return require_once realpath(__DIR__.'/../routes/web.php');
});
// Define magiclink config settings for all of our tests
$app['config']->set('statamic-magiclink', require(__DIR__.'/../config/config.php'));
}
}