Skip to content

Commit 012b6d6

Browse files
Migrate BrowserKit tests to HTTP tests (#984)
* migrate AdminTest from browserkit tests to http tests * update assertRedirectToRoute() by assertRedirect() * remove BrowserKit from AdminTest * update ArticleTest * update BlockUsersTest * update CanonicalUrlTest * update HomeTest * update ModeratorTest * update NavigationTest * update NotificationsTest * update ProfileTest * update ReplyTest * migrate settingsTest * update AuthTest * remove RouteServiceProvider from authtest * update ForumTest * fix: two failed forum tests * build: remove browser kit testing depedency
1 parent 7b2ff20 commit 012b6d6

14 files changed

+443
-351
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
},
4242
"require-dev": {
4343
"fakerphp/faker": "^1.10",
44-
"laravel/browser-kit-testing": "^7.0",
4544
"mockery/mockery": "^1.4.4",
4645
"nunomaduro/collision": "^7.0",
4746
"pestphp/pest": "^2.0",

tests/Feature/AdminTest.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
use App\Models\User;
77
use Carbon\Carbon;
88
use Illuminate\Foundation\Testing\DatabaseMigrations;
9-
use Tests\Feature\BrowserKitTestCase;
9+
use Tests\TestCase;
1010

11-
uses(BrowserKitTestCase::class);
11+
uses(TestCase::class);
1212
uses(DatabaseMigrations::class);
1313

1414
test('requires login', function () {
15-
$this->visit('/admin')
16-
->seePageIs('/login');
15+
$this->get('/admin')
16+
->assertRedirect('/login');
1717
});
1818

1919
test('normal users cannot visit the admin section', function () {
@@ -83,9 +83,9 @@
8383
$this->loginAsAdmin();
8484

8585
$this->put('/admin/users/'.$user->username().'/ban')
86-
->assertRedirectedTo('/');
86+
->assertRedirect('/');
8787

88-
test()->seeInDatabase('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
88+
test()->assertDatabaseHas('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
8989
});
9090

9191
test('moderators cannot ban a user without a reason', function () {
@@ -94,9 +94,9 @@
9494
$this->loginAsModerator();
9595

9696
$this->put('/admin/users/'.$user->username().'/ban')
97-
->assertRedirectedTo('/');
97+
->assertRedirect('/');
9898

99-
test()->seeInDatabase('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
99+
test()->assertDatabaseHas('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
100100
});
101101

102102
test('admins can delete a user', function () {
@@ -108,14 +108,14 @@
108108
$this->loginAsAdmin();
109109

110110
$this->delete('/admin/users/'.$user->username())
111-
->assertRedirectedTo('/admin/users');
111+
->assertRedirect('/admin/users');
112112

113-
$this->notSeeInDatabase('users', ['name' => 'Freek Murze']);
113+
$this->assertDatabaseMissing('users', ['name' => 'Freek Murze']);
114114

115115
// Make sure associated content is deleted.
116-
$this->notSeeInDatabase('threads', ['author_id' => $user->id()]);
117-
$this->notSeeInDatabase('replies', ['replyable_id' => $thread->id()]);
118-
$this->notSeeInDatabase('replies', ['author_id' => $user->id()]);
116+
$this->assertDatabaseMissing('threads', ['author_id' => $user->id()]);
117+
$this->assertDatabaseMissing('replies', ['replyable_id' => $thread->id()]);
118+
$this->assertDatabaseMissing('replies', ['author_id' => $user->id()]);
119119
});
120120

121121
test('admins cannot delete other admins', function () {
@@ -144,9 +144,9 @@
144144
$this->loginAsAdmin();
145145

146146
$this->get('admin')
147-
->see($submittedArticle->title())
148-
->dontSee($draftArticle->title())
149-
->dontSee($liveArticle->title());
147+
->assertSee($submittedArticle->title())
148+
->assertDontSee($draftArticle->title())
149+
->assertDontSee($liveArticle->title());
150150
});
151151

152152
test('moderators can list submitted articles', function () {
@@ -157,9 +157,9 @@
157157
$this->loginAsModerator();
158158

159159
$this->get('admin')
160-
->see($submittedArticle->title())
161-
->dontSee($draftArticle->title())
162-
->dontSee($liveArticle->title());
160+
->assertSee($submittedArticle->title())
161+
->assertDontSee($draftArticle->title())
162+
->assertDontSee($liveArticle->title());
163163
});
164164

165165
test('users cannot list submitted articles', function () {
@@ -171,7 +171,7 @@
171171

172172
test('guests cannot list submitted articles', function () {
173173
$this->get('admin')
174-
->assertRedirectedTo('login');
174+
->assertRedirect('/login');
175175
});
176176

177177
test('admins can view submitted articles', function () {
@@ -180,7 +180,7 @@
180180
$this->loginAsAdmin();
181181

182182
$this->get("articles/{$article->slug()}")
183-
->see('Awaiting Approval');
183+
->assertSee('Awaiting Approval');
184184
});
185185

186186
test('admins can approve articles', function () {
@@ -216,7 +216,7 @@
216216
$article = Article::factory()->create(['submitted_at' => now()]);
217217

218218
$this->put("/admin/articles/{$article->slug()}/approve")
219-
->assertRedirectedTo('/login');
219+
->assertRedirect('/login');
220220

221221
expect($article->fresh()->approvedAt())->toBeNull();
222222
});
@@ -254,7 +254,7 @@
254254
$article = Article::factory()->create(['submitted_at' => now(), 'approved_at' => now()]);
255255

256256
$this->put("/admin/articles/{$article->slug()}/disapprove")
257-
->assertRedirectedTo('/login');
257+
->assertRedirect('/login');
258258

259259
$this->assertNotNull($article->fresh()->approvedAt());
260260
});
@@ -357,30 +357,30 @@ function assertCanSeeTheUserOverview()
357357
User::factory()->create(['name' => 'Freek Murze']);
358358
User::factory()->create(['name' => 'Frederick Vanbrabant']);
359359

360-
test()->visit('/admin/users')
361-
->see('Freek Murze')
362-
->see('Frederick Vanbrabant');
360+
test()->get('/admin/users')
361+
->assertSee('Freek Murze')
362+
->assertSee('Frederick Vanbrabant');
363363
}
364364

365365
function assertCanBanUsers()
366366
{
367367
$user = User::factory()->create(['name' => 'Freek Murze']);
368368

369369
test()->put('/admin/users/'.$user->username().'/ban', ['reason' => 'A good reason'])
370-
->assertRedirectedTo('/user/'.$user->username());
370+
->assertRedirect('/user/'.$user->username());
371371

372-
test()->notSeeInDatabase('users', ['id' => $user->id(), 'banned_at' => null]);
373-
test()->seeInDatabase('users', ['id' => $user->id(), 'banned_reason' => 'A good reason']);
372+
test()->assertDatabaseMissing('users', ['id' => $user->id(), 'banned_at' => null]);
373+
test()->assertDatabaseHas('users', ['id' => $user->id(), 'banned_reason' => 'A good reason']);
374374
}
375375

376376
function assertCanUnbanUsers()
377377
{
378378
$user = User::factory()->create(['name' => 'Freek Murze', 'banned_at' => Carbon::now()]);
379379

380380
test()->put('/admin/users/'.$user->username().'/unban')
381-
->assertRedirectedTo('/user/'.$user->username());
381+
->assertRedirect('/user/'.$user->username());
382382

383-
test()->seeInDatabase('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
383+
test()->assertDatabaseHas('users', ['id' => $user->id(), 'banned_at' => null, 'banned_reason' => null]);
384384
}
385385

386386
function assertCannotBanAdmins()

0 commit comments

Comments
 (0)