-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDetailsTest.php
More file actions
100 lines (80 loc) · 3.24 KB
/
DetailsTest.php
File metadata and controls
100 lines (80 loc) · 3.24 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
<?php
namespace Tests\Routes\Wiki\Managers;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\Routes\Traits\OptionsRequestAllowed;
use Tests\TestCase;
use App\Wiki;
use App\WikiSetting;
use App\User;
use App\WikiManager;
use App\WikiProfile;
class DetailsTest extends TestCase
{
protected $route = 'wiki/details';
use OptionsRequestAllowed, RefreshDatabase;
public function setUp(): void
{
parent::setUp();
Wiki::query()->delete();
WikiSetting::query()->delete();
WikiManager::query()->delete();
}
public function tearDown(): void
{
Wiki::query()->delete();
WikiSetting::query()->delete();
WikiManager::query()->delete();
parent::tearDown();
}
public function testNoCredentials()
{
$wiki = Wiki::factory()->create(['domain' => 'test.wikibase.cloud']);
WikiSetting::factory()->create(['name' => 'wwUseQuestyCaptcha', 'value' => 1]);
$this->postJson($this->route, ['wiki' => $wiki->id])
->assertStatus(401);
}
public function testSkipsNonPublicSettings()
{
$user = User::factory()->create(['verified' => true]);
$wiki = Wiki::factory()->create(['domain' => 'other.wikibase.cloud']);
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
WikiSetting::factory()->create(['wiki_id' => $wiki->id, 'name' => 'wwUseQuestyCaptcha', 'value' => 1]);
WikiSetting::factory()->create(['wiki_id' => $wiki->id, 'name' => 'xxxSecret', 'value' => 'foobarbaz']);
$response = $this->actingAs($user, 'api')->postJson($this->route, ['wiki' => $wiki->id]);
$response->assertStatus(200);
$publicSettings = data_get($response->json(), 'data.public_settings', []);
$this->assertCount(1, $publicSettings);
$this->assertEquals('wwUseQuestyCaptcha', $publicSettings[0]['name']);
$this->assertEquals(1, $publicSettings[0]['value']);
}
public function testWikiProfile()
{
$wiki = Wiki::factory()->create();
$user = User::factory()->create(['verified' => true]);
WikiManager::factory()->create(['wiki_id' => $wiki->id, 'user_id' => $user->id]);
$versionA = WikiProfile::create([
'wiki_id' => $wiki->id,
'audience' => 'wide',
'temporality' => 'temporary',
'purpose' => 'data_hub'
])->refresh()->toArray();
$response = $this->actingAs($user, 'api')
->postJson($this->route, ['wiki' => $wiki->id])
->assertStatus(200);
$profile = data_get($response->json(), 'data.wiki_latest_profile', []);
$this->assertNotEmpty($profile);
$this->assertEquals($versionA, $profile);
$versionB = WikiProfile::create([
'wiki_id' => $wiki->id,
'audience' => 'wide',
'temporality' => 'permanent',
'purpose' => 'data_hub'
])->refresh()->toArray();
$response = $this->actingAs($user, 'api')
->postJson($this->route, ['wiki' => $wiki->id])
->assertStatus(200);
$profile = data_get($response->json(), 'data.wiki_latest_profile', []);
$this->assertNotEmpty($profile);
$this->assertEquals($versionB, $profile);
}
}