Migrated much test entity usage via find/replace · mohnkhan/BookStack@b56f735 · GitHub
Skip to content

Commit b56f735

Browse files
committed
Migrated much test entity usage via find/replace
1 parent 068a8a0 commit b56f735

45 files changed

Lines changed: 264 additions & 384 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/Actions/AuditLogTest.php

Lines changed: 11 additions & 15 deletions

tests/Actions/WebhookCallTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ public function test_webhook_call_data_format()
8888
'*' => Http::response('', 200),
8989
]);
9090
$webhook = $this->newWebhook(['active' => true, 'endpoint' => 'https://wh.example.com'], ['all']);
91-
/** @var Page $page */
92-
$page = Page::query()->first();
91+
$page = $this->entities->page();
9392
$editor = $this->getEditor();
9493

9594
$this->runEvent(ActivityType::PAGE_UPDATE, $page, $editor);

tests/Actions/WebhookFormatTesting.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function test_entity_events_show_related_user_info()
3232

3333
public function test_page_create_and_update_events_show_revision_info()
3434
{
35-
/** @var Page $page */
36-
$page = Page::query()->first();
35+
$page = $this->entities->page();
3736
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
3837

3938
$data = $this->getWebhookData(ActivityType::PAGE_UPDATE, $page);

tests/Api/AttachmentsApiTest.php

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AttachmentsApiTest extends TestCase
1717
public function test_index_endpoint_returns_expected_book()
1818
{
1919
$this->actingAsApiEditor();
20-
$page = Page::query()->first();
20+
$page = $this->entities->page();
2121
$attachment = $this->createAttachmentForPage($page, [
2222
'name' => 'My test attachment',
2323
'external' => true,
@@ -37,8 +37,7 @@ public function test_index_endpoint_returns_expected_book()
3737
public function test_attachments_listing_based_upon_page_visibility()
3838
{
3939
$this->actingAsApiEditor();
40-
/** @var Page $page */
41-
$page = Page::query()->first();
40+
$page = $this->entities->page();
4241
$attachment = $this->createAttachmentForPage($page, [
4342
'name' => 'My test attachment',
4443
'external' => true,
@@ -66,8 +65,7 @@ public function test_attachments_listing_based_upon_page_visibility()
6665
public function test_create_endpoint_for_link_attachment()
6766
{
6867
$this->actingAsApiAdmin();
69-
/** @var Page $page */
70-
$page = Page::query()->first();
68+
$page = $this->entities->page();
7169

7270
$details = [
7371
'name' => 'My attachment',
@@ -85,8 +83,7 @@ public function test_create_endpoint_for_link_attachment()
8583
public function test_create_endpoint_for_upload_attachment()
8684
{
8785
$this->actingAsApiAdmin();
88-
/** @var Page $page */
89-
$page = Page::query()->first();
86+
$page = $this->entities->page();
9087
$file = $this->getTestFile('textfile.txt');
9188

9289
$details = [
@@ -106,8 +103,7 @@ public function test_create_endpoint_for_upload_attachment()
106103
public function test_upload_limit_restricts_attachment_uploads()
107104
{
108105
$this->actingAsApiAdmin();
109-
/** @var Page $page */
110-
$page = Page::query()->first();
106+
$page = $this->entities->page();
111107

112108
config()->set('app.upload_limit', 1);
113109

@@ -130,8 +126,7 @@ public function test_upload_limit_restricts_attachment_uploads()
130126
public function test_name_needed_to_create()
131127
{
132128
$this->actingAsApiAdmin();
133-
/** @var Page $page */
134-
$page = Page::query()->first();
129+
$page = $this->entities->page();
135130

136131
$details = [
137132
'uploaded_to' => $page->id,
@@ -146,8 +141,7 @@ public function test_name_needed_to_create()
146141
public function test_link_or_file_needed_to_create()
147142
{
148143
$this->actingAsApiAdmin();
149-
/** @var Page $page */
150-
$page = Page::query()->first();
144+
$page = $this->entities->page();
151145

152146
$details = [
153147
'name' => 'my attachment',
@@ -165,8 +159,7 @@ public function test_link_or_file_needed_to_create()
165159
public function test_message_shown_if_file_is_not_a_valid_file()
166160
{
167161
$this->actingAsApiAdmin();
168-
/** @var Page $page */
169-
$page = Page::query()->first();
162+
$page = $this->entities->page();
170163

171164
$details = [
172165
'name' => 'my attachment',
@@ -182,8 +175,7 @@ public function test_message_shown_if_file_is_not_a_valid_file()
182175
public function test_read_endpoint_for_link_attachment()
183176
{
184177
$this->actingAsApiAdmin();
185-
/** @var Page $page */
186-
$page = Page::query()->first();
178+
$page = $this->entities->page();
187179

188180
$attachment = $this->createAttachmentForPage($page, [
189181
'name' => 'my attachment',
@@ -216,8 +208,7 @@ public function test_read_endpoint_for_link_attachment()
216208
public function test_read_endpoint_for_file_attachment()
217209
{
218210
$this->actingAsApiAdmin();
219-
/** @var Page $page */
220-
$page = Page::query()->first();
211+
$page = $this->entities->page();
221212
$file = $this->getTestFile('textfile.txt');
222213

223214
$details = [
@@ -259,8 +250,7 @@ public function test_attachment_not_visible_on_other_users_draft()
259250
$this->actingAsApiAdmin();
260251
$editor = $this->getEditor();
261252

262-
/** @var Page $page */
263-
$page = Page::query()->first();
253+
$page = $this->entities->page();
264254
$page->draft = true;
265255
$page->owned_by = $editor->id;
266256
$page->save();
@@ -280,8 +270,7 @@ public function test_attachment_not_visible_on_other_users_draft()
280270
public function test_update_endpoint()
281271
{
282272
$this->actingAsApiAdmin();
283-
/** @var Page $page */
284-
$page = Page::query()->first();
273+
$page = $this->entities->page();
285274
$attachment = $this->createAttachmentForPage($page);
286275

287276
$details = [
@@ -298,8 +287,7 @@ public function test_update_endpoint()
298287
public function test_update_link_attachment_to_file()
299288
{
300289
$this->actingAsApiAdmin();
301-
/** @var Page $page */
302-
$page = Page::query()->first();
290+
$page = $this->entities->page();
303291
$attachment = $this->createAttachmentForPage($page);
304292
$file = $this->getTestFile('textfile.txt');
305293

@@ -318,8 +306,7 @@ public function test_update_link_attachment_to_file()
318306
public function test_update_file_attachment_to_link()
319307
{
320308
$this->actingAsApiAdmin();
321-
/** @var Page $page */
322-
$page = Page::query()->first();
309+
$page = $this->entities->page();
323310
$file = $this->getTestFile('textfile.txt');
324311
$this->call('POST', $this->baseEndpoint, ['name' => 'My file attachment', 'uploaded_to' => $page->id], [], ['file' => $file]);
325312
/** @var Attachment $attachment */
@@ -346,8 +333,7 @@ public function test_update_file_attachment_to_link()
346333
public function test_delete_endpoint()
347334
{
348335
$this->actingAsApiAdmin();
349-
/** @var Page $page */
350-
$page = Page::query()->first();
336+
$page = $this->entities->page();
351337
$attachment = $this->createAttachmentForPage($page);
352338

353339
$resp = $this->deleteJson("{$this->baseEndpoint}/{$attachment->id}");

tests/Api/ChaptersApiTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function test_index_endpoint_returns_expected_chapter()
3434
public function test_create_endpoint()
3535
{
3636
$this->actingAsApiEditor();
37-
$book = Book::query()->first();
37+
$book = $this->entities->book();
3838
$details = [
3939
'name' => 'My API chapter',
4040
'description' => 'A chapter created via the API',
@@ -64,7 +64,7 @@ public function test_create_endpoint()
6464
public function test_chapter_name_needed_to_create()
6565
{
6666
$this->actingAsApiEditor();
67-
$book = Book::query()->first();
67+
$book = $this->entities->book();
6868
$details = [
6969
'book_id' => $book->id,
7070
'description' => 'A chapter created via the API',

tests/Api/PagesApiTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function test_index_endpoint_returns_expected_page()
3535
public function test_create_endpoint()
3636
{
3737
$this->actingAsApiEditor();
38-
$book = Book::query()->first();
38+
$book = $this->entities->book();
3939
$details = [
4040
'name' => 'My API page',
4141
'book_id' => $book->id,
@@ -67,7 +67,7 @@ public function test_create_endpoint()
6767
public function test_page_name_needed_to_create()
6868
{
6969
$this->actingAsApiEditor();
70-
$book = Book::query()->first();
70+
$book = $this->entities->book();
7171
$details = [
7272
'book_id' => $book->id,
7373
'html' => '<p>A page created via the API</p>',

tests/Api/RecycleBinApiTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function test_index_endpoint_returns_expected_page()
5050
{
5151
$admin = $this->getAdmin();
5252

53-
$page = Page::query()->first();
54-
$book = Book::query()->first();
53+
$page = $this->entities->page();
54+
$book = $this->entities->book();
5555
$this->actingAs($admin)->delete($page->getUrl());
5656
$this->delete($book->getUrl());
5757

@@ -139,7 +139,7 @@ public function test_index_endpoint_returns_parent()
139139

140140
public function test_restore_endpoint()
141141
{
142-
$page = Page::query()->first();
142+
$page = $this->entities->page();
143143
$this->asAdmin()->delete($page->getUrl());
144144
$page->refresh();
145145

@@ -163,7 +163,7 @@ public function test_restore_endpoint()
163163

164164
public function test_destroy_endpoint()
165165
{
166-
$page = Page::query()->first();
166+
$page = $this->entities->page();
167167
$this->asAdmin()->delete($page->getUrl());
168168
$page->refresh();
169169

tests/Api/SearchApiTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function test_all_endpoint_returns_search_filtered_results_with_query()
3838

3939
public function test_all_endpoint_returns_entity_url()
4040
{
41-
/** @var Page $page */
42-
$page = Page::query()->first();
41+
$page = $this->entities->page();
4342
$page->update(['name' => 'name with superuniquevalue within']);
4443
$page->indexForSearch();
4544

@@ -52,8 +51,7 @@ public function test_all_endpoint_returns_entity_url()
5251

5352
public function test_all_endpoint_returns_items_with_preview_html()
5453
{
55-
/** @var Book $book */
56-
$book = Book::query()->first();
54+
$book = $this->entities->book();
5755
$book->update(['name' => 'name with superuniquevalue within', 'description' => 'Description with superuniquevalue within']);
5856
$book->indexForSearch();
5957

tests/Auth/AuthTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ public function test_mfa_session_cleared_on_logout()
5858
public function test_login_redirects_to_initially_requested_url_correctly()
5959
{
6060
config()->set('app.url', 'http://localhost');
61-
/** @var Page $page */
62-
$page = Page::query()->first();
61+
$page = $this->entities->page();
6362

6463
$this->get($page->getUrl())->assertRedirect(url('/login'));
6564
$this->login('admin@admin.com', 'password')

tests/Commands/ClearActivityCommandTest.php

Lines changed: 1 addition & 2 deletions

0 commit comments

Comments
 (0)