|
| 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->putJson($this->route, [ |
| 17 | + 'domain' => 'nonexistent.wikibase.cloud', |
| 18 | + 'readOnly' => true, |
| 19 | + ]); |
| 20 | + |
| 21 | + $response->assertStatus(404) |
| 22 | + ->assertJson([ |
| 23 | + 'error' => "Wiki not found for domain 'nonexistent.wikibase.cloud'", |
| 24 | + ]); |
| 25 | + } |
| 26 | + |
| 27 | + public function testSetWikiToReadOnly() { |
| 28 | + $wiki = Wiki::factory()->create([ |
| 29 | + 'domain' => 'somewiki.wikibase.cloud', |
| 30 | + ]); |
| 31 | + |
| 32 | + $response = $this->putJson($this->route, [ |
| 33 | + 'domain' => 'somewiki.wikibase.cloud', |
| 34 | + 'readOnly' => true, |
| 35 | + ]); |
| 36 | + |
| 37 | + $response->assertStatus(200) |
| 38 | + ->assertJson([ |
| 39 | + 'success' => true, |
| 40 | + 'domain' => 'somewiki.wikibase.cloud', |
| 41 | + 'message' => 'Wiki set to read-only successfully.', |
| 42 | + ]); |
| 43 | + |
| 44 | + $this->assertSame( |
| 45 | + 'This wiki is currently read-only.', |
| 46 | + WikiSetting::whereWikiId($wiki->id)->whereName('wgReadOnly')->first()->value |
| 47 | + ); |
| 48 | + |
| 49 | + } |
| 50 | + |
| 51 | + public function testDeleteSettingForReadOnlyFalse() { |
| 52 | + $wiki = Wiki::factory()->create([ |
| 53 | + 'domain' => 'somewiki.wikibase.cloud', |
| 54 | + ]); |
| 55 | + $wiki->setSetting('wgReadOnly', 'test'); |
| 56 | + |
| 57 | + $this->putJson($this->route, [ |
| 58 | + 'domain' => $wiki->domain, |
| 59 | + 'readOnly' => false, |
| 60 | + ]) |
| 61 | + ->assertStatus(200) |
| 62 | + ->assertJson(['message' => 'Read-only setting successfully removed for wiki.']); |
| 63 | + |
| 64 | + $this->assertNull( |
| 65 | + WikiSetting::whereWikiId($wiki->id) |
| 66 | + ->whereName('wgReadOnly') |
| 67 | + ->first(), |
| 68 | + ); |
| 69 | + } |
| 70 | +} |
0 commit comments