Skip to content

Commit c91dee7

Browse files
committed
add test
1 parent a98246b commit c91dee7

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace Tests\Routes\Backend;
4+
5+
use App\Wiki;
6+
use App\WikiDb;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
class WikiControllerTest extends TestCase {
11+
use RefreshDatabase;
12+
13+
protected $route = '/backend/wiki/getWikiForDomain';
14+
15+
private function createWiki(string $domain) {
16+
$wiki = Wiki::factory()->create(['domain' => $domain]);
17+
WikiDb::create([
18+
'name' => $domain,
19+
'user' => 'someUser',
20+
'password' => 'somePassword',
21+
'prefix' => 'somePrefix',
22+
'version' => 'someVersion',
23+
'wiki_id' => $wiki->id,
24+
]);
25+
}
26+
27+
public function testGetWikiDomainSuccess() {
28+
$wikiDomain = 'coffeebase.wikibase.cloud';
29+
30+
$this->createWiki($wikiDomain);
31+
32+
$this->get("{$this->route}?domain={$wikiDomain}")
33+
->assertStatus(200)
34+
->assertJsonPath('data.domain', $wikiDomain)
35+
->assertJsonStructure([
36+
'data' => [
37+
'domain',
38+
'sitename',
39+
'wiki_queryservice_namespace',
40+
],
41+
]);
42+
}
43+
44+
public function testGetWikiDomainMissingWikiDomain() {
45+
$this->getJson("{$this->route}")
46+
->assertStatus(422);
47+
}
48+
49+
public function testGetWikiDomainWikiNotFound() {
50+
$this->getJson("{$this->route}?domain=somewiki")
51+
->assertStatus(404);
52+
}
53+
}

0 commit comments

Comments
 (0)