@@ -9,12 +9,68 @@ class AdminTest extends WebTestCase
9
9
protected $ pool ;
10
10
protected $ router ;
11
11
12
+ protected $ verifiablePatterns = array (
13
+ '/cmf/content/staticcontent/list ' ,
14
+ '/cmf/content/staticcontent/create ' ,
15
+ '/cmf/content/staticcontent/{id}/edit ' ,
16
+ '/cmf/content/staticcontent/{id}/delete ' ,
17
+ '/cmf/block/simpleblock/list ' ,
18
+ '/cmf/block/simpleblock/create ' ,
19
+ '/cmf/block/simpleblock/{id}/edit ' ,
20
+ '/cmf/block/simpleblock/{id}/delete ' ,
21
+ '/cmf/block/containerblock/list ' ,
22
+ '/cmf/block/containerblock/create ' ,
23
+ '/cmf/block/containerblock/{id}/edit ' ,
24
+ '/cmf/block/containerblock/{id}/delete ' ,
25
+ '/cmf/block/referenceblock/list ' ,
26
+ '/cmf/block/referenceblock/create ' ,
27
+ '/cmf/block/referenceblock/{id}/edit ' ,
28
+ '/cmf/block/referenceblock/{id}/delete ' ,
29
+ '/cmf/block/actionblock/list ' ,
30
+ '/cmf/block/actionblock/create ' ,
31
+ '/cmf/block/actionblock/{id}/edit ' ,
32
+ '/cmf/block/actionblock/{id}/delete ' ,
33
+ '/cmf/block/imagine/list ' ,
34
+ '/cmf/block/imagine/create ' ,
35
+ '/cmf/routing/route/list ' ,
36
+ '/cmf/routing/route/create ' ,
37
+ '/cmf/routing/route/{id}/edit ' ,
38
+ '/cmf/routing/route/{id}/delete ' ,
39
+ '/cmf/routing/redirectroute/list ' ,
40
+ '/cmf/routing/redirectroute/create ' ,
41
+ '/cmf/routing/redirectroute/{id}/edit ' ,
42
+ '/cmf/routing/redirectroute/{id}/delete ' ,
43
+ '/cmf/menu/menu/list ' ,
44
+ '/cmf/menu/menu/create ' ,
45
+ '/cmf/menu/menu/{id}/edit ' ,
46
+ '/cmf/menu/menu/{id}/delete ' ,
47
+ '/cmf/menu/menunode/list ' ,
48
+ '/cmf/menu/menunode/create ' ,
49
+ '/cmf/menu/menunode/{id}/edit ' ,
50
+ '/cmf/menu/menunode/{id}/delete ' ,
51
+ '/cmf/blog/blog/list ' ,
52
+ '/cmf/blog/blog/create ' ,
53
+ '/cmf/blog/blog/{id}/edit ' ,
54
+ '/cmf/blog/blog/{id}/delete ' ,
55
+ '/cmf/blog/post/list ' ,
56
+ '/cmf/blog/post/create ' ,
57
+ '/cmf/blog/post/{id}/edit ' ,
58
+ '/cmf/blog/post/{id}/delete ' ,
59
+ '/cmf/simplecms/page/list ' ,
60
+ '/cmf/simplecms/page/create ' ,
61
+ '/cmf/simplecms/page/{id}/edit ' ,
62
+ '/cmf/simplecms/page/{id}/delete ' ,
63
+ );
64
+
65
+ protected $ testedPatterns = array ();
66
+
12
67
public function setUp ()
13
68
{
14
69
parent ::setUp ();
15
70
$ this ->pool = $ this ->getContainer ()->get ('sonata.admin.pool ' );
16
71
$ this ->router = $ this ->getContainer ()->get ('router ' );
17
72
$ this ->client = $ this ->createClientAuthenticated ();
73
+ $ this ->dm = $ this ->getContainer ()->get ('doctrine_phpcr.odm.default_document_manager ' );
18
74
}
19
75
20
76
public function testAdmin ()
@@ -29,44 +85,63 @@ public function testAdmin()
29
85
foreach ($ admins as $ admin ) {
30
86
$ this ->doTestReachableAdminRoutes ($ admin );
31
87
}
88
+
89
+ // verify that we have tested everything we wanted to test.
90
+ $ this ->assertEquals ($ this ->verifiablePatterns , $ this ->testedPatterns );
32
91
}
33
92
34
93
protected function doTestReachableAdminRoutes ($ admin )
35
94
{
36
95
$ routeCollection = $ admin ->getRoutes ();
96
+ $ class = $ admin ->getClass ();
97
+ $ routeParams = array ('_locale ' => 'en ' );
37
98
38
99
foreach ($ routeCollection ->getElements () as $ route ) {
39
- try {
40
- $ url = $ this ->router ->generate ($ route ->getDefault ('_sonata_name ' ), array (
41
- '_locale ' => 'en '
42
- ));
43
- } catch (MissingMandatoryParametersException $ e ) {
44
- // do not try and load pages with parameters, e.g. edit, show, etc.
100
+ $ requirements = $ route ->getRequirements ();
101
+
102
+ // fix this one later
103
+ if (strpos ($ route ->getPattern (), 'export ' )) {
45
104
continue ;
46
105
}
47
106
48
- $ crawler = $ this ->client ->request ('GET ' , $ url );
49
- $ res = $ this ->client ->getResponse ();
50
- $ statusCode = $ res ->getStatusCode ();
51
-
52
- // hack around apparently mal-defined routes
53
- if ($ statusCode != 200 ) {
54
- $ exceptionMessage = $ crawler ->filter ('.text-exception h1 ' )->html ();
107
+ // these don't all work atm
108
+ if (strpos ($ route ->getPattern (), 'show ' )) {
109
+ continue ;
110
+ }
55
111
56
- // we cannot determine if sonata routes need a POST
57
- if (false !== strpos ($ exceptionMessage , 'POST expected ' )) {
112
+ // do not test POST routes
113
+ if (isset ($ requirements ['_method ' ])) {
114
+ if ($ requirements ['_method ' ] != 'GET ' ) {
58
115
continue ;
59
116
}
117
+ }
60
118
61
- // the export route has no _format requirement
62
- if (false !== strpos ($ exceptionMessage , 'Export in format `` is not allowed ' )) {
63
- continue ;
119
+ // if an ID is required, try and find a document to test
120
+ if (isset ($ requirements ['id ' ])) {
121
+ if ($ document = $ this ->dm ->getRepository ($ class )->findOneBy (array ())) {
122
+ $ node = $ this ->dm ->getNodeForDocument ($ document );
123
+ $ routeParams ['id ' ] = $ node ->getPath ();
124
+ } else {
125
+ // we should throw an exception here maybe and fix the missing fixtures
64
126
}
65
127
}
66
128
129
+ try {
130
+ $ url = $ this ->router ->generate ($ route ->getDefault ('_sonata_name ' ), $ routeParams );
131
+ } catch (MissingMandatoryParametersException $ e ) {
132
+ // do not try and load pages with parameters, e.g. edit, show, etc.
133
+ continue ;
134
+ }
135
+
136
+ $ crawler = $ this ->client ->request ('GET ' , $ url );
137
+ $ res = $ this ->client ->getResponse ();
138
+ $ statusCode = $ res ->getStatusCode ();
139
+
67
140
$ this ->assertEquals (200 , $ statusCode , sprintf (
68
141
'URL %s returns 200 OK HTTP Code ' , $ url
69
142
));
143
+
144
+ $ this ->testedPatterns [] = $ route ->getPattern ();
70
145
}
71
146
}
72
147
}
0 commit comments