diff options
Diffstat (limited to 'src/Wallabag/ApiBundle/Tests')
-rw-r--r-- | src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | 46 | ||||
-rw-r--r-- | src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | 238 |
2 files changed, 104 insertions, 180 deletions
diff --git a/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php new file mode 100644 index 00000000..119889b3 --- /dev/null +++ b/src/Wallabag/ApiBundle/Tests/AbstractControllerTest.php | |||
@@ -0,0 +1,46 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ApiBundle\Tests; | ||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
6 | use Symfony\Component\BrowserKit\Cookie; | ||
7 | |||
8 | abstract class AbstractControllerTest extends WebTestCase | ||
9 | { | ||
10 | /** | ||
11 | * @var Client | ||
12 | */ | ||
13 | protected $client = null; | ||
14 | |||
15 | public function setUp() | ||
16 | { | ||
17 | $this->client = $this->createAuthorizedClient(); | ||
18 | } | ||
19 | |||
20 | /** | ||
21 | * @return Client | ||
22 | */ | ||
23 | protected function createAuthorizedClient() | ||
24 | { | ||
25 | $client = static::createClient(); | ||
26 | $container = $client->getContainer(); | ||
27 | |||
28 | $session = $container->get('session'); | ||
29 | /** @var $userManager \FOS\UserBundle\Doctrine\UserManager */ | ||
30 | $userManager = $container->get('fos_user.user_manager'); | ||
31 | /** @var $loginManager \FOS\UserBundle\Security\LoginManager */ | ||
32 | $loginManager = $container->get('fos_user.security.login_manager'); | ||
33 | $firewallName = $container->getParameter('fos_user.firewall_name'); | ||
34 | |||
35 | $user = $userManager->findUserBy(array('username' => 'admin')); | ||
36 | $loginManager->loginUser($firewallName, $user); | ||
37 | |||
38 | // save the login token into the session and put it in a cookie | ||
39 | $container->get('session')->set('_security_'.$firewallName, | ||
40 | serialize($container->get('security.context')->getToken())); | ||
41 | $container->get('session')->save(); | ||
42 | $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); | ||
43 | |||
44 | return $client; | ||
45 | } | ||
46 | } | ||
diff --git a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php index 7ae54b57..bc7ef489 100644 --- a/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php +++ b/src/Wallabag/ApiBundle/Tests/Controller/WallabagRestControllerTest.php | |||
@@ -2,99 +2,15 @@ | |||
2 | 2 | ||
3 | namespace Wallabag\ApiBundle\Tests\Controller; | 3 | namespace Wallabag\ApiBundle\Tests\Controller; |
4 | 4 | ||
5 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | 5 | use Wallabag\ApiBundle\Tests\AbstractControllerTest; |
6 | 6 | ||
7 | class WallabagRestControllerTest extends WebTestCase | 7 | class WallabagRestControllerTest extends AbstractControllerTest |
8 | { | 8 | { |
9 | protected static $salt; | 9 | protected static $salt; |
10 | 10 | ||
11 | /** | ||
12 | * Grab the salt once and store it to be available for all tests. | ||
13 | */ | ||
14 | public static function setUpBeforeClass() | ||
15 | { | ||
16 | $client = self::createClient(); | ||
17 | |||
18 | $user = $client->getContainer() | ||
19 | ->get('doctrine.orm.entity_manager') | ||
20 | ->getRepository('WallabagCoreBundle:User') | ||
21 | ->findOneByUsername('admin'); | ||
22 | |||
23 | self::$salt = $user->getSalt(); | ||
24 | } | ||
25 | |||
26 | /** | ||
27 | * Generate HTTP headers for authenticate user on API. | ||
28 | * | ||
29 | * @param string $username | ||
30 | * @param string $password | ||
31 | * | ||
32 | * @return array | ||
33 | */ | ||
34 | private function generateHeaders($username, $password) | ||
35 | { | ||
36 | $encryptedPassword = sha1($password.$username.self::$salt); | ||
37 | $nonce = substr(md5(uniqid('nonce_', true)), 0, 16); | ||
38 | |||
39 | $now = new \DateTime('now', new \DateTimeZone('UTC')); | ||
40 | $created = (string) $now->format('Y-m-d\TH:i:s\Z'); | ||
41 | $digest = base64_encode(sha1(base64_decode($nonce).$created.$encryptedPassword, true)); | ||
42 | |||
43 | return array( | ||
44 | 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', | ||
45 | 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="'.$username.'", PasswordDigest="'.$digest.'", Nonce="'.$nonce.'", Created="'.$created.'"', | ||
46 | ); | ||
47 | } | ||
48 | |||
49 | public function testGetSalt() | ||
50 | { | ||
51 | $client = $this->createClient(); | ||
52 | $client->request('GET', '/api/salts/admin.json'); | ||
53 | |||
54 | $user = $client->getContainer() | ||
55 | ->get('doctrine.orm.entity_manager') | ||
56 | ->getRepository('WallabagCoreBundle:User') | ||
57 | ->findOneByUsername('admin'); | ||
58 | |||
59 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | ||
60 | |||
61 | $content = json_decode($client->getResponse()->getContent(), true); | ||
62 | |||
63 | $this->assertArrayHasKey(0, $content); | ||
64 | $this->assertEquals($user->getSalt(), $content[0]); | ||
65 | |||
66 | $client->request('GET', '/api/salts/notfound.json'); | ||
67 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | ||
68 | } | ||
69 | |||
70 | public function testWithBadHeaders() | ||
71 | { | ||
72 | $client = $this->createClient(); | ||
73 | |||
74 | $entry = $client->getContainer() | ||
75 | ->get('doctrine.orm.entity_manager') | ||
76 | ->getRepository('WallabagCoreBundle:Entry') | ||
77 | ->findOneByIsArchived(false); | ||
78 | |||
79 | if (!$entry) { | ||
80 | $this->markTestSkipped('No content found in db.'); | ||
81 | } | ||
82 | |||
83 | $badHeaders = array( | ||
84 | 'HTTP_AUTHORIZATION' => 'Authorization profile="UsernameToken"', | ||
85 | 'HTTP_x-wsse' => 'X-WSSE: UsernameToken Username="admin", PasswordDigest="Wr0ngDig3st", Nonce="n0Nc3", Created="2015-01-01T13:37:00Z"', | ||
86 | ); | ||
87 | |||
88 | $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $badHeaders); | ||
89 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | ||
90 | } | ||
91 | |||
92 | public function testGetOneEntry() | 11 | public function testGetOneEntry() |
93 | { | 12 | { |
94 | $client = $this->createClient(); | 13 | $entry = $this->client->getContainer() |
95 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
96 | |||
97 | $entry = $client->getContainer() | ||
98 | ->get('doctrine.orm.entity_manager') | 14 | ->get('doctrine.orm.entity_manager') |
99 | ->getRepository('WallabagCoreBundle:Entry') | 15 | ->getRepository('WallabagCoreBundle:Entry') |
100 | ->findOneBy(array('user' => 1, 'isArchived' => false)); | 16 | ->findOneBy(array('user' => 1, 'isArchived' => false)); |
@@ -103,18 +19,17 @@ class WallabagRestControllerTest extends WebTestCase | |||
103 | $this->markTestSkipped('No content found in db.'); | 19 | $this->markTestSkipped('No content found in db.'); |
104 | } | 20 | } |
105 | 21 | ||
106 | $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | 22 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); |
23 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
107 | 24 | ||
108 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 25 | $content = json_decode($this->client->getResponse()->getContent(), true); |
109 | |||
110 | $content = json_decode($client->getResponse()->getContent(), true); | ||
111 | 26 | ||
112 | $this->assertEquals($entry->getTitle(), $content['title']); | 27 | $this->assertEquals($entry->getTitle(), $content['title']); |
113 | $this->assertEquals($entry->getUrl(), $content['url']); | 28 | $this->assertEquals($entry->getUrl(), $content['url']); |
114 | $this->assertCount(count($entry->getTags()), $content['tags']); | 29 | $this->assertCount(count($entry->getTags()), $content['tags']); |
115 | 30 | ||
116 | $this->assertTrue( | 31 | $this->assertTrue( |
117 | $client->getResponse()->headers->contains( | 32 | $this->client->getResponse()->headers->contains( |
118 | 'Content-Type', | 33 | 'Content-Type', |
119 | 'application/json' | 34 | 'application/json' |
120 | ) | 35 | ) |
@@ -123,10 +38,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
123 | 38 | ||
124 | public function testGetOneEntryWrongUser() | 39 | public function testGetOneEntryWrongUser() |
125 | { | 40 | { |
126 | $client = $this->createClient(); | 41 | $entry = $this->client->getContainer() |
127 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
128 | |||
129 | $entry = $client->getContainer() | ||
130 | ->get('doctrine.orm.entity_manager') | 42 | ->get('doctrine.orm.entity_manager') |
131 | ->getRepository('WallabagCoreBundle:Entry') | 43 | ->getRepository('WallabagCoreBundle:Entry') |
132 | ->findOneBy(array('user' => 2, 'isArchived' => false)); | 44 | ->findOneBy(array('user' => 2, 'isArchived' => false)); |
@@ -135,21 +47,18 @@ class WallabagRestControllerTest extends WebTestCase | |||
135 | $this->markTestSkipped('No content found in db.'); | 47 | $this->markTestSkipped('No content found in db.'); |
136 | } | 48 | } |
137 | 49 | ||
138 | $client->request('GET', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | 50 | $this->client->request('GET', '/api/entries/'.$entry->getId().'.json'); |
139 | 51 | ||
140 | $this->assertEquals(403, $client->getResponse()->getStatusCode()); | 52 | $this->assertEquals(403, $this->client->getResponse()->getStatusCode()); |
141 | } | 53 | } |
142 | 54 | ||
143 | public function testGetEntries() | 55 | public function testGetEntries() |
144 | { | 56 | { |
145 | $client = $this->createClient(); | 57 | $this->client->request('GET', '/api/entries'); |
146 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
147 | |||
148 | $client->request('GET', '/api/entries', array(), array(), $headers); | ||
149 | 58 | ||
150 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 59 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
151 | 60 | ||
152 | $content = json_decode($client->getResponse()->getContent(), true); | 61 | $content = json_decode($this->client->getResponse()->getContent(), true); |
153 | 62 | ||
154 | $this->assertGreaterThanOrEqual(1, count($content)); | 63 | $this->assertGreaterThanOrEqual(1, count($content)); |
155 | $this->assertNotEmpty($content['_embedded']['items']); | 64 | $this->assertNotEmpty($content['_embedded']['items']); |
@@ -158,7 +67,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
158 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 67 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
159 | 68 | ||
160 | $this->assertTrue( | 69 | $this->assertTrue( |
161 | $client->getResponse()->headers->contains( | 70 | $this->client->getResponse()->headers->contains( |
162 | 'Content-Type', | 71 | 'Content-Type', |
163 | 'application/json' | 72 | 'application/json' |
164 | ) | 73 | ) |
@@ -167,14 +76,11 @@ class WallabagRestControllerTest extends WebTestCase | |||
167 | 76 | ||
168 | public function testGetStarredEntries() | 77 | public function testGetStarredEntries() |
169 | { | 78 | { |
170 | $client = $this->createClient(); | 79 | $this->client->request('GET', '/api/entries', array('star' => 1, 'sort' => 'updated')); |
171 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
172 | 80 | ||
173 | $client->request('GET', '/api/entries', array('star' => 1, 'sort' => 'updated'), array(), $headers); | 81 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
174 | 82 | ||
175 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 83 | $content = json_decode($this->client->getResponse()->getContent(), true); |
176 | |||
177 | $content = json_decode($client->getResponse()->getContent(), true); | ||
178 | 84 | ||
179 | $this->assertGreaterThanOrEqual(1, count($content)); | 85 | $this->assertGreaterThanOrEqual(1, count($content)); |
180 | $this->assertNotEmpty($content['_embedded']['items']); | 86 | $this->assertNotEmpty($content['_embedded']['items']); |
@@ -183,7 +89,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
183 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 89 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
184 | 90 | ||
185 | $this->assertTrue( | 91 | $this->assertTrue( |
186 | $client->getResponse()->headers->contains( | 92 | $this->client->getResponse()->headers->contains( |
187 | 'Content-Type', | 93 | 'Content-Type', |
188 | 'application/json' | 94 | 'application/json' |
189 | ) | 95 | ) |
@@ -192,14 +98,11 @@ class WallabagRestControllerTest extends WebTestCase | |||
192 | 98 | ||
193 | public function testGetArchiveEntries() | 99 | public function testGetArchiveEntries() |
194 | { | 100 | { |
195 | $client = $this->createClient(); | 101 | $this->client->request('GET', '/api/entries', array('archive' => 1)); |
196 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
197 | |||
198 | $client->request('GET', '/api/entries', array('archive' => 1), array(), $headers); | ||
199 | 102 | ||
200 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 103 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
201 | 104 | ||
202 | $content = json_decode($client->getResponse()->getContent(), true); | 105 | $content = json_decode($this->client->getResponse()->getContent(), true); |
203 | 106 | ||
204 | $this->assertGreaterThanOrEqual(1, count($content)); | 107 | $this->assertGreaterThanOrEqual(1, count($content)); |
205 | $this->assertNotEmpty($content['_embedded']['items']); | 108 | $this->assertNotEmpty($content['_embedded']['items']); |
@@ -208,7 +111,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
208 | $this->assertGreaterThanOrEqual(1, $content['pages']); | 111 | $this->assertGreaterThanOrEqual(1, $content['pages']); |
209 | 112 | ||
210 | $this->assertTrue( | 113 | $this->assertTrue( |
211 | $client->getResponse()->headers->contains( | 114 | $this->client->getResponse()->headers->contains( |
212 | 'Content-Type', | 115 | 'Content-Type', |
213 | 'application/json' | 116 | 'application/json' |
214 | ) | 117 | ) |
@@ -217,10 +120,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
217 | 120 | ||
218 | public function testDeleteEntry() | 121 | public function testDeleteEntry() |
219 | { | 122 | { |
220 | $client = $this->createClient(); | 123 | $entry = $this->client->getContainer() |
221 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
222 | |||
223 | $entry = $client->getContainer() | ||
224 | ->get('doctrine.orm.entity_manager') | 124 | ->get('doctrine.orm.entity_manager') |
225 | ->getRepository('WallabagCoreBundle:Entry') | 125 | ->getRepository('WallabagCoreBundle:Entry') |
226 | ->findOneByUser(1); | 126 | ->findOneByUser(1); |
@@ -229,36 +129,31 @@ class WallabagRestControllerTest extends WebTestCase | |||
229 | $this->markTestSkipped('No content found in db.'); | 129 | $this->markTestSkipped('No content found in db.'); |
230 | } | 130 | } |
231 | 131 | ||
232 | $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | 132 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); |
233 | 133 | ||
234 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 134 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
235 | 135 | ||
236 | $content = json_decode($client->getResponse()->getContent(), true); | 136 | $content = json_decode($this->client->getResponse()->getContent(), true); |
237 | 137 | ||
238 | $this->assertEquals($entry->getTitle(), $content['title']); | 138 | $this->assertEquals($entry->getTitle(), $content['title']); |
239 | $this->assertEquals($entry->getUrl(), $content['url']); | 139 | $this->assertEquals($entry->getUrl(), $content['url']); |
240 | 140 | ||
241 | // We'll try to delete this entry again | 141 | // We'll try to delete this entry again |
242 | $headers = $this->generateHeaders('admin', 'mypassword'); | 142 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'.json'); |
243 | |||
244 | $client->request('DELETE', '/api/entries/'.$entry->getId().'.json', array(), array(), $headers); | ||
245 | 143 | ||
246 | $this->assertEquals(404, $client->getResponse()->getStatusCode()); | 144 | $this->assertEquals(404, $this->client->getResponse()->getStatusCode()); |
247 | } | 145 | } |
248 | 146 | ||
249 | public function testPostEntry() | 147 | public function testPostEntry() |
250 | { | 148 | { |
251 | $client = $this->createClient(); | 149 | $this->client->request('POST', '/api/entries.json', array( |
252 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
253 | |||
254 | $client->request('POST', '/api/entries.json', array( | ||
255 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', | 150 | 'url' => 'http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', |
256 | 'tags' => 'google', | 151 | 'tags' => 'google', |
257 | ), array(), $headers); | 152 | )); |
258 | 153 | ||
259 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 154 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
260 | 155 | ||
261 | $content = json_decode($client->getResponse()->getContent(), true); | 156 | $content = json_decode($this->client->getResponse()->getContent(), true); |
262 | 157 | ||
263 | $this->assertGreaterThan(0, $content['id']); | 158 | $this->assertGreaterThan(0, $content['id']); |
264 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); | 159 | $this->assertEquals('http://www.lemonde.fr/pixels/article/2015/03/28/plongee-dans-l-univers-d-ingress-le-jeu-de-google-aux-frontieres-du-reel_4601155_4408996.html', $content['url']); |
@@ -269,10 +164,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
269 | 164 | ||
270 | public function testPatchEntry() | 165 | public function testPatchEntry() |
271 | { | 166 | { |
272 | $client = $this->createClient(); | 167 | $entry = $this->client->getContainer() |
273 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
274 | |||
275 | $entry = $client->getContainer() | ||
276 | ->get('doctrine.orm.entity_manager') | 168 | ->get('doctrine.orm.entity_manager') |
277 | ->getRepository('WallabagCoreBundle:Entry') | 169 | ->getRepository('WallabagCoreBundle:Entry') |
278 | ->findOneByUser(1); | 170 | ->findOneByUser(1); |
@@ -284,16 +176,16 @@ class WallabagRestControllerTest extends WebTestCase | |||
284 | // hydrate the tags relations | 176 | // hydrate the tags relations |
285 | $nbTags = count($entry->getTags()); | 177 | $nbTags = count($entry->getTags()); |
286 | 178 | ||
287 | $client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( | 179 | $this->client->request('PATCH', '/api/entries/'.$entry->getId().'.json', array( |
288 | 'title' => 'New awesome title', | 180 | 'title' => 'New awesome title', |
289 | 'tags' => 'new tag '.uniqid(), | 181 | 'tags' => 'new tag '.uniqid(), |
290 | 'star' => true, | 182 | 'star' => true, |
291 | 'archive' => false, | 183 | 'archive' => false, |
292 | ), array(), $headers); | 184 | )); |
293 | 185 | ||
294 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 186 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
295 | 187 | ||
296 | $content = json_decode($client->getResponse()->getContent(), true); | 188 | $content = json_decode($this->client->getResponse()->getContent(), true); |
297 | 189 | ||
298 | $this->assertEquals($entry->getId(), $content['id']); | 190 | $this->assertEquals($entry->getId(), $content['id']); |
299 | $this->assertEquals($entry->getUrl(), $content['url']); | 191 | $this->assertEquals($entry->getUrl(), $content['url']); |
@@ -303,10 +195,7 @@ class WallabagRestControllerTest extends WebTestCase | |||
303 | 195 | ||
304 | public function testGetTagsEntry() | 196 | public function testGetTagsEntry() |
305 | { | 197 | { |
306 | $client = $this->createClient(); | 198 | $entry = $this->client->getContainer() |
307 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
308 | |||
309 | $entry = $client->getContainer() | ||
310 | ->get('doctrine.orm.entity_manager') | 199 | ->get('doctrine.orm.entity_manager') |
311 | ->getRepository('WallabagCoreBundle:Entry') | 200 | ->getRepository('WallabagCoreBundle:Entry') |
312 | ->findOneWithTags(1); | 201 | ->findOneWithTags(1); |
@@ -322,17 +211,14 @@ class WallabagRestControllerTest extends WebTestCase | |||
322 | $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); | 211 | $tags[] = array('id' => $tag->getId(), 'label' => $tag->getLabel()); |
323 | } | 212 | } |
324 | 213 | ||
325 | $client->request('GET', '/api/entries/'.$entry->getId().'/tags', array(), array(), $headers); | 214 | $this->client->request('GET', '/api/entries/'.$entry->getId().'/tags'); |
326 | 215 | ||
327 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $client->getResponse()->getContent()); | 216 | $this->assertEquals(json_encode($tags, JSON_HEX_QUOT), $this->client->getResponse()->getContent()); |
328 | } | 217 | } |
329 | 218 | ||
330 | public function testPostTagsOnEntry() | 219 | public function testPostTagsOnEntry() |
331 | { | 220 | { |
332 | $client = $this->createClient(); | 221 | $entry = $this->client->getContainer() |
333 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
334 | |||
335 | $entry = $client->getContainer() | ||
336 | ->get('doctrine.orm.entity_manager') | 222 | ->get('doctrine.orm.entity_manager') |
337 | ->getRepository('WallabagCoreBundle:Entry') | 223 | ->getRepository('WallabagCoreBundle:Entry') |
338 | ->findOneByUser(1); | 224 | ->findOneByUser(1); |
@@ -345,16 +231,16 @@ class WallabagRestControllerTest extends WebTestCase | |||
345 | 231 | ||
346 | $newTags = 'tag1,tag2,tag3'; | 232 | $newTags = 'tag1,tag2,tag3'; |
347 | 233 | ||
348 | $client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags), array(), $headers); | 234 | $this->client->request('POST', '/api/entries/'.$entry->getId().'/tags', array('tags' => $newTags)); |
349 | 235 | ||
350 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 236 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
351 | 237 | ||
352 | $content = json_decode($client->getResponse()->getContent(), true); | 238 | $content = json_decode($this->client->getResponse()->getContent(), true); |
353 | 239 | ||
354 | $this->assertArrayHasKey('tags', $content); | 240 | $this->assertArrayHasKey('tags', $content); |
355 | $this->assertEquals($nbTags + 3, count($content['tags'])); | 241 | $this->assertEquals($nbTags + 3, count($content['tags'])); |
356 | 242 | ||
357 | $entryDB = $client->getContainer() | 243 | $entryDB = $this->client->getContainer() |
358 | ->get('doctrine.orm.entity_manager') | 244 | ->get('doctrine.orm.entity_manager') |
359 | ->getRepository('WallabagCoreBundle:Entry') | 245 | ->getRepository('WallabagCoreBundle:Entry') |
360 | ->find($entry->getId()); | 246 | ->find($entry->getId()); |
@@ -369,15 +255,13 @@ class WallabagRestControllerTest extends WebTestCase | |||
369 | } | 255 | } |
370 | } | 256 | } |
371 | 257 | ||
372 | public function testDeleteOneTagEntrie() | 258 | public function testDeleteOneTagEntry() |
373 | { | 259 | { |
374 | $client = $this->createClient(); | 260 | $entry = $this->client->getContainer() |
375 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
376 | |||
377 | $entry = $client->getContainer() | ||
378 | ->get('doctrine.orm.entity_manager') | 261 | ->get('doctrine.orm.entity_manager') |
379 | ->getRepository('WallabagCoreBundle:Entry') | 262 | ->getRepository('WallabagCoreBundle:Entry') |
380 | ->findOneByUser(1); | 263 | ->findOneWithTags(1); |
264 | $entry = $entry[0]; | ||
381 | 265 | ||
382 | if (!$entry) { | 266 | if (!$entry) { |
383 | $this->markTestSkipped('No content found in db.'); | 267 | $this->markTestSkipped('No content found in db.'); |
@@ -387,11 +271,11 @@ class WallabagRestControllerTest extends WebTestCase | |||
387 | $nbTags = count($entry->getTags()); | 271 | $nbTags = count($entry->getTags()); |
388 | $tag = $entry->getTags()[0]; | 272 | $tag = $entry->getTags()[0]; |
389 | 273 | ||
390 | $client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json', array(), array(), $headers); | 274 | $this->client->request('DELETE', '/api/entries/'.$entry->getId().'/tags/'.$tag->getId().'.json'); |
391 | 275 | ||
392 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 276 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
393 | 277 | ||
394 | $content = json_decode($client->getResponse()->getContent(), true); | 278 | $content = json_decode($this->client->getResponse()->getContent(), true); |
395 | 279 | ||
396 | $this->assertArrayHasKey('tags', $content); | 280 | $this->assertArrayHasKey('tags', $content); |
397 | $this->assertEquals($nbTags - 1, count($content['tags'])); | 281 | $this->assertEquals($nbTags - 1, count($content['tags'])); |
@@ -399,14 +283,11 @@ class WallabagRestControllerTest extends WebTestCase | |||
399 | 283 | ||
400 | public function testGetUserTags() | 284 | public function testGetUserTags() |
401 | { | 285 | { |
402 | $client = $this->createClient(); | 286 | $this->client->request('GET', '/api/tags.json'); |
403 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
404 | |||
405 | $client->request('GET', '/api/tags.json', array(), array(), $headers); | ||
406 | 287 | ||
407 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 288 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
408 | 289 | ||
409 | $content = json_decode($client->getResponse()->getContent(), true); | 290 | $content = json_decode($this->client->getResponse()->getContent(), true); |
410 | 291 | ||
411 | $this->assertGreaterThan(0, $content); | 292 | $this->assertGreaterThan(0, $content); |
412 | $this->assertArrayHasKey('id', $content[0]); | 293 | $this->assertArrayHasKey('id', $content[0]); |
@@ -420,14 +301,11 @@ class WallabagRestControllerTest extends WebTestCase | |||
420 | */ | 301 | */ |
421 | public function testDeleteUserTag($tag) | 302 | public function testDeleteUserTag($tag) |
422 | { | 303 | { |
423 | $client = $this->createClient(); | 304 | $this->client->request('DELETE', '/api/tags/'.$tag['id'].'.json'); |
424 | $headers = $this->generateHeaders('admin', 'mypassword'); | ||
425 | |||
426 | $client->request('DELETE', '/api/tags/'.$tag['id'].'.json', array(), array(), $headers); | ||
427 | 305 | ||
428 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); | 306 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
429 | 307 | ||
430 | $content = json_decode($client->getResponse()->getContent(), true); | 308 | $content = json_decode($this->client->getResponse()->getContent(), true); |
431 | 309 | ||
432 | $this->assertArrayHasKey('label', $content); | 310 | $this->assertArrayHasKey('label', $content); |
433 | $this->assertEquals($tag['label'], $content['label']); | 311 | $this->assertEquals($tag['label'], $content['label']); |