diff options
Diffstat (limited to 'tests/Wallabag/ApiBundle')
3 files changed, 121 insertions, 1 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php index bf7d373a..e9ba4634 100644 --- a/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/EntryRestControllerTest.php | |||
@@ -342,6 +342,10 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
342 | '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', | 342 | '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', |
343 | 'tags' => 'google', | 343 | 'tags' => 'google', |
344 | 'title' => 'New title for my article', | 344 | 'title' => 'New title for my article', |
345 | 'content' => 'my content', | ||
346 | 'language' => 'de_DE', | ||
347 | 'published_at' => '2016-09-08T11:55:58+0200', | ||
348 | 'authors' => 'bob,helen', | ||
345 | ]); | 349 | ]); |
346 | 350 | ||
347 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | 351 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); |
@@ -355,6 +359,12 @@ class EntryRestControllerTest extends WallabagApiTestCase | |||
355 | $this->assertEquals('New title for my article', $content['title']); | 359 | $this->assertEquals('New title for my article', $content['title']); |
356 | $this->assertEquals(1, $content['user_id']); | 360 | $this->assertEquals(1, $content['user_id']); |
357 | $this->assertCount(2, $content['tags']); | 361 | $this->assertCount(2, $content['tags']); |
362 | $this->assertSame('my content', $content['content']); | ||
363 | $this->assertSame('de_DE', $content['language']); | ||
364 | $this->assertSame('2016-09-08T11:55:58+0200', $content['published_at']); | ||
365 | $this->assertCount(2, $content['published_by']); | ||
366 | $this->assertContains('bob', $content['published_by']); | ||
367 | $this->assertContains('helen', $content['published_by']); | ||
358 | } | 368 | } |
359 | 369 | ||
360 | public function testPostSameEntry() | 370 | public function testPostSameEntry() |
diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php new file mode 100644 index 00000000..3f4969a5 --- /dev/null +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php | |||
@@ -0,0 +1,110 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Tests\Wallabag\ApiBundle\Controller; | ||
4 | |||
5 | use Tests\Wallabag\ApiBundle\WallabagApiTestCase; | ||
6 | |||
7 | class UserRestControllerTest extends WallabagApiTestCase | ||
8 | { | ||
9 | public function testGetUser() | ||
10 | { | ||
11 | $this->client->request('GET', '/api/user.json'); | ||
12 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
13 | |||
14 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
15 | |||
16 | $this->assertArrayHasKey('id', $content); | ||
17 | $this->assertArrayHasKey('email', $content); | ||
18 | $this->assertArrayHasKey('name', $content); | ||
19 | $this->assertArrayHasKey('username', $content); | ||
20 | $this->assertArrayHasKey('created_at', $content); | ||
21 | $this->assertArrayHasKey('updated_at', $content); | ||
22 | |||
23 | $this->assertEquals('bigboss@wallabag.org', $content['email']); | ||
24 | $this->assertEquals('Big boss', $content['name']); | ||
25 | $this->assertEquals('admin', $content['username']); | ||
26 | |||
27 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
28 | } | ||
29 | |||
30 | public function testCreateNewUser() | ||
31 | { | ||
32 | $this->client->request('PUT', '/api/user.json', [ | ||
33 | 'username' => 'google', | ||
34 | 'password' => 'googlegoogle', | ||
35 | 'email' => 'wallabag@google.com', | ||
36 | ]); | ||
37 | |||
38 | $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); | ||
39 | |||
40 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
41 | |||
42 | $this->assertArrayHasKey('id', $content); | ||
43 | $this->assertArrayHasKey('email', $content); | ||
44 | $this->assertArrayHasKey('username', $content); | ||
45 | $this->assertArrayHasKey('created_at', $content); | ||
46 | $this->assertArrayHasKey('updated_at', $content); | ||
47 | |||
48 | $this->assertEquals('wallabag@google.com', $content['email']); | ||
49 | $this->assertEquals('google', $content['username']); | ||
50 | |||
51 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
52 | |||
53 | // remove the created user to avoid side effect on other tests | ||
54 | // @todo remove these lines when test will be isolated | ||
55 | $em = $this->client->getContainer()->get('doctrine.orm.entity_manager'); | ||
56 | |||
57 | $query = $em->createQuery('DELETE FROM Wallabag\CoreBundle\Entity\Config c WHERE c.user = :user_id'); | ||
58 | $query->setParameter('user_id', $content['id']); | ||
59 | $query->execute(); | ||
60 | |||
61 | $query = $em->createQuery('DELETE FROM Wallabag\UserBundle\Entity\User u WHERE u.id = :id'); | ||
62 | $query->setParameter('id', $content['id']); | ||
63 | $query->execute(); | ||
64 | } | ||
65 | |||
66 | public function testCreateNewUserWithExistingEmail() | ||
67 | { | ||
68 | $this->client->request('PUT', '/api/user.json', [ | ||
69 | 'username' => 'admin', | ||
70 | 'password' => 'googlegoogle', | ||
71 | 'email' => 'bigboss@wallabag.org', | ||
72 | ]); | ||
73 | |||
74 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); | ||
75 | |||
76 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
77 | |||
78 | $this->assertArrayHasKey('error', $content); | ||
79 | $this->assertArrayHasKey('username', $content['error']); | ||
80 | $this->assertArrayHasKey('email', $content['error']); | ||
81 | |||
82 | // $this->assertEquals('fos_user.username.already_used', $content['error']['username'][0]); | ||
83 | // $this->assertEquals('fos_user.email.already_used', $content['error']['email'][0]); | ||
84 | // This shouldn't be translated ... | ||
85 | $this->assertEquals('This value is already used.', $content['error']['username'][0]); | ||
86 | $this->assertEquals('This value is already used.', $content['error']['email'][0]); | ||
87 | |||
88 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
89 | } | ||
90 | |||
91 | public function testCreateNewUserWithTooShortPassword() | ||
92 | { | ||
93 | $this->client->request('PUT', '/api/user.json', [ | ||
94 | 'username' => 'facebook', | ||
95 | 'password' => 'face', | ||
96 | 'email' => 'facebook@wallabag.org', | ||
97 | ]); | ||
98 | |||
99 | $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); | ||
100 | |||
101 | $content = json_decode($this->client->getResponse()->getContent(), true); | ||
102 | |||
103 | $this->assertArrayHasKey('error', $content); | ||
104 | $this->assertArrayHasKey('password', $content['error']); | ||
105 | |||
106 | $this->assertEquals('validator.password_too_short', $content['error']['password'][0]); | ||
107 | |||
108 | $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type')); | ||
109 | } | ||
110 | } | ||
diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index cf9b3347..a67655c8 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php | |||
@@ -37,7 +37,7 @@ abstract class WallabagApiTestCase extends WebTestCase | |||
37 | $firewallName = $container->getParameter('fos_user.firewall_name'); | 37 | $firewallName = $container->getParameter('fos_user.firewall_name'); |
38 | 38 | ||
39 | $this->user = $userManager->findUserBy(['username' => 'admin']); | 39 | $this->user = $userManager->findUserBy(['username' => 'admin']); |
40 | $loginManager->loginUser($firewallName, $this->user); | 40 | $loginManager->logInUser($firewallName, $this->user); |
41 | 41 | ||
42 | // save the login token into the session and put it in a cookie | 42 | // save the login token into the session and put it in a cookie |
43 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); | 43 | $container->get('session')->set('_security_'.$firewallName, serialize($container->get('security.token_storage')->getToken())); |