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 pathSettingsTest.php
More file actions
149 lines (121 loc) · 3.92 KB
/
SettingsTest.php
File metadata and controls
149 lines (121 loc) · 3.92 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
<?php
declare(strict_types=1);
namespace Codedge\MagicLink\Tests\CP\Settings;
use Codedge\MagicLink\Repositories\SettingsRepository;
use Codedge\MagicLink\Tests\TestCase;
class SettingsTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->signInAdmin();
}
public function can_see_settings(): void
{
$this->get(cp_route('magiclink.index'))
->assertOk()
->assertSee(__('magiclink::cp.settings.ml_expire_time'))
->assertSee(__('magiclink::cp.settings.ml_enabled'));
}
/** @test */
public function cannot_see_settings_with_no_permissions(): void
{
$this->signInUser();
$this->get(cp_route('magiclink.index'))
->assertRedirect(cp_route('index'));
}
/** @test */
public function can_update_settings_without_error(): void
{
$payload = [
'enabled' => true,
'expireTime' => 999,
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload)->assertOk();
$this->get(cp_route('magiclink.index'))
->assertSee(999);
}
/** @test */
public function cannot_update_settings_with_all_errors(): void
{
$payload = [
'enabled' => 123,
'expireTime' => 'test',
'allowedAddresses' => ['wrong'],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload)
->assertSessionMissing('success')
->assertSessionHasErrors(['enabled', 'expireTime', 'allowedAddresses.0']);
}
/** @test */
public function cannot_update_settings_with_enabled_errors(): void
{
$payload = [
'enabled' => 123,
'expireTime' => 30,
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload)
->assertSessionHasErrors(['enabled']);
$payload = [
'expireTime' => 30,
];
$this->patch(cp_route('magiclink.update'), $payload)
->assertSessionHasErrors(['enabled']);
}
/** @test */
public function cannot_update_settings_with_expire_time_errors(): void
{
$payload = [
'enabled' => true,
'expireTime' => 'test',
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload)
->assertSessionHasErrors(['expireTime']);
$payload = [
'enabled' => true,
];
$this->patch(cp_route('magiclink.update'), $payload)
->assertSessionHasErrors(['expireTime']);
}
/** @test */
public function can_set_enabled_to_true_false(): void
{
$repository = $this->app->make(SettingsRepository::class);
$payload = [
'enabled' => true,
'expireTime' => 300,
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload);
$this->assertTrue($repository->isEnabled());
$payload = [
'enabled' => false,
'expireTime' => 300,
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload);
$this->assertFalse($repository->isEnabled());
}
/** @test */
public function can_set_expireTime_to_values(): void
{
$repository = $this->app->make(SettingsRepository::class);
$payload = [
'enabled' => true,
'expireTime' => 300,
'allowedAddresses' => [],
'allowedDomains' => [],
];
$this->patch(cp_route('magiclink.update'), $payload);
$this->assertEquals(300, $repository->expireTime());
}
}