Completed
Push — master ( 945d9a...e5db64 )
by Schlaefer
02:51
created
app/Plugin/Api/Test/Case/Controller/ApiAppControllerTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
 		public function testApiDisabled() {
34 34
 			Configure::write('Saito.Settings.api_enabled', '0');
35 35
 			$this->setExpectedException('Saito\Api\ApiDisabledException');
36
-			$this->testAction($this->_apiRoot . 'bootstrap.json');
36
+			$this->testAction($this->_apiRoot.'bootstrap.json');
37 37
 		}
38 38
 
39 39
 		public function testApiEnabled() {
40 40
 			Configure::write('Saito.Settings.api_enabled', '1');
41 41
 			$this->setExpectedException('Saito\Api\UnknownRouteException');
42
-			$this->testAction($this->_apiRoot . 'foobar');
42
+			$this->testAction($this->_apiRoot.'foobar');
43 43
 		}
44 44
 
45 45
 		public function testApiAllowOriginHeader() {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			Configure::write('Saito.Settings.api_crossdomain', $expected);
48 48
 			$Controller = $this->generate('ApiCore');
49 49
 			$this->testAction(
50
-				$this->_apiRoot . 'bootstrap.json',
50
+				$this->_apiRoot.'bootstrap.json',
51 51
 				[
52 52
 					'method' => 'GET',
53 53
 					'return' => 'contents'
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 			Configure::write('Saito.Settings.api_crossdomain', '');
62 62
 			$Controller = $this->generate('ApiCore');
63 63
 			$this->testAction(
64
-				$this->_apiRoot . 'bootstrap.json',
64
+				$this->_apiRoot.'bootstrap.json',
65 65
 				[
66 66
 					'method' => 'GET',
67 67
 					'return' => 'contents'
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,74 +1,74 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('ApiControllerTestCase', 'Api.Lib');
3
+    App::uses('ApiControllerTestCase', 'Api.Lib');
4 4
 
5 5
 /**
6 6
  * ApiUsersController Test Case
7 7
  *
8 8
  */
9
-	class ApiAppControllerTest extends ApiControllerTestCase {
9
+    class ApiAppControllerTest extends ApiControllerTestCase {
10 10
 
11
-		protected $_apiRoot = 'api/v1/';
11
+        protected $_apiRoot = 'api/v1/';
12 12
 
13 13
 /**
14 14
  * Fixtures
15 15
  *
16 16
  * @var array
17 17
  */
18
-		public $fixtures = array(
19
-			'plugin.api.entry',
20
-			'plugin.api.category',
21
-			'plugin.api.user',
22
-			'plugin.api.user_block',
23
-			'plugin.api.user_ignore',
24
-			'plugin.api.user_online',
25
-			'plugin.api.user_read',
26
-			'plugin.api.bookmark',
27
-			'plugin.api.esnotification',
28
-			'plugin.api.esevent',
29
-			'plugin.api.upload',
30
-			'plugin.api.setting'
31
-		);
18
+        public $fixtures = array(
19
+            'plugin.api.entry',
20
+            'plugin.api.category',
21
+            'plugin.api.user',
22
+            'plugin.api.user_block',
23
+            'plugin.api.user_ignore',
24
+            'plugin.api.user_online',
25
+            'plugin.api.user_read',
26
+            'plugin.api.bookmark',
27
+            'plugin.api.esnotification',
28
+            'plugin.api.esevent',
29
+            'plugin.api.upload',
30
+            'plugin.api.setting'
31
+        );
32 32
 
33
-		public function testApiDisabled() {
34
-			Configure::write('Saito.Settings.api_enabled', '0');
35
-			$this->setExpectedException('Saito\Api\ApiDisabledException');
36
-			$this->testAction($this->_apiRoot . 'bootstrap.json');
37
-		}
33
+        public function testApiDisabled() {
34
+            Configure::write('Saito.Settings.api_enabled', '0');
35
+            $this->setExpectedException('Saito\Api\ApiDisabledException');
36
+            $this->testAction($this->_apiRoot . 'bootstrap.json');
37
+        }
38 38
 
39
-		public function testApiEnabled() {
40
-			Configure::write('Saito.Settings.api_enabled', '1');
41
-			$this->setExpectedException('Saito\Api\UnknownRouteException');
42
-			$this->testAction($this->_apiRoot . 'foobar');
43
-		}
39
+        public function testApiEnabled() {
40
+            Configure::write('Saito.Settings.api_enabled', '1');
41
+            $this->setExpectedException('Saito\Api\UnknownRouteException');
42
+            $this->testAction($this->_apiRoot . 'foobar');
43
+        }
44 44
 
45
-		public function testApiAllowOriginHeader() {
46
-			$expected = rand();
47
-			Configure::write('Saito.Settings.api_crossdomain', $expected);
48
-			$Controller = $this->generate('ApiCore');
49
-			$this->testAction(
50
-				$this->_apiRoot . 'bootstrap.json',
51
-				[
52
-					'method' => 'GET',
53
-					'return' => 'contents'
54
-				]
55
-			);
56
-			$header = $Controller->response->header()['Access-Control-Allow-Origin'];
57
-			$this->assertEqual($header, $expected);
58
-		}
45
+        public function testApiAllowOriginHeader() {
46
+            $expected = rand();
47
+            Configure::write('Saito.Settings.api_crossdomain', $expected);
48
+            $Controller = $this->generate('ApiCore');
49
+            $this->testAction(
50
+                $this->_apiRoot . 'bootstrap.json',
51
+                [
52
+                    'method' => 'GET',
53
+                    'return' => 'contents'
54
+                ]
55
+            );
56
+            $header = $Controller->response->header()['Access-Control-Allow-Origin'];
57
+            $this->assertEqual($header, $expected);
58
+        }
59 59
 
60
-		public function testApiAllowOriginHeaderNotSet() {
61
-			Configure::write('Saito.Settings.api_crossdomain', '');
62
-			$Controller = $this->generate('ApiCore');
63
-			$this->testAction(
64
-				$this->_apiRoot . 'bootstrap.json',
65
-				[
66
-					'method' => 'GET',
67
-					'return' => 'contents'
68
-				]
69
-			);
70
-			$headers = $Controller->response->header();
71
-			$this->assertFalse(isset($headers['Access-Control-Allow-Origin']));
72
-		}
60
+        public function testApiAllowOriginHeaderNotSet() {
61
+            Configure::write('Saito.Settings.api_crossdomain', '');
62
+            $Controller = $this->generate('ApiCore');
63
+            $this->testAction(
64
+                $this->_apiRoot . 'bootstrap.json',
65
+                [
66
+                    'method' => 'GET',
67
+                    'return' => 'contents'
68
+                ]
69
+            );
70
+            $headers = $Controller->response->header();
71
+            $this->assertFalse(isset($headers['Access-Control-Allow-Origin']));
72
+        }
73 73
 
74
-	}
74
+    }
Please login to merge, or discard this patch.
app/Plugin/Api/Test/Case/Controller/ApiUsersControllerTest.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 				'BadRequestException',
36 36
 				'Field `username` is missing.'
37 37
 			);
38
-			$this->testAction($this->_apiRoot . 'login', ['method' => 'POST']);
38
+			$this->testAction($this->_apiRoot.'login', ['method' => 'POST']);
39 39
 		}
40 40
 
41 41
 		public function testLoginNoPassword() {
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 				'username' => 'Jane'
48 48
 			];
49 49
 			$this->testAction(
50
-				$this->_apiRoot . 'login',
50
+				$this->_apiRoot.'login',
51 51
 				['data' => $data, 'method' => 'POST']
52 52
 			);
53 53
 		}
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 			');
73 73
 
74 74
 			$result = $this->testAction(
75
-				$this->_apiRoot . 'login.json',
75
+				$this->_apiRoot.'login.json',
76 76
 				['method' => 'POST', 'data' => $data, 'return' => 'contents']
77 77
 			);
78 78
 			$this->assertEqual(json_decode($result), $expected);
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 					->will($this->returnValue(false));
107 107
 			$this->setExpectedException('UnauthorizedException');
108 108
 			$this->testAction(
109
-				$this->_apiRoot . 'login',
109
+				$this->_apiRoot.'login',
110 110
 				['method' => 'POST', 'data' => $data]
111 111
 			);
112 112
 		}
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
 		public function testLoginDisallowedRequestType() {
115 115
 			$this->_checkDisallowedRequestType(
116 116
 				['GET', 'PUT', 'DELETE'],
117
-					$this->_apiRoot . 'login'
117
+					$this->_apiRoot.'login'
118 118
 			);
119 119
 		}
120 120
 
121 121
 		public function testMarkAsReadMissingUserId() {
122 122
 			$this->generate('Api.ApiUsers');
123 123
 			$this->_loginUser(3);
124
-			$data = [ ];
124
+			$data = [];
125 125
 			$this->setExpectedException('InvalidArgumentException', 'User id is missing.');
126 126
 			$this->testAction(
127
-				$this->_apiRoot . 'markasread',
127
+				$this->_apiRoot.'markasread',
128 128
 				['method' => 'POST', 'data' => $data]
129 129
 			);
130 130
 		}
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			];
138 138
 			$this->setExpectedException('ForbiddenException', 'You are not authorized for user id `1`.');
139 139
 			$this->testAction(
140
-				$this->_apiRoot . 'markasread',
140
+				$this->_apiRoot.'markasread',
141 141
 				['method' => 'POST', 'data' => $data]
142 142
 			);
143 143
 		}
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			];
177 177
 
178 178
 			$result = $this->testAction(
179
-				$this->_apiRoot . 'markasread.json',
179
+				$this->_apiRoot.'markasread.json',
180 180
 				['method' => 'POST', 'data' => $data, 'return' => 'contents']
181 181
 			);
182 182
 			$result = json_decode($result, true);
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 			];
219 219
 
220 220
 			$result = $this->testAction(
221
-				$this->_apiRoot . 'markasread.json',
221
+				$this->_apiRoot.'markasread.json',
222 222
 				['method' => 'POST', 'data' => $data, 'return' => 'contents']
223 223
 			);
224 224
 			$result = json_decode($result, true);
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 			];
244 244
 
245 245
 			$result = $this->testAction(
246
-				$this->_apiRoot . 'markasread.json',
246
+				$this->_apiRoot.'markasread.json',
247 247
 				['method' => 'POST', 'data' => $data, 'return' => 'contents']
248 248
 			);
249 249
 			$result = json_decode($result, true);
@@ -255,14 +255,14 @@  discard block
 block discarded – undo
255 255
 
256 256
 		public function testMarkAsReadOnlyAuthenticatedUsers() {
257 257
 			$this->generate('ApiUsers', ['methods' => 'markasread']);
258
-			$this->testAction($this->_apiRoot . 'markasread.json', ['method' => 'POST']);
258
+			$this->testAction($this->_apiRoot.'markasread.json', ['method' => 'POST']);
259 259
 			$this->assertRedirectedTo('login');
260 260
 		}
261 261
 
262 262
 		public function testMarkAsReadDisallowedRequestType() {
263 263
 			$this->_checkDisallowedRequestType(
264 264
 				['GET', 'PUT', 'DELETE'],
265
-					$this->_apiRoot . 'markasread'
265
+					$this->_apiRoot.'markasread'
266 266
 			);
267 267
 		}
268 268
 
Please login to merge, or discard this patch.
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('ApiControllerTestCase', 'Api.Lib');
3
+    App::uses('ApiControllerTestCase', 'Api.Lib');
4 4
 
5 5
 /**
6 6
  * ApiUsersController Test Case
7 7
  *
8 8
  */
9
-	class ApiUsersControllerTest extends ApiControllerTestCase {
9
+    class ApiUsersControllerTest extends ApiControllerTestCase {
10 10
 
11
-		protected $_apiRoot = 'api/v1/';
11
+        protected $_apiRoot = 'api/v1/';
12 12
 
13 13
 /**
14 14
  * Fixtures
15 15
  *
16 16
  * @var array
17 17
  */
18
-		public $fixtures = array(
19
-			'plugin.api.entry',
20
-			'plugin.api.category',
21
-			'plugin.api.user',
22
-			'plugin.api.user_block',
23
-			'plugin.api.user_ignore',
24
-			'plugin.api.user_online',
25
-			'plugin.api.user_read',
26
-			'plugin.api.bookmark',
27
-			'plugin.api.esnotification',
28
-			'plugin.api.esevent',
29
-			'plugin.api.upload',
30
-			'plugin.api.setting'
31
-		);
32
-
33
-		public function testLoginNoUsername() {
34
-			$this->setExpectedException(
35
-				'BadRequestException',
36
-				'Field `username` is missing.'
37
-			);
38
-			$this->testAction($this->_apiRoot . 'login', ['method' => 'POST']);
39
-		}
40
-
41
-		public function testLoginNoPassword() {
42
-			$this->setExpectedException(
43
-				'BadRequestException',
44
-				'Field `password` is missing.'
45
-			);
46
-			$data = [
47
-				'username' => 'Jane'
48
-			];
49
-			$this->testAction(
50
-				$this->_apiRoot . 'login',
51
-				['data' => $data, 'method' => 'POST']
52
-			);
53
-		}
54
-
55
-		public function testLoginSuccess() {
56
-			$data = [
57
-				'username' => 'Alice',
58
-				'password' => 'test',
59
-				'remember_me' => '1'
60
-			];
61
-
62
-			$expected = json_decode('
18
+        public $fixtures = array(
19
+            'plugin.api.entry',
20
+            'plugin.api.category',
21
+            'plugin.api.user',
22
+            'plugin.api.user_block',
23
+            'plugin.api.user_ignore',
24
+            'plugin.api.user_online',
25
+            'plugin.api.user_read',
26
+            'plugin.api.bookmark',
27
+            'plugin.api.esnotification',
28
+            'plugin.api.esevent',
29
+            'plugin.api.upload',
30
+            'plugin.api.setting'
31
+        );
32
+
33
+        public function testLoginNoUsername() {
34
+            $this->setExpectedException(
35
+                'BadRequestException',
36
+                'Field `username` is missing.'
37
+            );
38
+            $this->testAction($this->_apiRoot . 'login', ['method' => 'POST']);
39
+        }
40
+
41
+        public function testLoginNoPassword() {
42
+            $this->setExpectedException(
43
+                'BadRequestException',
44
+                'Field `password` is missing.'
45
+            );
46
+            $data = [
47
+                'username' => 'Jane'
48
+            ];
49
+            $this->testAction(
50
+                $this->_apiRoot . 'login',
51
+                ['data' => $data, 'method' => 'POST']
52
+            );
53
+        }
54
+
55
+        public function testLoginSuccess() {
56
+            $data = [
57
+                'username' => 'Alice',
58
+                'password' => 'test',
59
+                'remember_me' => '1'
60
+            ];
61
+
62
+            $expected = json_decode('
63 63
 				{
64 64
 					"user": {
65 65
 						"isLoggedIn": true,
@@ -71,199 +71,199 @@  discard block
 block discarded – undo
71 71
 				}
72 72
 			');
73 73
 
74
-			$result = $this->testAction(
75
-				$this->_apiRoot . 'login.json',
76
-				['method' => 'POST', 'data' => $data, 'return' => 'contents']
77
-			);
78
-			$this->assertEqual(json_decode($result), $expected);
79
-		}
80
-
81
-		public function testLoginFailure() {
82
-			$data = [
83
-				'username' => 'Jane',
84
-				'password' => 'N7',
85
-				'remember_me' => '1'
86
-			];
87
-			$ApiUsers = $this->generate(
88
-				'ApiUsers',
89
-				[
90
-					'components' => [
91
-						'CurrentUser' => [
92
-							'login',
93
-							'initialize',
94
-							'isLoggedIn',
95
-							'logout'
96
-						]
97
-					]
98
-				]
99
-			);
100
-			$ApiUsers->CurrentUser->expects($this->once())
101
-					->method('logout');
102
-			$ApiUsers->CurrentUser->expects($this->once())
103
-					->method('login');
104
-			$ApiUsers->CurrentUser->expects($this->any())
105
-					->method('isLoggedIn')
106
-					->will($this->returnValue(false));
107
-			$this->setExpectedException('UnauthorizedException');
108
-			$this->testAction(
109
-				$this->_apiRoot . 'login',
110
-				['method' => 'POST', 'data' => $data]
111
-			);
112
-		}
113
-
114
-		public function testLoginDisallowedRequestType() {
115
-			$this->_checkDisallowedRequestType(
116
-				['GET', 'PUT', 'DELETE'],
117
-					$this->_apiRoot . 'login'
118
-			);
119
-		}
120
-
121
-		public function testMarkAsReadMissingUserId() {
122
-			$this->generate('Api.ApiUsers');
123
-			$this->_loginUser(3);
124
-			$data = [ ];
125
-			$this->setExpectedException('InvalidArgumentException', 'User id is missing.');
126
-			$this->testAction(
127
-				$this->_apiRoot . 'markasread',
128
-				['method' => 'POST', 'data' => $data]
129
-			);
130
-		}
131
-
132
-		public function testMarkAsReadUserIdNotAuthorized() {
133
-			$this->generate('Api.ApiUsers');
134
-			$this->_loginUser(3);
135
-			$data = [
136
-				'id' => 1
137
-			];
138
-			$this->setExpectedException('ForbiddenException', 'You are not authorized for user id `1`.');
139
-			$this->testAction(
140
-				$this->_apiRoot . 'markasread',
141
-				['method' => 'POST', 'data' => $data]
142
-			);
143
-		}
144
-
145
-		public function testMarkAsReadSuccessNow() {
146
-			$ApiUsers = $this->generate(
147
-				'ApiUsers',
148
-				[
149
-					'components' => [
150
-						'CurrentUser' => [
151
-							'isLoggedIn',
152
-							'getId',
153
-							'initialize'
154
-						]
155
-					]
156
-				]
157
-			);
158
-
159
-			$_userId = 3;
160
-
161
-			$ApiUsers->CurrentUser->expects($this->any())
162
-					->method('isLoggedIn')
163
-					->will($this->returnValue(true));
164
-			$ApiUsers->CurrentUser->expects($this->any())
165
-					->method('getId')
166
-					->will($this->returnValue($_userId));
167
-
168
-			$ApiUsers->CurrentUser->LastRefresh = $this->getMock('Object', ['set']);
169
-			$ApiUsers->CurrentUser->LastRefresh->expects($this->once())
170
-					->method('set')
171
-					->with('now');
172
-
173
-			$this->_loginUser($_userId);
174
-			$data = [
175
-				'id' => $_userId
176
-			];
177
-
178
-			$result = $this->testAction(
179
-				$this->_apiRoot . 'markasread.json',
180
-				['method' => 'POST', 'data' => $data, 'return' => 'contents']
181
-			);
182
-			$result = json_decode($result, true);
183
-			$this->assertTrue(isset($result['last_refresh']));
184
-		}
185
-
186
-		public function testMarkAsReadSuccessTimestamp() {
187
-			$ApiUsers = $this->generate(
188
-				'ApiUsers',
189
-				[
190
-					'components' => [
191
-						'CurrentUser' => [
192
-							'isLoggedIn',
193
-							'getId',
194
-							'initialize'
195
-						]
196
-					]
197
-				]
198
-			);
199
-
200
-			$_userId = 3;
201
-
202
-			$ApiUsers->CurrentUser->expects($this->any())
203
-					->method('isLoggedIn')
204
-					->will($this->returnValue(true));
205
-			$ApiUsers->CurrentUser->expects($this->any())
206
-					->method('getId')
207
-					->will($this->returnValue($_userId));
208
-
209
-			$ApiUsers->CurrentUser->LastRefresh = $this->getMock('Object', ['set']);
210
-			$ApiUsers->CurrentUser->LastRefresh->expects($this->once())
211
-					->method('set')
212
-					->with('2013-07-04 19:53:14');
213
-
214
-			$this->_loginUser($_userId);
215
-			$data = [
216
-				'id' => $_userId,
217
-				'last_refresh' => '2013-07-04T19:53:14+00:00'
218
-			];
219
-
220
-			$result = $this->testAction(
221
-				$this->_apiRoot . 'markasread.json',
222
-				['method' => 'POST', 'data' => $data, 'return' => 'contents']
223
-			);
224
-			$result = json_decode($result, true);
225
-			$this->assertTrue(isset($result['last_refresh']));
226
-		}
74
+            $result = $this->testAction(
75
+                $this->_apiRoot . 'login.json',
76
+                ['method' => 'POST', 'data' => $data, 'return' => 'contents']
77
+            );
78
+            $this->assertEqual(json_decode($result), $expected);
79
+        }
80
+
81
+        public function testLoginFailure() {
82
+            $data = [
83
+                'username' => 'Jane',
84
+                'password' => 'N7',
85
+                'remember_me' => '1'
86
+            ];
87
+            $ApiUsers = $this->generate(
88
+                'ApiUsers',
89
+                [
90
+                    'components' => [
91
+                        'CurrentUser' => [
92
+                            'login',
93
+                            'initialize',
94
+                            'isLoggedIn',
95
+                            'logout'
96
+                        ]
97
+                    ]
98
+                ]
99
+            );
100
+            $ApiUsers->CurrentUser->expects($this->once())
101
+                    ->method('logout');
102
+            $ApiUsers->CurrentUser->expects($this->once())
103
+                    ->method('login');
104
+            $ApiUsers->CurrentUser->expects($this->any())
105
+                    ->method('isLoggedIn')
106
+                    ->will($this->returnValue(false));
107
+            $this->setExpectedException('UnauthorizedException');
108
+            $this->testAction(
109
+                $this->_apiRoot . 'login',
110
+                ['method' => 'POST', 'data' => $data]
111
+            );
112
+        }
113
+
114
+        public function testLoginDisallowedRequestType() {
115
+            $this->_checkDisallowedRequestType(
116
+                ['GET', 'PUT', 'DELETE'],
117
+                    $this->_apiRoot . 'login'
118
+            );
119
+        }
120
+
121
+        public function testMarkAsReadMissingUserId() {
122
+            $this->generate('Api.ApiUsers');
123
+            $this->_loginUser(3);
124
+            $data = [ ];
125
+            $this->setExpectedException('InvalidArgumentException', 'User id is missing.');
126
+            $this->testAction(
127
+                $this->_apiRoot . 'markasread',
128
+                ['method' => 'POST', 'data' => $data]
129
+            );
130
+        }
131
+
132
+        public function testMarkAsReadUserIdNotAuthorized() {
133
+            $this->generate('Api.ApiUsers');
134
+            $this->_loginUser(3);
135
+            $data = [
136
+                'id' => 1
137
+            ];
138
+            $this->setExpectedException('ForbiddenException', 'You are not authorized for user id `1`.');
139
+            $this->testAction(
140
+                $this->_apiRoot . 'markasread',
141
+                ['method' => 'POST', 'data' => $data]
142
+            );
143
+        }
144
+
145
+        public function testMarkAsReadSuccessNow() {
146
+            $ApiUsers = $this->generate(
147
+                'ApiUsers',
148
+                [
149
+                    'components' => [
150
+                        'CurrentUser' => [
151
+                            'isLoggedIn',
152
+                            'getId',
153
+                            'initialize'
154
+                        ]
155
+                    ]
156
+                ]
157
+            );
158
+
159
+            $_userId = 3;
160
+
161
+            $ApiUsers->CurrentUser->expects($this->any())
162
+                    ->method('isLoggedIn')
163
+                    ->will($this->returnValue(true));
164
+            $ApiUsers->CurrentUser->expects($this->any())
165
+                    ->method('getId')
166
+                    ->will($this->returnValue($_userId));
167
+
168
+            $ApiUsers->CurrentUser->LastRefresh = $this->getMock('Object', ['set']);
169
+            $ApiUsers->CurrentUser->LastRefresh->expects($this->once())
170
+                    ->method('set')
171
+                    ->with('now');
172
+
173
+            $this->_loginUser($_userId);
174
+            $data = [
175
+                'id' => $_userId
176
+            ];
177
+
178
+            $result = $this->testAction(
179
+                $this->_apiRoot . 'markasread.json',
180
+                ['method' => 'POST', 'data' => $data, 'return' => 'contents']
181
+            );
182
+            $result = json_decode($result, true);
183
+            $this->assertTrue(isset($result['last_refresh']));
184
+        }
185
+
186
+        public function testMarkAsReadSuccessTimestamp() {
187
+            $ApiUsers = $this->generate(
188
+                'ApiUsers',
189
+                [
190
+                    'components' => [
191
+                        'CurrentUser' => [
192
+                            'isLoggedIn',
193
+                            'getId',
194
+                            'initialize'
195
+                        ]
196
+                    ]
197
+                ]
198
+            );
199
+
200
+            $_userId = 3;
201
+
202
+            $ApiUsers->CurrentUser->expects($this->any())
203
+                    ->method('isLoggedIn')
204
+                    ->will($this->returnValue(true));
205
+            $ApiUsers->CurrentUser->expects($this->any())
206
+                    ->method('getId')
207
+                    ->will($this->returnValue($_userId));
208
+
209
+            $ApiUsers->CurrentUser->LastRefresh = $this->getMock('Object', ['set']);
210
+            $ApiUsers->CurrentUser->LastRefresh->expects($this->once())
211
+                    ->method('set')
212
+                    ->with('2013-07-04 19:53:14');
213
+
214
+            $this->_loginUser($_userId);
215
+            $data = [
216
+                'id' => $_userId,
217
+                'last_refresh' => '2013-07-04T19:53:14+00:00'
218
+            ];
219
+
220
+            $result = $this->testAction(
221
+                $this->_apiRoot . 'markasread.json',
222
+                ['method' => 'POST', 'data' => $data, 'return' => 'contents']
223
+            );
224
+            $result = json_decode($result, true);
225
+            $this->assertTrue(isset($result['last_refresh']));
226
+        }
227 227
 
228 228
 /**
229 229
  * Send timestamp is ignored is not set if it's older than the current one
230 230
  */
231
-		public function testMarkAsReadNoPastValues() {
232
-			$ApiUsers = $this->generate('ApiUsers');
233
-
234
-			$_userId = 3;
235
-			$this->_loginUser($_userId);
236
-
237
-			$ApiUsers->User->id = $_userId;
238
-			$ApiUsers->User->saveField('last_refresh', '2013-07-04 19:53:14');
239
-
240
-			$data = [
241
-				'id' => $_userId,
242
-				'last_refresh' => '2013-07-04T19:53:13+00:00'
243
-			];
244
-
245
-			$result = $this->testAction(
246
-				$this->_apiRoot . 'markasread.json',
247
-				['method' => 'POST', 'data' => $data, 'return' => 'contents']
248
-			);
249
-			$result = json_decode($result, true);
250
-			$expected = [
251
-				'last_refresh' => '2013-07-04T19:53:14+00:00'
252
-			] + $data;
253
-			$this->assertEqual($result, $expected);
254
-		}
255
-
256
-		public function testMarkAsReadOnlyAuthenticatedUsers() {
257
-			$this->generate('ApiUsers', ['methods' => 'markasread']);
258
-			$this->testAction($this->_apiRoot . 'markasread.json', ['method' => 'POST']);
259
-			$this->assertRedirectedTo('login');
260
-		}
261
-
262
-		public function testMarkAsReadDisallowedRequestType() {
263
-			$this->_checkDisallowedRequestType(
264
-				['GET', 'PUT', 'DELETE'],
265
-					$this->_apiRoot . 'markasread'
266
-			);
267
-		}
268
-
269
-	}
231
+        public function testMarkAsReadNoPastValues() {
232
+            $ApiUsers = $this->generate('ApiUsers');
233
+
234
+            $_userId = 3;
235
+            $this->_loginUser($_userId);
236
+
237
+            $ApiUsers->User->id = $_userId;
238
+            $ApiUsers->User->saveField('last_refresh', '2013-07-04 19:53:14');
239
+
240
+            $data = [
241
+                'id' => $_userId,
242
+                'last_refresh' => '2013-07-04T19:53:13+00:00'
243
+            ];
244
+
245
+            $result = $this->testAction(
246
+                $this->_apiRoot . 'markasread.json',
247
+                ['method' => 'POST', 'data' => $data, 'return' => 'contents']
248
+            );
249
+            $result = json_decode($result, true);
250
+            $expected = [
251
+                'last_refresh' => '2013-07-04T19:53:14+00:00'
252
+            ] + $data;
253
+            $this->assertEqual($result, $expected);
254
+        }
255
+
256
+        public function testMarkAsReadOnlyAuthenticatedUsers() {
257
+            $this->generate('ApiUsers', ['methods' => 'markasread']);
258
+            $this->testAction($this->_apiRoot . 'markasread.json', ['method' => 'POST']);
259
+            $this->assertRedirectedTo('login');
260
+        }
261
+
262
+        public function testMarkAsReadDisallowedRequestType() {
263
+            $this->_checkDisallowedRequestType(
264
+                ['GET', 'PUT', 'DELETE'],
265
+                    $this->_apiRoot . 'markasread'
266
+            );
267
+        }
268
+
269
+    }
Please login to merge, or discard this patch.
app/Plugin/Api/Test/Case/Controller/ApiCoreControllerTest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			$expected = json_decode($_json, true);
64 64
 
65 65
 			$result = $this->testAction(
66
-				$this->_apiRoot . 'bootstrap.json',
66
+				$this->_apiRoot.'bootstrap.json',
67 67
 				[
68 68
 					'method' => 'GET',
69 69
 					'return' => 'contents'
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 			$this->generate('ApiCore');
124 124
 			$this->_loginUser(3);
125 125
 			$result = $this->testAction(
126
-				$this->_apiRoot . 'bootstrap.json',
126
+				$this->_apiRoot.'bootstrap.json',
127 127
 				[
128 128
 					'method' => 'GET',
129 129
 					'return' => 'contents'
Please login to merge, or discard this patch.
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,38 +1,38 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('ApiControllerTestCase', 'Api.Lib');
3
+    App::uses('ApiControllerTestCase', 'Api.Lib');
4 4
 
5 5
 /**
6 6
  * ApiUsersController Test Case
7 7
  *
8 8
  */
9
-	class ApiCoreControllerTest extends ApiControllerTestCase {
9
+    class ApiCoreControllerTest extends ApiControllerTestCase {
10 10
 
11
-		protected $_apiRoot = 'api/v1/';
11
+        protected $_apiRoot = 'api/v1/';
12 12
 
13 13
 /**
14 14
  * Fixtures
15 15
  *
16 16
  * @var array
17 17
  */
18
-		public $fixtures = array(
19
-			'plugin.api.entry',
20
-			'plugin.api.category',
21
-			'plugin.api.user',
22
-			'plugin.api.user_block',
23
-			'plugin.api.user_ignore',
24
-			'plugin.api.user_online',
25
-			'plugin.api.bookmark',
26
-			'plugin.api.esnotification',
27
-			'plugin.api.esevent',
28
-			'plugin.api.upload',
29
-			'plugin.api.setting'
30
-		);
18
+        public $fixtures = array(
19
+            'plugin.api.entry',
20
+            'plugin.api.category',
21
+            'plugin.api.user',
22
+            'plugin.api.user_block',
23
+            'plugin.api.user_ignore',
24
+            'plugin.api.user_online',
25
+            'plugin.api.bookmark',
26
+            'plugin.api.esnotification',
27
+            'plugin.api.esevent',
28
+            'plugin.api.upload',
29
+            'plugin.api.setting'
30
+        );
31 31
 
32
-		public function testBootstrap() {
33
-			Configure::write('Saito.Settings.edit_period', 20);
32
+        public function testBootstrap() {
33
+            Configure::write('Saito.Settings.edit_period', 20);
34 34
 
35
-			$_json = <<<EOF
35
+            $_json = <<<EOF
36 36
 {
37 37
   "categories": [
38 38
     {
@@ -60,34 +60,34 @@  discard block
 block discarded – undo
60 60
   }
61 61
 }
62 62
 EOF;
63
-			$expected = json_decode($_json, true);
63
+            $expected = json_decode($_json, true);
64 64
 
65
-			$result = $this->testAction(
66
-				$this->_apiRoot . 'bootstrap.json',
67
-				[
68
-					'method' => 'GET',
69
-					'return' => 'contents'
70
-				]
71
-			);
65
+            $result = $this->testAction(
66
+                $this->_apiRoot . 'bootstrap.json',
67
+                [
68
+                    'method' => 'GET',
69
+                    'return' => 'contents'
70
+                ]
71
+            );
72 72
 
73
-			$result = json_decode($result, true);
73
+            $result = json_decode($result, true);
74 74
 
75
-			// test server_time
76
-			$this->assertNotEmpty($result['server']['time']);
77
-			$_serverTime = strtotime($result['server']['time']);
78
-			$withinTheLastFewSeconds = $_serverTime > (time() - 20);
79
-			$this->assertTrue($withinTheLastFewSeconds);
80
-			unset($result['server']['time']);
75
+            // test server_time
76
+            $this->assertNotEmpty($result['server']['time']);
77
+            $_serverTime = strtotime($result['server']['time']);
78
+            $withinTheLastFewSeconds = $_serverTime > (time() - 20);
79
+            $this->assertTrue($withinTheLastFewSeconds);
80
+            unset($result['server']['time']);
81 81
 
82
-			if (empty($result['server'])) {
83
-				unset($result['server']);
84
-			}
82
+            if (empty($result['server'])) {
83
+                unset($result['server']);
84
+            }
85 85
 
86
-			$this->assertEqual($result, $expected);
87
-		}
86
+            $this->assertEqual($result, $expected);
87
+        }
88 88
 
89
-		public function testBootstrapCategoriesLoggedIn() {
90
-			$_json = <<<EOF
89
+        public function testBootstrapCategoriesLoggedIn() {
90
+            $_json = <<<EOF
91 91
  [
92 92
     {
93 93
       "id": 2,
@@ -119,18 +119,18 @@  discard block
 block discarded – undo
119 119
     }
120 120
 ]
121 121
 EOF;
122
-			$expected = json_decode($_json, true);
123
-			$this->generate('ApiCore');
124
-			$this->_loginUser(3);
125
-			$result = $this->testAction(
126
-				$this->_apiRoot . 'bootstrap.json',
127
-				[
128
-					'method' => 'GET',
129
-					'return' => 'contents'
130
-				]
131
-			);
132
-			$result = json_decode($result, true)['categories'];
133
-			$this->assertEqual($result, $expected);
134
-		}
122
+            $expected = json_decode($_json, true);
123
+            $this->generate('ApiCore');
124
+            $this->_loginUser(3);
125
+            $result = $this->testAction(
126
+                $this->_apiRoot . 'bootstrap.json',
127
+                [
128
+                    'method' => 'GET',
129
+                    'return' => 'contents'
130
+                ]
131
+            );
132
+            $result = json_decode($result, true)['categories'];
133
+            $this->assertEqual($result, $expected);
134
+        }
135 135
 
136
-	}
136
+    }
Please login to merge, or discard this patch.
app/Plugin/Api/Test/Case/Controller/ApiShoutsControllerTest.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 		public function testShoutsDisallowedRequestTypes() {
66 66
 			$this->_checkDisallowedRequestType(
67 67
 				['PUT', 'DELETE'],
68
-					$this->_apiRoot . 'shouts'
68
+					$this->_apiRoot.'shouts'
69 69
 			);
70 70
 		}
71 71
 
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			$this->_loginUser(3);
75 75
 
76 76
 			$expected = $this->_fixtureResult;
77
-			$result = $this->testAction($this->_apiRoot . 'shouts.json',
77
+			$result = $this->testAction($this->_apiRoot.'shouts.json',
78 78
 				[
79 79
 					'method' => 'GET',
80 80
 					'return' => 'contents'
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 		public function testShoutsGetNotLoggedIn() {
87 87
 			$this->generate('Api.ApiShouts');
88 88
 			$this->setExpectedException('Saito\Api\ApiAuthException');
89
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'GET']);
89
+			$this->testAction($this->_apiRoot.'shouts.json', ['method' => 'GET']);
90 90
 		}
91 91
 
92 92
 		public function testShoutsPost() {
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 			$data = [
97 97
 				'text' => 'test < shout'
98 98
 			];
99
-			$result = $this->testAction($this->_apiRoot . 'shouts.json',
99
+			$result = $this->testAction($this->_apiRoot.'shouts.json',
100 100
 				[
101 101
 					'method' => 'POST',
102 102
 					'data' => $data,
@@ -127,13 +127,13 @@  discard block
 block discarded – undo
127 127
 			$this->_loginUser(3);
128 128
 
129 129
 			$this->setExpectedException('BadRequestException', 'Missing text.');
130
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
130
+			$this->testAction($this->_apiRoot.'shouts.json', ['method' => 'POST']);
131 131
 		}
132 132
 
133 133
 		public function testShoutsPostNotLoggedIn() {
134 134
 			$this->generate('Api.ApiShouts');
135 135
 			$this->setExpectedException('Saito\Api\ApiAuthException');
136
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
136
+			$this->testAction($this->_apiRoot.'shouts.json', ['method' => 'POST']);
137 137
 		}
138 138
 
139 139
 	}
Please login to merge, or discard this patch.
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -1,139 +1,139 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('ApiControllerTestCase', 'Api.Lib');
4
-
5
-	/**
6
-	 * ApiEntriesController Test Case
7
-	 *
8
-	 */
9
-	class ApiShoutsControllerTest extends ApiControllerTestCase {
10
-
11
-		protected $_apiRoot = 'api/v1/';
12
-
13
-		protected $_fixtureResult = [
14
-			0 =>
15
-					array(
16
-						'id' => 4,
17
-						'time' => '2013-02-08T11:49:31+00:00',
18
-						'text' => '<script></script>[i]italic[/i]',
19
-						'html' => '&lt;script&gt;&lt;/script&gt;<em>italic</em>',
20
-						'user_id' => 1,
21
-						'user_name' => 'Alice',
22
-					),
23
-			1 =>
24
-					array(
25
-						'id' => 3,
26
-						'time' => '2013-02-08T11:49:31+00:00',
27
-						'text' => 'Lorem ipsum dolor sit amet',
28
-						'html' => 'Lorem ipsum dolor sit amet',
29
-						'user_id' => 1,
30
-						'user_name' => 'Alice',
31
-					),
32
-			2 =>
33
-					array(
34
-						'id' => 2,
35
-						'time' => '2013-02-08T11:49:31+00:00',
36
-						'text' => 'Lorem ipsum dolor sit amet',
37
-						'html' => 'Lorem ipsum dolor sit amet',
38
-						'user_id' => 1,
39
-						'user_name' => 'Alice',
40
-					),
41
-		];
42
-
43
-		/**
44
-		 * Fixtures
45
-		 *
46
-		 * @var array
47
-		 */
48
-		public $fixtures = array(
49
-			'plugin.api.entry',
50
-			'plugin.api.category',
51
-			'plugin.api.user',
52
-			'plugin.api.user_block',
53
-			'plugin.api.user_ignore',
54
-			'plugin.api.user_online',
55
-			'plugin.api.bookmark',
56
-			'plugin.api.esnotification',
57
-			'plugin.api.esevent',
58
-			'plugin.api.setting',
59
-			'plugin.api.smiley',
60
-			'plugin.api.smiley_code',
61
-			'plugin.api.shout',
62
-			'plugin.api.upload'
63
-		);
64
-
65
-		public function testShoutsDisallowedRequestTypes() {
66
-			$this->_checkDisallowedRequestType(
67
-				['PUT', 'DELETE'],
68
-					$this->_apiRoot . 'shouts'
69
-			);
70
-		}
71
-
72
-		public function testShoutsGet() {
73
-			$this->generate('Api.ApiShouts');
74
-			$this->_loginUser(3);
75
-
76
-			$expected = $this->_fixtureResult;
77
-			$result = $this->testAction($this->_apiRoot . 'shouts.json',
78
-				[
79
-					'method' => 'GET',
80
-					'return' => 'contents'
81
-				]);
82
-			$result = json_decode($result, true);
83
-			$this->assertEqual($result, $expected);
84
-		}
85
-
86
-		public function testShoutsGetNotLoggedIn() {
87
-			$this->generate('Api.ApiShouts');
88
-			$this->setExpectedException('Saito\Api\ApiAuthException');
89
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'GET']);
90
-		}
91
-
92
-		public function testShoutsPost() {
93
-			$this->generate('Api.ApiShouts');
94
-			$this->_loginUser(3);
95
-
96
-			$data = [
97
-				'text' => 'test < shout'
98
-			];
99
-			$result = $this->testAction($this->_apiRoot . 'shouts.json',
100
-				[
101
-					'method' => 'POST',
102
-					'data' => $data,
103
-					'return' => 'contents'
104
-				]);
105
-			$result = json_decode($result, true);
106
-			$_newEntry = array_shift($result);
107
-
108
-			$_newEntryTime = strtotime($_newEntry['time']);
109
-			$this->assertGreaterThanOrEqual(time() - 1, $_newEntryTime);
110
-			unset($_newEntry['time']);
111
-
112
-			$expected = [
113
-				'id' => 5,
114
-				'text' => 'test < shout',
115
-				'html' => 'test &lt; shout',
116
-				'user_id' => 3,
117
-				'user_name' => 'Ulysses',
118
-			];
119
-			$this->assertEqual($_newEntry, $expected);
120
-
121
-			$expected = $this->_fixtureResult;
122
-			$this->assertEqual($result, $expected);
123
-		}
124
-
125
-		public function testShoutsPostTextMissing() {
126
-			$this->generate('Api.ApiShouts');
127
-			$this->_loginUser(3);
128
-
129
-			$this->setExpectedException('BadRequestException', 'Missing text.');
130
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
131
-		}
132
-
133
-		public function testShoutsPostNotLoggedIn() {
134
-			$this->generate('Api.ApiShouts');
135
-			$this->setExpectedException('Saito\Api\ApiAuthException');
136
-			$this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
137
-		}
138
-
139
-	}
3
+    App::uses('ApiControllerTestCase', 'Api.Lib');
4
+
5
+    /**
6
+     * ApiEntriesController Test Case
7
+     *
8
+     */
9
+    class ApiShoutsControllerTest extends ApiControllerTestCase {
10
+
11
+        protected $_apiRoot = 'api/v1/';
12
+
13
+        protected $_fixtureResult = [
14
+            0 =>
15
+                    array(
16
+                        'id' => 4,
17
+                        'time' => '2013-02-08T11:49:31+00:00',
18
+                        'text' => '<script></script>[i]italic[/i]',
19
+                        'html' => '&lt;script&gt;&lt;/script&gt;<em>italic</em>',
20
+                        'user_id' => 1,
21
+                        'user_name' => 'Alice',
22
+                    ),
23
+            1 =>
24
+                    array(
25
+                        'id' => 3,
26
+                        'time' => '2013-02-08T11:49:31+00:00',
27
+                        'text' => 'Lorem ipsum dolor sit amet',
28
+                        'html' => 'Lorem ipsum dolor sit amet',
29
+                        'user_id' => 1,
30
+                        'user_name' => 'Alice',
31
+                    ),
32
+            2 =>
33
+                    array(
34
+                        'id' => 2,
35
+                        'time' => '2013-02-08T11:49:31+00:00',
36
+                        'text' => 'Lorem ipsum dolor sit amet',
37
+                        'html' => 'Lorem ipsum dolor sit amet',
38
+                        'user_id' => 1,
39
+                        'user_name' => 'Alice',
40
+                    ),
41
+        ];
42
+
43
+        /**
44
+         * Fixtures
45
+         *
46
+         * @var array
47
+         */
48
+        public $fixtures = array(
49
+            'plugin.api.entry',
50
+            'plugin.api.category',
51
+            'plugin.api.user',
52
+            'plugin.api.user_block',
53
+            'plugin.api.user_ignore',
54
+            'plugin.api.user_online',
55
+            'plugin.api.bookmark',
56
+            'plugin.api.esnotification',
57
+            'plugin.api.esevent',
58
+            'plugin.api.setting',
59
+            'plugin.api.smiley',
60
+            'plugin.api.smiley_code',
61
+            'plugin.api.shout',
62
+            'plugin.api.upload'
63
+        );
64
+
65
+        public function testShoutsDisallowedRequestTypes() {
66
+            $this->_checkDisallowedRequestType(
67
+                ['PUT', 'DELETE'],
68
+                    $this->_apiRoot . 'shouts'
69
+            );
70
+        }
71
+
72
+        public function testShoutsGet() {
73
+            $this->generate('Api.ApiShouts');
74
+            $this->_loginUser(3);
75
+
76
+            $expected = $this->_fixtureResult;
77
+            $result = $this->testAction($this->_apiRoot . 'shouts.json',
78
+                [
79
+                    'method' => 'GET',
80
+                    'return' => 'contents'
81
+                ]);
82
+            $result = json_decode($result, true);
83
+            $this->assertEqual($result, $expected);
84
+        }
85
+
86
+        public function testShoutsGetNotLoggedIn() {
87
+            $this->generate('Api.ApiShouts');
88
+            $this->setExpectedException('Saito\Api\ApiAuthException');
89
+            $this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'GET']);
90
+        }
91
+
92
+        public function testShoutsPost() {
93
+            $this->generate('Api.ApiShouts');
94
+            $this->_loginUser(3);
95
+
96
+            $data = [
97
+                'text' => 'test < shout'
98
+            ];
99
+            $result = $this->testAction($this->_apiRoot . 'shouts.json',
100
+                [
101
+                    'method' => 'POST',
102
+                    'data' => $data,
103
+                    'return' => 'contents'
104
+                ]);
105
+            $result = json_decode($result, true);
106
+            $_newEntry = array_shift($result);
107
+
108
+            $_newEntryTime = strtotime($_newEntry['time']);
109
+            $this->assertGreaterThanOrEqual(time() - 1, $_newEntryTime);
110
+            unset($_newEntry['time']);
111
+
112
+            $expected = [
113
+                'id' => 5,
114
+                'text' => 'test < shout',
115
+                'html' => 'test &lt; shout',
116
+                'user_id' => 3,
117
+                'user_name' => 'Ulysses',
118
+            ];
119
+            $this->assertEqual($_newEntry, $expected);
120
+
121
+            $expected = $this->_fixtureResult;
122
+            $this->assertEqual($result, $expected);
123
+        }
124
+
125
+        public function testShoutsPostTextMissing() {
126
+            $this->generate('Api.ApiShouts');
127
+            $this->_loginUser(3);
128
+
129
+            $this->setExpectedException('BadRequestException', 'Missing text.');
130
+            $this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
131
+        }
132
+
133
+        public function testShoutsPostNotLoggedIn() {
134
+            $this->generate('Api.ApiShouts');
135
+            $this->setExpectedException('Saito\Api\ApiAuthException');
136
+            $this->testAction($this->_apiRoot . 'shouts.json', ['method' => 'POST']);
137
+        }
138
+
139
+    }
Please login to merge, or discard this patch.
app/Plugin/Api/Test/Case/Controller/ApiEntriesControllerTest.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 
45 45
 			$data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
46 46
 			$result = $this->testAction(
47
-				$this->_apiRoot . 'threads.json',
47
+				$this->_apiRoot.'threads.json',
48 48
 				['return' => 'contents', 'method' => 'GET', 'data' => $data]
49 49
 			);
50 50
 			$expected = json_decode('
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		public function testThreadsNoAdminAnon() {
84 84
 			$data = ['limit' => 3];
85 85
 			$result = $this->testAction(
86
-				$this->_apiRoot . 'threads.json',
86
+				$this->_apiRoot.'threads.json',
87 87
 				['return' => 'contents', 'method' => 'GET', 'data' => $data]
88 88
 			);
89 89
 			$result = json_decode($result, true);
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			$this->_loginUser(3);
101 101
 			$data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
102 102
 			$result = $this->testAction(
103
-				$this->_apiRoot . 'threads.json',
103
+				$this->_apiRoot.'threads.json',
104 104
 				['return' => 'contents', 'method' => 'GET', 'data' => $data]
105 105
 			);
106 106
 			$result = json_decode($result, true);
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		public function testThreadsDisallowedRequestTypes() {
112 112
 			$this->_checkDisallowedRequestType(
113 113
 				['POST', 'PUT', 'DELETE'],
114
-					$this->_apiRoot . 'threads'
114
+					$this->_apiRoot.'threads'
115 115
 			);
116 116
 		}
117 117
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			$this->setExpectedException('Saito\Api\ApiValidationError',
122 122
 				'Subject must not be empty.');
123 123
 			$this->testAction(
124
-				$this->_apiRoot . 'entries.json',
124
+				$this->_apiRoot.'entries.json',
125 125
 				[
126 126
 					'method' => 'POST',
127 127
 					'data' => [
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 			$this->generate('Api.ApiEntries');
138 138
 			$this->_loginUser(3);
139 139
 			$result = $this->testAction(
140
-				$this->_apiRoot . 'entries.json',
140
+				$this->_apiRoot.'entries.json',
141 141
 				[
142 142
 					'return' => 'view',
143 143
 					'method' => 'POST',
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
 
155 155
 		public function testEntriesItemPutOnlyAuthenticatedUsers() {
156 156
 			$this->generate('ApiEntries', ['methods' => 'entriesItemPut']);
157
-			$this->testAction($this->_apiRoot . 'entries/1', ['method' => 'PUT']);
157
+			$this->testAction($this->_apiRoot.'entries/1', ['method' => 'PUT']);
158 158
 			$this->assertRedirectedTo('login');
159 159
 		}
160 160
 
161 161
 		public function testEntriesItemEntryIdMustBeProvided() {
162 162
 			$this->setExpectedException('BadRequestException', 'Missing entry id.');
163
-			$this->testAction($this->_apiRoot . 'entries/', ['method' => 'PUT']);
163
+			$this->testAction($this->_apiRoot.'entries/', ['method' => 'PUT']);
164 164
 		}
165 165
 
166 166
 		public function testEntriesItemPutEntryMustExist() {
167 167
 			$this->setExpectedException('NotFoundException', 'Entry with id `999` not found.');
168
-			$this->testAction($this->_apiRoot . 'entries/999', ['method' => 'PUT']);
168
+			$this->testAction($this->_apiRoot.'entries/999', ['method' => 'PUT']);
169 169
 		}
170 170
 
171 171
 		public function testEntriesItemPutForbiddenTime() {
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 			$this->_loginUser(3);
174 174
 			$this->setExpectedException('ForbiddenException', 'The editing time ran out.');
175 175
 			$this->testAction(
176
-				$this->_apiRoot . 'entries/1',
176
+				$this->_apiRoot.'entries/1',
177 177
 				[
178 178
 					'method' => 'PUT',
179 179
 					'data' => [
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
 			$id = 2;
192 192
 			$ApiEntries->Entry->save(['id' => $id, 'time' => bdate()]);
193 193
 			$this->testAction(
194
-				$this->_apiRoot . 'entries/' . $id,
194
+				$this->_apiRoot.'entries/'.$id,
195 195
 				[
196 196
 					'method' => 'PUT',
197 197
 					'data' => [
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			$this->_loginUser(3);
224 224
 			$this->setExpectedException('ForbiddenException', 'Editing is forbidden for unknown reason.');
225 225
 			$this->testAction(
226
-				$this->_apiRoot . 'entries/1',
226
+				$this->_apiRoot.'entries/1',
227 227
 				[
228 228
 					'method' => 'PUT',
229 229
 					'data' => [
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 			$this->_loginUser(1);
240 240
 			$id = 1;
241 241
 			$result = $this->testAction(
242
-				$this->_apiRoot . 'entries/' . $id . '.json',
242
+				$this->_apiRoot.'entries/'.$id.'.json',
243 243
 				[
244 244
 					'method' => 'PUT',
245 245
 					'data' => [
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 				->method('update')
293 293
 				->will($this->returnValue(false));
294 294
 			$this->testAction(
295
-				$this->_apiRoot . 'entries/' . $id,
295
+				$this->_apiRoot.'entries/'.$id,
296 296
 				[
297 297
 					'method' => 'PUT',
298 298
 					'data' => [
@@ -306,20 +306,20 @@  discard block
 block discarded – undo
306 306
 		public function testEntriesItemDisallowedRequestTypes() {
307 307
 			$this->_checkDisallowedRequestType(
308 308
 				['GET', 'POST', 'DELETE'],
309
-					$this->_apiRoot . 'entries/1'
309
+					$this->_apiRoot.'entries/1'
310 310
 			);
311 311
 		}
312 312
 
313 313
 		public function testThreadsItemGetThreadNotFound() {
314 314
 			$this->setExpectedException('NotFoundException', 'Thread with id `2` not found.');
315
-			$this->testAction($this->_apiRoot . 'threads/2.json', ['method' => 'GET']);
315
+			$this->testAction($this->_apiRoot.'threads/2.json', ['method' => 'GET']);
316 316
 		}
317 317
 
318 318
 		public function testThreadsItemGet() {
319 319
 			$this->generate('ApiEntries');
320 320
 			$this->_loginUser(3);
321 321
 			$result = $this->testAction(
322
-				$this->_apiRoot . 'threads/1.json',
322
+				$this->_apiRoot.'threads/1.json',
323 323
 				['method' => 'GET', 'return' => 'contents']
324 324
 			);
325 325
 			$json = <<< EOF
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
 		public function testThreadsItemGetNotLoggedIn() {
355 355
 			$result = $this->testAction(
356
-				$this->_apiRoot . 'threads/10.json',
356
+				$this->_apiRoot.'threads/10.json',
357 357
 				['method' => 'GET', 'return' => 'contents']
358 358
 			);
359 359
 			$result = json_decode($result, true);
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 		public function testThreadsItemGetNotLoggedInCategory() {
370 370
 			$this->setExpectedException('NotFoundException', 'Thread with id `4` not found.');
371 371
 			$this->testAction(
372
-				$this->_apiRoot . 'threads/4.json',
372
+				$this->_apiRoot.'threads/4.json',
373 373
 				['method' => 'GET', 'return' => 'contents']
374 374
 			);
375 375
 		}
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 			$this->generate('ApiEntries');
382 382
 			$this->_loginUser(3);
383 383
 			$result = $this->testAction(
384
-				$this->_apiRoot . 'threads/4.json',
384
+				$this->_apiRoot.'threads/4.json',
385 385
 				['method' => 'GET', 'return' => 'contents']
386 386
 			);
387 387
 			$result = json_decode($result, true);
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 		public function testThreadsItemGetNotAdminAnonCategory() {
395 395
 			$this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
396 396
 			$this->testAction(
397
-				$this->_apiRoot . 'threads/6.json',
397
+				$this->_apiRoot.'threads/6.json',
398 398
 				['method' => 'GET', 'return' => 'contents']
399 399
 			);
400 400
 		}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 
409 409
 			$this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
410 410
 			$this->testAction(
411
-				$this->_apiRoot . 'threads/6.json',
411
+				$this->_apiRoot.'threads/6.json',
412 412
 				['method' => 'GET', 'return' => 'contents']
413 413
 			);
414 414
 		}
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 			$this->generate('ApiEntries');
421 421
 			$this->_loginUser(1);
422 422
 			$result = $this->testAction(
423
-				$this->_apiRoot . 'threads/6.json',
423
+				$this->_apiRoot.'threads/6.json',
424 424
 				['method' => 'GET', 'return' => 'contents']
425 425
 			);
426 426
 			$result = json_decode($result, true);
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 		public function testThreadsItemDisallowedRequestTypes() {
431 431
 			$this->_checkDisallowedRequestType(
432 432
 				['PUT', 'POST', 'DELETE'],
433
-					$this->_apiRoot . 'threads/1'
433
+					$this->_apiRoot.'threads/1'
434 434
 			);
435 435
 		}
436 436
 
Please login to merge, or discard this patch.
Indentation   +318 added lines, -318 removed lines patch added patch discarded remove patch
@@ -1,53 +1,53 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-	App::uses('ApiControllerTestCase', 'Api.Lib');
3
+    App::uses('ApiControllerTestCase', 'Api.Lib');
4 4
 
5 5
 /**
6 6
  * ApiEntriesController Test Case
7 7
  *
8 8
  */
9
-	class ApiEntriesControllerTest extends ApiControllerTestCase {
9
+    class ApiEntriesControllerTest extends ApiControllerTestCase {
10 10
 
11
-		protected $_apiRoot = 'api/v1/';
11
+        protected $_apiRoot = 'api/v1/';
12 12
 
13 13
 /**
14 14
  * Fixtures
15 15
  *
16 16
  * @var array
17 17
  */
18
-		public $fixtures = array(
19
-			'plugin.api.entry',
20
-			'plugin.api.category',
21
-			'plugin.api.user',
22
-			'plugin.api.user_block',
23
-			'plugin.api.user_ignore',
24
-			'plugin.api.user_online',
25
-			'plugin.api.user_read',
26
-			'plugin.api.bookmark',
27
-			'plugin.api.esnotification',
28
-			'plugin.api.esevent',
29
-			'plugin.api.upload',
30
-			'plugin.api.setting',
31
-			'plugin.api.smiley',
32
-			'plugin.api.smiley_code'
33
-		);
18
+        public $fixtures = array(
19
+            'plugin.api.entry',
20
+            'plugin.api.category',
21
+            'plugin.api.user',
22
+            'plugin.api.user_block',
23
+            'plugin.api.user_ignore',
24
+            'plugin.api.user_online',
25
+            'plugin.api.user_read',
26
+            'plugin.api.bookmark',
27
+            'plugin.api.esnotification',
28
+            'plugin.api.esevent',
29
+            'plugin.api.upload',
30
+            'plugin.api.setting',
31
+            'plugin.api.smiley',
32
+            'plugin.api.smiley_code'
33
+        );
34 34
 
35 35
 /**
36 36
  * testThreads method
37 37
  *
38 38
  * @return void
39 39
  */
40
-		public function testThreads() {
41
-			$this->generate('Api.ApiEntries');
40
+        public function testThreads() {
41
+            $this->generate('Api.ApiEntries');
42 42
 
43
-			$this->_loginUser(1);
43
+            $this->_loginUser(1);
44 44
 
45
-			$data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
46
-			$result = $this->testAction(
47
-				$this->_apiRoot . 'threads.json',
48
-				['return' => 'contents', 'method' => 'GET', 'data' => $data]
49
-			);
50
-			$expected = json_decode('
45
+            $data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
46
+            $result = $this->testAction(
47
+                $this->_apiRoot . 'threads.json',
48
+                ['return' => 'contents', 'method' => 'GET', 'data' => $data]
49
+            );
50
+            $expected = json_decode('
51 51
 			[
52 52
 				{
53 53
 					"id": 4,
@@ -74,182 +74,182 @@  discard block
 block discarded – undo
74 74
 					"category_name": "Admin"
75 75
 				}
76 76
 			]');
77
-			$this->assertEqual(json_decode($result), $expected);
78
-		}
77
+            $this->assertEqual(json_decode($result), $expected);
78
+        }
79 79
 
80 80
 /**
81 81
  * Tests that anon doesn't see user and admin categories
82 82
  */
83
-		public function testThreadsNoAdminAnon() {
84
-			$data = ['limit' => 3];
85
-			$result = $this->testAction(
86
-				$this->_apiRoot . 'threads.json',
87
-				['return' => 'contents', 'method' => 'GET', 'data' => $data]
88
-			);
89
-			$result = json_decode($result, true);
90
-			$this->assertEqual(count($result), 3);
91
-			$this->assertEqual($result[0]['id'], 1);
92
-			$this->assertEqual($result[1]['id'], 10);
93
-		}
83
+        public function testThreadsNoAdminAnon() {
84
+            $data = ['limit' => 3];
85
+            $result = $this->testAction(
86
+                $this->_apiRoot . 'threads.json',
87
+                ['return' => 'contents', 'method' => 'GET', 'data' => $data]
88
+            );
89
+            $result = json_decode($result, true);
90
+            $this->assertEqual(count($result), 3);
91
+            $this->assertEqual($result[0]['id'], 1);
92
+            $this->assertEqual($result[1]['id'], 10);
93
+        }
94 94
 
95 95
 /**
96 96
  * Tests that user doesn't see admin category
97 97
  */
98
-		public function testThreadsNoAdminUser() {
99
-			$this->generate('ApiEntries');
100
-			$this->_loginUser(3);
101
-			$data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
102
-			$result = $this->testAction(
103
-				$this->_apiRoot . 'threads.json',
104
-				['return' => 'contents', 'method' => 'GET', 'data' => $data]
105
-			);
106
-			$result = json_decode($result, true);
107
-			$this->assertEqual($result[0]['id'], 4);
108
-			$this->assertEqual($result[1]['id'], 10);
109
-		}
110
-
111
-		public function testThreadsDisallowedRequestTypes() {
112
-			$this->_checkDisallowedRequestType(
113
-				['POST', 'PUT', 'DELETE'],
114
-					$this->_apiRoot . 'threads'
115
-			);
116
-		}
117
-
118
-		public function testEntriesItemPostEmptySubject() {
119
-			$this->generate('Api.ApiEntries');
120
-			$this->_loginUser(3);
121
-			$this->setExpectedException('Saito\Api\ApiValidationError',
122
-				'Subject must not be empty.');
123
-			$this->testAction(
124
-				$this->_apiRoot . 'entries.json',
125
-				[
126
-					'method' => 'POST',
127
-					'data' => [
128
-						'subject' => '',
129
-						'parent_id' => 0,
130
-						'category_id' => 2
131
-					]
132
-				]
133
-			);
134
-		}
135
-
136
-		public function testEntriesItemPostSuccess() {
137
-			$this->generate('Api.ApiEntries');
138
-			$this->_loginUser(3);
139
-			$result = $this->testAction(
140
-				$this->_apiRoot . 'entries.json',
141
-				[
142
-					'return' => 'view',
143
-					'method' => 'POST',
144
-					'data' => [
145
-						'subject' => 'subject',
146
-						'parent_id' => 0,
147
-						'category_id' => 2
148
-					]
149
-				]
150
-			);
151
-			$statusCode = $this->controller->response->statusCode();
152
-			$this->assertEquals(200, $statusCode);
153
-		}
154
-
155
-		public function testEntriesItemPutOnlyAuthenticatedUsers() {
156
-			$this->generate('ApiEntries', ['methods' => 'entriesItemPut']);
157
-			$this->testAction($this->_apiRoot . 'entries/1', ['method' => 'PUT']);
158
-			$this->assertRedirectedTo('login');
159
-		}
160
-
161
-		public function testEntriesItemEntryIdMustBeProvided() {
162
-			$this->setExpectedException('BadRequestException', 'Missing entry id.');
163
-			$this->testAction($this->_apiRoot . 'entries/', ['method' => 'PUT']);
164
-		}
165
-
166
-		public function testEntriesItemPutEntryMustExist() {
167
-			$this->setExpectedException('NotFoundException', 'Entry with id `999` not found.');
168
-			$this->testAction($this->_apiRoot . 'entries/999', ['method' => 'PUT']);
169
-		}
170
-
171
-		public function testEntriesItemPutForbiddenTime() {
172
-			$this->generate('Api.ApiEntries');
173
-			$this->_loginUser(3);
174
-			$this->setExpectedException('ForbiddenException', 'The editing time ran out.');
175
-			$this->testAction(
176
-				$this->_apiRoot . 'entries/1',
177
-				[
178
-					'method' => 'PUT',
179
-					'data' => [
180
-						'subject' => 'foo',
181
-						'text' => 'bar'
182
-					]
183
-				]
184
-			);
185
-		}
186
-
187
-		public function testEntriesItemPutForbiddenUser() {
188
-			$ApiEntries = $this->generate('Api.ApiEntries');
189
-			$this->_loginUser(3);
190
-			$this->setExpectedException('ForbiddenException', 'The user `Ulysses` is not allowed to edit.');
191
-			$id = 2;
192
-			$ApiEntries->Entry->save(['id' => $id, 'time' => bdate()]);
193
-			$this->testAction(
194
-				$this->_apiRoot . 'entries/' . $id,
195
-				[
196
-					'method' => 'PUT',
197
-					'data' => [
198
-						'subject' => 'foo',
199
-						'text' => 'bar'
200
-					]
201
-				]
202
-			);
203
-		}
204
-
205
-		public function testEntriesItemPutForbiddenJustTrue() {
206
-			$ApiEntries = $this->generate(
207
-				'Api.ApiEntries',
208
-				['models' => ['Entry' => ['get']]]
209
-			);
210
-
211
-			$entry = [
212
-				'Entry' => [
213
-					'id' => 1,
214
-					'locked' => true,
215
-					'time' => bDate(time() + 9999),
216
-					'user_id' => 3
217
-				]
218
-			];
219
-
220
-			$ApiEntries->Entry->expects($this->once())
221
-					->method('get')
222
-					->will($this->returnValue($entry));
223
-			$this->_loginUser(3);
224
-			$this->setExpectedException('ForbiddenException', 'Editing is forbidden for unknown reason.');
225
-			$this->testAction(
226
-				$this->_apiRoot . 'entries/1',
227
-				[
228
-					'method' => 'PUT',
229
-					'data' => [
230
-						'subject' => 'foo',
231
-						'text' => 'bar'
232
-					]
233
-				]
234
-			);
235
-		}
236
-
237
-		public function testEntriesItemPutSuccess() {
238
-			$this->generate('Api.ApiEntries');
239
-			$this->_loginUser(1);
240
-			$id = 1;
241
-			$result = $this->testAction(
242
-				$this->_apiRoot . 'entries/' . $id . '.json',
243
-				[
244
-					'method' => 'PUT',
245
-					'data' => [
246
-						'subject' => 'foo',
247
-						'text' => 'bar'
248
-					],
249
-					'return' => 'contents'
250
-				]
251
-			);
252
-			$expected = json_decode('
98
+        public function testThreadsNoAdminUser() {
99
+            $this->generate('ApiEntries');
100
+            $this->_loginUser(3);
101
+            $data = ['limit' => 2, 'offset' => 1, 'order' => 'answer'];
102
+            $result = $this->testAction(
103
+                $this->_apiRoot . 'threads.json',
104
+                ['return' => 'contents', 'method' => 'GET', 'data' => $data]
105
+            );
106
+            $result = json_decode($result, true);
107
+            $this->assertEqual($result[0]['id'], 4);
108
+            $this->assertEqual($result[1]['id'], 10);
109
+        }
110
+
111
+        public function testThreadsDisallowedRequestTypes() {
112
+            $this->_checkDisallowedRequestType(
113
+                ['POST', 'PUT', 'DELETE'],
114
+                    $this->_apiRoot . 'threads'
115
+            );
116
+        }
117
+
118
+        public function testEntriesItemPostEmptySubject() {
119
+            $this->generate('Api.ApiEntries');
120
+            $this->_loginUser(3);
121
+            $this->setExpectedException('Saito\Api\ApiValidationError',
122
+                'Subject must not be empty.');
123
+            $this->testAction(
124
+                $this->_apiRoot . 'entries.json',
125
+                [
126
+                    'method' => 'POST',
127
+                    'data' => [
128
+                        'subject' => '',
129
+                        'parent_id' => 0,
130
+                        'category_id' => 2
131
+                    ]
132
+                ]
133
+            );
134
+        }
135
+
136
+        public function testEntriesItemPostSuccess() {
137
+            $this->generate('Api.ApiEntries');
138
+            $this->_loginUser(3);
139
+            $result = $this->testAction(
140
+                $this->_apiRoot . 'entries.json',
141
+                [
142
+                    'return' => 'view',
143
+                    'method' => 'POST',
144
+                    'data' => [
145
+                        'subject' => 'subject',
146
+                        'parent_id' => 0,
147
+                        'category_id' => 2
148
+                    ]
149
+                ]
150
+            );
151
+            $statusCode = $this->controller->response->statusCode();
152
+            $this->assertEquals(200, $statusCode);
153
+        }
154
+
155
+        public function testEntriesItemPutOnlyAuthenticatedUsers() {
156
+            $this->generate('ApiEntries', ['methods' => 'entriesItemPut']);
157
+            $this->testAction($this->_apiRoot . 'entries/1', ['method' => 'PUT']);
158
+            $this->assertRedirectedTo('login');
159
+        }
160
+
161
+        public function testEntriesItemEntryIdMustBeProvided() {
162
+            $this->setExpectedException('BadRequestException', 'Missing entry id.');
163
+            $this->testAction($this->_apiRoot . 'entries/', ['method' => 'PUT']);
164
+        }
165
+
166
+        public function testEntriesItemPutEntryMustExist() {
167
+            $this->setExpectedException('NotFoundException', 'Entry with id `999` not found.');
168
+            $this->testAction($this->_apiRoot . 'entries/999', ['method' => 'PUT']);
169
+        }
170
+
171
+        public function testEntriesItemPutForbiddenTime() {
172
+            $this->generate('Api.ApiEntries');
173
+            $this->_loginUser(3);
174
+            $this->setExpectedException('ForbiddenException', 'The editing time ran out.');
175
+            $this->testAction(
176
+                $this->_apiRoot . 'entries/1',
177
+                [
178
+                    'method' => 'PUT',
179
+                    'data' => [
180
+                        'subject' => 'foo',
181
+                        'text' => 'bar'
182
+                    ]
183
+                ]
184
+            );
185
+        }
186
+
187
+        public function testEntriesItemPutForbiddenUser() {
188
+            $ApiEntries = $this->generate('Api.ApiEntries');
189
+            $this->_loginUser(3);
190
+            $this->setExpectedException('ForbiddenException', 'The user `Ulysses` is not allowed to edit.');
191
+            $id = 2;
192
+            $ApiEntries->Entry->save(['id' => $id, 'time' => bdate()]);
193
+            $this->testAction(
194
+                $this->_apiRoot . 'entries/' . $id,
195
+                [
196
+                    'method' => 'PUT',
197
+                    'data' => [
198
+                        'subject' => 'foo',
199
+                        'text' => 'bar'
200
+                    ]
201
+                ]
202
+            );
203
+        }
204
+
205
+        public function testEntriesItemPutForbiddenJustTrue() {
206
+            $ApiEntries = $this->generate(
207
+                'Api.ApiEntries',
208
+                ['models' => ['Entry' => ['get']]]
209
+            );
210
+
211
+            $entry = [
212
+                'Entry' => [
213
+                    'id' => 1,
214
+                    'locked' => true,
215
+                    'time' => bDate(time() + 9999),
216
+                    'user_id' => 3
217
+                ]
218
+            ];
219
+
220
+            $ApiEntries->Entry->expects($this->once())
221
+                    ->method('get')
222
+                    ->will($this->returnValue($entry));
223
+            $this->_loginUser(3);
224
+            $this->setExpectedException('ForbiddenException', 'Editing is forbidden for unknown reason.');
225
+            $this->testAction(
226
+                $this->_apiRoot . 'entries/1',
227
+                [
228
+                    'method' => 'PUT',
229
+                    'data' => [
230
+                        'subject' => 'foo',
231
+                        'text' => 'bar'
232
+                    ]
233
+                ]
234
+            );
235
+        }
236
+
237
+        public function testEntriesItemPutSuccess() {
238
+            $this->generate('Api.ApiEntries');
239
+            $this->_loginUser(1);
240
+            $id = 1;
241
+            $result = $this->testAction(
242
+                $this->_apiRoot . 'entries/' . $id . '.json',
243
+                [
244
+                    'method' => 'PUT',
245
+                    'data' => [
246
+                        'subject' => 'foo',
247
+                        'text' => 'bar'
248
+                    ],
249
+                    'return' => 'contents'
250
+                ]
251
+            );
252
+            $expected = json_decode('
253 253
 			{
254 254
 				"id": 1,
255 255
 				"parent_id": 0,
@@ -270,59 +270,59 @@  discard block
 block discarded – undo
270 270
 			}
271 271
 			', true);
272 272
 
273
-			$result = json_decode($result, true);
274
-			$_editTime = $result['edit_time'];
275
-			unset($result['edit_time']);
276
-
277
-			$this->assertGreaterThan(time() - 5, strtotime($_editTime));
278
-
279
-			$this->assertEqual($result, $expected);
280
-		}
281
-
282
-		public function testEntriesItemPutErrorOnUpdate() {
283
-			$ApiEntries = $this->generate(
284
-				'Api.ApiEntries',
285
-				['models' => ['Entry' => ['update']]]
286
-			);
287
-			$this->_loginUser(1);
288
-			$this->setExpectedException('BadRequestException', 'Tried to save entry but failed for unknown reason.');
289
-			$id = 1;
290
-			$ApiEntries->Entry->save(['id' => $id, 'time' => bdate()]);
291
-			$ApiEntries->Entry->expects($this->once())
292
-				->method('update')
293
-				->will($this->returnValue(false));
294
-			$this->testAction(
295
-				$this->_apiRoot . 'entries/' . $id,
296
-				[
297
-					'method' => 'PUT',
298
-					'data' => [
299
-						'subject' => 'foo',
300
-						'text' => 'bar'
301
-					]
302
-				]
303
-			);
304
-		}
305
-
306
-		public function testEntriesItemDisallowedRequestTypes() {
307
-			$this->_checkDisallowedRequestType(
308
-				['GET', 'POST', 'DELETE'],
309
-					$this->_apiRoot . 'entries/1'
310
-			);
311
-		}
312
-
313
-		public function testThreadsItemGetThreadNotFound() {
314
-			$this->setExpectedException('NotFoundException', 'Thread with id `2` not found.');
315
-			$this->testAction($this->_apiRoot . 'threads/2.json', ['method' => 'GET']);
316
-		}
317
-
318
-		public function testThreadsItemGet() {
319
-			$this->generate('ApiEntries');
320
-			$this->_loginUser(3);
321
-			$result = $this->testAction(
322
-				$this->_apiRoot . 'threads/1.json',
323
-				['method' => 'GET', 'return' => 'contents']
324
-			);
325
-			$json = <<< EOF
273
+            $result = json_decode($result, true);
274
+            $_editTime = $result['edit_time'];
275
+            unset($result['edit_time']);
276
+
277
+            $this->assertGreaterThan(time() - 5, strtotime($_editTime));
278
+
279
+            $this->assertEqual($result, $expected);
280
+        }
281
+
282
+        public function testEntriesItemPutErrorOnUpdate() {
283
+            $ApiEntries = $this->generate(
284
+                'Api.ApiEntries',
285
+                ['models' => ['Entry' => ['update']]]
286
+            );
287
+            $this->_loginUser(1);
288
+            $this->setExpectedException('BadRequestException', 'Tried to save entry but failed for unknown reason.');
289
+            $id = 1;
290
+            $ApiEntries->Entry->save(['id' => $id, 'time' => bdate()]);
291
+            $ApiEntries->Entry->expects($this->once())
292
+                ->method('update')
293
+                ->will($this->returnValue(false));
294
+            $this->testAction(
295
+                $this->_apiRoot . 'entries/' . $id,
296
+                [
297
+                    'method' => 'PUT',
298
+                    'data' => [
299
+                        'subject' => 'foo',
300
+                        'text' => 'bar'
301
+                    ]
302
+                ]
303
+            );
304
+        }
305
+
306
+        public function testEntriesItemDisallowedRequestTypes() {
307
+            $this->_checkDisallowedRequestType(
308
+                ['GET', 'POST', 'DELETE'],
309
+                    $this->_apiRoot . 'entries/1'
310
+            );
311
+        }
312
+
313
+        public function testThreadsItemGetThreadNotFound() {
314
+            $this->setExpectedException('NotFoundException', 'Thread with id `2` not found.');
315
+            $this->testAction($this->_apiRoot . 'threads/2.json', ['method' => 'GET']);
316
+        }
317
+
318
+        public function testThreadsItemGet() {
319
+            $this->generate('ApiEntries');
320
+            $this->_loginUser(3);
321
+            $result = $this->testAction(
322
+                $this->_apiRoot . 'threads/1.json',
323
+                ['method' => 'GET', 'return' => 'contents']
324
+            );
325
+            $json = <<< EOF
326 326
 				[
327 327
 					{
328 328
 						"id": 3,
@@ -345,93 +345,93 @@  discard block
 block discarded – undo
345 345
 				}
346 346
 			]
347 347
 EOF;
348
-			$expected = json_decode($json, true);
349
-			$result = json_decode($result, true);
350
-			$this->assertCount(6, $result);
351
-			$this->assertEqual($result[2], $expected[0]);
352
-		}
353
-
354
-		public function testThreadsItemGetNotLoggedIn() {
355
-			$result = $this->testAction(
356
-				$this->_apiRoot . 'threads/10.json',
357
-				['method' => 'GET', 'return' => 'contents']
358
-			);
359
-			$result = json_decode($result, true);
360
-			$this->assertFalse(
361
-				isset($result[0]['is_locked']),
362
-				'Property `is_locked` should not be visible to anon user.'
363
-			);
364
-		}
348
+            $expected = json_decode($json, true);
349
+            $result = json_decode($result, true);
350
+            $this->assertCount(6, $result);
351
+            $this->assertEqual($result[2], $expected[0]);
352
+        }
353
+
354
+        public function testThreadsItemGetNotLoggedIn() {
355
+            $result = $this->testAction(
356
+                $this->_apiRoot . 'threads/10.json',
357
+                ['method' => 'GET', 'return' => 'contents']
358
+            );
359
+            $result = json_decode($result, true);
360
+            $this->assertFalse(
361
+                isset($result[0]['is_locked']),
362
+                'Property `is_locked` should not be visible to anon user.'
363
+            );
364
+        }
365 365
 
366 366
 /**
367 367
  * Tests that anon can't see user category
368 368
  */
369
-		public function testThreadsItemGetNotLoggedInCategory() {
370
-			$this->setExpectedException('NotFoundException', 'Thread with id `4` not found.');
371
-			$this->testAction(
372
-				$this->_apiRoot . 'threads/4.json',
373
-				['method' => 'GET', 'return' => 'contents']
374
-			);
375
-		}
369
+        public function testThreadsItemGetNotLoggedInCategory() {
370
+            $this->setExpectedException('NotFoundException', 'Thread with id `4` not found.');
371
+            $this->testAction(
372
+                $this->_apiRoot . 'threads/4.json',
373
+                ['method' => 'GET', 'return' => 'contents']
374
+            );
375
+        }
376 376
 
377 377
 /**
378 378
  * Tests that user can see user category
379 379
  */
380
-		public function testThreadsItemGetLoggedInCategory() {
381
-			$this->generate('ApiEntries');
382
-			$this->_loginUser(3);
383
-			$result = $this->testAction(
384
-				$this->_apiRoot . 'threads/4.json',
385
-				['method' => 'GET', 'return' => 'contents']
386
-			);
387
-			$result = json_decode($result, true);
388
-			$this->assertEqual($result[0]['id'], 4);
389
-		}
380
+        public function testThreadsItemGetLoggedInCategory() {
381
+            $this->generate('ApiEntries');
382
+            $this->_loginUser(3);
383
+            $result = $this->testAction(
384
+                $this->_apiRoot . 'threads/4.json',
385
+                ['method' => 'GET', 'return' => 'contents']
386
+            );
387
+            $result = json_decode($result, true);
388
+            $this->assertEqual($result[0]['id'], 4);
389
+        }
390 390
 
391 391
 /**
392 392
  * Tests that anon can't see admin category
393 393
  */
394
-		public function testThreadsItemGetNotAdminAnonCategory() {
395
-			$this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
396
-			$this->testAction(
397
-				$this->_apiRoot . 'threads/6.json',
398
-				['method' => 'GET', 'return' => 'contents']
399
-			);
400
-		}
394
+        public function testThreadsItemGetNotAdminAnonCategory() {
395
+            $this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
396
+            $this->testAction(
397
+                $this->_apiRoot . 'threads/6.json',
398
+                ['method' => 'GET', 'return' => 'contents']
399
+            );
400
+        }
401 401
 
402 402
 /**
403 403
  * Tests that user can't see admin category
404 404
  */
405
-		public function testThreadsItemGetNotAdminUserCategory() {
406
-			$this->generate('ApiEntries');
407
-			$this->_loginUser(3);
405
+        public function testThreadsItemGetNotAdminUserCategory() {
406
+            $this->generate('ApiEntries');
407
+            $this->_loginUser(3);
408 408
 
409
-			$this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
410
-			$this->testAction(
411
-				$this->_apiRoot . 'threads/6.json',
412
-				['method' => 'GET', 'return' => 'contents']
413
-			);
414
-		}
409
+            $this->setExpectedException('NotFoundException', 'Thread with id `6` not found.');
410
+            $this->testAction(
411
+                $this->_apiRoot . 'threads/6.json',
412
+                ['method' => 'GET', 'return' => 'contents']
413
+            );
414
+        }
415 415
 
416 416
 /**
417 417
  * Tests that admin can see admin category.
418 418
  */
419
-		public function testThreadsItemGetAdminCategory() {
420
-			$this->generate('ApiEntries');
421
-			$this->_loginUser(1);
422
-			$result = $this->testAction(
423
-				$this->_apiRoot . 'threads/6.json',
424
-				['method' => 'GET', 'return' => 'contents']
425
-			);
426
-			$result = json_decode($result, true);
427
-			$this->assertEqual($result[0]['id'], 6);
428
-		}
429
-
430
-		public function testThreadsItemDisallowedRequestTypes() {
431
-			$this->_checkDisallowedRequestType(
432
-				['PUT', 'POST', 'DELETE'],
433
-					$this->_apiRoot . 'threads/1'
434
-			);
435
-		}
436
-
437
-	}
419
+        public function testThreadsItemGetAdminCategory() {
420
+            $this->generate('ApiEntries');
421
+            $this->_loginUser(1);
422
+            $result = $this->testAction(
423
+                $this->_apiRoot . 'threads/6.json',
424
+                ['method' => 'GET', 'return' => 'contents']
425
+            );
426
+            $result = json_decode($result, true);
427
+            $this->assertEqual($result[0]['id'], 6);
428
+        }
429
+
430
+        public function testThreadsItemDisallowedRequestTypes() {
431
+            $this->_checkDisallowedRequestType(
432
+                ['PUT', 'POST', 'DELETE'],
433
+                    $this->_apiRoot . 'threads/1'
434
+            );
435
+        }
436
+
437
+    }
Please login to merge, or discard this patch.
app/Plugin/Api/Test/Case/AllApiTest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@
 block discarded – undo
3 3
 	class AllApiTest extends CakeTestSuite {
4 4
 
5 5
 		public static function suite() {
6
-			$testPath = CakePlugin::path('Api') . 'Test' . DS;
6
+			$testPath = CakePlugin::path('Api').'Test'.DS;
7 7
 			$suite = new CakeTestSuite('All Api tests.');
8
-			$suite->addTestDirectoryRecursive($testPath . 'Case' . DS . 'Controller');
8
+			$suite->addTestDirectoryRecursive($testPath.'Case'.DS.'Controller');
9 9
 			return $suite;
10 10
 		}
11 11
 
Please login to merge, or discard this patch.
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	class AllApiTest extends CakeTestSuite {
3
+    class AllApiTest extends CakeTestSuite {
4 4
 
5
-		public static function suite() {
6
-			$testPath = CakePlugin::path('Api') . 'Test' . DS;
7
-			$suite = new CakeTestSuite('All Api tests.');
8
-			$suite->addTestDirectoryRecursive($testPath . 'Case' . DS . 'Controller');
9
-			return $suite;
10
-		}
5
+        public static function suite() {
6
+            $testPath = CakePlugin::path('Api') . 'Test' . DS;
7
+            $suite = new CakeTestSuite('All Api tests.');
8
+            $suite->addTestDirectoryRecursive($testPath . 'Case' . DS . 'Controller');
9
+            return $suite;
10
+        }
11 11
 
12
-	}
12
+    }
13 13
 
Please login to merge, or discard this patch.
app/Plugin/Api/Config/bootstrap.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	include CakePlugin::path('Api') . 'Lib' . DS . 'exceptions.php';
3
+	include CakePlugin::path('Api').'Lib'.DS.'exceptions.php';
4 4
 
5
-	$getUri = function () {
5
+	$getUri = function() {
6 6
 		if (!empty($_SERVER['PATH_INFO'])) {
7 7
 			$uri = $_SERVER['PATH_INFO'];
8 8
 		} elseif (isset($_SERVER['REQUEST_URI'])) {
Please login to merge, or discard this patch.
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,28 +1,28 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-	include CakePlugin::path('Api') . 'Lib' . DS . 'exceptions.php';
3
+    include CakePlugin::path('Api') . 'Lib' . DS . 'exceptions.php';
4 4
 
5
-	$getUri = function () {
6
-		if (!empty($_SERVER['PATH_INFO'])) {
7
-			$uri = $_SERVER['PATH_INFO'];
8
-		} elseif (isset($_SERVER['REQUEST_URI'])) {
9
-				$uri = $_SERVER['REQUEST_URI'];
10
-		} elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
11
-			$uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
12
-		} elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
13
-			$uri = $_SERVER['HTTP_X_REWRITE_URL'];
14
-		} elseif ($var = env('argv')) {
15
-			$uri = $var[0];
16
-		}
17
-		return $uri;
18
-	};
5
+    $getUri = function () {
6
+        if (!empty($_SERVER['PATH_INFO'])) {
7
+            $uri = $_SERVER['PATH_INFO'];
8
+        } elseif (isset($_SERVER['REQUEST_URI'])) {
9
+                $uri = $_SERVER['REQUEST_URI'];
10
+        } elseif (isset($_SERVER['PHP_SELF']) && isset($_SERVER['SCRIPT_NAME'])) {
11
+            $uri = str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['PHP_SELF']);
12
+        } elseif (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
13
+            $uri = $_SERVER['HTTP_X_REWRITE_URL'];
14
+        } elseif ($var = env('argv')) {
15
+            $uri = $var[0];
16
+        }
17
+        return $uri;
18
+    };
19 19
 
20
-	if (strstr($getUri(), 'api/v1')) {
21
-		Configure::write(
22
-			'Exception',
23
-			[
24
-				'renderer' => 'Api.ApiExceptionRenderer'
25
-			]
26
-		);
27
-	}
20
+    if (strstr($getUri(), 'api/v1')) {
21
+        Configure::write(
22
+            'Exception',
23
+            [
24
+                'renderer' => 'Api.ApiExceptionRenderer'
25
+            ]
26
+        );
27
+    }
28 28
 
Please login to merge, or discard this patch.
app/Plugin/Api/Lib/exceptions.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
 	class ApiValidationError extends GenericApiError {
50 50
 
51 51
 		public function __construct($field, $rule) {
52
-			$lookup = $field . ' ' . $rule;
52
+			$lookup = $field.' '.$rule;
53 53
 			\Configure::write('Config.language', 'eng');
54 54
 			$message = __d('api', $lookup);
55 55
 			$_noExplanation = $lookup === $message;
Please login to merge, or discard this patch.
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -1,62 +1,62 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 
4
-	// @codingStandardsIgnoreStart
5
-	namespace Saito\Api;
6
-	// @codingStandardsIgnoreEnd
4
+    // @codingStandardsIgnoreStart
5
+    namespace Saito\Api;
6
+    // @codingStandardsIgnoreEnd
7 7
 
8 8
 
9
-	class GenericApiError extends \BadRequestException {
9
+    class GenericApiError extends \BadRequestException {
10 10
 
11
-		public function __construct($message = '') {
12
-			if (empty($message)) {
13
-				$message = 'Api Error. Check URL, request type and headers.';
14
-			}
15
-			parent::__construct($message);
16
-		}
11
+        public function __construct($message = '') {
12
+            if (empty($message)) {
13
+                $message = 'Api Error. Check URL, request type and headers.';
14
+            }
15
+            parent::__construct($message);
16
+        }
17 17
 
18
-	}
18
+    }
19 19
 
20
-	class ApiDisabledException extends GenericApiError {
20
+    class ApiDisabledException extends GenericApiError {
21 21
 
22
-		public function __construct($message = '') {
23
-			$message = 'API is disabled.';
24
-			parent::__construct($message);
25
-		}
22
+        public function __construct($message = '') {
23
+            $message = 'API is disabled.';
24
+            parent::__construct($message);
25
+        }
26 26
 
27
-	}
27
+    }
28 28
 
29
-	class ApiAuthException extends GenericApiError {
29
+    class ApiAuthException extends GenericApiError {
30 30
 
31
-		public function __construct($message = '') {
32
-			$message = 'Route or action is not authorized.';
33
-			parent::__construct($message);
34
-		}
31
+        public function __construct($message = '') {
32
+            $message = 'Route or action is not authorized.';
33
+            parent::__construct($message);
34
+        }
35 35
 
36
-	}
36
+    }
37 37
 
38
-	class UnknownRouteException extends GenericApiError {
38
+    class UnknownRouteException extends GenericApiError {
39 39
 
40
-		public function __construct($message = '') {
41
-			if (empty($message)) {
42
-				$message = 'Unknown REST route. Check URL and request type (GET, POST, …).';
43
-			}
44
-			parent::__construct($message);
45
-		}
40
+        public function __construct($message = '') {
41
+            if (empty($message)) {
42
+                $message = 'Unknown REST route. Check URL and request type (GET, POST, …).';
43
+            }
44
+            parent::__construct($message);
45
+        }
46 46
 
47
-	}
47
+    }
48 48
 
49
-	class ApiValidationError extends GenericApiError {
49
+    class ApiValidationError extends GenericApiError {
50 50
 
51
-		public function __construct($field, $rule) {
52
-			$lookup = $field . ' ' . $rule;
53
-			\Configure::write('Config.language', 'eng');
54
-			$message = __d('api', $lookup);
55
-			$_noExplanation = $lookup === $message;
56
-			if ($_noExplanation) {
57
-				$message = "Internal validation error. Field: `$field` Rule: `$rule`.";
58
-			}
59
-			parent::__construct($message);
60
-		}
51
+        public function __construct($field, $rule) {
52
+            $lookup = $field . ' ' . $rule;
53
+            \Configure::write('Config.language', 'eng');
54
+            $message = __d('api', $lookup);
55
+            $_noExplanation = $lookup === $message;
56
+            if ($_noExplanation) {
57
+                $message = "Internal validation error. Field: `$field` Rule: `$rule`.";
58
+            }
59
+            parent::__construct($message);
60
+        }
61 61
 
62
-	}
63 62
\ No newline at end of file
63
+    }
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
app/index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,4 +16,4 @@
 block discarded – undo
16 16
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
17 17
  */
18 18
 
19
-require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
19
+require 'webroot'.DIRECTORY_SEPARATOR.'index.php';
Please login to merge, or discard this patch.