@@ -9,20 +9,64 @@ class GeneratedCrudControllerTest extends WebTestCase
9
9
public function testIndexAction ()
10
10
{
11
11
$ client = self ::createClient ();
12
- $ client ->request ('GET ' , '/sweet/food/ ' );
13
-
14
- $ this ->assertEquals (200 , $ client ->getResponse ()->getStatusCode ());
12
+ $ crawler = $ client ->request ('GET ' , '/sweet/food/ ' );
13
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
15
14
$ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
16
15
$ this ->assertContains ('SweetFood index ' , $ client ->getResponse ()->getContent ());
17
- }
18
16
19
- public function testNewAction ()
20
- {
21
- $ client = self ::createClient ();
22
- $ client ->request ('GET ' , '/sweet/food/new ' );
17
+ $ newLink = $ crawler ->filter ('a:contains("Create new") ' )->eq (0 )->link ();
23
18
24
- $ this ->assertEquals (200 , $ client ->getResponse ()->getStatusCode ());
19
+ $ crawler = $ client ->click ($ newLink );
20
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
25
21
$ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
26
22
$ this ->assertContains ('New SweetFood ' , $ client ->getResponse ()->getContent ());
23
+
24
+ $ newForm = $ crawler ->selectButton ('Save ' )->form ();
25
+ $ client ->submit ($ newForm , ['sweet_food[title] ' => 'Candy ' ]);
26
+ $ this ->assertTrue ($ client ->getResponse ()->isRedirect ());
27
+
28
+ $ crawler = $ client ->followRedirect ();
29
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
30
+ $ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
31
+ $ this ->assertContains ('Edit SweetFood ' , $ client ->getResponse ()->getContent ());
32
+ $ this ->assertGreaterThan (0 , $ crawler ->filter ('input[type=text] ' )->count ());
33
+ $ this ->assertEquals ('Candy ' , $ crawler ->filter ('input[type=text] ' )->attr ('value ' ));
34
+
35
+ $ editForm = $ crawler ->selectButton ('Edit ' )->form ();
36
+ $ client ->submit ($ editForm , ['sweet_food[title] ' => 'Candy edited ' ]);
37
+ $ this ->assertTrue ($ client ->getResponse ()->isRedirect ());
38
+
39
+ $ crawler = $ client ->followRedirect ();
40
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
41
+ $ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
42
+ $ this ->assertContains ('Edit SweetFood ' , $ client ->getResponse ()->getContent ());
43
+ $ this ->assertGreaterThan (0 , $ crawler ->filter ('input[type=text] ' )->count ());
44
+ $ this ->assertEquals ('Candy edited ' , $ crawler ->filter ('input[type=text] ' )->attr ('value ' ));
45
+
46
+ $ backTolistLink = $ crawler ->filter ('a:contains("back to list") ' )->eq (0 )->link ();
47
+
48
+ $ crawler = $ client ->click ($ backTolistLink );
49
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
50
+ $ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
51
+ $ this ->assertContains ('SweetFood index ' , $ client ->getResponse ()->getContent ());
52
+ $ this ->assertContains ('Candy edited ' , $ client ->getResponse ()->getContent ());
53
+
54
+ $ showLink = $ crawler ->filter ('a:contains("show") ' )->eq (0 )->link ();
55
+
56
+ $ crawler = $ client ->click ($ showLink );
57
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
58
+ $ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
59
+ $ this ->assertContains ('SweetFood ' , $ client ->getResponse ()->getContent ());
60
+ $ this ->assertContains ('Candy edited ' , $ client ->getResponse ()->getContent ());
61
+
62
+ $ deleteForm = $ crawler ->selectButton ('Delete ' )->form ();
63
+ $ client ->submit ($ deleteForm );
64
+ $ this ->assertTrue ($ client ->getResponse ()->isRedirect ());
65
+
66
+ $ client ->followRedirect ();
67
+ $ this ->assertTrue ($ client ->getResponse ()->isSuccessful ());
68
+ $ this ->assertContains ('<!DOCTYPE html> ' , $ client ->getResponse ()->getContent ());
69
+ $ this ->assertContains ('SweetFood index ' , $ client ->getResponse ()->getContent ());
70
+ $ this ->assertContains ('no records found ' , $ client ->getResponse ()->getContent ());
27
71
}
28
72
}
0 commit comments