-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWikiReadOnlyControllerTest.php
More file actions
70 lines (56 loc) · 1.95 KB
/
WikiReadOnlyControllerTest.php
File metadata and controls
70 lines (56 loc) · 1.95 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
<?php
namespace Tests\Routes\Backend;
use App\Wiki;
use App\WikiSetting;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class WikiReadOnlyControllerTest extends TestCase {
use RefreshDatabase;
protected string $route = '/backend/setWikiReadOnly';
public function testItReturns404WhenWikiNotFound() {
$response = $this->putJson($this->route, [
'domain' => 'nonexistent.wikibase.cloud',
'readOnly' => 1,
]);
$response->assertStatus(404)
->assertJson([
'error' => "Wiki not found for domain 'nonexistent.wikibase.cloud'",
]);
}
public function testSetWikiToReadOnly() {
$wiki = Wiki::factory()->create([
'domain' => 'somewiki.wikibase.cloud',
]);
$response = $this->putJson($this->route, [
'domain' => 'somewiki.wikibase.cloud',
'readOnly' => 1,
]);
$response->assertStatus(200)
->assertJson([
'success' => true,
'domain' => 'somewiki.wikibase.cloud',
'message' => 'Wiki set to read-only successfully.',
]);
$this->assertSame(
'This wiki is currently read-only.',
WikiSetting::whereWikiId($wiki->id)->whereName('wgReadOnly')->first()->value
);
}
public function testDeleteSettingForReadOnlyFalse() {
$wiki = Wiki::factory()->create([
'domain' => 'somewiki.wikibase.cloud',
]);
$wiki->setSetting('wgReadOnly', 'test');
$this->putJson($this->route, [
'domain' => $wiki->domain,
'readOnly' => 0,
])
->assertStatus(200)
->assertJson(['message' => 'Read-only setting successfully removed for wiki.']);
$this->assertNull(
WikiSetting::whereWikiId($wiki->id)
->whereName('wgReadOnly')
->first(),
);
}
}