aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/Wallabag/ApiBundle/Controller
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-05-30 07:56:01 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-05-30 07:56:01 +0200
commit5709ecb36809fb009446a11a758232bbe8f264e4 (patch)
tree0880f40fe8e6e563ef5648c267bb1f65251a0355 /tests/Wallabag/ApiBundle/Controller
parent2251045901875aa815dee43ec467fb1af8d416d0 (diff)
downloadwallabag-5709ecb36809fb009446a11a758232bbe8f264e4.tar.gz
wallabag-5709ecb36809fb009446a11a758232bbe8f264e4.tar.zst
wallabag-5709ecb36809fb009446a11a758232bbe8f264e4.zip
Re-use `NewUserType` to validate registration
The only ugly things is how we handle error by generating the view and then parse the content to retrieve all errors… Fix exposition fields in User entity
Diffstat (limited to 'tests/Wallabag/ApiBundle/Controller')
-rw-r--r--tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php
new file mode 100644
index 00000000..21d59a16
--- /dev/null
+++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php
@@ -0,0 +1,98 @@
1<?php
2
3namespace Tests\Wallabag\ApiBundle\Controller;
4
5use Tests\Wallabag\ApiBundle\WallabagApiTestCase;
6
7class 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
54 public function testCreateNewUserWithExistingEmail()
55 {
56 $this->client->request('PUT', '/api/user.json', [
57 'username' => 'google',
58 'password' => 'googlegoogle',
59 'email' => 'bigboss@wallabag.org',
60 ]);
61
62 $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
63
64 $content = json_decode($this->client->getResponse()->getContent(), true);
65
66 $this->assertArrayHasKey('error', $content);
67 $this->assertArrayHasKey('username', $content['error']);
68 $this->assertArrayHasKey('email', $content['error']);
69
70 // $this->assertEquals('fos_user.username.already_used', $content['error']['username'][0]);
71 // $this->assertEquals('fos_user.email.already_used', $content['error']['email'][0]);
72 // This shouldn't be translated ...
73 $this->assertEquals('This value is already used.', $content['error']['username'][0]);
74 $this->assertEquals('This value is already used.', $content['error']['email'][0]);
75
76 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
77 }
78
79 public function testCreateNewUserWithTooShortPassword()
80 {
81 $this->client->request('PUT', '/api/user.json', [
82 'username' => 'facebook',
83 'password' => 'face',
84 'email' => 'facebook@wallabag.org',
85 ]);
86
87 $this->assertEquals(400, $this->client->getResponse()->getStatusCode());
88
89 $content = json_decode($this->client->getResponse()->getContent(), true);
90
91 $this->assertArrayHasKey('error', $content);
92 $this->assertArrayHasKey('password', $content['error']);
93
94 $this->assertEquals('validator.password_too_short', $content['error']['password'][0]);
95
96 $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-Type'));
97 }
98}