@@ -80,44 +80,44 @@ public function testAdminBackendHomePage()
80
80
}
81
81
82
82
/**
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.
88
87
*/
89
88
public function testAdminDeletePost ()
90
89
{
91
90
$ client = $ this ->getAdminClient ();
92
-
93
91
$ crawler = $ client ->request ('GET ' , '/en/admin/post/1 ' );
94
-
95
- $ client ->submit ($ crawler ->filter ('form ' )->form ());
92
+ $ client ->submit ($ crawler ->filter ('#delete-form ' )->form ());
96
93
97
94
$ this ->assertSame (Response::HTTP_FOUND , $ client ->getResponse ()->getStatusCode ());
98
95
99
96
$ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
100
97
$ this ->assertNull ($ post );
101
98
}
102
99
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
+ */
103
106
public function testAdminEditPost ()
104
107
{
105
- $ client = $ this -> getAdminClient ();
108
+ $ newBlogPostTitle = ' Blog Post Title ' . mt_rand ();
106
109
110
+ $ client = $ this ->getAdminClient ();
107
111
$ 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 ,
113
114
]);
114
-
115
115
$ client ->submit ($ form );
116
116
117
117
$ this ->assertSame (Response::HTTP_FOUND , $ client ->getResponse ()->getStatusCode ());
118
118
119
119
/** @var Post $post */
120
120
$ post = $ client ->getContainer ()->get ('doctrine ' )->getRepository (Post::class)->find (1 );
121
- $ this ->assertSame ($ newTitle , $ post ->getTitle ());
121
+ $ this ->assertSame ($ newBlogPostTitle , $ post ->getTitle ());
122
122
}
123
123
}
0 commit comments