|
63 | 63 | '/my-api/v1/my-actions/v2/middleware/on-request/(?P<action>\w+)', |
64 | 64 | '/my-api/v1/my-actions/v2/middleware/on-response/(?P<action>\w+)', |
65 | 65 | '/my-api/v1/my-actions/v2/permission/(?P<action>\w+)', |
| 66 | + '/my-api/v1/my-actions/v2/bool/permission/(?P<action>\w+)', |
66 | 67 | ]) |
67 | 68 | ->and($routes['/my-api/v1/my-posts/v1/(?P<ID>[\\d]+)']) |
68 | 69 | ->toBeArray() |
|
75 | 76 | ->toHaveCount(1) |
76 | 77 | ->and($routes['/my-api/v1/my-actions/v2/permission/(?P<action>\w+)']) |
77 | 78 | ->toBeArray() |
| 79 | + ->toHaveCount(1) |
| 80 | + ->and($routes['/my-api/v1/my-actions/v2/bool/permission/(?P<action>\w+)']) |
| 81 | + ->toBeArray() |
78 | 82 | ->toHaveCount(1); |
79 | 83 | })->group('multiple'); |
80 | 84 |
|
|
134 | 138 | expect($response->get_status())->toBe(200); |
135 | 139 | })->with(['on-request', 'on-response'])->group('multiple'); |
136 | 140 |
|
137 | | -test('Trigger no permissions in permission callback', function () { |
| 141 | +test('Trigger no permissions in permission callback - WP Error', function () { |
138 | 142 | $request = new WP_REST_Request('GET', '/my-api/v1/my-actions/v2/permission/notAllowed'); |
139 | 143 | $response = $this->server->dispatch($request); |
140 | 144 | expect($response->get_status())->toBe(403) |
|
144 | 148 | ->toHaveProperty('data', ['status' => 403]); |
145 | 149 | })->group('multiple'); |
146 | 150 |
|
147 | | -test('Trigger has permissions in permission callback', function () { |
148 | | - $request = new WP_REST_Request('GET', '/my-api/v1/my-actions/v2/permission/allowed'); |
| 151 | +test('Trigger no permissions in permission callback - boolean', function () { |
| 152 | + $request = new WP_REST_Request('GET', '/my-api/v1/my-actions/v2/bool/permission/notAllowed'); |
149 | 153 | $response = $this->server->dispatch($request); |
150 | | - expect($response->get_status())->toBe(200); |
| 154 | + expect($response->get_status())->toBe(401) |
| 155 | + ->and((object) $response->get_data()) |
| 156 | + ->toHaveProperty('code', 'rest_forbidden') |
| 157 | + ->toHaveProperty('message', 'Sorry, you are not allowed to do that.') |
| 158 | + ->toHaveProperty('data', ['status' => 401]); |
151 | 159 | })->group('multiple'); |
| 160 | + |
| 161 | +test('Trigger has permissions in permission callback', function (string $endpoint) { |
| 162 | + $request = new WP_REST_Request('GET', $endpoint); |
| 163 | + $response = $this->server->dispatch($request); |
| 164 | + expect($response->get_status())->toBe(200); |
| 165 | +}) |
| 166 | + ->with(['/my-api/v1/my-actions/v2/permission/allowed', '/my-api/v1/my-actions/v2/bool/permission/allowed']) |
| 167 | + ->group('multiple'); |
0 commit comments