Skip to content

Commit b56f735

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

Some content is hidden

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

45 files changed

+264
-384
lines changed

tests/Actions/AuditLogTest.php

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function test_shows_activity()
4646
{
4747
$admin = $this->getAdmin();
4848
$this->actingAs($admin);
49-
$page = Page::query()->first();
49+
$page = $this->entities->page();
5050
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
5151
$activity = Activity::query()->orderBy('id', 'desc')->first();
5252

@@ -60,7 +60,7 @@ public function test_shows_activity()
6060
public function test_shows_name_for_deleted_items()
6161
{
6262
$this->actingAs($this->getAdmin());
63-
$page = Page::query()->first();
63+
$page = $this->entities->page();
6464
$pageName = $page->name;
6565
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
6666

@@ -76,7 +76,7 @@ public function test_shows_activity_for_deleted_users()
7676
{
7777
$viewer = $this->getViewer();
7878
$this->actingAs($viewer);
79-
$page = Page::query()->first();
79+
$page = $this->entities->page();
8080
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
8181

8282
$this->actingAs($this->getAdmin());
@@ -89,7 +89,7 @@ public function test_shows_activity_for_deleted_users()
8989
public function test_filters_by_key()
9090
{
9191
$this->actingAs($this->getAdmin());
92-
$page = Page::query()->first();
92+
$page = $this->entities->page();
9393
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
9494

9595
$resp = $this->get('settings/audit');
@@ -102,7 +102,7 @@ public function test_filters_by_key()
102102
public function test_date_filters()
103103
{
104104
$this->actingAs($this->getAdmin());
105-
$page = Page::query()->first();
105+
$page = $this->entities->page();
106106
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
107107

108108
$yesterday = (Carbon::now()->subDay()->format('Y-m-d'));
@@ -126,11 +126,11 @@ public function test_user_filter()
126126
$admin = $this->getAdmin();
127127
$editor = $this->getEditor();
128128
$this->actingAs($admin);
129-
$page = Page::query()->first();
129+
$page = $this->entities->page();
130130
$this->activityService->add(ActivityType::PAGE_CREATE, $page);
131131

132132
$this->actingAs($editor);
133-
$chapter = Chapter::query()->first();
133+
$chapter = $this->entities->chapter();
134134
$this->activityService->add(ActivityType::CHAPTER_UPDATE, $chapter);
135135

136136
$resp = $this->actingAs($admin)->get('settings/audit?user=' . $admin->id);
@@ -146,8 +146,7 @@ public function test_ip_address_logged_and_visible()
146146
{
147147
config()->set('app.proxies', '*');
148148
$editor = $this->getEditor();
149-
/** @var Page $page */
150-
$page = Page::query()->first();
149+
$page = $this->entities->page();
151150

152151
$this->actingAs($editor)->put($page->getUrl(), [
153152
'name' => 'Updated page',
@@ -171,8 +170,7 @@ public function test_ip_address_is_searchable()
171170
{
172171
config()->set('app.proxies', '*');
173172
$editor = $this->getEditor();
174-
/** @var Page $page */
175-
$page = Page::query()->first();
173+
$page = $this->entities->page();
176174

177175
$this->actingAs($editor)->put($page->getUrl(), [
178176
'name' => 'Updated page',
@@ -198,8 +196,7 @@ public function test_ip_address_not_logged_in_demo_mode()
198196
config()->set('app.proxies', '*');
199197
config()->set('app.env', 'demo');
200198
$editor = $this->getEditor();
201-
/** @var Page $page */
202-
$page = Page::query()->first();
199+
$page = $this->entities->page();
203200

204201
$this->actingAs($editor)->put($page->getUrl(), [
205202
'name' => 'Updated page',
@@ -222,8 +219,7 @@ public function test_ip_address_respects_precision_setting()
222219
config()->set('app.proxies', '*');
223220
config()->set('app.ip_address_precision', 2);
224221
$editor = $this->getEditor();
225-
/** @var Page $page */
226-
$page = Page::query()->first();
222+
$page = $this->entities->page();
227223

228224
$this->actingAs($editor)->put($page->getUrl(), [
229225
'name' => 'Updated page',

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
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ class ClearActivityCommandTest extends TestCase
1414
public function test_clear_activity_command()
1515
{
1616
$this->asEditor();
17-
/** @var Page $page */
18-
$page = Page::query()->first();
17+
$page = $this->entities->page();
1918
Activity::add(ActivityType::PAGE_UPDATE, $page);
2019

2120
$this->assertDatabaseHas('activities', [

0 commit comments

Comments
 (0)