Skip to content

Commit 50d480b

Browse files
committed
Fix tests
1 parent 5eed49b commit 50d480b

File tree

2 files changed

+36
-47
lines changed

2 files changed

+36
-47
lines changed

tests/Feature/ForumTest.php

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,12 @@ public function the_thread_subject_cannot_be_an_url()
6565

6666
$this->login();
6767

68-
$this->visit('/forum/create-thread')
69-
->submitForm('Create Thread', [
68+
$this->post('/forum/create-thread', [
7069
'subject' => 'http://example.com Foo title',
7170
'body' => 'This text explains how to work with Eloquent.',
7271
'tags' => [$tag->id()],
7372
])
74-
->seePageIs('/forum/create-thread')
75-
->see('The subject field cannot contain an url.');
73+
->assertSessionHasErrors(['subject' => 'The subject field cannot contain an url.']);
7674
}
7775

7876
/** @test */
@@ -82,16 +80,13 @@ public function users_can_create_a_thread()
8280

8381
$this->login();
8482

85-
$this->visit('/forum/create-thread')
86-
->submitForm('Create Thread', [
83+
$this->post('/forum/create-thread', [
8784
'subject' => 'How to work with Eloquent?',
8885
'body' => 'This text explains how to work with Eloquent.',
8986
'tags' => [$tag->id()],
9087
])
91-
->seePageIs('/forum/how-to-work-with-eloquent')
92-
->see('How to work with Eloquent?')
93-
->see('Test Tag')
94-
->see('Thread successfully created!');
88+
->assertRedirectedTo('/forum/how-to-work-with-eloquent')
89+
->assertSessionHas('success', 'Thread successfully created!');
9590
}
9691

9792
/** @test */
@@ -106,16 +101,13 @@ public function users_can_edit_a_thread()
106101

107102
$this->loginAs($user);
108103

109-
$this->visit('/forum/my-first-thread/edit')
110-
->submitForm('Update Thread', [
104+
$this->put('/forum/my-first-thread', [
111105
'subject' => 'How to work with Eloquent?',
112106
'body' => 'This text explains how to work with Eloquent.',
113107
'tags' => [$tag->id()],
114108
])
115-
->seePageIs('/forum/how-to-work-with-eloquent')
116-
->see('How to work with Eloquent?')
117-
->see('Test Tag')
118-
->see('Thread successfully updated!');
109+
->assertRedirectedTo('/forum/how-to-work-with-eloquent')
110+
->assertSessionHas('success', 'Thread successfully updated!');
119111
}
120112

121113
/** @test */
@@ -147,15 +139,14 @@ public function users_cannot_create_a_thread_with_a_subject_that_is_too_long()
147139

148140
$this->login();
149141

150-
$this->visit('/forum/create-thread')
151-
->submitForm('Create Thread', [
152-
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
153-
'body' => 'This is a thread with 82 characters in the subject',
154-
'tags' => [$tag->id()],
155-
])
156-
->seePageIs('/forum/create-thread')
157-
->see('Something went wrong. Please review the fields below.')
158-
->see('The subject may not be greater than 60 characters.');
142+
$response = $this->post('/forum/create-thread', [
143+
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
144+
'body' => 'This is a thread with 82 characters in the subject',
145+
'tags' => [$tag->id()],
146+
]);
147+
148+
$response->assertSessionHas('error', 'Something went wrong. Please review the fields below.');
149+
$response->assertSessionHasErrors(['subject' => 'The subject may not be greater than 60 characters.']);
159150
}
160151

161152
/** @test */
@@ -170,14 +161,13 @@ public function users_cannot_edit_a_thread_with_a_subject_that_is_too_long()
170161

171162
$this->loginAs($user);
172163

173-
$this->visit('/forum/my-first-thread/edit')
174-
->submitForm('Update Thread', [
175-
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
176-
'body' => 'This is a thread with 82 characters in the subject',
177-
'tags' => [$tag->id()],
178-
])
179-
->seePageIs('/forum/my-first-thread/edit')
180-
->see('Something went wrong. Please review the fields below.')
181-
->see('The subject may not be greater than 60 characters.');
164+
$response = $this->put('/forum/my-first-thread', [
165+
'subject' => 'How to make Eloquent, Doctrine, Entities and Annotations work together in Laravel?',
166+
'body' => 'This is a thread with 82 characters in the subject',
167+
'tags' => [$tag->id()],
168+
]);
169+
170+
$response->assertSessionHas('error', 'Something went wrong. Please review the fields below.');
171+
$response->assertSessionHasErrors(['subject' => 'The subject may not be greater than 60 characters.']);
182172
}
183173
}

tests/Feature/ReplyTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ class ReplyTest extends BrowserKitTestCase
1515
/** @test */
1616
public function users_can_add_a_reply_to_a_thread()
1717
{
18-
factory(Thread::class)->create(['subject' => 'The first thread', 'slug' => 'the-first-thread']);
18+
$thread = factory(Thread::class)->create(['subject' => 'The first thread', 'slug' => 'the-first-thread']);
1919

2020
$this->login();
2121

22-
$this->visit('/forum/the-first-thread')
23-
->type('The first reply', 'body')
24-
->press('Reply')
25-
->see('The first thread')
26-
->see('The first reply')
27-
->see('Reply successfully added!');
22+
$this->post('/replies', [
23+
'body' => 'The first reply',
24+
'replyable_id' => $thread->id,
25+
'replyable_type' => Thread::TABLE,
26+
])
27+
->assertSessionHas('success', 'Reply successfully added!');
2828
}
2929

3030
/** @test */
@@ -36,12 +36,11 @@ public function users_can_edit_a_reply()
3636

3737
$this->loginAs($user);
3838

39-
$this->visit('/replies/1/edit')
40-
->type('The edited reply', 'body')
41-
->press('Update')
42-
->seePageIs('/forum/the-first-thread')
43-
->see('The edited reply')
44-
->see('Reply successfully updated!');
39+
$this->put('/replies/1', [
40+
'body' => 'The edited reply',
41+
])
42+
->assertRedirectedTo('/forum/the-first-thread')
43+
->assertSessionHas('success', 'Reply successfully updated!');
4544
}
4645

4746
/** @test */

0 commit comments

Comments
 (0)