@@ -80,44 +80,44 @@ public function testAdminBackendHomePage()
8080 }
8181
8282 /**
83- * This test will manipulate the database state by deleting a Post.
84- * All changes to the database are rolled back before the next test case is executed.
85- * This is done by using https://github.com/dmaicher/doctrine-test-bundle.
86- *
87- * Therefore in the following test case we can edit the Post with ID=1 although we deleted it in this test.
83+ * This test changes the database contents by deleting a blog post. However,
84+ * thanks to the DAMADoctrineTestBundle and its PRPUnit listener, all changes
85+ * to the database are rolled back when this test completes. This means that
86+ * all the application tests begin with the same database contents.
8887 */
8988 public function testAdminDeletePost ()
9089 {
9190 $ client = $ this ->getAdminClient ();
92-
9391 $ crawler = $ client ->request ('GET ' , '/en/admin/post/1 ' );
94-
95- $ client ->submit ($ crawler ->filter ('form ' )->form ());
92+ $ client ->submit ($ crawler ->filter ('#delete-form ' )->form ());
9693
9794 $ this ->assertSame (Response::HTTP_FOUND , $ client ->getResponse ()->getStatusCode ());
9895
9996 $ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
10097 $ this ->assertNull ($ post );
10198 }
10299
100+ /**
101+ * This test changes the database contents by editing a blog post. However,
102+ * thanks to the DAMADoctrineTestBundle and its PRPUnit listener, all changes
103+ * to the database are rolled back when this test completes. This means that
104+ * all the application tests begin with the same database contents.
105+ */
103106 public function testAdminEditPost ()
104107 {
105- $ client = $ this -> getAdminClient ();
108+ $ newBlogPostTitle = ' Blog Post Title ' . mt_rand ();
106109
110+ $ client = $ this ->getAdminClient ();
107111 $ crawler = $ client ->request ('GET ' , '/en/admin/post/1/edit ' );
108-
109- $ newTitle = 'what a nice new title! ' ;
110-
111- $ form = $ crawler ->filter ('form ' )->form ([
112- 'post[title] ' => $ newTitle ,
112+ $ form = $ crawler ->selectButton ('Save changes ' )->form ([
113+ 'post[title] ' => $ newBlogPostTitle ,
113114 ]);
114-
115115 $ client ->submit ($ form );
116116
117117 $ this ->assertSame (Response::HTTP_FOUND , $ client ->getResponse ()->getStatusCode ());
118118
119119 /** @var Post $post */
120120 $ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
121- $ this ->assertSame ($ newTitle , $ post ->getTitle ());
121+ $ this ->assertSame ($ newBlogPostTitle , $ post ->getTitle ());
122122 }
123123}
0 commit comments