@@ -18,13 +18,31 @@ public function users_cannot_create_an_article_when_not_logged_in()
1818 ->seePageIs ('/login ' );
1919 }
2020
21+ /** @test */
22+ public function users_cannot_see_series_they_do_not_own_when_creating_a_series ()
23+ {
24+ $ user = $ this ->createUser ();
25+ factory (Series::class)->create (['title ' => 'This should be seen ' , 'author_id ' => $ user ->id ]);
26+ factory (Series::class)->create (['title ' => 'This should not be seen ' ]);
27+
28+ $ this ->loginAs ($ user );
29+
30+ $ this ->get ('/articles/create ' )
31+ ->see ('This should be seen ' )
32+ ->dontSee ('This should not be seen ' );
33+ }
34+
2135 /** @test */
2236 public function users_can_create_an_article ()
2337 {
38+ $ user = $ this ->createUser ();
2439 $ tag = factory (Tag::class)->create (['name ' => 'Test Tag ' ]);
25- $ series = factory (Series::class)->create (['title ' => 'Test series ' ]);
40+ $ series = factory (Series::class)->create ([
41+ 'title ' => 'Test series ' ,
42+ 'author_id ' => $ user ->id ,
43+ ]);
2644
27- $ this ->login ( );
45+ $ this ->loginAs ( $ user );
2846
2947 $ this ->post ('/articles ' , [
3048 'title ' => 'Using database migrations ' ,
@@ -36,6 +54,25 @@ public function users_can_create_an_article()
3654 ->assertSessionHas ('success ' , 'Article successfully created! ' );
3755 }
3856
57+ /** @test */
58+ public function users_cannot_create_an_article_using_a_series_they_do_not_own ()
59+ {
60+ $ tag = factory (Tag::class)->create (['name ' => 'Test Tag ' ]);
61+ $ series = factory (Series::class)->create (['title ' => 'Test series ' ]);
62+
63+ $ this ->login ();
64+
65+ $ response = $ this ->post ('/articles ' , [
66+ 'title ' => 'Using database migrations ' ,
67+ 'body ' => 'This article will go into depth on working with database migrations. ' ,
68+ 'tags ' => [$ tag ->id ()],
69+ 'series ' => $ series ->id (),
70+ ]);
71+
72+ $ response ->assertSessionHas ('error ' , 'Something went wrong. Please review the fields below. ' );
73+ $ response ->assertSessionHasErrors (['series ' => 'The series field does not belong to you. ' ]);
74+ }
75+
3976 /** @test */
4077 public function users_cannot_create_an_article_with_a_title_that_is_too_long ()
4178 {
@@ -63,12 +100,30 @@ public function an_article_may_not_contain_an_http_image_url()
63100 $ response ->assertSessionHasErrors (['body ' => 'The body field contains at least one image with an HTTP link. ' ]);
64101 }
65102
103+ /** @test */
104+ public function users_cannot_see_series_they_do_not_own_when_editing_an_article ()
105+ {
106+ $ user = $ this ->createUser ();
107+ factory (Article::class)->create (['slug ' => 'my-first-article ' , 'author_id ' => $ user ->id ]);
108+ factory (Series::class)->create (['title ' => 'This should be seen ' , 'author_id ' => $ user ->id ]);
109+ factory (Series::class)->create (['title ' => 'This should not be seen ' ]);
110+
111+ $ this ->loginAs ($ user );
112+
113+ $ this ->get ('/articles/my-first-article/edit ' )
114+ ->see ('This should be seen ' )
115+ ->dontSee ('This should not be seen ' );
116+ }
117+
66118 /** @test */
67119 public function users_can_edit_an_article ()
68120 {
69121 $ user = $ this ->createUser ();
70122 $ tag = factory (Tag::class)->create (['name ' => 'Test Tag ' ]);
71- $ series = factory (Series::class)->create (['title ' => 'Test series ' ]);
123+ $ series = factory (Series::class)->create ([
124+ 'title ' => 'Test series ' ,
125+ 'author_id ' => $ user ->id ,
126+ ]);
72127
73128 factory (Article::class)->create ([
74129 'author_id ' => $ user ->id (),
@@ -87,6 +142,31 @@ public function users_can_edit_an_article()
87142 ->assertSessionHas ('success ' , 'Article successfully updated! ' );
88143 }
89144
145+ /** @test */
146+ public function users_cannot_edit_an_article_using_a_series_they_do_not_own ()
147+ {
148+ $ user = $ this ->createUser ();
149+ $ tag = factory (Tag::class)->create (['name ' => 'Test Tag ' ]);
150+ $ series = factory (Series::class)->create (['title ' => 'Test series ' ]);
151+
152+ factory (Article::class)->create ([
153+ 'author_id ' => $ user ->id (),
154+ 'slug ' => 'my-first-article ' ,
155+ ]);
156+
157+ $ this ->loginAs ($ user );
158+
159+ $ response = $ this ->put ('/articles/my-first-article ' , [
160+ 'title ' => 'Using database migrations ' ,
161+ 'body ' => 'This article will go into depth on working with database migrations. ' ,
162+ 'tags ' => [$ tag ->id ()],
163+ 'series ' => $ series ->id (),
164+ ]);
165+
166+ $ response ->assertSessionHas ('error ' , 'Something went wrong. Please review the fields below. ' );
167+ $ response ->assertSessionHasErrors (['series ' => 'The series field does not belong to you. ' ]);
168+ }
169+
90170 /** @test */
91171 public function users_cannot_edit_an_article_with_a_title_that_is_too_long ()
92172 {
0 commit comments