Skip to content

Commit 1fc42a7

Browse files
committed
Add tests
1 parent f92967a commit 1fc42a7

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Tests\Routes\Backend;
4+
5+
use App\Wiki;
6+
use App\WikiSetting;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
class WikiReadOnlyControllerTest extends TestCase {
11+
use RefreshDatabase;
12+
13+
protected string $route = '/backend/setWikiReadOnly';
14+
15+
public function testItReturns404WhenWikiNotFound(){
16+
$response = $this->postJson($this->route, [
17+
'domain' => 'nonexistent.wikibase.cloud'
18+
]);
19+
20+
$response->assertStatus(404)
21+
->assertJson([
22+
'error' => 'Wiki not found for domain: nonexistent.wikibase.cloud',
23+
]);
24+
}
25+
26+
public function testSetWikiToReadOnly(){
27+
$wiki = Wiki::factory()->create([
28+
'domain' => 'somewiki.wikibase.cloud',
29+
]);
30+
31+
$response = $this->postJson($this->route, [
32+
'domain' => 'somewiki.wikibase.cloud',
33+
]);
34+
35+
$response->assertStatus(200)
36+
->assertJson([
37+
'success' => true,
38+
'domain' => 'somewiki.wikibase.cloud',
39+
'message' => 'Wiki set to read-only successfully.',
40+
]);
41+
42+
$this->assertSame(
43+
'This wiki is currently read-only.',
44+
WikiSetting::whereWikiId($wiki->id)->whereName('wgReadOnly')->first()->value
45+
);
46+
47+
}
48+
49+
}

0 commit comments

Comments
 (0)