@@ -29,36 +29,68 @@ public function testJsonGetPageAction()
2929
3030 $ decoded = json_decode ($ content , true );
3131 $ this ->assertTrue (isset ($ decoded ['id ' ]));
32-
3332 }
3433
35- public function testJsonPutPageAction ()
34+ public function testHeadRoute ()
3635 {
3736 $ fixtures = array ('Acme\BlogBundle\Tests\Fixtures\Entity\LoadPageData ' );
3837 $ this ->customSetUp ($ fixtures );
3938 $ pages = LoadPageData::$ pages ;
4039 $ page = array_pop ($ pages );
4140
41+ $ this ->client ->request ('HEAD ' , sprintf ('/api/v1/pages/%d.json ' , $ page ->getId ()), array ('ACCEPT ' => 'application/json ' ));
42+ $ response = $ this ->client ->getResponse ();
43+ $ this ->assertJsonResponse ($ response , 200 , false );
44+ }
45+
46+ public function testJsonNewPageAction ()
47+ {
4248 $ this ->client = static ::createClient ();
4349 $ this ->client ->request (
44- 'PUT ' ,
45- sprintf ('/api/v1/pages/%d.json ' , $ page ->getId ()),
50+ 'GET ' ,
51+ '/api/v1/pages/new.json ' ,
52+ array (),
53+ array ()
54+ );
55+
56+ $ this ->assertJsonResponse ($ this ->client ->getResponse (), 200 , true );
57+ $ this ->assertEquals (
58+ '{"children":{"title":[],"body":[]}} ' ,
59+ $ this ->client ->getResponse ()->getContent (),
60+ $ this ->client ->getResponse ()->getContent ());
61+ }
62+
63+ public function testJsonPostPageAction ()
64+ {
65+ $ this ->client = static ::createClient ();
66+ $ this ->client ->request (
67+ 'POST ' ,
68+ '/api/v1/pages.json ' ,
4669 array (),
4770 array (),
4871 array ('CONTENT_TYPE ' => 'application/json ' ),
49- '{"title":"abc ","body":"def "} '
72+ '{"title":"title1 ","body":"body1 "} '
5073 );
5174
52- $ page -> setTitle ( ' abc ' );
53- $ page -> setBody ( ' def ' );
75+ $ this -> assertJsonResponse ( $ this -> client -> getResponse (), 201 , false );
76+ }
5477
55- $ this ->assertJsonResponse ($ this ->client ->getResponse (), 204 , false );
78+ public function testJsonPostPageActionShouldReturn400WithBadParameters ()
79+ {
80+ $ this ->client = static ::createClient ();
81+ $ this ->client ->request (
82+ 'POST ' ,
83+ '/api/v1/pages.json ' ,
84+ array (),
85+ array (),
86+ array ('CONTENT_TYPE ' => 'application/json ' ),
87+ '{"titles":"title1","bodys":"body1"} '
88+ );
5689
57- $ updatedPage = $ this ->getContainer ()->get ('acme_blog.page.handler ' )->get ($ page ->getId ());
58- $ this ->assertEquals ($ updatedPage , $ page );
90+ $ this ->assertJsonResponse ($ this ->client ->getResponse (), 400 , false );
5991 }
6092
61- public function testJsonPatchPageAction ()
93+ public function testJsonPutPageActionShouldModify ()
6294 {
6395 $ fixtures = array ('Acme\BlogBundle\Tests\Fixtures\Entity\LoadPageData ' );
6496 $ this ->customSetUp ($ fixtures );
@@ -67,54 +99,76 @@ public function testJsonPatchPageAction()
6799
68100 $ this ->client = static ::createClient ();
69101 $ this ->client ->request (
70- 'PATCH ' ,
102+ 'PUT ' ,
71103 sprintf ('/api/v1/pages/%d.json ' , $ page ->getId ()),
72104 array (),
73105 array (),
74106 array ('CONTENT_TYPE ' => 'application/json ' ),
75- '{"body":"def"} '
107+ '{"title":"abc"," body":"def"} '
76108 );
77109
78- $ page ->setBody ('def ' );
79-
80110 $ this ->assertJsonResponse ($ this ->client ->getResponse (), 204 , false );
81-
82- $ updatedPage = $ this ->getContainer ()->get ('acme_blog.page.handler ' )->get ($ page ->getId ());
83- $ this ->assertEquals ($ updatedPage , $ page );
111+ $ this ->assertTrue (
112+ $ this ->client ->getResponse ()->headers ->contains (
113+ 'Location ' ,
114+ sprintf ('http://localhost/api/v1/pages/%d.json ' , $ page ->getId ())
115+ ),
116+ $ this ->client ->getResponse ()->headers
117+ );
84118 }
85119
86-
87- public function testJsonPostPageAction ()
120+ public function testJsonPutPageActionShouldCreate ()
88121 {
89122 $ this ->client = static ::createClient ();
123+ $ id = 0 ;
124+
125+ $ this ->client ->request ('GET ' , sprintf ('/api/v1/pages/%d.json ' , $ id ), array ('ACCEPT ' => 'application/json ' ));
126+
127+ $ this ->assertEquals (404 , $ this ->client ->getResponse ()->getStatusCode (), $ this ->client ->getResponse ()->getContent ());
128+
90129 $ this ->client ->request (
91- 'POST ' ,
92- '/api/v1/pages.json ' ,
130+ 'PUT ' ,
131+ sprintf ( '/api/v1/pages/%d .json ' , $ id ) ,
93132 array (),
94133 array (),
95134 array ('CONTENT_TYPE ' => 'application/json ' ),
96- '{"title":"title1 ","body":"body1 "} '
135+ '{"title":"abc ","body":"def "} '
97136 );
98137
99138 $ this ->assertJsonResponse ($ this ->client ->getResponse (), 201 , false );
100139 }
101140
102- public function testJsonPostPageActionShouldReturn400WithBadParameters ()
141+ public function testJsonPatchPageAction ()
103142 {
143+ $ fixtures = array ('Acme\BlogBundle\Tests\Fixtures\Entity\LoadPageData ' );
144+ $ this ->customSetUp ($ fixtures );
145+ $ pages = LoadPageData::$ pages ;
146+ $ page = array_pop ($ pages );
147+
104148 $ this ->client = static ::createClient ();
105149 $ this ->client ->request (
106- 'POST ' ,
107- '/api/v1/pages.json ' ,
150+ 'PATCH ' ,
151+ sprintf ( '/api/v1/pages/%d .json ' , $ page -> getId ()) ,
108152 array (),
109153 array (),
110154 array ('CONTENT_TYPE ' => 'application/json ' ),
111- '{"titles ":"title1","bodys":"body1 "} '
155+ '{"body ":"def "} '
112156 );
113157
114- $ this ->assertJsonResponse ($ this ->client ->getResponse (), 400 , false );
158+ $ this ->assertJsonResponse ($ this ->client ->getResponse (), 204 , false );
159+ $ this ->assertTrue (
160+ $ this ->client ->getResponse ()->headers ->contains (
161+ 'Location ' ,
162+ sprintf ('http://localhost/api/v1/pages/%d.json ' , $ page ->getId ())
163+ ),
164+ $ this ->client ->getResponse ()->headers
165+ );
115166 }
116167
117168
169+
170+
171+
118172 protected function assertJsonResponse ($ response , $ statusCode = 200 , $ checkValidJson = true , $ contentType = 'application/json ' )
119173 {
120174 $ this ->assertEquals (
0 commit comments