Skip to content

Commit 5f9bebe

Browse files
committed
Add missing test cases prior to refactoring
1 parent ba51ae5 commit 5f9bebe

4 files changed

Lines changed: 45 additions & 8 deletions

File tree

tests/Routes/Wiki/DeleteWikiTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ public function testDelete()
3434
Wiki::withTrashed()->find($wiki->id)->wiki_deletion_reason
3535
);
3636
}
37+
38+
public function testFailOnWrongWikiManager(): void
39+
{
40+
$userWiki = Wiki::factory()->create();
41+
$otherWiki = Wiki::factory()->create();
42+
$user = User::factory()->create(['verified' => true]);
43+
WikiManager::factory()->create(['wiki_id' => $userWiki->id, 'user_id' => $user->id]);
44+
$this->actingAs($user, 'api')
45+
->post('wiki/delete', ['wiki' => $otherWiki->id])
46+
->assertStatus(401);
47+
}
3748
}

tests/Routes/Wiki/DetailsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function testSkipsNonPublicSettings()
6161
$this->assertEquals(1, $publicSettings[0]['value']);
6262
}
6363

64+
public function testFailOnWrongWikiManager(): void
65+
{
66+
$userWiki = Wiki::factory()->create();
67+
$otherWiki = Wiki::factory()->create();
68+
$user = User::factory()->create(['verified' => true]);
69+
WikiManager::factory()->create(['wiki_id' => $userWiki->id, 'user_id' => $user->id]);
70+
$this->actingAs($user, 'api')
71+
->postJson($this->route, ['wiki' => $otherWiki->id])
72+
->assertStatus(403);
73+
}
74+
6475
public function testWikiProfile()
6576
{
6677
$wiki = Wiki::factory()->create();

tests/Routes/Wiki/LogoUpdateTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,17 @@ public function testUpdate()
5454
$this->assertSame(64, $logo->height());
5555
$this->assertSame(64, $logo->width());
5656
}
57+
58+
public function testFailOnWrongWikiManager(): void
59+
{
60+
$userWiki = Wiki::factory()->create();
61+
$otherWiki = Wiki::factory()->create();
62+
$user = User::factory()->create(['verified' => true]);
63+
WikiManager::factory()->create(['wiki_id' => $userWiki->id, 'user_id' => $user->id]);
64+
$file = UploadedFile::fake()
65+
->createWithContent("logo_200x200.png", file_get_contents(__DIR__ . "/../../data/logo_200x200.png"));
66+
$this->actingAs($user, 'api')
67+
->post('wiki/logo/update', ['wiki' => $otherWiki->id, 'logo' => $file])
68+
->assertStatus(401);
69+
}
5770
}

tests/Routes/Wiki/SettingUpdateTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ public function testSetInvalidSetting()
3838
->assertJsonStructure(['errors' => ['setting']]);
3939
}
4040

41-
public function testValidSettingNoWiki()
41+
public function testFailOnWrongWikiManager(): void
4242
{
4343
$settingName = 'wwExtEnableConfirmAccount';
44-
44+
$userWiki = Wiki::factory()->create();
45+
$otherWiki = Wiki::factory()->create();
4546
$user = User::factory()->create(['verified' => true]);
47+
WikiManager::factory()->create(['wiki_id' => $userWiki->id, 'user_id' => $user->id]);
4648
$this->actingAs($user, 'api')
47-
->json('POST', str_replace('foo', $settingName, $this->route), [
48-
'wiki' => 99856,
49-
'setting' => $settingName,
50-
'value' => '1',
51-
])
52-
->assertStatus(401);
49+
->postJson(str_replace('foo', $settingName, $this->route), [
50+
'wiki' => $otherWiki->id,
51+
'setting' => $settingName,
52+
'value' => '1'
53+
])
54+
->assertStatus(401);
5355
}
5456

5557
static public function provideValidSettings()

0 commit comments

Comments
 (0)