@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function test_register_routes() { |
29 | 29 | $routes = $this->server->get_routes(); |
30 | - $this->assertArrayHasKey( '/wc/v3/reports/products/totals', $routes ); |
|
30 | + $this->assertArrayHasKey('/wc/v3/reports/products/totals', $routes); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | * @since 3.5.0 |
37 | 37 | */ |
38 | 38 | public function test_get_reports() { |
39 | - wp_set_current_user( $this->user ); |
|
39 | + wp_set_current_user($this->user); |
|
40 | 40 | WC_Install::create_terms(); |
41 | 41 | |
42 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/products/totals' ) ); |
|
42 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/products/totals')); |
|
43 | 43 | $report = $response->get_data(); |
44 | 44 | $types = wc_get_product_types(); |
45 | 45 | $terms = get_terms( |
@@ -48,23 +48,23 @@ discard block |
||
48 | 48 | 'hide_empty' => false, |
49 | 49 | ) |
50 | 50 | ); |
51 | - $data = array(); |
|
51 | + $data = array(); |
|
52 | 52 | |
53 | - foreach ( $terms as $product_type ) { |
|
54 | - if ( ! isset( $types[ $product_type->name ] ) ) { |
|
53 | + foreach ($terms as $product_type) { |
|
54 | + if ( ! isset($types[$product_type->name])) { |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $data[] = array( |
59 | 59 | 'slug' => $product_type->name, |
60 | - 'name' => $types[ $product_type->name ], |
|
60 | + 'name' => $types[$product_type->name], |
|
61 | 61 | 'total' => (int) $product_type->count, |
62 | 62 | ); |
63 | 63 | } |
64 | 64 | |
65 | - $this->assertEquals( 200, $response->get_status() ); |
|
66 | - $this->assertEquals( count( $types ), count( $report ) ); |
|
67 | - $this->assertEquals( $data, $report ); |
|
65 | + $this->assertEquals(200, $response->get_status()); |
|
66 | + $this->assertEquals(count($types), count($report)); |
|
67 | + $this->assertEquals($data, $report); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @since 3.5.0 |
74 | 74 | */ |
75 | 75 | public function test_get_reports_without_permission() { |
76 | - wp_set_current_user( 0 ); |
|
77 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/products/totals' ) ); |
|
78 | - $this->assertEquals( 401, $response->get_status() ); |
|
76 | + wp_set_current_user(0); |
|
77 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/products/totals')); |
|
78 | + $this->assertEquals(401, $response->get_status()); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | * @since 3.5.0 |
85 | 85 | */ |
86 | 86 | public function test_product_review_schema() { |
87 | - wp_set_current_user( $this->user ); |
|
87 | + wp_set_current_user($this->user); |
|
88 | 88 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
89 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/products/totals' ); |
|
90 | - $response = $this->server->dispatch( $request ); |
|
89 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/reports/products/totals'); |
|
90 | + $response = $this->server->dispatch($request); |
|
91 | 91 | $data = $response->get_data(); |
92 | 92 | $properties = $data['schema']['properties']; |
93 | 93 | |
94 | - $this->assertEquals( 3, count( $properties ) ); |
|
95 | - $this->assertArrayHasKey( 'slug', $properties ); |
|
96 | - $this->assertArrayHasKey( 'name', $properties ); |
|
97 | - $this->assertArrayHasKey( 'total', $properties ); |
|
94 | + $this->assertEquals(3, count($properties)); |
|
95 | + $this->assertArrayHasKey('slug', $properties); |
|
96 | + $this->assertArrayHasKey('name', $properties); |
|
97 | + $this->assertArrayHasKey('total', $properties); |
|
98 | 98 | } |
99 | 99 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | 'role' => 'administrator', |
28 | 28 | ) |
29 | 29 | ); |
30 | - $this->zones = array(); |
|
30 | + $this->zones = array(); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | * @param int $order Optional. Zone sort order. |
38 | 38 | * @return WC_Shipping_Zone |
39 | 39 | */ |
40 | - protected function create_shipping_zone( $name, $order = 0, $locations = array() ) { |
|
41 | - $zone = new WC_Shipping_Zone( null ); |
|
42 | - $zone->set_zone_name( $name ); |
|
43 | - $zone->set_zone_order( $order ); |
|
44 | - $zone->set_locations( $locations ); |
|
40 | + protected function create_shipping_zone($name, $order = 0, $locations = array()) { |
|
41 | + $zone = new WC_Shipping_Zone(null); |
|
42 | + $zone->set_zone_name($name); |
|
43 | + $zone->set_zone_order($order); |
|
44 | + $zone->set_locations($locations); |
|
45 | 45 | $zone->save(); |
46 | 46 | |
47 | 47 | $this->zones[] = $zone; |
@@ -56,11 +56,11 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function test_register_routes() { |
58 | 58 | $routes = $this->server->get_routes(); |
59 | - $this->assertArrayHasKey( '/wc/v3/shipping/zones', $routes ); |
|
60 | - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P<id>[\d-]+)', $routes ); |
|
61 | - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P<id>[\d]+)/locations', $routes ); |
|
62 | - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes ); |
|
63 | - $this->assertArrayHasKey( '/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes ); |
|
59 | + $this->assertArrayHasKey('/wc/v3/shipping/zones', $routes); |
|
60 | + $this->assertArrayHasKey('/wc/v3/shipping/zones/(?P<id>[\d-]+)', $routes); |
|
61 | + $this->assertArrayHasKey('/wc/v3/shipping/zones/(?P<id>[\d]+)/locations', $routes); |
|
62 | + $this->assertArrayHasKey('/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods', $routes); |
|
63 | + $this->assertArrayHasKey('/wc/v3/shipping/zones/(?P<zone_id>[\d]+)/methods/(?P<instance_id>[\d]+)', $routes); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | * @since 3.5.0 |
70 | 70 | */ |
71 | 71 | public function test_get_zones() { |
72 | - wp_set_current_user( $this->user ); |
|
72 | + wp_set_current_user($this->user); |
|
73 | 73 | |
74 | 74 | // "Rest of the World" zone exists by default |
75 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); |
|
75 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones')); |
|
76 | 76 | $data = $response->get_data(); |
77 | 77 | |
78 | - $this->assertEquals( 200, $response->get_status() ); |
|
79 | - $this->assertEquals( count( $data ), 1 ); |
|
78 | + $this->assertEquals(200, $response->get_status()); |
|
79 | + $this->assertEquals(count($data), 1); |
|
80 | 80 | $this->assertContains( |
81 | 81 | array( |
82 | 82 | 'id' => $data[0]['id'], |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | '_links' => array( |
86 | 86 | 'self' => array( |
87 | 87 | array( |
88 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[0]['id'] ), |
|
88 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data[0]['id']), |
|
89 | 89 | ), |
90 | 90 | ), |
91 | 91 | 'collection' => array( |
92 | 92 | array( |
93 | - 'href' => rest_url( '/wc/v3/shipping/zones' ), |
|
93 | + 'href' => rest_url('/wc/v3/shipping/zones'), |
|
94 | 94 | ), |
95 | 95 | ), |
96 | 96 | 'describedby' => array( |
97 | 97 | array( |
98 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[0]['id'] . '/locations' ), |
|
98 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data[0]['id'] . '/locations'), |
|
99 | 99 | ), |
100 | 100 | ), |
101 | 101 | ), |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | ); |
105 | 105 | |
106 | 106 | // Create a zone and make sure it's in the response |
107 | - $this->create_shipping_zone( 'Zone 1' ); |
|
107 | + $this->create_shipping_zone('Zone 1'); |
|
108 | 108 | |
109 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); |
|
109 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones')); |
|
110 | 110 | $data = $response->get_data(); |
111 | 111 | |
112 | - $this->assertEquals( 200, $response->get_status() ); |
|
113 | - $this->assertEquals( count( $data ), 2 ); |
|
112 | + $this->assertEquals(200, $response->get_status()); |
|
113 | + $this->assertEquals(count($data), 2); |
|
114 | 114 | $this->assertContains( |
115 | 115 | array( |
116 | 116 | 'id' => $data[1]['id'], |
@@ -119,17 +119,17 @@ discard block |
||
119 | 119 | '_links' => array( |
120 | 120 | 'self' => array( |
121 | 121 | array( |
122 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[1]['id'] ), |
|
122 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data[1]['id']), |
|
123 | 123 | ), |
124 | 124 | ), |
125 | 125 | 'collection' => array( |
126 | 126 | array( |
127 | - 'href' => rest_url( '/wc/v3/shipping/zones' ), |
|
127 | + 'href' => rest_url('/wc/v3/shipping/zones'), |
|
128 | 128 | ), |
129 | 129 | ), |
130 | 130 | 'describedby' => array( |
131 | 131 | array( |
132 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data[1]['id'] . '/locations' ), |
|
132 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data[1]['id'] . '/locations'), |
|
133 | 133 | ), |
134 | 134 | ), |
135 | 135 | ), |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | * @since 3.5.0 |
145 | 145 | */ |
146 | 146 | public function test_get_shipping_zones_without_permission() { |
147 | - wp_set_current_user( 0 ); |
|
147 | + wp_set_current_user(0); |
|
148 | 148 | |
149 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); |
|
150 | - $this->assertEquals( 401, $response->get_status() ); |
|
149 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones')); |
|
150 | + $this->assertEquals(401, $response->get_status()); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | /** |
@@ -156,14 +156,14 @@ discard block |
||
156 | 156 | * @since 3.5.0 |
157 | 157 | */ |
158 | 158 | public function test_get_shipping_zones_disabled_shipping() { |
159 | - wp_set_current_user( $this->user ); |
|
159 | + wp_set_current_user($this->user); |
|
160 | 160 | |
161 | - add_filter( 'wc_shipping_enabled', '__return_false' ); |
|
161 | + add_filter('wc_shipping_enabled', '__return_false'); |
|
162 | 162 | |
163 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones' ) ); |
|
164 | - $this->assertEquals( 404, $response->get_status() ); |
|
163 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones')); |
|
164 | + $this->assertEquals(404, $response->get_status()); |
|
165 | 165 | |
166 | - remove_filter( 'wc_shipping_enabled', '__return_false' ); |
|
166 | + remove_filter('wc_shipping_enabled', '__return_false'); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | * @since 3.5.0 |
173 | 173 | */ |
174 | 174 | public function test_get_shipping_zone_schema() { |
175 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping/zones' ); |
|
176 | - $response = $this->server->dispatch( $request ); |
|
175 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/shipping/zones'); |
|
176 | + $response = $this->server->dispatch($request); |
|
177 | 177 | $data = $response->get_data(); |
178 | 178 | $properties = $data['schema']['properties']; |
179 | - $this->assertEquals( 3, count( $properties ) ); |
|
180 | - $this->assertArrayHasKey( 'id', $properties ); |
|
181 | - $this->assertTrue( $properties['id']['readonly'] ); |
|
182 | - $this->assertArrayHasKey( 'name', $properties ); |
|
183 | - $this->assertArrayHasKey( 'order', $properties ); |
|
179 | + $this->assertEquals(3, count($properties)); |
|
180 | + $this->assertArrayHasKey('id', $properties); |
|
181 | + $this->assertTrue($properties['id']['readonly']); |
|
182 | + $this->assertArrayHasKey('name', $properties); |
|
183 | + $this->assertArrayHasKey('order', $properties); |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | /** |
@@ -189,19 +189,19 @@ discard block |
||
189 | 189 | * @since 3.5.0 |
190 | 190 | */ |
191 | 191 | public function test_create_shipping_zone() { |
192 | - wp_set_current_user( $this->user ); |
|
192 | + wp_set_current_user($this->user); |
|
193 | 193 | |
194 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones' ); |
|
194 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones'); |
|
195 | 195 | $request->set_body_params( |
196 | 196 | array( |
197 | 197 | 'name' => 'Test Zone', |
198 | 198 | 'order' => 1, |
199 | 199 | ) |
200 | 200 | ); |
201 | - $response = $this->server->dispatch( $request ); |
|
201 | + $response = $this->server->dispatch($request); |
|
202 | 202 | $data = $response->get_data(); |
203 | 203 | |
204 | - $this->assertEquals( 201, $response->get_status() ); |
|
204 | + $this->assertEquals(201, $response->get_status()); |
|
205 | 205 | $this->assertEquals( |
206 | 206 | array( |
207 | 207 | 'id' => $data['id'], |
@@ -210,17 +210,17 @@ discard block |
||
210 | 210 | '_links' => array( |
211 | 211 | 'self' => array( |
212 | 212 | array( |
213 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data['id'] ), |
|
213 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data['id']), |
|
214 | 214 | ), |
215 | 215 | ), |
216 | 216 | 'collection' => array( |
217 | 217 | array( |
218 | - 'href' => rest_url( '/wc/v3/shipping/zones' ), |
|
218 | + 'href' => rest_url('/wc/v3/shipping/zones'), |
|
219 | 219 | ), |
220 | 220 | ), |
221 | 221 | 'describedby' => array( |
222 | 222 | array( |
223 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $data['id'] . '/locations' ), |
|
223 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $data['id'] . '/locations'), |
|
224 | 224 | ), |
225 | 225 | ), |
226 | 226 | ), |
@@ -235,17 +235,17 @@ discard block |
||
235 | 235 | * @since 3.5.0 |
236 | 236 | */ |
237 | 237 | public function test_create_shipping_zone_without_permission() { |
238 | - wp_set_current_user( 0 ); |
|
238 | + wp_set_current_user(0); |
|
239 | 239 | |
240 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones' ); |
|
240 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones'); |
|
241 | 241 | $request->set_body_params( |
242 | 242 | array( |
243 | 243 | 'name' => 'Test Zone', |
244 | 244 | 'order' => 1, |
245 | 245 | ) |
246 | 246 | ); |
247 | - $response = $this->server->dispatch( $request ); |
|
248 | - $this->assertEquals( 401, $response->get_status() ); |
|
247 | + $response = $this->server->dispatch($request); |
|
248 | + $this->assertEquals(401, $response->get_status()); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -254,21 +254,21 @@ discard block |
||
254 | 254 | * @since 3.5.0 |
255 | 255 | */ |
256 | 256 | public function test_update_shipping_zone() { |
257 | - wp_set_current_user( $this->user ); |
|
257 | + wp_set_current_user($this->user); |
|
258 | 258 | |
259 | - $zone = $this->create_shipping_zone( 'Test Zone' ); |
|
259 | + $zone = $this->create_shipping_zone('Test Zone'); |
|
260 | 260 | |
261 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/' . $zone->get_id() ); |
|
261 | + $request = new WP_REST_Request('PUT', '/wc/v3/shipping/zones/' . $zone->get_id()); |
|
262 | 262 | $request->set_body_params( |
263 | 263 | array( |
264 | 264 | 'name' => 'Zone Test', |
265 | 265 | 'order' => 2, |
266 | 266 | ) |
267 | 267 | ); |
268 | - $response = $this->server->dispatch( $request ); |
|
268 | + $response = $this->server->dispatch($request); |
|
269 | 269 | $data = $response->get_data(); |
270 | 270 | |
271 | - $this->assertEquals( 200, $response->get_status() ); |
|
271 | + $this->assertEquals(200, $response->get_status()); |
|
272 | 272 | $this->assertEquals( |
273 | 273 | array( |
274 | 274 | 'id' => $zone->get_id(), |
@@ -277,17 +277,17 @@ discard block |
||
277 | 277 | '_links' => array( |
278 | 278 | 'self' => array( |
279 | 279 | array( |
280 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
280 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
281 | 281 | ), |
282 | 282 | ), |
283 | 283 | 'collection' => array( |
284 | 284 | array( |
285 | - 'href' => rest_url( '/wc/v3/shipping/zones' ), |
|
285 | + 'href' => rest_url('/wc/v3/shipping/zones'), |
|
286 | 286 | ), |
287 | 287 | ), |
288 | 288 | 'describedby' => array( |
289 | 289 | array( |
290 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
290 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
291 | 291 | ), |
292 | 292 | ), |
293 | 293 | ), |
@@ -302,18 +302,18 @@ discard block |
||
302 | 302 | * @since 3.5.0 |
303 | 303 | */ |
304 | 304 | public function test_update_shipping_zone_invalid_id() { |
305 | - wp_set_current_user( $this->user ); |
|
305 | + wp_set_current_user($this->user); |
|
306 | 306 | |
307 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/555555' ); |
|
307 | + $request = new WP_REST_Request('PUT', '/wc/v3/shipping/zones/555555'); |
|
308 | 308 | $request->set_body_params( |
309 | 309 | array( |
310 | 310 | 'name' => 'Zone Test', |
311 | 311 | 'order' => 2, |
312 | 312 | ) |
313 | 313 | ); |
314 | - $response = $this->server->dispatch( $request ); |
|
314 | + $response = $this->server->dispatch($request); |
|
315 | 315 | |
316 | - $this->assertEquals( 404, $response->get_status() ); |
|
316 | + $this->assertEquals(404, $response->get_status()); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -322,15 +322,15 @@ discard block |
||
322 | 322 | * @since 3.5.0 |
323 | 323 | */ |
324 | 324 | public function test_delete_shipping_zone() { |
325 | - wp_set_current_user( $this->user ); |
|
326 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
325 | + wp_set_current_user($this->user); |
|
326 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
327 | 327 | |
328 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() ); |
|
329 | - $request->set_param( 'force', true ); |
|
330 | - $response = $this->server->dispatch( $request ); |
|
328 | + $request = new WP_REST_Request('DELETE', '/wc/v3/shipping/zones/' . $zone->get_id()); |
|
329 | + $request->set_param('force', true); |
|
330 | + $response = $this->server->dispatch($request); |
|
331 | 331 | $data = $response->get_data(); |
332 | 332 | |
333 | - $this->assertEquals( 200, $response->get_status() ); |
|
333 | + $this->assertEquals(200, $response->get_status()); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,13 +339,13 @@ discard block |
||
339 | 339 | * @since 3.5.0 |
340 | 340 | */ |
341 | 341 | public function test_delete_shipping_zone_without_permission() { |
342 | - wp_set_current_user( 0 ); |
|
343 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
342 | + wp_set_current_user(0); |
|
343 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
344 | 344 | |
345 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() ); |
|
346 | - $request->set_param( 'force', true ); |
|
347 | - $response = $this->server->dispatch( $request ); |
|
348 | - $this->assertEquals( 401, $response->get_status() ); |
|
345 | + $request = new WP_REST_Request('DELETE', '/wc/v3/shipping/zones/' . $zone->get_id()); |
|
346 | + $request->set_param('force', true); |
|
347 | + $response = $this->server->dispatch($request); |
|
348 | + $this->assertEquals(401, $response->get_status()); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | * @since 3.5.0 |
355 | 355 | */ |
356 | 356 | public function test_delete_shipping_zone_invalid_id() { |
357 | - wp_set_current_user( $this->user ); |
|
358 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/555555' ); |
|
359 | - $response = $this->server->dispatch( $request ); |
|
360 | - $this->assertEquals( 404, $response->get_status() ); |
|
357 | + wp_set_current_user($this->user); |
|
358 | + $request = new WP_REST_Request('DELETE', '/wc/v3/shipping/zones/555555'); |
|
359 | + $response = $this->server->dispatch($request); |
|
360 | + $this->assertEquals(404, $response->get_status()); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | * @since 3.5.0 |
367 | 367 | */ |
368 | 368 | public function test_get_single_shipping_zone() { |
369 | - wp_set_current_user( $this->user ); |
|
369 | + wp_set_current_user($this->user); |
|
370 | 370 | |
371 | - $zone = $this->create_shipping_zone( 'Test Zone' ); |
|
372 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() ) ); |
|
371 | + $zone = $this->create_shipping_zone('Test Zone'); |
|
372 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id())); |
|
373 | 373 | $data = $response->get_data(); |
374 | 374 | |
375 | - $this->assertEquals( 200, $response->get_status() ); |
|
375 | + $this->assertEquals(200, $response->get_status()); |
|
376 | 376 | $this->assertEquals( |
377 | 377 | array( |
378 | 378 | 'id' => $zone->get_id(), |
@@ -381,17 +381,17 @@ discard block |
||
381 | 381 | '_links' => array( |
382 | 382 | 'self' => array( |
383 | 383 | array( |
384 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
384 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
385 | 385 | ), |
386 | 386 | ), |
387 | 387 | 'collection' => array( |
388 | 388 | array( |
389 | - 'href' => rest_url( '/wc/v3/shipping/zones' ), |
|
389 | + 'href' => rest_url('/wc/v3/shipping/zones'), |
|
390 | 390 | ), |
391 | 391 | ), |
392 | 392 | 'describedby' => array( |
393 | 393 | array( |
394 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
394 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
395 | 395 | ), |
396 | 396 | ), |
397 | 397 | ), |
@@ -406,11 +406,11 @@ discard block |
||
406 | 406 | * @since 3.5.0 |
407 | 407 | */ |
408 | 408 | public function test_get_single_shipping_zone_invalid_id() { |
409 | - wp_set_current_user( $this->user ); |
|
409 | + wp_set_current_user($this->user); |
|
410 | 410 | |
411 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1' ) ); |
|
411 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/1')); |
|
412 | 412 | |
413 | - $this->assertEquals( 404, $response->get_status() ); |
|
413 | + $this->assertEquals(404, $response->get_status()); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | * @since 3.5.0 |
420 | 420 | */ |
421 | 421 | public function test_get_locations() { |
422 | - wp_set_current_user( $this->user ); |
|
422 | + wp_set_current_user($this->user); |
|
423 | 423 | |
424 | 424 | // Create a zone |
425 | 425 | $zone = $this->create_shipping_zone( |
@@ -433,11 +433,11 @@ discard block |
||
433 | 433 | ) |
434 | 434 | ); |
435 | 435 | |
436 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ) ); |
|
436 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations')); |
|
437 | 437 | $data = $response->get_data(); |
438 | 438 | |
439 | - $this->assertEquals( 200, $response->get_status() ); |
|
440 | - $this->assertEquals( count( $data ), 1 ); |
|
439 | + $this->assertEquals(200, $response->get_status()); |
|
440 | + $this->assertEquals(count($data), 1); |
|
441 | 441 | $this->assertEquals( |
442 | 442 | array( |
443 | 443 | array( |
@@ -446,12 +446,12 @@ discard block |
||
446 | 446 | '_links' => array( |
447 | 447 | 'collection' => array( |
448 | 448 | array( |
449 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
449 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
450 | 450 | ), |
451 | 451 | ), |
452 | 452 | 'describes' => array( |
453 | 453 | array( |
454 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
454 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
455 | 455 | ), |
456 | 456 | ), |
457 | 457 | ), |
@@ -467,11 +467,11 @@ discard block |
||
467 | 467 | * @since 3.5.0 |
468 | 468 | */ |
469 | 469 | public function test_get_locations_invalid_id() { |
470 | - wp_set_current_user( $this->user ); |
|
470 | + wp_set_current_user($this->user); |
|
471 | 471 | |
472 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/locations' ) ); |
|
472 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/1/locations')); |
|
473 | 473 | |
474 | - $this->assertEquals( 404, $response->get_status() ); |
|
474 | + $this->assertEquals(404, $response->get_status()); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -480,12 +480,12 @@ discard block |
||
480 | 480 | * @since 3.5.0 |
481 | 481 | */ |
482 | 482 | public function test_update_locations() { |
483 | - wp_set_current_user( $this->user ); |
|
483 | + wp_set_current_user($this->user); |
|
484 | 484 | |
485 | - $zone = $this->create_shipping_zone( 'Test Zone' ); |
|
485 | + $zone = $this->create_shipping_zone('Test Zone'); |
|
486 | 486 | |
487 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ); |
|
488 | - $request->add_header( 'Content-Type', 'application/json' ); |
|
487 | + $request = new WP_REST_Request('PUT', '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'); |
|
488 | + $request->add_header('Content-Type', 'application/json'); |
|
489 | 489 | $request->set_body( |
490 | 490 | json_encode( |
491 | 491 | array( |
@@ -506,10 +506,10 @@ discard block |
||
506 | 506 | ) |
507 | 507 | ) |
508 | 508 | ); |
509 | - $response = $this->server->dispatch( $request ); |
|
509 | + $response = $this->server->dispatch($request); |
|
510 | 510 | $data = $response->get_data(); |
511 | 511 | |
512 | - $this->assertEquals( 3, count( $data ) ); |
|
512 | + $this->assertEquals(3, count($data)); |
|
513 | 513 | $this->assertEquals( |
514 | 514 | array( |
515 | 515 | array( |
@@ -518,12 +518,12 @@ discard block |
||
518 | 518 | '_links' => array( |
519 | 519 | 'collection' => array( |
520 | 520 | array( |
521 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
521 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
522 | 522 | ), |
523 | 523 | ), |
524 | 524 | 'describes' => array( |
525 | 525 | array( |
526 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
526 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
527 | 527 | ), |
528 | 528 | ), |
529 | 529 | ), |
@@ -534,12 +534,12 @@ discard block |
||
534 | 534 | '_links' => array( |
535 | 535 | 'collection' => array( |
536 | 536 | array( |
537 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
537 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
538 | 538 | ), |
539 | 539 | ), |
540 | 540 | 'describes' => array( |
541 | 541 | array( |
542 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
542 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
543 | 543 | ), |
544 | 544 | ), |
545 | 545 | ), |
@@ -550,12 +550,12 @@ discard block |
||
550 | 550 | '_links' => array( |
551 | 551 | 'collection' => array( |
552 | 552 | array( |
553 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/locations' ), |
|
553 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/locations'), |
|
554 | 554 | ), |
555 | 555 | ), |
556 | 556 | 'describes' => array( |
557 | 557 | array( |
558 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
558 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
559 | 559 | ), |
560 | 560 | ), |
561 | 561 | ), |
@@ -571,11 +571,11 @@ discard block |
||
571 | 571 | * @since 3.5.0 |
572 | 572 | */ |
573 | 573 | public function test_update_locations_invalid_id() { |
574 | - wp_set_current_user( $this->user ); |
|
574 | + wp_set_current_user($this->user); |
|
575 | 575 | |
576 | - $response = $this->server->dispatch( new WP_REST_Request( 'PUT', '/wc/v3/shipping/zones/1/locations' ) ); |
|
576 | + $response = $this->server->dispatch(new WP_REST_Request('PUT', '/wc/v3/shipping/zones/1/locations')); |
|
577 | 577 | |
578 | - $this->assertEquals( 404, $response->get_status() ); |
|
578 | + $this->assertEquals(404, $response->get_status()); |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | /** |
@@ -584,41 +584,41 @@ discard block |
||
584 | 584 | * @since 3.5.0 |
585 | 585 | */ |
586 | 586 | public function test_get_methods() { |
587 | - wp_set_current_user( $this->user ); |
|
587 | + wp_set_current_user($this->user); |
|
588 | 588 | |
589 | 589 | // Create a shipping method and make sure it's in the response |
590 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
591 | - $instance_id = $zone->add_shipping_method( 'flat_rate' ); |
|
590 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
591 | + $instance_id = $zone->add_shipping_method('flat_rate'); |
|
592 | 592 | $methods = $zone->get_shipping_methods(); |
593 | - $method = $methods[ $instance_id ]; |
|
593 | + $method = $methods[$instance_id]; |
|
594 | 594 | |
595 | 595 | $settings = array(); |
596 | 596 | $method->init_instance_settings(); |
597 | - foreach ( $method->get_instance_form_fields() as $id => $field ) { |
|
597 | + foreach ($method->get_instance_form_fields() as $id => $field) { |
|
598 | 598 | $data = array( |
599 | 599 | 'id' => $id, |
600 | 600 | 'label' => $field['title'], |
601 | - 'description' => ( empty( $field['description'] ) ? '' : $field['description'] ), |
|
601 | + 'description' => (empty($field['description']) ? '' : $field['description']), |
|
602 | 602 | 'type' => $field['type'], |
603 | - 'value' => $method->instance_settings[ $id ], |
|
604 | - 'default' => ( empty( $field['default'] ) ? '' : $field['default'] ), |
|
605 | - 'tip' => ( empty( $field['description'] ) ? '' : $field['description'] ), |
|
606 | - 'placeholder' => ( empty( $field['placeholder'] ) ? '' : $field['placeholder'] ), |
|
603 | + 'value' => $method->instance_settings[$id], |
|
604 | + 'default' => (empty($field['default']) ? '' : $field['default']), |
|
605 | + 'tip' => (empty($field['description']) ? '' : $field['description']), |
|
606 | + 'placeholder' => (empty($field['placeholder']) ? '' : $field['placeholder']), |
|
607 | 607 | ); |
608 | - if ( ! empty( $field['options'] ) ) { |
|
608 | + if ( ! empty($field['options'])) { |
|
609 | 609 | $data['options'] = $field['options']; |
610 | 610 | } |
611 | - $settings[ $id ] = $data; |
|
611 | + $settings[$id] = $data; |
|
612 | 612 | } |
613 | 613 | |
614 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ) ); |
|
614 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods')); |
|
615 | 615 | $data = $response->get_data(); |
616 | 616 | $expected = array( |
617 | 617 | 'id' => $instance_id, |
618 | 618 | 'instance_id' => $instance_id, |
619 | 619 | 'title' => $method->instance_settings['title'], |
620 | 620 | 'order' => $method->method_order, |
621 | - 'enabled' => ( 'yes' === $method->enabled ), |
|
621 | + 'enabled' => ('yes' === $method->enabled), |
|
622 | 622 | 'method_id' => $method->id, |
623 | 623 | 'method_title' => $method->method_title, |
624 | 624 | 'method_description' => $method->method_description, |
@@ -626,31 +626,31 @@ discard block |
||
626 | 626 | '_links' => array( |
627 | 627 | 'self' => array( |
628 | 628 | array( |
629 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ), |
|
629 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id), |
|
630 | 630 | ), |
631 | 631 | ), |
632 | 632 | 'collection' => array( |
633 | 633 | array( |
634 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ), |
|
634 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id() . '/methods'), |
|
635 | 635 | ), |
636 | 636 | ), |
637 | 637 | 'describes' => array( |
638 | 638 | array( |
639 | - 'href' => rest_url( '/wc/v3/shipping/zones/' . $zone->get_id() ), |
|
639 | + 'href' => rest_url('/wc/v3/shipping/zones/' . $zone->get_id()), |
|
640 | 640 | ), |
641 | 641 | ), |
642 | 642 | ), |
643 | 643 | ); |
644 | 644 | |
645 | - $this->assertEquals( 200, $response->get_status() ); |
|
646 | - $this->assertEquals( count( $data ), 1 ); |
|
647 | - $this->assertContains( $expected, $data ); |
|
645 | + $this->assertEquals(200, $response->get_status()); |
|
646 | + $this->assertEquals(count($data), 1); |
|
647 | + $this->assertContains($expected, $data); |
|
648 | 648 | |
649 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ) ); |
|
649 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id)); |
|
650 | 650 | $data = $response->get_data(); |
651 | 651 | |
652 | - $this->assertEquals( 200, $response->get_status() ); |
|
653 | - $this->assertEquals( $expected, $data ); |
|
652 | + $this->assertEquals(200, $response->get_status()); |
|
653 | + $this->assertEquals($expected, $data); |
|
654 | 654 | } |
655 | 655 | |
656 | 656 | /** |
@@ -659,15 +659,15 @@ discard block |
||
659 | 659 | * @since 3.5.0 |
660 | 660 | */ |
661 | 661 | public function test_get_methods_invalid_zone_id() { |
662 | - wp_set_current_user( $this->user ); |
|
662 | + wp_set_current_user($this->user); |
|
663 | 663 | |
664 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/methods' ) ); |
|
664 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/1/methods')); |
|
665 | 665 | |
666 | - $this->assertEquals( 404, $response->get_status() ); |
|
666 | + $this->assertEquals(404, $response->get_status()); |
|
667 | 667 | |
668 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/1/methods/1' ) ); |
|
668 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/1/methods/1')); |
|
669 | 669 | |
670 | - $this->assertEquals( 404, $response->get_status() ); |
|
670 | + $this->assertEquals(404, $response->get_status()); |
|
671 | 671 | } |
672 | 672 | |
673 | 673 | /** |
@@ -676,12 +676,12 @@ discard block |
||
676 | 676 | * @since 3.5.0 |
677 | 677 | */ |
678 | 678 | public function test_get_methods_invalid_method_id() { |
679 | - wp_set_current_user( $this->user ); |
|
679 | + wp_set_current_user($this->user); |
|
680 | 680 | |
681 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
682 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/1' ) ); |
|
681 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
682 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/1')); |
|
683 | 683 | |
684 | - $this->assertEquals( 404, $response->get_status() ); |
|
684 | + $this->assertEquals(404, $response->get_status()); |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | /** |
@@ -690,27 +690,27 @@ discard block |
||
690 | 690 | * @since 3.5.0 |
691 | 691 | */ |
692 | 692 | public function test_update_methods() { |
693 | - wp_set_current_user( $this->user ); |
|
693 | + wp_set_current_user($this->user); |
|
694 | 694 | |
695 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
696 | - $instance_id = $zone->add_shipping_method( 'flat_rate' ); |
|
695 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
696 | + $instance_id = $zone->add_shipping_method('flat_rate'); |
|
697 | 697 | $methods = $zone->get_shipping_methods(); |
698 | - $method = $methods[ $instance_id ]; |
|
698 | + $method = $methods[$instance_id]; |
|
699 | 699 | |
700 | 700 | // Test defaults |
701 | - $request = new WP_REST_Request( 'GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
702 | - $response = $this->server->dispatch( $request ); |
|
701 | + $request = new WP_REST_Request('GET', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
702 | + $response = $this->server->dispatch($request); |
|
703 | 703 | $data = $response->get_data(); |
704 | 704 | |
705 | - $this->assertArrayHasKey( 'title', $data['settings'] ); |
|
706 | - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); |
|
707 | - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); |
|
708 | - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); |
|
709 | - $this->assertArrayHasKey( 'cost', $data['settings'] ); |
|
710 | - $this->assertEquals( '0', $data['settings']['cost']['value'] ); |
|
705 | + $this->assertArrayHasKey('title', $data['settings']); |
|
706 | + $this->assertEquals('Flat rate', $data['settings']['title']['value']); |
|
707 | + $this->assertArrayHasKey('tax_status', $data['settings']); |
|
708 | + $this->assertEquals('taxable', $data['settings']['tax_status']['value']); |
|
709 | + $this->assertArrayHasKey('cost', $data['settings']); |
|
710 | + $this->assertEquals('0', $data['settings']['cost']['value']); |
|
711 | 711 | |
712 | 712 | // Update a single value |
713 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
713 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
714 | 714 | $request->set_body_params( |
715 | 715 | array( |
716 | 716 | 'settings' => array( |
@@ -718,18 +718,18 @@ discard block |
||
718 | 718 | ), |
719 | 719 | ) |
720 | 720 | ); |
721 | - $response = $this->server->dispatch( $request ); |
|
721 | + $response = $this->server->dispatch($request); |
|
722 | 722 | $data = $response->get_data(); |
723 | 723 | |
724 | - $this->assertArrayHasKey( 'title', $data['settings'] ); |
|
725 | - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); |
|
726 | - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); |
|
727 | - $this->assertEquals( 'taxable', $data['settings']['tax_status']['value'] ); |
|
728 | - $this->assertArrayHasKey( 'cost', $data['settings'] ); |
|
729 | - $this->assertEquals( '5', $data['settings']['cost']['value'] ); |
|
724 | + $this->assertArrayHasKey('title', $data['settings']); |
|
725 | + $this->assertEquals('Flat rate', $data['settings']['title']['value']); |
|
726 | + $this->assertArrayHasKey('tax_status', $data['settings']); |
|
727 | + $this->assertEquals('taxable', $data['settings']['tax_status']['value']); |
|
728 | + $this->assertArrayHasKey('cost', $data['settings']); |
|
729 | + $this->assertEquals('5', $data['settings']['cost']['value']); |
|
730 | 730 | |
731 | 731 | // Test multiple settings |
732 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
732 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
733 | 733 | $request->set_body_params( |
734 | 734 | array( |
735 | 735 | 'settings' => array( |
@@ -738,18 +738,18 @@ discard block |
||
738 | 738 | ), |
739 | 739 | ) |
740 | 740 | ); |
741 | - $response = $this->server->dispatch( $request ); |
|
741 | + $response = $this->server->dispatch($request); |
|
742 | 742 | $data = $response->get_data(); |
743 | 743 | |
744 | - $this->assertArrayHasKey( 'title', $data['settings'] ); |
|
745 | - $this->assertEquals( 'Flat rate', $data['settings']['title']['value'] ); |
|
746 | - $this->assertArrayHasKey( 'tax_status', $data['settings'] ); |
|
747 | - $this->assertEquals( 'none', $data['settings']['tax_status']['value'] ); |
|
748 | - $this->assertArrayHasKey( 'cost', $data['settings'] ); |
|
749 | - $this->assertEquals( '10', $data['settings']['cost']['value'] ); |
|
744 | + $this->assertArrayHasKey('title', $data['settings']); |
|
745 | + $this->assertEquals('Flat rate', $data['settings']['title']['value']); |
|
746 | + $this->assertArrayHasKey('tax_status', $data['settings']); |
|
747 | + $this->assertEquals('none', $data['settings']['tax_status']['value']); |
|
748 | + $this->assertArrayHasKey('cost', $data['settings']); |
|
749 | + $this->assertEquals('10', $data['settings']['cost']['value']); |
|
750 | 750 | |
751 | 751 | // Test bogus |
752 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
752 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
753 | 753 | $request->set_body_params( |
754 | 754 | array( |
755 | 755 | 'settings' => array( |
@@ -758,27 +758,27 @@ discard block |
||
758 | 758 | ), |
759 | 759 | ) |
760 | 760 | ); |
761 | - $response = $this->server->dispatch( $request ); |
|
762 | - $this->assertEquals( 400, $response->get_status() ); |
|
761 | + $response = $this->server->dispatch($request); |
|
762 | + $this->assertEquals(400, $response->get_status()); |
|
763 | 763 | |
764 | 764 | // Test other parameters |
765 | - $this->assertTrue( $data['enabled'] ); |
|
766 | - $this->assertEquals( 1, $data['order'] ); |
|
765 | + $this->assertTrue($data['enabled']); |
|
766 | + $this->assertEquals(1, $data['order']); |
|
767 | 767 | |
768 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
768 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
769 | 769 | $request->set_body_params( |
770 | 770 | array( |
771 | 771 | 'enabled' => false, |
772 | 772 | 'order' => 2, |
773 | 773 | ) |
774 | 774 | ); |
775 | - $response = $this->server->dispatch( $request ); |
|
775 | + $response = $this->server->dispatch($request); |
|
776 | 776 | $data = $response->get_data(); |
777 | 777 | |
778 | - $this->assertFalse( $data['enabled'] ); |
|
779 | - $this->assertEquals( 2, $data['order'] ); |
|
780 | - $this->assertArrayHasKey( 'cost', $data['settings'] ); |
|
781 | - $this->assertEquals( '10', $data['settings']['cost']['value'] ); |
|
778 | + $this->assertFalse($data['enabled']); |
|
779 | + $this->assertEquals(2, $data['order']); |
|
780 | + $this->assertArrayHasKey('cost', $data['settings']); |
|
781 | + $this->assertEquals('10', $data['settings']['cost']['value']); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
@@ -787,9 +787,9 @@ discard block |
||
787 | 787 | * @since 3.5.0 |
788 | 788 | */ |
789 | 789 | public function test_create_method() { |
790 | - wp_set_current_user( $this->user ); |
|
791 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
792 | - $request = new WP_REST_Request( 'POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods' ); |
|
790 | + wp_set_current_user($this->user); |
|
791 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
792 | + $request = new WP_REST_Request('POST', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods'); |
|
793 | 793 | $request->set_body_params( |
794 | 794 | array( |
795 | 795 | 'method_id' => 'flat_rate', |
@@ -797,13 +797,13 @@ discard block |
||
797 | 797 | 'order' => 2, |
798 | 798 | ) |
799 | 799 | ); |
800 | - $response = $this->server->dispatch( $request ); |
|
800 | + $response = $this->server->dispatch($request); |
|
801 | 801 | $data = $response->get_data(); |
802 | 802 | |
803 | - $this->assertFalse( $data['enabled'] ); |
|
804 | - $this->assertEquals( 2, $data['order'] ); |
|
805 | - $this->assertArrayHasKey( 'cost', $data['settings'] ); |
|
806 | - $this->assertEquals( '0', $data['settings']['cost']['value'] ); |
|
803 | + $this->assertFalse($data['enabled']); |
|
804 | + $this->assertEquals(2, $data['order']); |
|
805 | + $this->assertArrayHasKey('cost', $data['settings']); |
|
806 | + $this->assertEquals('0', $data['settings']['cost']['value']); |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -812,14 +812,14 @@ discard block |
||
812 | 812 | * @since 3.5.0 |
813 | 813 | */ |
814 | 814 | public function test_delete_method() { |
815 | - wp_set_current_user( $this->user ); |
|
816 | - $zone = $this->create_shipping_zone( 'Zone 1' ); |
|
817 | - $instance_id = $zone->add_shipping_method( 'flat_rate' ); |
|
815 | + wp_set_current_user($this->user); |
|
816 | + $zone = $this->create_shipping_zone('Zone 1'); |
|
817 | + $instance_id = $zone->add_shipping_method('flat_rate'); |
|
818 | 818 | $methods = $zone->get_shipping_methods(); |
819 | - $method = $methods[ $instance_id ]; |
|
820 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id ); |
|
821 | - $request->set_param( 'force', true ); |
|
822 | - $response = $this->server->dispatch( $request ); |
|
823 | - $this->assertEquals( 200, $response->get_status() ); |
|
819 | + $method = $methods[$instance_id]; |
|
820 | + $request = new WP_REST_Request('DELETE', '/wc/v3/shipping/zones/' . $zone->get_id() . '/methods/' . $instance_id); |
|
821 | + $request->set_param('force', true); |
|
822 | + $response = $this->server->dispatch($request); |
|
823 | + $this->assertEquals(200, $response->get_status()); |
|
824 | 824 | } |
825 | 825 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function test_register_routes() { |
29 | 29 | $routes = $this->server->get_routes(); |
30 | - $this->assertArrayHasKey( '/wc/v3/reports/orders/totals', $routes ); |
|
30 | + $this->assertArrayHasKey('/wc/v3/reports/orders/totals', $routes); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -36,28 +36,28 @@ discard block |
||
36 | 36 | * @since 3.5.0 |
37 | 37 | */ |
38 | 38 | public function test_get_reports() { |
39 | - wp_set_current_user( $this->user ); |
|
39 | + wp_set_current_user($this->user); |
|
40 | 40 | |
41 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/orders/totals' ) ); |
|
41 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/orders/totals')); |
|
42 | 42 | $report = $response->get_data(); |
43 | - $totals = wp_count_posts( 'shop_order' ); |
|
43 | + $totals = wp_count_posts('shop_order'); |
|
44 | 44 | $data = array(); |
45 | 45 | |
46 | - foreach ( wc_get_order_statuses() as $slug => $name ) { |
|
47 | - if ( ! isset( $totals->$slug ) ) { |
|
46 | + foreach (wc_get_order_statuses() as $slug => $name) { |
|
47 | + if ( ! isset($totals->$slug)) { |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
51 | 51 | $data[] = array( |
52 | - 'slug' => str_replace( 'wc-', '', $slug ), |
|
52 | + 'slug' => str_replace('wc-', '', $slug), |
|
53 | 53 | 'name' => $name, |
54 | 54 | 'total' => (int) $totals->$slug, |
55 | 55 | ); |
56 | 56 | } |
57 | 57 | |
58 | - $this->assertEquals( 200, $response->get_status() ); |
|
59 | - $this->assertEquals( count( wc_get_order_statuses() ), count( $report ) ); |
|
60 | - $this->assertEquals( $data, $report ); |
|
58 | + $this->assertEquals(200, $response->get_status()); |
|
59 | + $this->assertEquals(count(wc_get_order_statuses()), count($report)); |
|
60 | + $this->assertEquals($data, $report); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @since 3.5.0 |
67 | 67 | */ |
68 | 68 | public function test_get_reports_without_permission() { |
69 | - wp_set_current_user( 0 ); |
|
70 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/orders/totals' ) ); |
|
71 | - $this->assertEquals( 401, $response->get_status() ); |
|
69 | + wp_set_current_user(0); |
|
70 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/orders/totals')); |
|
71 | + $this->assertEquals(401, $response->get_status()); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,16 +77,16 @@ discard block |
||
77 | 77 | * @since 3.5.0 |
78 | 78 | */ |
79 | 79 | public function test_product_review_schema() { |
80 | - wp_set_current_user( $this->user ); |
|
80 | + wp_set_current_user($this->user); |
|
81 | 81 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
82 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/orders/totals' ); |
|
83 | - $response = $this->server->dispatch( $request ); |
|
82 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/reports/orders/totals'); |
|
83 | + $response = $this->server->dispatch($request); |
|
84 | 84 | $data = $response->get_data(); |
85 | 85 | $properties = $data['schema']['properties']; |
86 | 86 | |
87 | - $this->assertEquals( 3, count( $properties ) ); |
|
88 | - $this->assertArrayHasKey( 'slug', $properties ); |
|
89 | - $this->assertArrayHasKey( 'name', $properties ); |
|
90 | - $this->assertArrayHasKey( 'total', $properties ); |
|
87 | + $this->assertEquals(3, count($properties)); |
|
88 | + $this->assertArrayHasKey('slug', $properties); |
|
89 | + $this->assertArrayHasKey('name', $properties); |
|
90 | + $this->assertArrayHasKey('total', $properties); |
|
91 | 91 | } |
92 | 92 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function test_register_routes() { |
31 | 31 | $routes = $this->server->get_routes(); |
32 | - $this->assertArrayHasKey( '/wc/v3/settings', $routes ); |
|
33 | - $this->assertArrayHasKey( '/wc/v3/settings/(?P<group_id>[\w-]+)', $routes ); |
|
34 | - $this->assertArrayHasKey( '/wc/v3/settings/(?P<group_id>[\w-]+)/(?P<id>[\w-]+)', $routes ); |
|
32 | + $this->assertArrayHasKey('/wc/v3/settings', $routes); |
|
33 | + $this->assertArrayHasKey('/wc/v3/settings/(?P<group_id>[\w-]+)', $routes); |
|
34 | + $this->assertArrayHasKey('/wc/v3/settings/(?P<group_id>[\w-]+)/(?P<id>[\w-]+)', $routes); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | * @since 3.5.0 |
41 | 41 | */ |
42 | 42 | public function test_get_groups() { |
43 | - wp_set_current_user( $this->user ); |
|
43 | + wp_set_current_user($this->user); |
|
44 | 44 | |
45 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); |
|
45 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings')); |
|
46 | 46 | $data = $response->get_data(); |
47 | 47 | |
48 | - $this->assertEquals( 200, $response->get_status() ); |
|
48 | + $this->assertEquals(200, $response->get_status()); |
|
49 | 49 | |
50 | 50 | $this->assertContains( |
51 | 51 | array( |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | 'label' => 'Test extension', |
54 | 54 | 'parent_id' => '', |
55 | 55 | 'description' => 'My awesome test settings.', |
56 | - 'sub_groups' => array( 'sub-test' ), |
|
56 | + 'sub_groups' => array('sub-test'), |
|
57 | 57 | '_links' => array( |
58 | 58 | 'options' => array( |
59 | 59 | array( |
60 | - 'href' => rest_url( '/wc/v3/settings/test' ), |
|
60 | + 'href' => rest_url('/wc/v3/settings/test'), |
|
61 | 61 | ), |
62 | 62 | ), |
63 | 63 | ), |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | '_links' => array( |
76 | 76 | 'options' => array( |
77 | 77 | array( |
78 | - 'href' => rest_url( '/wc/v3/settings/sub-test' ), |
|
78 | + 'href' => rest_url('/wc/v3/settings/sub-test'), |
|
79 | 79 | ), |
80 | 80 | ), |
81 | 81 | ), |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @since 3.5.0 |
91 | 91 | */ |
92 | 92 | public function test_get_groups_without_permission() { |
93 | - wp_set_current_user( 0 ); |
|
93 | + wp_set_current_user(0); |
|
94 | 94 | |
95 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); |
|
96 | - $this->assertEquals( 401, $response->get_status() ); |
|
95 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings')); |
|
96 | + $this->assertEquals(401, $response->get_status()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | * @covers WC_Rest_Settings_Controller::get_items |
104 | 104 | */ |
105 | 105 | public function test_get_groups_none_registered() { |
106 | - wp_set_current_user( $this->user ); |
|
106 | + wp_set_current_user($this->user); |
|
107 | 107 | |
108 | - remove_all_filters( 'woocommerce_settings_groups' ); |
|
108 | + remove_all_filters('woocommerce_settings_groups'); |
|
109 | 109 | |
110 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings' ) ); |
|
111 | - $this->assertEquals( 500, $response->get_status() ); |
|
110 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings')); |
|
111 | + $this->assertEquals(500, $response->get_status()); |
|
112 | 112 | |
113 | 113 | \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register(); |
114 | 114 | } |
@@ -119,16 +119,16 @@ discard block |
||
119 | 119 | * @since 3.5.0 |
120 | 120 | */ |
121 | 121 | public function test_get_group_schema() { |
122 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings' ); |
|
123 | - $response = $this->server->dispatch( $request ); |
|
122 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/settings'); |
|
123 | + $response = $this->server->dispatch($request); |
|
124 | 124 | $data = $response->get_data(); |
125 | 125 | $properties = $data['schema']['properties']; |
126 | - $this->assertEquals( 5, count( $properties ) ); |
|
127 | - $this->assertArrayHasKey( 'id', $properties ); |
|
128 | - $this->assertArrayHasKey( 'parent_id', $properties ); |
|
129 | - $this->assertArrayHasKey( 'label', $properties ); |
|
130 | - $this->assertArrayHasKey( 'description', $properties ); |
|
131 | - $this->assertArrayHasKey( 'sub_groups', $properties ); |
|
126 | + $this->assertEquals(5, count($properties)); |
|
127 | + $this->assertArrayHasKey('id', $properties); |
|
128 | + $this->assertArrayHasKey('parent_id', $properties); |
|
129 | + $this->assertArrayHasKey('label', $properties); |
|
130 | + $this->assertArrayHasKey('description', $properties); |
|
131 | + $this->assertArrayHasKey('sub_groups', $properties); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,21 +137,21 @@ discard block |
||
137 | 137 | * @since 3.5.0 |
138 | 138 | */ |
139 | 139 | public function test_get_setting_schema() { |
140 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/settings/test/woocommerce_shop_page_display' ); |
|
141 | - $response = $this->server->dispatch( $request ); |
|
140 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/settings/test/woocommerce_shop_page_display'); |
|
141 | + $response = $this->server->dispatch($request); |
|
142 | 142 | $data = $response->get_data(); |
143 | 143 | $properties = $data['schema']['properties']; |
144 | - $this->assertEquals( 10, count( $properties ) ); |
|
145 | - $this->assertArrayHasKey( 'id', $properties ); |
|
146 | - $this->assertArrayHasKey( 'label', $properties ); |
|
147 | - $this->assertArrayHasKey( 'description', $properties ); |
|
148 | - $this->assertArrayHasKey( 'value', $properties ); |
|
149 | - $this->assertArrayHasKey( 'default', $properties ); |
|
150 | - $this->assertArrayHasKey( 'tip', $properties ); |
|
151 | - $this->assertArrayHasKey( 'placeholder', $properties ); |
|
152 | - $this->assertArrayHasKey( 'type', $properties ); |
|
153 | - $this->assertArrayHasKey( 'options', $properties ); |
|
154 | - $this->assertArrayHasKey( 'group_id', $properties ); |
|
144 | + $this->assertEquals(10, count($properties)); |
|
145 | + $this->assertArrayHasKey('id', $properties); |
|
146 | + $this->assertArrayHasKey('label', $properties); |
|
147 | + $this->assertArrayHasKey('description', $properties); |
|
148 | + $this->assertArrayHasKey('value', $properties); |
|
149 | + $this->assertArrayHasKey('default', $properties); |
|
150 | + $this->assertArrayHasKey('tip', $properties); |
|
151 | + $this->assertArrayHasKey('placeholder', $properties); |
|
152 | + $this->assertArrayHasKey('type', $properties); |
|
153 | + $this->assertArrayHasKey('options', $properties); |
|
154 | + $this->assertArrayHasKey('group_id', $properties); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -160,26 +160,26 @@ discard block |
||
160 | 160 | * @since 3.5.0 |
161 | 161 | */ |
162 | 162 | public function test_get_group() { |
163 | - wp_set_current_user( $this->user ); |
|
163 | + wp_set_current_user($this->user); |
|
164 | 164 | |
165 | 165 | // test route callback receiving an empty group id |
166 | - $result = $this->endpoint->get_group_settings( '' ); |
|
167 | - $this->assertIsWPError( $result ); |
|
166 | + $result = $this->endpoint->get_group_settings(''); |
|
167 | + $this->assertIsWPError($result); |
|
168 | 168 | |
169 | 169 | // test getting a group that does not exist |
170 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real' ) ); |
|
171 | - $this->assertEquals( 404, $response->get_status() ); |
|
170 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/not-real')); |
|
171 | + $this->assertEquals(404, $response->get_status()); |
|
172 | 172 | |
173 | 173 | // test getting the 'invalid' group |
174 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid' ) ); |
|
175 | - $this->assertEquals( 404, $response->get_status() ); |
|
174 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/invalid')); |
|
175 | + $this->assertEquals(404, $response->get_status()); |
|
176 | 176 | |
177 | 177 | // test getting a valid group with settings attached to it |
178 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) ); |
|
178 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/test')); |
|
179 | 179 | $data = $response->get_data(); |
180 | - $this->assertEquals( 1, count( $data ) ); |
|
181 | - $this->assertEquals( 'woocommerce_shop_page_display', $data[0]['id'] ); |
|
182 | - $this->assertEmpty( $data[0]['value'] ); |
|
180 | + $this->assertEquals(1, count($data)); |
|
181 | + $this->assertEquals('woocommerce_shop_page_display', $data[0]['id']); |
|
182 | + $this->assertEmpty($data[0]['value']); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | * @since 3.5.0 |
189 | 189 | */ |
190 | 190 | public function test_get_group_without_permission() { |
191 | - wp_set_current_user( 0 ); |
|
191 | + wp_set_current_user(0); |
|
192 | 192 | |
193 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/coupon-data' ) ); |
|
194 | - $this->assertEquals( 401, $response->get_status() ); |
|
193 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/coupon-data')); |
|
194 | + $this->assertEquals(401, $response->get_status()); |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
@@ -200,49 +200,49 @@ discard block |
||
200 | 200 | * @since 3.5.0 |
201 | 201 | */ |
202 | 202 | public function test_update_setting() { |
203 | - wp_set_current_user( $this->user ); |
|
203 | + wp_set_current_user($this->user); |
|
204 | 204 | |
205 | 205 | // test defaults first |
206 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); |
|
206 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/test/woocommerce_shop_page_display')); |
|
207 | 207 | $data = $response->get_data(); |
208 | - $this->assertEquals( '', $data['value'] ); |
|
208 | + $this->assertEquals('', $data['value']); |
|
209 | 209 | |
210 | 210 | // test updating shop display setting |
211 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); |
|
211 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display')); |
|
212 | 212 | $request->set_body_params( |
213 | 213 | array( |
214 | 214 | 'value' => 'both', |
215 | 215 | ) |
216 | 216 | ); |
217 | - $response = $this->server->dispatch( $request ); |
|
217 | + $response = $this->server->dispatch($request); |
|
218 | 218 | $data = $response->get_data(); |
219 | 219 | |
220 | - $this->assertEquals( 'both', $data['value'] ); |
|
221 | - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); |
|
220 | + $this->assertEquals('both', $data['value']); |
|
221 | + $this->assertEquals('both', get_option('woocommerce_shop_page_display')); |
|
222 | 222 | |
223 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); |
|
223 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display')); |
|
224 | 224 | $request->set_body_params( |
225 | 225 | array( |
226 | 226 | 'value' => 'subcategories', |
227 | 227 | ) |
228 | 228 | ); |
229 | - $response = $this->server->dispatch( $request ); |
|
229 | + $response = $this->server->dispatch($request); |
|
230 | 230 | $data = $response->get_data(); |
231 | 231 | |
232 | - $this->assertEquals( 'subcategories', $data['value'] ); |
|
233 | - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); |
|
232 | + $this->assertEquals('subcategories', $data['value']); |
|
233 | + $this->assertEquals('subcategories', get_option('woocommerce_shop_page_display')); |
|
234 | 234 | |
235 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); |
|
235 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display')); |
|
236 | 236 | $request->set_body_params( |
237 | 237 | array( |
238 | 238 | 'value' => '', |
239 | 239 | ) |
240 | 240 | ); |
241 | - $response = $this->server->dispatch( $request ); |
|
241 | + $response = $this->server->dispatch($request); |
|
242 | 242 | $data = $response->get_data(); |
243 | 243 | |
244 | - $this->assertEquals( '', $data['value'] ); |
|
245 | - $this->assertEquals( '', get_option( 'woocommerce_shop_page_display' ) ); |
|
244 | + $this->assertEquals('', $data['value']); |
|
245 | + $this->assertEquals('', get_option('woocommerce_shop_page_display')); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,15 +251,15 @@ discard block |
||
251 | 251 | * @since 3.5.0 |
252 | 252 | */ |
253 | 253 | public function test_update_settings() { |
254 | - wp_set_current_user( $this->user ); |
|
254 | + wp_set_current_user($this->user); |
|
255 | 255 | |
256 | 256 | // test defaults first |
257 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test' ) ); |
|
257 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/test')); |
|
258 | 258 | $data = $response->get_data(); |
259 | - $this->assertEquals( '', $data[0]['value'] ); |
|
259 | + $this->assertEquals('', $data[0]['value']); |
|
260 | 260 | |
261 | 261 | // test setting both at once |
262 | - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); |
|
262 | + $request = new WP_REST_Request('POST', '/wc/v3/settings/test/batch'); |
|
263 | 263 | $request->set_body_params( |
264 | 264 | array( |
265 | 265 | 'update' => array( |
@@ -270,14 +270,14 @@ discard block |
||
270 | 270 | ), |
271 | 271 | ) |
272 | 272 | ); |
273 | - $response = $this->server->dispatch( $request ); |
|
273 | + $response = $this->server->dispatch($request); |
|
274 | 274 | $data = $response->get_data(); |
275 | 275 | |
276 | - $this->assertEquals( 'both', $data['update'][0]['value'] ); |
|
277 | - $this->assertEquals( 'both', get_option( 'woocommerce_shop_page_display' ) ); |
|
276 | + $this->assertEquals('both', $data['update'][0]['value']); |
|
277 | + $this->assertEquals('both', get_option('woocommerce_shop_page_display')); |
|
278 | 278 | |
279 | 279 | // test updating one, but making sure the other value stays the same |
280 | - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); |
|
280 | + $request = new WP_REST_Request('POST', '/wc/v3/settings/test/batch'); |
|
281 | 281 | $request->set_body_params( |
282 | 282 | array( |
283 | 283 | 'update' => array( |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | ), |
289 | 289 | ) |
290 | 290 | ); |
291 | - $response = $this->server->dispatch( $request ); |
|
291 | + $response = $this->server->dispatch($request); |
|
292 | 292 | $data = $response->get_data(); |
293 | - $this->assertEquals( 'subcategories', $data['update'][0]['value'] ); |
|
294 | - $this->assertEquals( 'subcategories', get_option( 'woocommerce_shop_page_display' ) ); |
|
293 | + $this->assertEquals('subcategories', $data['update'][0]['value']); |
|
294 | + $this->assertEquals('subcategories', get_option('woocommerce_shop_page_display')); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
@@ -300,29 +300,29 @@ discard block |
||
300 | 300 | * @since 3.5.0 |
301 | 301 | */ |
302 | 302 | public function test_get_setting() { |
303 | - wp_set_current_user( $this->user ); |
|
303 | + wp_set_current_user($this->user); |
|
304 | 304 | |
305 | 305 | // test getting an invalid setting from a group that does not exist |
306 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/not-real/woocommerce_shop_page_display' ) ); |
|
306 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/not-real/woocommerce_shop_page_display')); |
|
307 | 307 | $data = $response->get_data(); |
308 | - $this->assertEquals( 404, $response->get_status() ); |
|
308 | + $this->assertEquals(404, $response->get_status()); |
|
309 | 309 | |
310 | 310 | // test getting an invalid setting from a group that does exist |
311 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/invalid/invalid' ) ); |
|
311 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/invalid/invalid')); |
|
312 | 312 | $data = $response->get_data(); |
313 | - $this->assertEquals( 404, $response->get_status() ); |
|
313 | + $this->assertEquals(404, $response->get_status()); |
|
314 | 314 | |
315 | 315 | // test getting a valid setting |
316 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); |
|
316 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/test/woocommerce_shop_page_display')); |
|
317 | 317 | $data = $response->get_data(); |
318 | 318 | |
319 | - $this->assertEquals( 200, $response->get_status() ); |
|
319 | + $this->assertEquals(200, $response->get_status()); |
|
320 | 320 | |
321 | - $this->assertEquals( 'woocommerce_shop_page_display', $data['id'] ); |
|
322 | - $this->assertEquals( 'Shop page display', $data['label'] ); |
|
323 | - $this->assertEquals( '', $data['default'] ); |
|
324 | - $this->assertEquals( 'select', $data['type'] ); |
|
325 | - $this->assertEquals( '', $data['value'] ); |
|
321 | + $this->assertEquals('woocommerce_shop_page_display', $data['id']); |
|
322 | + $this->assertEquals('Shop page display', $data['label']); |
|
323 | + $this->assertEquals('', $data['default']); |
|
324 | + $this->assertEquals('select', $data['type']); |
|
325 | + $this->assertEquals('', $data['value']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | /** |
@@ -331,10 +331,10 @@ discard block |
||
331 | 331 | * @since 3.5.0 |
332 | 332 | */ |
333 | 333 | public function test_get_setting_without_permission() { |
334 | - wp_set_current_user( 0 ); |
|
334 | + wp_set_current_user(0); |
|
335 | 335 | |
336 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/test/woocommerce_shop_page_display' ) ); |
|
337 | - $this->assertEquals( 401, $response->get_status() ); |
|
336 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/test/woocommerce_shop_page_display')); |
|
337 | + $this->assertEquals(401, $response->get_status()); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -343,9 +343,9 @@ discard block |
||
343 | 343 | * @since 3.5.0 |
344 | 344 | */ |
345 | 345 | public function test_get_setting_empty_setting_id() { |
346 | - $result = $this->endpoint->get_setting( 'test', '' ); |
|
346 | + $result = $this->endpoint->get_setting('test', ''); |
|
347 | 347 | |
348 | - $this->assertIsWPError( $result ); |
|
348 | + $this->assertIsWPError($result); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @since 3.5.0 |
355 | 355 | */ |
356 | 356 | public function test_get_setting_invalid_setting_id() { |
357 | - $result = $this->endpoint->get_setting( 'test', 'invalid' ); |
|
357 | + $result = $this->endpoint->get_setting('test', 'invalid'); |
|
358 | 358 | |
359 | - $this->assertIsWPError( $result ); |
|
359 | + $this->assertIsWPError($result); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | /** |
@@ -366,21 +366,21 @@ discard block |
||
366 | 366 | */ |
367 | 367 | public function test_get_setting_invalid_setting_type() { |
368 | 368 | // $controller = $this->getMock( 'WC_Rest_Setting_Options_Controller', array( 'get_group_settings', 'is_setting_type_valid' ) ); |
369 | - $controller = $this->getMockBuilder( 'WC_Rest_Setting_Options_Controller' )->setMethods( array( 'get_group_settings', 'is_setting_type_valid' ) )->getMock(); |
|
369 | + $controller = $this->getMockBuilder('WC_Rest_Setting_Options_Controller')->setMethods(array('get_group_settings', 'is_setting_type_valid'))->getMock(); |
|
370 | 370 | |
371 | 371 | $controller |
372 | - ->expects( $this->any() ) |
|
373 | - ->method( 'get_group_settings' ) |
|
374 | - ->will( $this->returnValue( \WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings( array() ) ) ); |
|
372 | + ->expects($this->any()) |
|
373 | + ->method('get_group_settings') |
|
374 | + ->will($this->returnValue(\WooCommerce\RestApi\UnitTests\Helpers\SettingsHelper::register_test_settings(array()))); |
|
375 | 375 | |
376 | 376 | $controller |
377 | - ->expects( $this->any() ) |
|
378 | - ->method( 'is_setting_type_valid' ) |
|
379 | - ->will( $this->returnValue( false ) ); |
|
377 | + ->expects($this->any()) |
|
378 | + ->method('is_setting_type_valid') |
|
379 | + ->will($this->returnValue(false)); |
|
380 | 380 | |
381 | - $result = $controller->get_setting( 'test', 'woocommerce_shop_page_display' ); |
|
381 | + $result = $controller->get_setting('test', 'woocommerce_shop_page_display'); |
|
382 | 382 | |
383 | - $this->assertIsWPError( $result ); |
|
383 | + $this->assertIsWPError($result); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -389,16 +389,16 @@ discard block |
||
389 | 389 | * @since 3.5.0 |
390 | 390 | */ |
391 | 391 | public function test_update_setting_without_permission() { |
392 | - wp_set_current_user( 0 ); |
|
392 | + wp_set_current_user(0); |
|
393 | 393 | |
394 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display' ) ); |
|
394 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'test', 'woocommerce_shop_page_display')); |
|
395 | 395 | $request->set_body_params( |
396 | 396 | array( |
397 | 397 | 'value' => 'subcategories', |
398 | 398 | ) |
399 | 399 | ); |
400 | - $response = $this->server->dispatch( $request ); |
|
401 | - $this->assertEquals( 401, $response->get_status() ); |
|
400 | + $response = $this->server->dispatch($request); |
|
401 | + $this->assertEquals(401, $response->get_status()); |
|
402 | 402 | } |
403 | 403 | |
404 | 404 | |
@@ -408,9 +408,9 @@ discard block |
||
408 | 408 | * @since 3.5.0 |
409 | 409 | */ |
410 | 410 | public function test_update_settings_without_permission() { |
411 | - wp_set_current_user( 0 ); |
|
411 | + wp_set_current_user(0); |
|
412 | 412 | |
413 | - $request = new WP_REST_Request( 'POST', '/wc/v3/settings/test/batch' ); |
|
413 | + $request = new WP_REST_Request('POST', '/wc/v3/settings/test/batch'); |
|
414 | 414 | $request->set_body_params( |
415 | 415 | array( |
416 | 416 | 'update' => array( |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | ), |
422 | 422 | ) |
423 | 423 | ); |
424 | - $response = $this->server->dispatch( $request ); |
|
425 | - $this->assertEquals( 401, $response->get_status() ); |
|
424 | + $response = $this->server->dispatch($request); |
|
425 | + $this->assertEquals(401, $response->get_status()); |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
@@ -432,16 +432,16 @@ discard block |
||
432 | 432 | * @covers WC_Rest_Setting_Options_Controller::update_item |
433 | 433 | */ |
434 | 434 | public function test_update_setting_bad_setting_id() { |
435 | - wp_set_current_user( $this->user ); |
|
435 | + wp_set_current_user($this->user); |
|
436 | 436 | |
437 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/test/invalid' ); |
|
437 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/test/invalid'); |
|
438 | 438 | $request->set_body_params( |
439 | 439 | array( |
440 | 440 | 'value' => 'test', |
441 | 441 | ) |
442 | 442 | ); |
443 | - $response = $this->server->dispatch( $request ); |
|
444 | - $this->assertEquals( 404, $response->get_status() ); |
|
443 | + $response = $this->server->dispatch($request); |
|
444 | + $this->assertEquals(404, $response->get_status()); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | /** |
@@ -450,12 +450,12 @@ discard block |
||
450 | 450 | * @since 3.5.0 |
451 | 451 | */ |
452 | 452 | public function test_classic_settings() { |
453 | - wp_set_current_user( $this->user ); |
|
453 | + wp_set_current_user($this->user); |
|
454 | 454 | |
455 | 455 | // Make sure the group is properly registered |
456 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products' ) ); |
|
456 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/products')); |
|
457 | 457 | $data = $response->get_data(); |
458 | - $this->assertTrue( is_array( $data ) ); |
|
458 | + $this->assertTrue(is_array($data)); |
|
459 | 459 | $this->assertContains( |
460 | 460 | array( |
461 | 461 | 'id' => 'woocommerce_downloads_require_login', |
@@ -468,12 +468,12 @@ discard block |
||
468 | 468 | '_links' => array( |
469 | 469 | 'self' => array( |
470 | 470 | array( |
471 | - 'href' => rest_url( '/wc/v3/settings/products/woocommerce_downloads_require_login' ), |
|
471 | + 'href' => rest_url('/wc/v3/settings/products/woocommerce_downloads_require_login'), |
|
472 | 472 | ), |
473 | 473 | ), |
474 | 474 | 'collection' => array( |
475 | 475 | array( |
476 | - 'href' => rest_url( '/wc/v3/settings/products' ), |
|
476 | + 'href' => rest_url('/wc/v3/settings/products'), |
|
477 | 477 | ), |
478 | 478 | ), |
479 | 479 | ), |
@@ -482,23 +482,23 @@ discard block |
||
482 | 482 | ); |
483 | 483 | |
484 | 484 | // test get single |
485 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/products/woocommerce_dimension_unit' ) ); |
|
485 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/products/woocommerce_dimension_unit')); |
|
486 | 486 | $data = $response->get_data(); |
487 | 487 | |
488 | - $this->assertEquals( 'cm', $data['default'] ); |
|
488 | + $this->assertEquals('cm', $data['default']); |
|
489 | 489 | |
490 | 490 | // test update |
491 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_dimension_unit' ) ); |
|
491 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'products', 'woocommerce_dimension_unit')); |
|
492 | 492 | $request->set_body_params( |
493 | 493 | array( |
494 | 494 | 'value' => 'yd', |
495 | 495 | ) |
496 | 496 | ); |
497 | - $response = $this->server->dispatch( $request ); |
|
497 | + $response = $this->server->dispatch($request); |
|
498 | 498 | $data = $response->get_data(); |
499 | 499 | |
500 | - $this->assertEquals( 'yd', $data['value'] ); |
|
501 | - $this->assertEquals( 'yd', get_option( 'woocommerce_dimension_unit' ) ); |
|
500 | + $this->assertEquals('yd', $data['value']); |
|
501 | + $this->assertEquals('yd', get_option('woocommerce_dimension_unit')); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | /** |
@@ -507,12 +507,12 @@ discard block |
||
507 | 507 | * @since 3.5.0 |
508 | 508 | */ |
509 | 509 | public function test_email_settings() { |
510 | - wp_set_current_user( $this->user ); |
|
510 | + wp_set_current_user($this->user); |
|
511 | 511 | |
512 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order' ) ); |
|
512 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/email_new_order')); |
|
513 | 513 | $settings = $response->get_data(); |
514 | 514 | |
515 | - $this->assertEquals( 200, $response->get_status() ); |
|
515 | + $this->assertEquals(200, $response->get_status()); |
|
516 | 516 | |
517 | 517 | $this->assertContains( |
518 | 518 | array( |
@@ -526,12 +526,12 @@ discard block |
||
526 | 526 | '_links' => array( |
527 | 527 | 'self' => array( |
528 | 528 | array( |
529 | - 'href' => rest_url( '/wc/v3/settings/email_new_order/recipient' ), |
|
529 | + 'href' => rest_url('/wc/v3/settings/email_new_order/recipient'), |
|
530 | 530 | ), |
531 | 531 | ), |
532 | 532 | 'collection' => array( |
533 | 533 | array( |
534 | - 'href' => rest_url( '/wc/v3/settings/email_new_order' ), |
|
534 | + 'href' => rest_url('/wc/v3/settings/email_new_order'), |
|
535 | 535 | ), |
536 | 536 | ), |
537 | 537 | ), |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | ); |
541 | 541 | |
542 | 542 | // test get single |
543 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) ); |
|
543 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/email_new_order/subject')); |
|
544 | 544 | $setting = $response->get_data(); |
545 | 545 | |
546 | 546 | $this->assertEquals( |
@@ -558,13 +558,13 @@ discard block |
||
558 | 558 | ); |
559 | 559 | |
560 | 560 | // test update |
561 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_new_order', 'subject' ) ); |
|
561 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'email_new_order', 'subject')); |
|
562 | 562 | $request->set_body_params( |
563 | 563 | array( |
564 | 564 | 'value' => 'This is my subject', |
565 | 565 | ) |
566 | 566 | ); |
567 | - $response = $this->server->dispatch( $request ); |
|
567 | + $response = $this->server->dispatch($request); |
|
568 | 568 | $setting = $response->get_data(); |
569 | 569 | |
570 | 570 | $this->assertEquals( |
@@ -582,29 +582,29 @@ discard block |
||
582 | 582 | ); |
583 | 583 | |
584 | 584 | // test updating another subject and making sure it works with a "similar" id |
585 | - $request = new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); |
|
586 | - $response = $this->server->dispatch( $request ); |
|
585 | + $request = new WP_REST_Request('GET', sprintf('/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject')); |
|
586 | + $response = $this->server->dispatch($request); |
|
587 | 587 | $setting = $response->get_data(); |
588 | 588 | |
589 | - $this->assertEmpty( $setting['value'] ); |
|
589 | + $this->assertEmpty($setting['value']); |
|
590 | 590 | |
591 | 591 | // test update |
592 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject' ) ); |
|
592 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'email_customer_new_account', 'subject')); |
|
593 | 593 | $request->set_body_params( |
594 | 594 | array( |
595 | 595 | 'value' => 'This is my new subject', |
596 | 596 | ) |
597 | 597 | ); |
598 | - $response = $this->server->dispatch( $request ); |
|
598 | + $response = $this->server->dispatch($request); |
|
599 | 599 | $setting = $response->get_data(); |
600 | 600 | |
601 | - $this->assertEquals( 'This is my new subject', $setting['value'] ); |
|
601 | + $this->assertEquals('This is my new subject', $setting['value']); |
|
602 | 602 | |
603 | 603 | // make sure the other is what we left it |
604 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/email_new_order/subject' ) ); |
|
604 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/email_new_order/subject')); |
|
605 | 605 | $setting = $response->get_data(); |
606 | 606 | |
607 | - $this->assertEquals( 'This is my subject', $setting['value'] ); |
|
607 | + $this->assertEquals('This is my subject', $setting['value']); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -613,37 +613,37 @@ discard block |
||
613 | 613 | * @since 3.5.0 |
614 | 614 | */ |
615 | 615 | public function test_validation_checkbox() { |
616 | - wp_set_current_user( $this->user ); |
|
616 | + wp_set_current_user($this->user); |
|
617 | 617 | |
618 | 618 | // test bogus value |
619 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); |
|
619 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled')); |
|
620 | 620 | $request->set_body_params( |
621 | 621 | array( |
622 | 622 | 'value' => 'not_yes_or_no', |
623 | 623 | ) |
624 | 624 | ); |
625 | - $response = $this->server->dispatch( $request ); |
|
626 | - $this->assertEquals( 400, $response->get_status() ); |
|
625 | + $response = $this->server->dispatch($request); |
|
626 | + $this->assertEquals(400, $response->get_status()); |
|
627 | 627 | |
628 | 628 | // test yes |
629 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); |
|
629 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled')); |
|
630 | 630 | $request->set_body_params( |
631 | 631 | array( |
632 | 632 | 'value' => 'yes', |
633 | 633 | ) |
634 | 634 | ); |
635 | - $response = $this->server->dispatch( $request ); |
|
636 | - $this->assertEquals( 200, $response->get_status() ); |
|
635 | + $response = $this->server->dispatch($request); |
|
636 | + $this->assertEquals(200, $response->get_status()); |
|
637 | 637 | |
638 | 638 | // test no |
639 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled' ) ); |
|
639 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'email_cancelled_order', 'enabled')); |
|
640 | 640 | $request->set_body_params( |
641 | 641 | array( |
642 | 642 | 'value' => 'no', |
643 | 643 | ) |
644 | 644 | ); |
645 | - $response = $this->server->dispatch( $request ); |
|
646 | - $this->assertEquals( 200, $response->get_status() ); |
|
645 | + $response = $this->server->dispatch($request); |
|
646 | + $this->assertEquals(200, $response->get_status()); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -652,27 +652,27 @@ discard block |
||
652 | 652 | * @since 3.5.0 |
653 | 653 | */ |
654 | 654 | public function test_validation_radio() { |
655 | - wp_set_current_user( $this->user ); |
|
655 | + wp_set_current_user($this->user); |
|
656 | 656 | |
657 | 657 | // not a valid option |
658 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); |
|
658 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination')); |
|
659 | 659 | $request->set_body_params( |
660 | 660 | array( |
661 | 661 | 'value' => 'billing2', |
662 | 662 | ) |
663 | 663 | ); |
664 | - $response = $this->server->dispatch( $request ); |
|
665 | - $this->assertEquals( 400, $response->get_status() ); |
|
664 | + $response = $this->server->dispatch($request); |
|
665 | + $this->assertEquals(400, $response->get_status()); |
|
666 | 666 | |
667 | 667 | // valid |
668 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination' ) ); |
|
668 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'shipping', 'woocommerce_ship_to_destination')); |
|
669 | 669 | $request->set_body_params( |
670 | 670 | array( |
671 | 671 | 'value' => 'billing', |
672 | 672 | ) |
673 | 673 | ); |
674 | - $response = $this->server->dispatch( $request ); |
|
675 | - $this->assertEquals( 200, $response->get_status() ); |
|
674 | + $response = $this->server->dispatch($request); |
|
675 | + $this->assertEquals(200, $response->get_status()); |
|
676 | 676 | } |
677 | 677 | |
678 | 678 | /** |
@@ -681,21 +681,21 @@ discard block |
||
681 | 681 | * @since 3.5.0 |
682 | 682 | */ |
683 | 683 | public function test_validation_multiselect() { |
684 | - wp_set_current_user( $this->user ); |
|
684 | + wp_set_current_user($this->user); |
|
685 | 685 | |
686 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ) ); |
|
686 | + $response = $this->server->dispatch(new WP_REST_Request('GET', sprintf('/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries'))); |
|
687 | 687 | $setting = $response->get_data(); |
688 | - $this->assertEmpty( $setting['value'] ); |
|
688 | + $this->assertEmpty($setting['value']); |
|
689 | 689 | |
690 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries' ) ); |
|
690 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'general', 'woocommerce_specific_allowed_countries')); |
|
691 | 691 | $request->set_body_params( |
692 | 692 | array( |
693 | - 'value' => array( 'AX', 'DZ', 'MMM' ), |
|
693 | + 'value' => array('AX', 'DZ', 'MMM'), |
|
694 | 694 | ) |
695 | 695 | ); |
696 | - $response = $this->server->dispatch( $request ); |
|
696 | + $response = $this->server->dispatch($request); |
|
697 | 697 | $setting = $response->get_data(); |
698 | - $this->assertEquals( array( 'AX', 'DZ' ), $setting['value'] ); |
|
698 | + $this->assertEquals(array('AX', 'DZ'), $setting['value']); |
|
699 | 699 | } |
700 | 700 | |
701 | 701 | /** |
@@ -704,32 +704,32 @@ discard block |
||
704 | 704 | * @since 3.5.0 |
705 | 705 | */ |
706 | 706 | public function test_validation_select() { |
707 | - wp_set_current_user( $this->user ); |
|
707 | + wp_set_current_user($this->user); |
|
708 | 708 | |
709 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ) ); |
|
709 | + $response = $this->server->dispatch(new WP_REST_Request('GET', sprintf('/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit'))); |
|
710 | 710 | $setting = $response->get_data(); |
711 | - $this->assertEquals( 'kg', $setting['value'] ); |
|
711 | + $this->assertEquals('kg', $setting['value']); |
|
712 | 712 | |
713 | 713 | // invalid |
714 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); |
|
714 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit')); |
|
715 | 715 | $request->set_body_params( |
716 | 716 | array( |
717 | 717 | 'value' => 'pounds', // invalid, should be lbs |
718 | 718 | ) |
719 | 719 | ); |
720 | - $response = $this->server->dispatch( $request ); |
|
721 | - $this->assertEquals( 400, $response->get_status() ); |
|
720 | + $response = $this->server->dispatch($request); |
|
721 | + $this->assertEquals(400, $response->get_status()); |
|
722 | 722 | |
723 | 723 | // valid |
724 | - $request = new WP_REST_Request( 'PUT', sprintf( '/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit' ) ); |
|
724 | + $request = new WP_REST_Request('PUT', sprintf('/wc/v3/settings/%s/%s', 'products', 'woocommerce_weight_unit')); |
|
725 | 725 | $request->set_body_params( |
726 | 726 | array( |
727 | 727 | 'value' => 'lbs', // invalid, should be lbs |
728 | 728 | ) |
729 | 729 | ); |
730 | - $response = $this->server->dispatch( $request ); |
|
730 | + $response = $this->server->dispatch($request); |
|
731 | 731 | $setting = $response->get_data(); |
732 | - $this->assertEquals( 'lbs', $setting['value'] ); |
|
732 | + $this->assertEquals('lbs', $setting['value']); |
|
733 | 733 | } |
734 | 734 | |
735 | 735 | /** |
@@ -740,13 +740,13 @@ discard block |
||
740 | 740 | * @since 3.5.0 |
741 | 741 | */ |
742 | 742 | public function test_woocommerce_default_country() { |
743 | - wp_set_current_user( $this->user ); |
|
744 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_default_country' ) ); |
|
743 | + wp_set_current_user($this->user); |
|
744 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/general/woocommerce_default_country')); |
|
745 | 745 | $setting = $response->get_data(); |
746 | 746 | |
747 | - $this->assertEquals( 'select', $setting['type'] ); |
|
748 | - $this->assertArrayHasKey( 'GB', $setting['options'] ); |
|
749 | - $this->assertArrayHasKey( 'US:OR', $setting['options'] ); |
|
747 | + $this->assertEquals('select', $setting['type']); |
|
748 | + $this->assertArrayHasKey('GB', $setting['options']); |
|
749 | + $this->assertArrayHasKey('US:OR', $setting['options']); |
|
750 | 750 | } |
751 | 751 | |
752 | 752 | /** |
@@ -755,34 +755,34 @@ discard block |
||
755 | 755 | * @since 3.5.0 |
756 | 756 | */ |
757 | 757 | public function test_woocommerce_store_address() { |
758 | - wp_set_current_user( $this->user ); |
|
759 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address' ) ); |
|
758 | + wp_set_current_user($this->user); |
|
759 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/general/woocommerce_store_address')); |
|
760 | 760 | $setting = $response->get_data(); |
761 | - $this->assertEquals( 'text', $setting['type'] ); |
|
761 | + $this->assertEquals('text', $setting['type']); |
|
762 | 762 | |
763 | 763 | // Repalce the old value with something uniquely new |
764 | 764 | $old_value = $setting['value']; |
765 | - $new_value = $old_value . ' ' . rand( 1000, 9999 ); |
|
766 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' ); |
|
765 | + $new_value = $old_value . ' ' . rand(1000, 9999); |
|
766 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_address'); |
|
767 | 767 | $request->set_body_params( |
768 | 768 | array( |
769 | 769 | 'value' => $new_value, |
770 | 770 | ) |
771 | 771 | ); |
772 | - $response = $this->server->dispatch( $request ); |
|
772 | + $response = $this->server->dispatch($request); |
|
773 | 773 | $setting = $response->get_data(); |
774 | - $this->assertEquals( $new_value, $setting['value'] ); |
|
774 | + $this->assertEquals($new_value, $setting['value']); |
|
775 | 775 | |
776 | 776 | // Put the original value back |
777 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address' ); |
|
777 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_address'); |
|
778 | 778 | $request->set_body_params( |
779 | 779 | array( |
780 | 780 | 'value' => $old_value, |
781 | 781 | ) |
782 | 782 | ); |
783 | - $response = $this->server->dispatch( $request ); |
|
783 | + $response = $this->server->dispatch($request); |
|
784 | 784 | $setting = $response->get_data(); |
785 | - $this->assertEquals( $old_value, $setting['value'] ); |
|
785 | + $this->assertEquals($old_value, $setting['value']); |
|
786 | 786 | } |
787 | 787 | |
788 | 788 | /** |
@@ -791,34 +791,34 @@ discard block |
||
791 | 791 | * @since 3.5.0 |
792 | 792 | */ |
793 | 793 | public function test_woocommerce_store_address_2() { |
794 | - wp_set_current_user( $this->user ); |
|
795 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_address_2' ) ); |
|
794 | + wp_set_current_user($this->user); |
|
795 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/general/woocommerce_store_address_2')); |
|
796 | 796 | $setting = $response->get_data(); |
797 | - $this->assertEquals( 'text', $setting['type'] ); |
|
797 | + $this->assertEquals('text', $setting['type']); |
|
798 | 798 | |
799 | 799 | // Repalce the old value with something uniquely new |
800 | 800 | $old_value = $setting['value']; |
801 | - $new_value = $old_value . ' ' . rand( 1000, 9999 ); |
|
802 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' ); |
|
801 | + $new_value = $old_value . ' ' . rand(1000, 9999); |
|
802 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_address_2'); |
|
803 | 803 | $request->set_body_params( |
804 | 804 | array( |
805 | 805 | 'value' => $new_value, |
806 | 806 | ) |
807 | 807 | ); |
808 | - $response = $this->server->dispatch( $request ); |
|
808 | + $response = $this->server->dispatch($request); |
|
809 | 809 | $setting = $response->get_data(); |
810 | - $this->assertEquals( $new_value, $setting['value'] ); |
|
810 | + $this->assertEquals($new_value, $setting['value']); |
|
811 | 811 | |
812 | 812 | // Put the original value back |
813 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_address_2' ); |
|
813 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_address_2'); |
|
814 | 814 | $request->set_body_params( |
815 | 815 | array( |
816 | 816 | 'value' => $old_value, |
817 | 817 | ) |
818 | 818 | ); |
819 | - $response = $this->server->dispatch( $request ); |
|
819 | + $response = $this->server->dispatch($request); |
|
820 | 820 | $setting = $response->get_data(); |
821 | - $this->assertEquals( $old_value, $setting['value'] ); |
|
821 | + $this->assertEquals($old_value, $setting['value']); |
|
822 | 822 | } |
823 | 823 | |
824 | 824 | /** |
@@ -827,34 +827,34 @@ discard block |
||
827 | 827 | * @since 3.5.0 |
828 | 828 | */ |
829 | 829 | public function test_woocommerce_store_city() { |
830 | - wp_set_current_user( $this->user ); |
|
831 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_city' ) ); |
|
830 | + wp_set_current_user($this->user); |
|
831 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/general/woocommerce_store_city')); |
|
832 | 832 | $setting = $response->get_data(); |
833 | - $this->assertEquals( 'text', $setting['type'] ); |
|
833 | + $this->assertEquals('text', $setting['type']); |
|
834 | 834 | |
835 | 835 | // Repalce the old value with something uniquely new |
836 | 836 | $old_value = $setting['value']; |
837 | - $new_value = $old_value . ' ' . rand( 1000, 9999 ); |
|
838 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' ); |
|
837 | + $new_value = $old_value . ' ' . rand(1000, 9999); |
|
838 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_city'); |
|
839 | 839 | $request->set_body_params( |
840 | 840 | array( |
841 | 841 | 'value' => $new_value, |
842 | 842 | ) |
843 | 843 | ); |
844 | - $response = $this->server->dispatch( $request ); |
|
844 | + $response = $this->server->dispatch($request); |
|
845 | 845 | $setting = $response->get_data(); |
846 | - $this->assertEquals( $new_value, $setting['value'] ); |
|
846 | + $this->assertEquals($new_value, $setting['value']); |
|
847 | 847 | |
848 | 848 | // Put the original value back |
849 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_city' ); |
|
849 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_city'); |
|
850 | 850 | $request->set_body_params( |
851 | 851 | array( |
852 | 852 | 'value' => $old_value, |
853 | 853 | ) |
854 | 854 | ); |
855 | - $response = $this->server->dispatch( $request ); |
|
855 | + $response = $this->server->dispatch($request); |
|
856 | 856 | $setting = $response->get_data(); |
857 | - $this->assertEquals( $old_value, $setting['value'] ); |
|
857 | + $this->assertEquals($old_value, $setting['value']); |
|
858 | 858 | } |
859 | 859 | |
860 | 860 | /** |
@@ -863,33 +863,33 @@ discard block |
||
863 | 863 | * @since 3.5.0 |
864 | 864 | */ |
865 | 865 | public function test_woocommerce_store_postcode() { |
866 | - wp_set_current_user( $this->user ); |
|
867 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/settings/general/woocommerce_store_postcode' ) ); |
|
866 | + wp_set_current_user($this->user); |
|
867 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/settings/general/woocommerce_store_postcode')); |
|
868 | 868 | $setting = $response->get_data(); |
869 | - $this->assertEquals( 'text', $setting['type'] ); |
|
869 | + $this->assertEquals('text', $setting['type']); |
|
870 | 870 | |
871 | 871 | // Repalce the old value with something uniquely new |
872 | 872 | $old_value = $setting['value']; |
873 | - $new_value = $old_value . ' ' . rand( 1000, 9999 ); |
|
874 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' ); |
|
873 | + $new_value = $old_value . ' ' . rand(1000, 9999); |
|
874 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_postcode'); |
|
875 | 875 | $request->set_body_params( |
876 | 876 | array( |
877 | 877 | 'value' => $new_value, |
878 | 878 | ) |
879 | 879 | ); |
880 | - $response = $this->server->dispatch( $request ); |
|
880 | + $response = $this->server->dispatch($request); |
|
881 | 881 | $setting = $response->get_data(); |
882 | - $this->assertEquals( $new_value, $setting['value'] ); |
|
882 | + $this->assertEquals($new_value, $setting['value']); |
|
883 | 883 | |
884 | 884 | // Put the original value back |
885 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/settings/general/woocommerce_store_postcode' ); |
|
885 | + $request = new WP_REST_Request('PUT', '/wc/v3/settings/general/woocommerce_store_postcode'); |
|
886 | 886 | $request->set_body_params( |
887 | 887 | array( |
888 | 888 | 'value' => $old_value, |
889 | 889 | ) |
890 | 890 | ); |
891 | - $response = $this->server->dispatch( $request ); |
|
891 | + $response = $this->server->dispatch($request); |
|
892 | 892 | $setting = $response->get_data(); |
893 | - $this->assertEquals( $old_value, $setting['value'] ); |
|
893 | + $this->assertEquals($old_value, $setting['value']); |
|
894 | 894 | } |
895 | 895 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function test_register_routes() { |
29 | 29 | $routes = $this->server->get_routes(); |
30 | - $this->assertArrayHasKey( '/wc/v3/reports/coupons/totals', $routes ); |
|
30 | + $this->assertArrayHasKey('/wc/v3/reports/coupons/totals', $routes); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
@@ -37,14 +37,14 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function test_get_reports() { |
39 | 39 | global $wpdb; |
40 | - wp_set_current_user( $this->user ); |
|
40 | + wp_set_current_user($this->user); |
|
41 | 41 | |
42 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/coupons/totals' ) ); |
|
42 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/coupons/totals')); |
|
43 | 43 | $report = $response->get_data(); |
44 | 44 | $types = wc_get_coupon_types(); |
45 | 45 | $data = array(); |
46 | 46 | |
47 | - foreach ( $types as $slug => $name ) { |
|
47 | + foreach ($types as $slug => $name) { |
|
48 | 48 | $results = $wpdb->get_results( |
49 | 49 | $wpdb->prepare( |
50 | 50 | " |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | ) |
58 | 58 | ); |
59 | 59 | |
60 | - $total = isset( $results[0] ) ? (int) $results[0]->total : 0; |
|
60 | + $total = isset($results[0]) ? (int) $results[0]->total : 0; |
|
61 | 61 | |
62 | 62 | $data[] = array( |
63 | 63 | 'slug' => $slug, |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | ); |
67 | 67 | } |
68 | 68 | |
69 | - $this->assertEquals( 200, $response->get_status() ); |
|
70 | - $this->assertEquals( count( $types ), count( $report ) ); |
|
71 | - $this->assertEquals( $data, $report ); |
|
69 | + $this->assertEquals(200, $response->get_status()); |
|
70 | + $this->assertEquals(count($types), count($report)); |
|
71 | + $this->assertEquals($data, $report); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | * @since 3.5.0 |
78 | 78 | */ |
79 | 79 | public function test_get_reports_without_permission() { |
80 | - wp_set_current_user( 0 ); |
|
81 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/coupons/totals' ) ); |
|
82 | - $this->assertEquals( 401, $response->get_status() ); |
|
80 | + wp_set_current_user(0); |
|
81 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/coupons/totals')); |
|
82 | + $this->assertEquals(401, $response->get_status()); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | * @since 3.5.0 |
89 | 89 | */ |
90 | 90 | public function test_product_review_schema() { |
91 | - wp_set_current_user( $this->user ); |
|
91 | + wp_set_current_user($this->user); |
|
92 | 92 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
93 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/coupons/totals' ); |
|
94 | - $response = $this->server->dispatch( $request ); |
|
93 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/reports/coupons/totals'); |
|
94 | + $response = $this->server->dispatch($request); |
|
95 | 95 | $data = $response->get_data(); |
96 | 96 | $properties = $data['schema']['properties']; |
97 | 97 | |
98 | - $this->assertEquals( 3, count( $properties ) ); |
|
99 | - $this->assertArrayHasKey( 'slug', $properties ); |
|
100 | - $this->assertArrayHasKey( 'name', $properties ); |
|
101 | - $this->assertArrayHasKey( 'total', $properties ); |
|
98 | + $this->assertEquals(3, count($properties)); |
|
99 | + $this->assertArrayHasKey('slug', $properties); |
|
100 | + $this->assertArrayHasKey('name', $properties); |
|
101 | + $this->assertArrayHasKey('total', $properties); |
|
102 | 102 | } |
103 | 103 | } |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function test_register_routes() { |
30 | 30 | $routes = $this->server->get_routes(); |
31 | - $this->assertArrayHasKey( '/wc/v3/products/(?P<product_id>[\d]+)/variations', $routes ); |
|
32 | - $this->assertArrayHasKey( '/wc/v3/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes ); |
|
33 | - $this->assertArrayHasKey( '/wc/v3/products/(?P<product_id>[\d]+)/variations/batch', $routes ); |
|
31 | + $this->assertArrayHasKey('/wc/v3/products/(?P<product_id>[\d]+)/variations', $routes); |
|
32 | + $this->assertArrayHasKey('/wc/v3/products/(?P<product_id>[\d]+)/variations/(?P<id>[\d]+)', $routes); |
|
33 | + $this->assertArrayHasKey('/wc/v3/products/(?P<product_id>[\d]+)/variations/batch', $routes); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | * @since 3.5.0 |
40 | 40 | */ |
41 | 41 | public function test_get_variations() { |
42 | - wp_set_current_user( $this->user ); |
|
42 | + wp_set_current_user($this->user); |
|
43 | 43 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
44 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); |
|
44 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations')); |
|
45 | 45 | $variations = $response->get_data(); |
46 | - $this->assertEquals( 200, $response->get_status() ); |
|
47 | - $this->assertEquals( 2, count( $variations ) ); |
|
48 | - $this->assertEquals( 'DUMMY SKU VARIABLE LARGE', $variations[0]['sku'] ); |
|
49 | - $this->assertEquals( 'size', $variations[0]['attributes'][0]['name'] ); |
|
46 | + $this->assertEquals(200, $response->get_status()); |
|
47 | + $this->assertEquals(2, count($variations)); |
|
48 | + $this->assertEquals('DUMMY SKU VARIABLE LARGE', $variations[0]['sku']); |
|
49 | + $this->assertEquals('size', $variations[0]['attributes'][0]['name']); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | * @since 3.5.0 |
56 | 56 | */ |
57 | 57 | public function test_get_variations_without_permission() { |
58 | - wp_set_current_user( 0 ); |
|
58 | + wp_set_current_user(0); |
|
59 | 59 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
60 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); |
|
61 | - $this->assertEquals( 401, $response->get_status() ); |
|
60 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations')); |
|
61 | + $this->assertEquals(401, $response->get_status()); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -67,17 +67,17 @@ discard block |
||
67 | 67 | * @since 3.5.0 |
68 | 68 | */ |
69 | 69 | public function test_get_variation() { |
70 | - wp_set_current_user( $this->user ); |
|
70 | + wp_set_current_user($this->user); |
|
71 | 71 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
72 | 72 | $children = $product->get_children(); |
73 | 73 | $variation_id = $children[0]; |
74 | 74 | |
75 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); |
|
75 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id)); |
|
76 | 76 | $variation = $response->get_data(); |
77 | 77 | |
78 | - $this->assertEquals( 200, $response->get_status() ); |
|
79 | - $this->assertEquals( $variation_id, $variation['id'] ); |
|
80 | - $this->assertEquals( 'size', $variation['attributes'][0]['name'] ); |
|
78 | + $this->assertEquals(200, $response->get_status()); |
|
79 | + $this->assertEquals($variation_id, $variation['id']); |
|
80 | + $this->assertEquals('size', $variation['attributes'][0]['name']); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -86,12 +86,12 @@ discard block |
||
86 | 86 | * @since 3.5.0 |
87 | 87 | */ |
88 | 88 | public function test_get_variation_without_permission() { |
89 | - wp_set_current_user( 0 ); |
|
89 | + wp_set_current_user(0); |
|
90 | 90 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
91 | 91 | $children = $product->get_children(); |
92 | 92 | $variation_id = $children[0]; |
93 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); |
|
94 | - $this->assertEquals( 401, $response->get_status() ); |
|
93 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id)); |
|
94 | + $this->assertEquals(401, $response->get_status()); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -100,19 +100,19 @@ discard block |
||
100 | 100 | * @since 3.5.0 |
101 | 101 | */ |
102 | 102 | public function test_delete_variation() { |
103 | - wp_set_current_user( $this->user ); |
|
103 | + wp_set_current_user($this->user); |
|
104 | 104 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
105 | 105 | $children = $product->get_children(); |
106 | 106 | $variation_id = $children[0]; |
107 | 107 | |
108 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
109 | - $request->set_param( 'force', true ); |
|
110 | - $response = $this->server->dispatch( $request ); |
|
111 | - $this->assertEquals( 200, $response->get_status() ); |
|
108 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
109 | + $request->set_param('force', true); |
|
110 | + $response = $this->server->dispatch($request); |
|
111 | + $this->assertEquals(200, $response->get_status()); |
|
112 | 112 | |
113 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); |
|
113 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations')); |
|
114 | 114 | $variations = $response->get_data(); |
115 | - $this->assertEquals( 1, count( $variations ) ); |
|
115 | + $this->assertEquals(1, count($variations)); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | /** |
@@ -121,15 +121,15 @@ discard block |
||
121 | 121 | * @since 3.5.0 |
122 | 122 | */ |
123 | 123 | public function test_delete_variation_without_permission() { |
124 | - wp_set_current_user( 0 ); |
|
124 | + wp_set_current_user(0); |
|
125 | 125 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
126 | 126 | $children = $product->get_children(); |
127 | 127 | $variation_id = $children[0]; |
128 | 128 | |
129 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
130 | - $request->set_param( 'force', true ); |
|
131 | - $response = $this->server->dispatch( $request ); |
|
132 | - $this->assertEquals( 401, $response->get_status() ); |
|
129 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
130 | + $request->set_param('force', true); |
|
131 | + $response = $this->server->dispatch($request); |
|
132 | + $this->assertEquals(401, $response->get_status()); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
@@ -138,12 +138,12 @@ discard block |
||
138 | 138 | * @since 3.5.0 |
139 | 139 | */ |
140 | 140 | public function test_delete_variation_with_invalid_id() { |
141 | - wp_set_current_user( 0 ); |
|
141 | + wp_set_current_user(0); |
|
142 | 142 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
143 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/0' ); |
|
144 | - $request->set_param( 'force', true ); |
|
145 | - $response = $this->server->dispatch( $request ); |
|
146 | - $this->assertEquals( 404, $response->get_status() ); |
|
143 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/' . $product->get_id() . '/variations/0'); |
|
144 | + $request->set_param('force', true); |
|
145 | + $response = $this->server->dispatch($request); |
|
146 | + $this->assertEquals(404, $response->get_status()); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | /** |
@@ -152,20 +152,20 @@ discard block |
||
152 | 152 | * @since 3.5.0 |
153 | 153 | */ |
154 | 154 | public function test_update_variation() { |
155 | - wp_set_current_user( $this->user ); |
|
155 | + wp_set_current_user($this->user); |
|
156 | 156 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
157 | 157 | $children = $product->get_children(); |
158 | 158 | $variation_id = $children[0]; |
159 | 159 | |
160 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ) ); |
|
160 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id)); |
|
161 | 161 | $variation = $response->get_data(); |
162 | 162 | |
163 | - $this->assertEquals( 'DUMMY SKU VARIABLE SMALL', $variation['sku'] ); |
|
164 | - $this->assertEquals( 10, $variation['regular_price'] ); |
|
165 | - $this->assertEmpty( $variation['sale_price'] ); |
|
166 | - $this->assertEquals( 'small', $variation['attributes'][0]['option'] ); |
|
163 | + $this->assertEquals('DUMMY SKU VARIABLE SMALL', $variation['sku']); |
|
164 | + $this->assertEquals(10, $variation['regular_price']); |
|
165 | + $this->assertEmpty($variation['sale_price']); |
|
166 | + $this->assertEquals('small', $variation['attributes'][0]['option']); |
|
167 | 167 | |
168 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
168 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
169 | 169 | $request->set_body_params( |
170 | 170 | array( |
171 | 171 | 'sku' => 'FIXED-\'SKU', |
@@ -184,18 +184,18 @@ discard block |
||
184 | 184 | ), |
185 | 185 | ) |
186 | 186 | ); |
187 | - $response = $this->server->dispatch( $request ); |
|
187 | + $response = $this->server->dispatch($request); |
|
188 | 188 | $variation = $response->get_data(); |
189 | 189 | |
190 | - $this->assertTrue( isset( $variation['description'] ), print_r( $variation, true ) ); |
|
191 | - $this->assertContains( 'O_O', $variation['description'], print_r( $variation, true ) ); |
|
192 | - $this->assertEquals( '8', $variation['price'], print_r( $variation, true ) ); |
|
193 | - $this->assertEquals( '8', $variation['sale_price'], print_r( $variation, true ) ); |
|
194 | - $this->assertEquals( '10', $variation['regular_price'], print_r( $variation, true ) ); |
|
195 | - $this->assertEquals( 'FIXED-\'SKU', $variation['sku'], print_r( $variation, true ) ); |
|
196 | - $this->assertEquals( 'medium', $variation['attributes'][0]['option'], print_r( $variation, true ) ); |
|
197 | - $this->assertContains( 'Dr1Bczxq4q', $variation['image']['src'], print_r( $variation, true ) ); |
|
198 | - $this->assertContains( 'test upload image', $variation['image']['alt'], print_r( $variation, true ) ); |
|
190 | + $this->assertTrue(isset($variation['description']), print_r($variation, true)); |
|
191 | + $this->assertContains('O_O', $variation['description'], print_r($variation, true)); |
|
192 | + $this->assertEquals('8', $variation['price'], print_r($variation, true)); |
|
193 | + $this->assertEquals('8', $variation['sale_price'], print_r($variation, true)); |
|
194 | + $this->assertEquals('10', $variation['regular_price'], print_r($variation, true)); |
|
195 | + $this->assertEquals('FIXED-\'SKU', $variation['sku'], print_r($variation, true)); |
|
196 | + $this->assertEquals('medium', $variation['attributes'][0]['option'], print_r($variation, true)); |
|
197 | + $this->assertContains('Dr1Bczxq4q', $variation['image']['src'], print_r($variation, true)); |
|
198 | + $this->assertContains('test upload image', $variation['image']['alt'], print_r($variation, true)); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
@@ -204,19 +204,19 @@ discard block |
||
204 | 204 | * @since 3.5.0 |
205 | 205 | */ |
206 | 206 | public function test_update_variation_without_permission() { |
207 | - wp_set_current_user( 0 ); |
|
207 | + wp_set_current_user(0); |
|
208 | 208 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
209 | 209 | $children = $product->get_children(); |
210 | 210 | $variation_id = $children[0]; |
211 | 211 | |
212 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
212 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
213 | 213 | $request->set_body_params( |
214 | 214 | array( |
215 | 215 | 'sku' => 'FIXED-SKU-NO-PERMISSION', |
216 | 216 | ) |
217 | 217 | ); |
218 | - $response = $this->server->dispatch( $request ); |
|
219 | - $this->assertEquals( 401, $response->get_status() ); |
|
218 | + $response = $this->server->dispatch($request); |
|
219 | + $this->assertEquals(401, $response->get_status()); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -225,16 +225,16 @@ discard block |
||
225 | 225 | * @since 3.5.0 |
226 | 226 | */ |
227 | 227 | public function test_update_variation_with_invalid_id() { |
228 | - wp_set_current_user( $this->user ); |
|
228 | + wp_set_current_user($this->user); |
|
229 | 229 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
230 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/0' ); |
|
230 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/0'); |
|
231 | 231 | $request->set_body_params( |
232 | 232 | array( |
233 | 233 | 'sku' => 'FIXED-SKU-NO-PERMISSION', |
234 | 234 | ) |
235 | 235 | ); |
236 | - $response = $this->server->dispatch( $request ); |
|
237 | - $this->assertEquals( 400, $response->get_status() ); |
|
236 | + $response = $this->server->dispatch($request); |
|
237 | + $this->assertEquals(400, $response->get_status()); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -243,14 +243,14 @@ discard block |
||
243 | 243 | * @since 3.5.0 |
244 | 244 | */ |
245 | 245 | public function test_create_variation() { |
246 | - wp_set_current_user( $this->user ); |
|
246 | + wp_set_current_user($this->user); |
|
247 | 247 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
248 | 248 | |
249 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); |
|
249 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations')); |
|
250 | 250 | $variations = $response->get_data(); |
251 | - $this->assertEquals( 2, count( $variations ) ); |
|
251 | + $this->assertEquals(2, count($variations)); |
|
252 | 252 | |
253 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations' ); |
|
253 | + $request = new WP_REST_Request('POST', '/wc/v3/products/' . $product->get_id() . '/variations'); |
|
254 | 254 | $request->set_body_params( |
255 | 255 | array( |
256 | 256 | 'sku' => 'DUMMY SKU VARIABLE MEDIUM', |
@@ -264,19 +264,19 @@ discard block |
||
264 | 264 | ), |
265 | 265 | ) |
266 | 266 | ); |
267 | - $response = $this->server->dispatch( $request ); |
|
267 | + $response = $this->server->dispatch($request); |
|
268 | 268 | $variation = $response->get_data(); |
269 | 269 | |
270 | - $this->assertContains( 'A medium size.', $variation['description'] ); |
|
271 | - $this->assertEquals( '12', $variation['price'] ); |
|
272 | - $this->assertEquals( '12', $variation['regular_price'] ); |
|
273 | - $this->assertTrue( $variation['purchasable'] ); |
|
274 | - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $variation['sku'] ); |
|
275 | - $this->assertEquals( 'medium', $variation['attributes'][0]['option'] ); |
|
270 | + $this->assertContains('A medium size.', $variation['description']); |
|
271 | + $this->assertEquals('12', $variation['price']); |
|
272 | + $this->assertEquals('12', $variation['regular_price']); |
|
273 | + $this->assertTrue($variation['purchasable']); |
|
274 | + $this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $variation['sku']); |
|
275 | + $this->assertEquals('medium', $variation['attributes'][0]['option']); |
|
276 | 276 | |
277 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ) ); |
|
277 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations')); |
|
278 | 278 | $variations = $response->get_data(); |
279 | - $this->assertEquals( 3, count( $variations ) ); |
|
279 | + $this->assertEquals(3, count($variations)); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | /** |
@@ -285,10 +285,10 @@ discard block |
||
285 | 285 | * @since 3.5.0 |
286 | 286 | */ |
287 | 287 | public function test_create_variation_without_permission() { |
288 | - wp_set_current_user( 0 ); |
|
288 | + wp_set_current_user(0); |
|
289 | 289 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
290 | 290 | |
291 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations' ); |
|
291 | + $request = new WP_REST_Request('POST', '/wc/v3/products/' . $product->get_id() . '/variations'); |
|
292 | 292 | $request->set_body_params( |
293 | 293 | array( |
294 | 294 | 'sku' => 'DUMMY SKU VARIABLE MEDIUM', |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | ), |
303 | 303 | ) |
304 | 304 | ); |
305 | - $response = $this->server->dispatch( $request ); |
|
306 | - $this->assertEquals( 401, $response->get_status() ); |
|
305 | + $response = $this->server->dispatch($request); |
|
306 | + $this->assertEquals(401, $response->get_status()); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -312,10 +312,10 @@ discard block |
||
312 | 312 | * @since 3.5.0 |
313 | 313 | */ |
314 | 314 | public function test_product_variations_batch() { |
315 | - wp_set_current_user( $this->user ); |
|
315 | + wp_set_current_user($this->user); |
|
316 | 316 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
317 | 317 | $children = $product->get_children(); |
318 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/' . $product->get_id() . '/variations/batch' ); |
|
318 | + $request = new WP_REST_Request('POST', '/wc/v3/products/' . $product->get_id() . '/variations/batch'); |
|
319 | 319 | $request->set_body_params( |
320 | 320 | array( |
321 | 321 | 'update' => array( |
@@ -347,19 +347,19 @@ discard block |
||
347 | 347 | ), |
348 | 348 | ) |
349 | 349 | ); |
350 | - $response = $this->server->dispatch( $request ); |
|
350 | + $response = $this->server->dispatch($request); |
|
351 | 351 | $data = $response->get_data(); |
352 | 352 | |
353 | - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); |
|
354 | - $this->assertEquals( 'DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku'] ); |
|
355 | - $this->assertEquals( 'medium', $data['create'][0]['attributes'][0]['option'] ); |
|
356 | - $this->assertEquals( $children[1], $data['delete'][0]['id'] ); |
|
353 | + $this->assertContains('Updated description.', $data['update'][0]['description']); |
|
354 | + $this->assertEquals('DUMMY SKU VARIABLE MEDIUM', $data['create'][0]['sku']); |
|
355 | + $this->assertEquals('medium', $data['create'][0]['attributes'][0]['option']); |
|
356 | + $this->assertEquals($children[1], $data['delete'][0]['id']); |
|
357 | 357 | |
358 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() . '/variations' ); |
|
359 | - $response = $this->server->dispatch( $request ); |
|
358 | + $request = new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id() . '/variations'); |
|
359 | + $response = $this->server->dispatch($request); |
|
360 | 360 | $data = $response->get_data(); |
361 | 361 | |
362 | - $this->assertEquals( 2, count( $data ) ); |
|
362 | + $this->assertEquals(2, count($data)); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -368,48 +368,48 @@ discard block |
||
368 | 368 | * @since 3.5.0 |
369 | 369 | */ |
370 | 370 | public function test_variation_schema() { |
371 | - wp_set_current_user( $this->user ); |
|
371 | + wp_set_current_user($this->user); |
|
372 | 372 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
373 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/' . $product->get_id() . '/variations' ); |
|
374 | - $response = $this->server->dispatch( $request ); |
|
373 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/products/' . $product->get_id() . '/variations'); |
|
374 | + $response = $this->server->dispatch($request); |
|
375 | 375 | $data = $response->get_data(); |
376 | 376 | $properties = $data['schema']['properties']; |
377 | 377 | |
378 | - $this->assertEquals( 37, count( $properties ) ); |
|
379 | - $this->assertArrayHasKey( 'id', $properties ); |
|
380 | - $this->assertArrayHasKey( 'date_created', $properties ); |
|
381 | - $this->assertArrayHasKey( 'date_modified', $properties ); |
|
382 | - $this->assertArrayHasKey( 'description', $properties ); |
|
383 | - $this->assertArrayHasKey( 'permalink', $properties ); |
|
384 | - $this->assertArrayHasKey( 'sku', $properties ); |
|
385 | - $this->assertArrayHasKey( 'price', $properties ); |
|
386 | - $this->assertArrayHasKey( 'regular_price', $properties ); |
|
387 | - $this->assertArrayHasKey( 'sale_price', $properties ); |
|
388 | - $this->assertArrayHasKey( 'date_on_sale_from', $properties ); |
|
389 | - $this->assertArrayHasKey( 'date_on_sale_to', $properties ); |
|
390 | - $this->assertArrayHasKey( 'on_sale', $properties ); |
|
391 | - $this->assertArrayHasKey( 'purchasable', $properties ); |
|
392 | - $this->assertArrayHasKey( 'virtual', $properties ); |
|
393 | - $this->assertArrayHasKey( 'downloadable', $properties ); |
|
394 | - $this->assertArrayHasKey( 'downloads', $properties ); |
|
395 | - $this->assertArrayHasKey( 'download_limit', $properties ); |
|
396 | - $this->assertArrayHasKey( 'download_expiry', $properties ); |
|
397 | - $this->assertArrayHasKey( 'tax_status', $properties ); |
|
398 | - $this->assertArrayHasKey( 'tax_class', $properties ); |
|
399 | - $this->assertArrayHasKey( 'manage_stock', $properties ); |
|
400 | - $this->assertArrayHasKey( 'stock_quantity', $properties ); |
|
401 | - $this->assertArrayHasKey( 'stock_status', $properties ); |
|
402 | - $this->assertArrayHasKey( 'backorders', $properties ); |
|
403 | - $this->assertArrayHasKey( 'backorders_allowed', $properties ); |
|
404 | - $this->assertArrayHasKey( 'backordered', $properties ); |
|
405 | - $this->assertArrayHasKey( 'weight', $properties ); |
|
406 | - $this->assertArrayHasKey( 'dimensions', $properties ); |
|
407 | - $this->assertArrayHasKey( 'shipping_class', $properties ); |
|
408 | - $this->assertArrayHasKey( 'shipping_class_id', $properties ); |
|
409 | - $this->assertArrayHasKey( 'image', $properties ); |
|
410 | - $this->assertArrayHasKey( 'attributes', $properties ); |
|
411 | - $this->assertArrayHasKey( 'menu_order', $properties ); |
|
412 | - $this->assertArrayHasKey( 'meta_data', $properties ); |
|
378 | + $this->assertEquals(37, count($properties)); |
|
379 | + $this->assertArrayHasKey('id', $properties); |
|
380 | + $this->assertArrayHasKey('date_created', $properties); |
|
381 | + $this->assertArrayHasKey('date_modified', $properties); |
|
382 | + $this->assertArrayHasKey('description', $properties); |
|
383 | + $this->assertArrayHasKey('permalink', $properties); |
|
384 | + $this->assertArrayHasKey('sku', $properties); |
|
385 | + $this->assertArrayHasKey('price', $properties); |
|
386 | + $this->assertArrayHasKey('regular_price', $properties); |
|
387 | + $this->assertArrayHasKey('sale_price', $properties); |
|
388 | + $this->assertArrayHasKey('date_on_sale_from', $properties); |
|
389 | + $this->assertArrayHasKey('date_on_sale_to', $properties); |
|
390 | + $this->assertArrayHasKey('on_sale', $properties); |
|
391 | + $this->assertArrayHasKey('purchasable', $properties); |
|
392 | + $this->assertArrayHasKey('virtual', $properties); |
|
393 | + $this->assertArrayHasKey('downloadable', $properties); |
|
394 | + $this->assertArrayHasKey('downloads', $properties); |
|
395 | + $this->assertArrayHasKey('download_limit', $properties); |
|
396 | + $this->assertArrayHasKey('download_expiry', $properties); |
|
397 | + $this->assertArrayHasKey('tax_status', $properties); |
|
398 | + $this->assertArrayHasKey('tax_class', $properties); |
|
399 | + $this->assertArrayHasKey('manage_stock', $properties); |
|
400 | + $this->assertArrayHasKey('stock_quantity', $properties); |
|
401 | + $this->assertArrayHasKey('stock_status', $properties); |
|
402 | + $this->assertArrayHasKey('backorders', $properties); |
|
403 | + $this->assertArrayHasKey('backorders_allowed', $properties); |
|
404 | + $this->assertArrayHasKey('backordered', $properties); |
|
405 | + $this->assertArrayHasKey('weight', $properties); |
|
406 | + $this->assertArrayHasKey('dimensions', $properties); |
|
407 | + $this->assertArrayHasKey('shipping_class', $properties); |
|
408 | + $this->assertArrayHasKey('shipping_class_id', $properties); |
|
409 | + $this->assertArrayHasKey('image', $properties); |
|
410 | + $this->assertArrayHasKey('attributes', $properties); |
|
411 | + $this->assertArrayHasKey('menu_order', $properties); |
|
412 | + $this->assertArrayHasKey('meta_data', $properties); |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
@@ -418,57 +418,57 @@ discard block |
||
418 | 418 | * @since 3.5.0 |
419 | 419 | */ |
420 | 420 | public function test_update_variation_manage_stock() { |
421 | - wp_set_current_user( $this->user ); |
|
421 | + wp_set_current_user($this->user); |
|
422 | 422 | |
423 | 423 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
424 | - $product->set_manage_stock( false ); |
|
424 | + $product->set_manage_stock(false); |
|
425 | 425 | $product->save(); |
426 | 426 | |
427 | 427 | $children = $product->get_children(); |
428 | 428 | $variation_id = $children[0]; |
429 | 429 | |
430 | 430 | // Set stock to true. |
431 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
431 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
432 | 432 | $request->set_body_params( |
433 | 433 | array( |
434 | 434 | 'manage_stock' => true, |
435 | 435 | ) |
436 | 436 | ); |
437 | 437 | |
438 | - $response = $this->server->dispatch( $request ); |
|
438 | + $response = $this->server->dispatch($request); |
|
439 | 439 | $variation = $response->get_data(); |
440 | 440 | |
441 | - $this->assertEquals( 200, $response->get_status() ); |
|
442 | - $this->assertEquals( true, $variation['manage_stock'] ); |
|
441 | + $this->assertEquals(200, $response->get_status()); |
|
442 | + $this->assertEquals(true, $variation['manage_stock']); |
|
443 | 443 | |
444 | 444 | // Set stock to false. |
445 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
445 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
446 | 446 | $request->set_body_params( |
447 | 447 | array( |
448 | 448 | 'manage_stock' => false, |
449 | 449 | ) |
450 | 450 | ); |
451 | 451 | |
452 | - $response = $this->server->dispatch( $request ); |
|
452 | + $response = $this->server->dispatch($request); |
|
453 | 453 | $variation = $response->get_data(); |
454 | 454 | |
455 | - $this->assertEquals( 200, $response->get_status() ); |
|
456 | - $this->assertEquals( false, $variation['manage_stock'] ); |
|
455 | + $this->assertEquals(200, $response->get_status()); |
|
456 | + $this->assertEquals(false, $variation['manage_stock']); |
|
457 | 457 | |
458 | 458 | // Set stock to false but parent is managing stock. |
459 | - $product->set_manage_stock( true ); |
|
459 | + $product->set_manage_stock(true); |
|
460 | 460 | $product->save(); |
461 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id ); |
|
461 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id() . '/variations/' . $variation_id); |
|
462 | 462 | $request->set_body_params( |
463 | 463 | array( |
464 | 464 | 'manage_stock' => false, |
465 | 465 | ) |
466 | 466 | ); |
467 | 467 | |
468 | - $response = $this->server->dispatch( $request ); |
|
468 | + $response = $this->server->dispatch($request); |
|
469 | 469 | $variation = $response->get_data(); |
470 | 470 | |
471 | - $this->assertEquals( 200, $response->get_status() ); |
|
472 | - $this->assertEquals( 'parent', $variation['manage_stock'] ); |
|
471 | + $this->assertEquals(200, $response->get_status()); |
|
472 | + $this->assertEquals('parent', $variation['manage_stock']); |
|
473 | 473 | } |
474 | 474 | } |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function test_register_routes() { |
30 | 30 | $routes = $this->server->get_routes(); |
31 | - $this->assertArrayHasKey( '/wc/v3/coupons', $routes ); |
|
32 | - $this->assertArrayHasKey( '/wc/v3/coupons/(?P<id>[\d]+)', $routes ); |
|
33 | - $this->assertArrayHasKey( '/wc/v3/coupons/batch', $routes ); |
|
31 | + $this->assertArrayHasKey('/wc/v3/coupons', $routes); |
|
32 | + $this->assertArrayHasKey('/wc/v3/coupons/(?P<id>[\d]+)', $routes); |
|
33 | + $this->assertArrayHasKey('/wc/v3/coupons/batch', $routes); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | /** |
@@ -38,26 +38,26 @@ discard block |
||
38 | 38 | * @since 3.5.0 |
39 | 39 | */ |
40 | 40 | public function test_get_coupons() { |
41 | - wp_set_current_user( $this->user ); |
|
41 | + wp_set_current_user($this->user); |
|
42 | 42 | |
43 | - $coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
44 | - $post_1 = get_post( $coupon_1->get_id() ); |
|
45 | - $coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); |
|
43 | + $coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
44 | + $post_1 = get_post($coupon_1->get_id()); |
|
45 | + $coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-2'); |
|
46 | 46 | |
47 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) ); |
|
47 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons')); |
|
48 | 48 | $coupons = $response->get_data(); |
49 | 49 | |
50 | - $this->assertEquals( 200, $response->get_status() ); |
|
51 | - $this->assertEquals( 2, count( $coupons ) ); |
|
50 | + $this->assertEquals(200, $response->get_status()); |
|
51 | + $this->assertEquals(2, count($coupons)); |
|
52 | 52 | $this->assertContains( |
53 | 53 | array( |
54 | 54 | 'id' => $coupon_1->get_id(), |
55 | 55 | 'code' => 'dummycoupon-1', |
56 | 56 | 'amount' => '1.00', |
57 | - 'date_created' => wc_rest_prepare_date_response( $post_1->post_date_gmt, false ), |
|
58 | - 'date_created_gmt' => wc_rest_prepare_date_response( $post_1->post_date_gmt ), |
|
59 | - 'date_modified' => wc_rest_prepare_date_response( $post_1->post_modified_gmt, false ), |
|
60 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $post_1->post_modified_gmt ), |
|
57 | + 'date_created' => wc_rest_prepare_date_response($post_1->post_date_gmt, false), |
|
58 | + 'date_created_gmt' => wc_rest_prepare_date_response($post_1->post_date_gmt), |
|
59 | + 'date_modified' => wc_rest_prepare_date_response($post_1->post_modified_gmt, false), |
|
60 | + 'date_modified_gmt' => wc_rest_prepare_date_response($post_1->post_modified_gmt), |
|
61 | 61 | 'discount_type' => 'fixed_cart', |
62 | 62 | 'description' => 'This is a dummy coupon', |
63 | 63 | 'date_expires' => '', |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | '_links' => array( |
82 | 82 | 'self' => array( |
83 | 83 | array( |
84 | - 'href' => rest_url( '/wc/v3/coupons/' . $coupon_1->get_id() ), |
|
84 | + 'href' => rest_url('/wc/v3/coupons/' . $coupon_1->get_id()), |
|
85 | 85 | ), |
86 | 86 | ), |
87 | 87 | 'collection' => array( |
88 | 88 | array( |
89 | - 'href' => rest_url( '/wc/v3/coupons' ), |
|
89 | + 'href' => rest_url('/wc/v3/coupons'), |
|
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ), |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | * @since 3.5.0 |
101 | 101 | */ |
102 | 102 | public function test_get_coupons_without_permission() { |
103 | - wp_set_current_user( 0 ); |
|
104 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons' ) ); |
|
105 | - $this->assertEquals( 401, $response->get_status() ); |
|
103 | + wp_set_current_user(0); |
|
104 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons')); |
|
105 | + $this->assertEquals(401, $response->get_status()); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | * @since 3.5.0 |
111 | 111 | */ |
112 | 112 | public function test_get_coupon() { |
113 | - wp_set_current_user( $this->user ); |
|
114 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
115 | - $post = get_post( $coupon->get_id() ); |
|
116 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); |
|
113 | + wp_set_current_user($this->user); |
|
114 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
115 | + $post = get_post($coupon->get_id()); |
|
116 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons/' . $coupon->get_id())); |
|
117 | 117 | $data = $response->get_data(); |
118 | 118 | |
119 | - $this->assertEquals( 200, $response->get_status() ); |
|
119 | + $this->assertEquals(200, $response->get_status()); |
|
120 | 120 | $this->assertEquals( |
121 | 121 | array( |
122 | 122 | 'id' => $coupon->get_id(), |
123 | 123 | 'code' => 'dummycoupon-1', |
124 | 124 | 'amount' => '1.00', |
125 | - 'date_created' => wc_rest_prepare_date_response( $post->post_date_gmt, false ), |
|
126 | - 'date_created_gmt' => wc_rest_prepare_date_response( $post->post_date_gmt ), |
|
127 | - 'date_modified' => wc_rest_prepare_date_response( $post->post_modified_gmt, false ), |
|
128 | - 'date_modified_gmt' => wc_rest_prepare_date_response( $post->post_modified_gmt ), |
|
125 | + 'date_created' => wc_rest_prepare_date_response($post->post_date_gmt, false), |
|
126 | + 'date_created_gmt' => wc_rest_prepare_date_response($post->post_date_gmt), |
|
127 | + 'date_modified' => wc_rest_prepare_date_response($post->post_modified_gmt, false), |
|
128 | + 'date_modified_gmt' => wc_rest_prepare_date_response($post->post_modified_gmt), |
|
129 | 129 | 'discount_type' => 'fixed_cart', |
130 | 130 | 'description' => 'This is a dummy coupon', |
131 | 131 | 'date_expires' => null, |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | * @since 3.5.0 |
157 | 157 | */ |
158 | 158 | public function test_get_coupon_invalid_id() { |
159 | - wp_set_current_user( $this->user ); |
|
160 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/0' ) ); |
|
161 | - $this->assertEquals( 404, $response->get_status() ); |
|
159 | + wp_set_current_user($this->user); |
|
160 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons/0')); |
|
161 | + $this->assertEquals(404, $response->get_status()); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | * @since 3.5.0 |
167 | 167 | */ |
168 | 168 | public function test_get_coupon_without_permission() { |
169 | - wp_set_current_user( 0 ); |
|
170 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
171 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); |
|
172 | - $this->assertEquals( 401, $response->get_status() ); |
|
169 | + wp_set_current_user(0); |
|
170 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
171 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons/' . $coupon->get_id())); |
|
172 | + $this->assertEquals(401, $response->get_status()); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | * @since 3.5.0 |
178 | 178 | */ |
179 | 179 | public function test_create_coupon() { |
180 | - wp_set_current_user( $this->user ); |
|
181 | - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); |
|
180 | + wp_set_current_user($this->user); |
|
181 | + $request = new WP_REST_Request('POST', '/wc/v3/coupons'); |
|
182 | 182 | $request->set_body_params( |
183 | 183 | array( |
184 | 184 | 'code' => 'test', |
@@ -188,10 +188,10 @@ discard block |
||
188 | 188 | 'usage_limit' => 10, |
189 | 189 | ) |
190 | 190 | ); |
191 | - $response = $this->server->dispatch( $request ); |
|
191 | + $response = $this->server->dispatch($request); |
|
192 | 192 | $data = $response->get_data(); |
193 | 193 | |
194 | - $this->assertEquals( 201, $response->get_status() ); |
|
194 | + $this->assertEquals(201, $response->get_status()); |
|
195 | 195 | $this->assertEquals( |
196 | 196 | array( |
197 | 197 | 'id' => $data['id'], |
@@ -231,20 +231,20 @@ discard block |
||
231 | 231 | * @since 3.5.0 |
232 | 232 | */ |
233 | 233 | public function test_create_coupon_invalid_fields() { |
234 | - wp_set_current_user( $this->user ); |
|
234 | + wp_set_current_user($this->user); |
|
235 | 235 | |
236 | 236 | // test no code... |
237 | - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); |
|
237 | + $request = new WP_REST_Request('POST', '/wc/v3/coupons'); |
|
238 | 238 | $request->set_body_params( |
239 | 239 | array( |
240 | 240 | 'amount' => '5.00', |
241 | 241 | 'discount_type' => 'fixed_product', |
242 | 242 | ) |
243 | 243 | ); |
244 | - $response = $this->server->dispatch( $request ); |
|
244 | + $response = $this->server->dispatch($request); |
|
245 | 245 | $data = $response->get_data(); |
246 | 246 | |
247 | - $this->assertEquals( 400, $response->get_status() ); |
|
247 | + $this->assertEquals(400, $response->get_status()); |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | /** |
@@ -252,10 +252,10 @@ discard block |
||
252 | 252 | * @since 3.5.0 |
253 | 253 | */ |
254 | 254 | public function test_create_coupon_without_permission() { |
255 | - wp_set_current_user( 0 ); |
|
255 | + wp_set_current_user(0); |
|
256 | 256 | |
257 | 257 | // test no code... |
258 | - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons' ); |
|
258 | + $request = new WP_REST_Request('POST', '/wc/v3/coupons'); |
|
259 | 259 | $request->set_body_params( |
260 | 260 | array( |
261 | 261 | 'code' => 'fail', |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | 'discount_type' => 'fixed_product', |
264 | 264 | ) |
265 | 265 | ); |
266 | - $response = $this->server->dispatch( $request ); |
|
266 | + $response = $this->server->dispatch($request); |
|
267 | 267 | $data = $response->get_data(); |
268 | 268 | |
269 | - $this->assertEquals( 401, $response->get_status() ); |
|
269 | + $this->assertEquals(401, $response->get_status()); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -274,29 +274,29 @@ discard block |
||
274 | 274 | * @since 3.5.0 |
275 | 275 | */ |
276 | 276 | public function test_update_coupon() { |
277 | - wp_set_current_user( $this->user ); |
|
278 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
279 | - $post = get_post( $coupon->get_id() ); |
|
277 | + wp_set_current_user($this->user); |
|
278 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
279 | + $post = get_post($coupon->get_id()); |
|
280 | 280 | |
281 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/coupons/' . $coupon->get_id() ) ); |
|
281 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/coupons/' . $coupon->get_id())); |
|
282 | 282 | $data = $response->get_data(); |
283 | - $this->assertEquals( 'This is a dummy coupon', $data['description'] ); |
|
284 | - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); |
|
285 | - $this->assertEquals( '1.00', $data['amount'] ); |
|
283 | + $this->assertEquals('This is a dummy coupon', $data['description']); |
|
284 | + $this->assertEquals('fixed_cart', $data['discount_type']); |
|
285 | + $this->assertEquals('1.00', $data['amount']); |
|
286 | 286 | |
287 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() ); |
|
287 | + $request = new WP_REST_Request('PUT', '/wc/v3/coupons/' . $coupon->get_id()); |
|
288 | 288 | $request->set_body_params( |
289 | 289 | array( |
290 | 290 | 'amount' => '10.00', |
291 | 291 | 'description' => 'New description', |
292 | 292 | ) |
293 | 293 | ); |
294 | - $response = $this->server->dispatch( $request ); |
|
294 | + $response = $this->server->dispatch($request); |
|
295 | 295 | $data = $response->get_data(); |
296 | 296 | |
297 | - $this->assertEquals( '10.00', $data['amount'] ); |
|
298 | - $this->assertEquals( 'New description', $data['description'] ); |
|
299 | - $this->assertEquals( 'fixed_cart', $data['discount_type'] ); |
|
297 | + $this->assertEquals('10.00', $data['amount']); |
|
298 | + $this->assertEquals('New description', $data['description']); |
|
299 | + $this->assertEquals('fixed_cart', $data['discount_type']); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -304,9 +304,9 @@ discard block |
||
304 | 304 | * @since 3.5.0 |
305 | 305 | */ |
306 | 306 | public function test_update_coupon_invalid_id() { |
307 | - wp_set_current_user( $this->user ); |
|
307 | + wp_set_current_user($this->user); |
|
308 | 308 | |
309 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/0' ); |
|
309 | + $request = new WP_REST_Request('PUT', '/wc/v3/coupons/0'); |
|
310 | 310 | $request->set_body_params( |
311 | 311 | array( |
312 | 312 | 'code' => 'tester', |
@@ -314,10 +314,10 @@ discard block |
||
314 | 314 | 'description' => 'New description', |
315 | 315 | ) |
316 | 316 | ); |
317 | - $response = $this->server->dispatch( $request ); |
|
317 | + $response = $this->server->dispatch($request); |
|
318 | 318 | $data = $response->get_data(); |
319 | 319 | |
320 | - $this->assertEquals( 400, $response->get_status() ); |
|
320 | + $this->assertEquals(400, $response->get_status()); |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -325,20 +325,20 @@ discard block |
||
325 | 325 | * @since 3.5.0 |
326 | 326 | */ |
327 | 327 | public function test_update_coupon_without_permission() { |
328 | - wp_set_current_user( 0 ); |
|
329 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
330 | - $post = get_post( $coupon->get_id() ); |
|
328 | + wp_set_current_user(0); |
|
329 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
330 | + $post = get_post($coupon->get_id()); |
|
331 | 331 | |
332 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/coupons/' . $coupon->get_id() ); |
|
332 | + $request = new WP_REST_Request('PUT', '/wc/v3/coupons/' . $coupon->get_id()); |
|
333 | 333 | $request->set_body_params( |
334 | 334 | array( |
335 | 335 | 'amount' => '10.00', |
336 | 336 | 'description' => 'New description', |
337 | 337 | ) |
338 | 338 | ); |
339 | - $response = $this->server->dispatch( $request ); |
|
339 | + $response = $this->server->dispatch($request); |
|
340 | 340 | |
341 | - $this->assertEquals( 401, $response->get_status() ); |
|
341 | + $this->assertEquals(401, $response->get_status()); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | * @since 3.5.0 |
347 | 347 | */ |
348 | 348 | public function test_delete_coupon() { |
349 | - wp_set_current_user( $this->user ); |
|
350 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
351 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() ); |
|
352 | - $request->set_param( 'force', true ); |
|
353 | - $response = $this->server->dispatch( $request ); |
|
354 | - $this->assertEquals( 200, $response->get_status() ); |
|
349 | + wp_set_current_user($this->user); |
|
350 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
351 | + $request = new WP_REST_Request('DELETE', '/wc/v3/coupons/' . $coupon->get_id()); |
|
352 | + $request->set_param('force', true); |
|
353 | + $response = $this->server->dispatch($request); |
|
354 | + $this->assertEquals(200, $response->get_status()); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | /** |
@@ -359,12 +359,12 @@ discard block |
||
359 | 359 | * @since 3.5.0 |
360 | 360 | */ |
361 | 361 | public function test_delete_coupon_invalid_id() { |
362 | - wp_set_current_user( $this->user ); |
|
363 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/0' ); |
|
364 | - $request->set_param( 'force', true ); |
|
365 | - $response = $this->server->dispatch( $request ); |
|
362 | + wp_set_current_user($this->user); |
|
363 | + $request = new WP_REST_Request('DELETE', '/wc/v3/coupons/0'); |
|
364 | + $request->set_param('force', true); |
|
365 | + $response = $this->server->dispatch($request); |
|
366 | 366 | |
367 | - $this->assertEquals( 404, $response->get_status() ); |
|
367 | + $this->assertEquals(404, $response->get_status()); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -372,12 +372,12 @@ discard block |
||
372 | 372 | * @since 3.5.0 |
373 | 373 | */ |
374 | 374 | public function test_delete_coupon_without_permission() { |
375 | - wp_set_current_user( 0 ); |
|
376 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
377 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/coupons/' . $coupon->get_id() ); |
|
378 | - $response = $this->server->dispatch( $request ); |
|
375 | + wp_set_current_user(0); |
|
376 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
377 | + $request = new WP_REST_Request('DELETE', '/wc/v3/coupons/' . $coupon->get_id()); |
|
378 | + $response = $this->server->dispatch($request); |
|
379 | 379 | |
380 | - $this->assertEquals( 401, $response->get_status() ); |
|
380 | + $this->assertEquals(401, $response->get_status()); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -385,14 +385,14 @@ discard block |
||
385 | 385 | * @since 3.5.0 |
386 | 386 | */ |
387 | 387 | public function test_batch_coupon() { |
388 | - wp_set_current_user( $this->user ); |
|
388 | + wp_set_current_user($this->user); |
|
389 | 389 | |
390 | - $coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-1' ); |
|
391 | - $coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-2' ); |
|
392 | - $coupon_3 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-3' ); |
|
393 | - $coupon_4 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'dummycoupon-4' ); |
|
390 | + $coupon_1 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-1'); |
|
391 | + $coupon_2 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-2'); |
|
392 | + $coupon_3 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-3'); |
|
393 | + $coupon_4 = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('dummycoupon-4'); |
|
394 | 394 | |
395 | - $request = new WP_REST_Request( 'POST', '/wc/v3/coupons/batch' ); |
|
395 | + $request = new WP_REST_Request('POST', '/wc/v3/coupons/batch'); |
|
396 | 396 | $request->set_body_params( |
397 | 397 | array( |
398 | 398 | 'update' => array( |
@@ -413,20 +413,20 @@ discard block |
||
413 | 413 | ), |
414 | 414 | ) |
415 | 415 | ); |
416 | - $response = $this->server->dispatch( $request ); |
|
416 | + $response = $this->server->dispatch($request); |
|
417 | 417 | $data = $response->get_data(); |
418 | 418 | |
419 | - $this->assertEquals( '5.15', $data['update'][0]['amount'] ); |
|
420 | - $this->assertEquals( '11.00', $data['create'][0]['amount'] ); |
|
421 | - $this->assertEquals( 'new-coupon', $data['create'][0]['code'] ); |
|
422 | - $this->assertEquals( $coupon_2->get_id(), $data['delete'][0]['id'] ); |
|
423 | - $this->assertEquals( $coupon_3->get_id(), $data['delete'][1]['id'] ); |
|
419 | + $this->assertEquals('5.15', $data['update'][0]['amount']); |
|
420 | + $this->assertEquals('11.00', $data['create'][0]['amount']); |
|
421 | + $this->assertEquals('new-coupon', $data['create'][0]['code']); |
|
422 | + $this->assertEquals($coupon_2->get_id(), $data['delete'][0]['id']); |
|
423 | + $this->assertEquals($coupon_3->get_id(), $data['delete'][1]['id']); |
|
424 | 424 | |
425 | - $request = new WP_REST_Request( 'GET', '/wc/v3/coupons' ); |
|
426 | - $response = $this->server->dispatch( $request ); |
|
425 | + $request = new WP_REST_Request('GET', '/wc/v3/coupons'); |
|
426 | + $response = $this->server->dispatch($request); |
|
427 | 427 | $data = $response->get_data(); |
428 | 428 | |
429 | - $this->assertEquals( 3, count( $data ) ); |
|
429 | + $this->assertEquals(3, count($data)); |
|
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
@@ -434,38 +434,38 @@ discard block |
||
434 | 434 | * @since 3.5.0 |
435 | 435 | */ |
436 | 436 | public function test_coupon_schema() { |
437 | - wp_set_current_user( $this->user ); |
|
438 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/coupons' ); |
|
439 | - $response = $this->server->dispatch( $request ); |
|
437 | + wp_set_current_user($this->user); |
|
438 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/coupons'); |
|
439 | + $response = $this->server->dispatch($request); |
|
440 | 440 | $data = $response->get_data(); |
441 | 441 | $properties = $data['schema']['properties']; |
442 | 442 | |
443 | - $this->assertEquals( 27, count( $properties ) ); |
|
444 | - $this->assertArrayHasKey( 'id', $properties ); |
|
445 | - $this->assertArrayHasKey( 'code', $properties ); |
|
446 | - $this->assertArrayHasKey( 'date_created', $properties ); |
|
447 | - $this->assertArrayHasKey( 'date_created_gmt', $properties ); |
|
448 | - $this->assertArrayHasKey( 'date_modified', $properties ); |
|
449 | - $this->assertArrayHasKey( 'date_modified_gmt', $properties ); |
|
450 | - $this->assertArrayHasKey( 'description', $properties ); |
|
451 | - $this->assertArrayHasKey( 'discount_type', $properties ); |
|
452 | - $this->assertArrayHasKey( 'amount', $properties ); |
|
453 | - $this->assertArrayHasKey( 'date_expires', $properties ); |
|
454 | - $this->assertArrayHasKey( 'date_expires_gmt', $properties ); |
|
455 | - $this->assertArrayHasKey( 'usage_count', $properties ); |
|
456 | - $this->assertArrayHasKey( 'individual_use', $properties ); |
|
457 | - $this->assertArrayHasKey( 'product_ids', $properties ); |
|
458 | - $this->assertArrayHasKey( 'excluded_product_ids', $properties ); |
|
459 | - $this->assertArrayHasKey( 'usage_limit', $properties ); |
|
460 | - $this->assertArrayHasKey( 'usage_limit_per_user', $properties ); |
|
461 | - $this->assertArrayHasKey( 'limit_usage_to_x_items', $properties ); |
|
462 | - $this->assertArrayHasKey( 'free_shipping', $properties ); |
|
463 | - $this->assertArrayHasKey( 'product_categories', $properties ); |
|
464 | - $this->assertArrayHasKey( 'excluded_product_categories', $properties ); |
|
465 | - $this->assertArrayHasKey( 'exclude_sale_items', $properties ); |
|
466 | - $this->assertArrayHasKey( 'minimum_amount', $properties ); |
|
467 | - $this->assertArrayHasKey( 'maximum_amount', $properties ); |
|
468 | - $this->assertArrayHasKey( 'email_restrictions', $properties ); |
|
469 | - $this->assertArrayHasKey( 'used_by', $properties ); |
|
443 | + $this->assertEquals(27, count($properties)); |
|
444 | + $this->assertArrayHasKey('id', $properties); |
|
445 | + $this->assertArrayHasKey('code', $properties); |
|
446 | + $this->assertArrayHasKey('date_created', $properties); |
|
447 | + $this->assertArrayHasKey('date_created_gmt', $properties); |
|
448 | + $this->assertArrayHasKey('date_modified', $properties); |
|
449 | + $this->assertArrayHasKey('date_modified_gmt', $properties); |
|
450 | + $this->assertArrayHasKey('description', $properties); |
|
451 | + $this->assertArrayHasKey('discount_type', $properties); |
|
452 | + $this->assertArrayHasKey('amount', $properties); |
|
453 | + $this->assertArrayHasKey('date_expires', $properties); |
|
454 | + $this->assertArrayHasKey('date_expires_gmt', $properties); |
|
455 | + $this->assertArrayHasKey('usage_count', $properties); |
|
456 | + $this->assertArrayHasKey('individual_use', $properties); |
|
457 | + $this->assertArrayHasKey('product_ids', $properties); |
|
458 | + $this->assertArrayHasKey('excluded_product_ids', $properties); |
|
459 | + $this->assertArrayHasKey('usage_limit', $properties); |
|
460 | + $this->assertArrayHasKey('usage_limit_per_user', $properties); |
|
461 | + $this->assertArrayHasKey('limit_usage_to_x_items', $properties); |
|
462 | + $this->assertArrayHasKey('free_shipping', $properties); |
|
463 | + $this->assertArrayHasKey('product_categories', $properties); |
|
464 | + $this->assertArrayHasKey('excluded_product_categories', $properties); |
|
465 | + $this->assertArrayHasKey('exclude_sale_items', $properties); |
|
466 | + $this->assertArrayHasKey('minimum_amount', $properties); |
|
467 | + $this->assertArrayHasKey('maximum_amount', $properties); |
|
468 | + $this->assertArrayHasKey('email_restrictions', $properties); |
|
469 | + $this->assertArrayHasKey('used_by', $properties); |
|
470 | 470 | } |
471 | 471 | } |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function test_register_routes() { |
38 | 38 | $routes = $this->server->get_routes(); |
39 | - $this->assertArrayHasKey( '/wc/v3/orders', $routes ); |
|
40 | - $this->assertArrayHasKey( '/wc/v3/orders/batch', $routes ); |
|
41 | - $this->assertArrayHasKey( '/wc/v3/orders/(?P<id>[\d]+)', $routes ); |
|
39 | + $this->assertArrayHasKey('/wc/v3/orders', $routes); |
|
40 | + $this->assertArrayHasKey('/wc/v3/orders/batch', $routes); |
|
41 | + $this->assertArrayHasKey('/wc/v3/orders/(?P<id>[\d]+)', $routes); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | /** |
@@ -46,18 +46,18 @@ discard block |
||
46 | 46 | * @since 3.5.0 |
47 | 47 | */ |
48 | 48 | public function test_get_items() { |
49 | - wp_set_current_user( $this->user ); |
|
49 | + wp_set_current_user($this->user); |
|
50 | 50 | |
51 | 51 | // Create 10 orders. |
52 | - for ( $i = 0; $i < 10; $i++ ) { |
|
53 | - $this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order( $this->user ); |
|
52 | + for ($i = 0; $i < 10; $i++) { |
|
53 | + $this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order($this->user); |
|
54 | 54 | } |
55 | 55 | |
56 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders' ) ); |
|
56 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders')); |
|
57 | 57 | $orders = $response->get_data(); |
58 | 58 | |
59 | - $this->assertEquals( 200, $response->get_status() ); |
|
60 | - $this->assertEquals( 10, count( $orders ) ); |
|
59 | + $this->assertEquals(200, $response->get_status()); |
|
60 | + $this->assertEquals(10, count($orders)); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -66,10 +66,10 @@ discard block |
||
66 | 66 | * @since 3.5.0 |
67 | 67 | */ |
68 | 68 | public function test_get_items_without_permission() { |
69 | - wp_set_current_user( 0 ); |
|
69 | + wp_set_current_user(0); |
|
70 | 70 | $this->orders[] = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
71 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders' ) ); |
|
72 | - $this->assertEquals( 401, $response->get_status() ); |
|
71 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders')); |
|
72 | + $this->assertEquals(401, $response->get_status()); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -77,23 +77,23 @@ discard block |
||
77 | 77 | * @since 3.5.0 |
78 | 78 | */ |
79 | 79 | public function test_get_item() { |
80 | - wp_set_current_user( $this->user ); |
|
80 | + wp_set_current_user($this->user); |
|
81 | 81 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
82 | - $order->add_meta_data( 'key', 'value' ); |
|
83 | - $order->add_meta_data( 'key2', 'value2' ); |
|
82 | + $order->add_meta_data('key', 'value'); |
|
83 | + $order->add_meta_data('key2', 'value2'); |
|
84 | 84 | $order->save(); |
85 | 85 | $this->orders[] = $order; |
86 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $order->get_id() ) ); |
|
86 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders/' . $order->get_id())); |
|
87 | 87 | $data = $response->get_data(); |
88 | 88 | |
89 | - $this->assertEquals( 200, $response->get_status() ); |
|
90 | - $this->assertEquals( $order->get_id(), $data['id'] ); |
|
89 | + $this->assertEquals(200, $response->get_status()); |
|
90 | + $this->assertEquals($order->get_id(), $data['id']); |
|
91 | 91 | |
92 | 92 | // Test meta data is set. |
93 | - $this->assertEquals( 'key', $data['meta_data'][0]->key ); |
|
94 | - $this->assertEquals( 'value', $data['meta_data'][0]->value ); |
|
95 | - $this->assertEquals( 'key2', $data['meta_data'][1]->key ); |
|
96 | - $this->assertEquals( 'value2', $data['meta_data'][1]->value ); |
|
93 | + $this->assertEquals('key', $data['meta_data'][0]->key); |
|
94 | + $this->assertEquals('value', $data['meta_data'][0]->value); |
|
95 | + $this->assertEquals('key2', $data['meta_data'][1]->key); |
|
96 | + $this->assertEquals('value2', $data['meta_data'][1]->value); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,11 +101,11 @@ discard block |
||
101 | 101 | * @since 3.5.0 |
102 | 102 | */ |
103 | 103 | public function test_get_item_without_permission() { |
104 | - wp_set_current_user( 0 ); |
|
104 | + wp_set_current_user(0); |
|
105 | 105 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
106 | 106 | $this->orders[] = $order; |
107 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $order->get_id() ) ); |
|
108 | - $this->assertEquals( 401, $response->get_status() ); |
|
107 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders/' . $order->get_id())); |
|
108 | + $this->assertEquals(401, $response->get_status()); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -113,9 +113,9 @@ discard block |
||
113 | 113 | * @since 3.5.0 |
114 | 114 | */ |
115 | 115 | public function test_get_item_invalid_id() { |
116 | - wp_set_current_user( $this->user ); |
|
117 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/99999999' ) ); |
|
118 | - $this->assertEquals( 404, $response->get_status() ); |
|
116 | + wp_set_current_user($this->user); |
|
117 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders/99999999')); |
|
118 | + $this->assertEquals(404, $response->get_status()); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @since 3.5.0 |
124 | 124 | */ |
125 | 125 | public function test_get_item_refund_id() { |
126 | - wp_set_current_user( $this->user ); |
|
126 | + wp_set_current_user($this->user); |
|
127 | 127 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
128 | 128 | $refund = wc_create_refund( |
129 | 129 | array( |
130 | 130 | 'order_id' => $order->get_id(), |
131 | 131 | ) |
132 | 132 | ); |
133 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/orders/' . $refund->get_id() ) ); |
|
134 | - $this->assertEquals( 404, $response->get_status() ); |
|
133 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/orders/' . $refund->get_id())); |
|
134 | + $this->assertEquals(404, $response->get_status()); |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @since 3.5.0 |
140 | 140 | */ |
141 | 141 | public function test_create_order() { |
142 | - wp_set_current_user( $this->user ); |
|
142 | + wp_set_current_user($this->user); |
|
143 | 143 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
144 | - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); |
|
144 | + $request = new WP_REST_Request('POST', '/wc/v3/orders'); |
|
145 | 145 | $request->set_body_params( |
146 | 146 | array( |
147 | 147 | 'payment_method' => 'bacs', |
@@ -184,34 +184,34 @@ discard block |
||
184 | 184 | ), |
185 | 185 | ) |
186 | 186 | ); |
187 | - $response = $this->server->dispatch( $request ); |
|
187 | + $response = $this->server->dispatch($request); |
|
188 | 188 | $data = $response->get_data(); |
189 | - $order = wc_get_order( $data['id'] ); |
|
190 | - $this->assertEquals( 201, $response->get_status() ); |
|
191 | - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); |
|
192 | - $this->assertEquals( $order->get_payment_method_title(), $data['payment_method_title'] ); |
|
193 | - $this->assertEquals( $order->get_billing_first_name(), $data['billing']['first_name'] ); |
|
194 | - $this->assertEquals( $order->get_billing_last_name(), $data['billing']['last_name'] ); |
|
195 | - $this->assertEquals( '', $data['billing']['company'] ); |
|
196 | - $this->assertEquals( $order->get_billing_address_1(), $data['billing']['address_1'] ); |
|
197 | - $this->assertEquals( $order->get_billing_address_2(), $data['billing']['address_2'] ); |
|
198 | - $this->assertEquals( $order->get_billing_city(), $data['billing']['city'] ); |
|
199 | - $this->assertEquals( $order->get_billing_state(), $data['billing']['state'] ); |
|
200 | - $this->assertEquals( $order->get_billing_postcode(), $data['billing']['postcode'] ); |
|
201 | - $this->assertEquals( $order->get_billing_country(), $data['billing']['country'] ); |
|
202 | - $this->assertEquals( $order->get_billing_email(), $data['billing']['email'] ); |
|
203 | - $this->assertEquals( $order->get_billing_phone(), $data['billing']['phone'] ); |
|
204 | - $this->assertEquals( $order->get_shipping_first_name(), $data['shipping']['first_name'] ); |
|
205 | - $this->assertEquals( $order->get_shipping_last_name(), $data['shipping']['last_name'] ); |
|
206 | - $this->assertEquals( '', $data['shipping']['company'] ); |
|
207 | - $this->assertEquals( $order->get_shipping_address_1(), $data['shipping']['address_1'] ); |
|
208 | - $this->assertEquals( $order->get_shipping_address_2(), $data['shipping']['address_2'] ); |
|
209 | - $this->assertEquals( $order->get_shipping_city(), $data['shipping']['city'] ); |
|
210 | - $this->assertEquals( $order->get_shipping_state(), $data['shipping']['state'] ); |
|
211 | - $this->assertEquals( $order->get_shipping_postcode(), $data['shipping']['postcode'] ); |
|
212 | - $this->assertEquals( $order->get_shipping_country(), $data['shipping']['country'] ); |
|
213 | - $this->assertEquals( 1, count( $data['line_items'] ) ); |
|
214 | - $this->assertEquals( 1, count( $data['shipping_lines'] ) ); |
|
189 | + $order = wc_get_order($data['id']); |
|
190 | + $this->assertEquals(201, $response->get_status()); |
|
191 | + $this->assertEquals($order->get_payment_method(), $data['payment_method']); |
|
192 | + $this->assertEquals($order->get_payment_method_title(), $data['payment_method_title']); |
|
193 | + $this->assertEquals($order->get_billing_first_name(), $data['billing']['first_name']); |
|
194 | + $this->assertEquals($order->get_billing_last_name(), $data['billing']['last_name']); |
|
195 | + $this->assertEquals('', $data['billing']['company']); |
|
196 | + $this->assertEquals($order->get_billing_address_1(), $data['billing']['address_1']); |
|
197 | + $this->assertEquals($order->get_billing_address_2(), $data['billing']['address_2']); |
|
198 | + $this->assertEquals($order->get_billing_city(), $data['billing']['city']); |
|
199 | + $this->assertEquals($order->get_billing_state(), $data['billing']['state']); |
|
200 | + $this->assertEquals($order->get_billing_postcode(), $data['billing']['postcode']); |
|
201 | + $this->assertEquals($order->get_billing_country(), $data['billing']['country']); |
|
202 | + $this->assertEquals($order->get_billing_email(), $data['billing']['email']); |
|
203 | + $this->assertEquals($order->get_billing_phone(), $data['billing']['phone']); |
|
204 | + $this->assertEquals($order->get_shipping_first_name(), $data['shipping']['first_name']); |
|
205 | + $this->assertEquals($order->get_shipping_last_name(), $data['shipping']['last_name']); |
|
206 | + $this->assertEquals('', $data['shipping']['company']); |
|
207 | + $this->assertEquals($order->get_shipping_address_1(), $data['shipping']['address_1']); |
|
208 | + $this->assertEquals($order->get_shipping_address_2(), $data['shipping']['address_2']); |
|
209 | + $this->assertEquals($order->get_shipping_city(), $data['shipping']['city']); |
|
210 | + $this->assertEquals($order->get_shipping_state(), $data['shipping']['state']); |
|
211 | + $this->assertEquals($order->get_shipping_postcode(), $data['shipping']['postcode']); |
|
212 | + $this->assertEquals($order->get_shipping_country(), $data['shipping']['country']); |
|
213 | + $this->assertEquals(1, count($data['line_items'])); |
|
214 | + $this->assertEquals(1, count($data['shipping_lines'])); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -220,11 +220,11 @@ discard block |
||
220 | 220 | * @since 3.5.2 |
221 | 221 | */ |
222 | 222 | public function test_create_update_order_payment_method_title_sanitize() { |
223 | - wp_set_current_user( $this->user ); |
|
223 | + wp_set_current_user($this->user); |
|
224 | 224 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
225 | 225 | |
226 | 226 | // Test when creating order. |
227 | - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); |
|
227 | + $request = new WP_REST_Request('POST', '/wc/v3/orders'); |
|
228 | 228 | $request->set_body_params( |
229 | 229 | array( |
230 | 230 | 'payment_method' => 'bacs', |
@@ -267,27 +267,27 @@ discard block |
||
267 | 267 | ), |
268 | 268 | ) |
269 | 269 | ); |
270 | - $response = $this->server->dispatch( $request ); |
|
270 | + $response = $this->server->dispatch($request); |
|
271 | 271 | $data = $response->get_data(); |
272 | - $order = wc_get_order( $data['id'] ); |
|
273 | - $this->assertEquals( 201, $response->get_status() ); |
|
274 | - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); |
|
275 | - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this' ); |
|
272 | + $order = wc_get_order($data['id']); |
|
273 | + $this->assertEquals(201, $response->get_status()); |
|
274 | + $this->assertEquals($order->get_payment_method(), $data['payment_method']); |
|
275 | + $this->assertEquals($order->get_payment_method_title(), 'Sanitize this'); |
|
276 | 276 | |
277 | 277 | // Test when updating order. |
278 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $data['id'] ); |
|
278 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $data['id']); |
|
279 | 279 | $request->set_body_params( |
280 | 280 | array( |
281 | 281 | 'payment_method' => 'bacs', |
282 | 282 | 'payment_method_title' => '<h1>Sanitize this too <script>alert(1);</script></h1>', |
283 | 283 | ) |
284 | 284 | ); |
285 | - $response = $this->server->dispatch( $request ); |
|
285 | + $response = $this->server->dispatch($request); |
|
286 | 286 | $data = $response->get_data(); |
287 | - $order = wc_get_order( $data['id'] ); |
|
288 | - $this->assertEquals( 200, $response->get_status() ); |
|
289 | - $this->assertEquals( $order->get_payment_method(), $data['payment_method'] ); |
|
290 | - $this->assertEquals( $order->get_payment_method_title(), 'Sanitize this too' ); |
|
287 | + $order = wc_get_order($data['id']); |
|
288 | + $this->assertEquals(200, $response->get_status()); |
|
289 | + $this->assertEquals($order->get_payment_method(), $data['payment_method']); |
|
290 | + $this->assertEquals($order->get_payment_method_title(), 'Sanitize this too'); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
@@ -295,11 +295,11 @@ discard block |
||
295 | 295 | * @since 3.5.0 |
296 | 296 | */ |
297 | 297 | public function test_create_order_invalid_fields() { |
298 | - wp_set_current_user( $this->user ); |
|
298 | + wp_set_current_user($this->user); |
|
299 | 299 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
300 | 300 | |
301 | 301 | // Non-existent customer. |
302 | - $request = new WP_REST_Request( 'POST', '/wc/v3/orders' ); |
|
302 | + $request = new WP_REST_Request('POST', '/wc/v3/orders'); |
|
303 | 303 | $request->set_body_params( |
304 | 304 | array( |
305 | 305 | 'payment_method' => 'bacs', |
@@ -343,9 +343,9 @@ discard block |
||
343 | 343 | ), |
344 | 344 | ) |
345 | 345 | ); |
346 | - $response = $this->server->dispatch( $request ); |
|
346 | + $response = $this->server->dispatch($request); |
|
347 | 347 | $data = $response->get_data(); |
348 | - $this->assertEquals( 400, $response->get_status() ); |
|
348 | + $this->assertEquals(400, $response->get_status()); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | * @since 3.5.0 |
355 | 355 | */ |
356 | 356 | public function test_update_order() { |
357 | - wp_set_current_user( $this->user ); |
|
357 | + wp_set_current_user($this->user); |
|
358 | 358 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
359 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
359 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
360 | 360 | $request->set_body_params( |
361 | 361 | array( |
362 | 362 | 'payment_method' => 'test-update', |
@@ -366,13 +366,13 @@ discard block |
||
366 | 366 | ), |
367 | 367 | ) |
368 | 368 | ); |
369 | - $response = $this->server->dispatch( $request ); |
|
369 | + $response = $this->server->dispatch($request); |
|
370 | 370 | $data = $response->get_data(); |
371 | 371 | |
372 | - $this->assertEquals( 200, $response->get_status() ); |
|
373 | - $this->assertEquals( 'test-update', $data['payment_method'] ); |
|
374 | - $this->assertEquals( 'Fish', $data['billing']['first_name'] ); |
|
375 | - $this->assertEquals( 'Face', $data['billing']['last_name'] ); |
|
372 | + $this->assertEquals(200, $response->get_status()); |
|
373 | + $this->assertEquals('test-update', $data['payment_method']); |
|
374 | + $this->assertEquals('Fish', $data['billing']['first_name']); |
|
375 | + $this->assertEquals('Face', $data['billing']['last_name']); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @since 3.5.0 |
382 | 382 | */ |
383 | 383 | public function test_update_order_remove_items() { |
384 | - wp_set_current_user( $this->user ); |
|
384 | + wp_set_current_user($this->user); |
|
385 | 385 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
386 | 386 | $fee = new WC_Order_Item_Fee(); |
387 | 387 | $fee->set_props( |
@@ -392,11 +392,11 @@ discard block |
||
392 | 392 | 'tax_class' => '', |
393 | 393 | ) |
394 | 394 | ); |
395 | - $order->add_item( $fee ); |
|
395 | + $order->add_item($fee); |
|
396 | 396 | $order->save(); |
397 | 397 | |
398 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
399 | - $fee_data = current( $order->get_items( 'fee' ) ); |
|
398 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
399 | + $fee_data = current($order->get_items('fee')); |
|
400 | 400 | |
401 | 401 | $request->set_body_params( |
402 | 402 | array( |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | ), |
409 | 409 | ) |
410 | 410 | ); |
411 | - $response = $this->server->dispatch( $request ); |
|
411 | + $response = $this->server->dispatch($request); |
|
412 | 412 | $data = $response->get_data(); |
413 | 413 | |
414 | - $this->assertEquals( 200, $response->get_status() ); |
|
415 | - $this->assertTrue( empty( $data['fee_lines'] ) ); |
|
414 | + $this->assertEquals(200, $response->get_status()); |
|
415 | + $this->assertTrue(empty($data['fee_lines'])); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | /** |
@@ -421,15 +421,15 @@ discard block |
||
421 | 421 | * @since 3.5.0 |
422 | 422 | */ |
423 | 423 | public function test_update_order_add_coupons() { |
424 | - wp_set_current_user( $this->user ); |
|
424 | + wp_set_current_user($this->user); |
|
425 | 425 | |
426 | 426 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
427 | - $order_item = current( $order->get_items() ); |
|
428 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); |
|
429 | - $coupon->set_amount( 5 ); |
|
427 | + $order_item = current($order->get_items()); |
|
428 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon'); |
|
429 | + $coupon->set_amount(5); |
|
430 | 430 | $coupon->save(); |
431 | 431 | |
432 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
432 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
433 | 433 | $request->set_body_params( |
434 | 434 | array( |
435 | 435 | 'coupon_lines' => array( |
@@ -439,12 +439,12 @@ discard block |
||
439 | 439 | ), |
440 | 440 | ) |
441 | 441 | ); |
442 | - $response = $this->server->dispatch( $request ); |
|
442 | + $response = $this->server->dispatch($request); |
|
443 | 443 | $data = $response->get_data(); |
444 | 444 | |
445 | - $this->assertEquals( 200, $response->get_status() ); |
|
446 | - $this->assertCount( 1, $data['coupon_lines'] ); |
|
447 | - $this->assertEquals( '45.00', $data['total'] ); |
|
445 | + $this->assertEquals(200, $response->get_status()); |
|
446 | + $this->assertCount(1, $data['coupon_lines']); |
|
447 | + $this->assertEquals('45.00', $data['total']); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
@@ -453,21 +453,21 @@ discard block |
||
453 | 453 | * @since 3.5.0 |
454 | 454 | */ |
455 | 455 | public function test_update_order_remove_coupons() { |
456 | - wp_set_current_user( $this->user ); |
|
456 | + wp_set_current_user($this->user); |
|
457 | 457 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
458 | - $order_item = current( $order->get_items() ); |
|
459 | - $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon( 'fake-coupon' ); |
|
460 | - $coupon->set_amount( 5 ); |
|
458 | + $order_item = current($order->get_items()); |
|
459 | + $coupon = \WooCommerce\RestApi\UnitTests\Helpers\CouponHelper::create_coupon('fake-coupon'); |
|
460 | + $coupon->set_amount(5); |
|
461 | 461 | $coupon->save(); |
462 | 462 | |
463 | - $order->apply_coupon( $coupon ); |
|
463 | + $order->apply_coupon($coupon); |
|
464 | 464 | $order->save(); |
465 | 465 | |
466 | 466 | // Check that the coupon is applied. |
467 | - $this->assertEquals( '45.00', $order->get_total() ); |
|
467 | + $this->assertEquals('45.00', $order->get_total()); |
|
468 | 468 | |
469 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
470 | - $coupon_data = current( $order->get_items( 'coupon' ) ); |
|
469 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
470 | + $coupon_data = current($order->get_items('coupon')); |
|
471 | 471 | |
472 | 472 | $request->set_body_params( |
473 | 473 | array( |
@@ -486,12 +486,12 @@ discard block |
||
486 | 486 | ), |
487 | 487 | ) |
488 | 488 | ); |
489 | - $response = $this->server->dispatch( $request ); |
|
489 | + $response = $this->server->dispatch($request); |
|
490 | 490 | $data = $response->get_data(); |
491 | 491 | |
492 | - $this->assertEquals( 200, $response->get_status() ); |
|
493 | - $this->assertTrue( empty( $data['coupon_lines'] ) ); |
|
494 | - $this->assertEquals( '50.00', $data['total'] ); |
|
492 | + $this->assertEquals(200, $response->get_status()); |
|
493 | + $this->assertTrue(empty($data['coupon_lines'])); |
|
494 | + $this->assertEquals('50.00', $data['total']); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | /** |
@@ -500,9 +500,9 @@ discard block |
||
500 | 500 | * @since 3.5.0 |
501 | 501 | */ |
502 | 502 | public function test_invalid_coupon() { |
503 | - wp_set_current_user( $this->user ); |
|
503 | + wp_set_current_user($this->user); |
|
504 | 504 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
505 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
505 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
506 | 506 | |
507 | 507 | $request->set_body_params( |
508 | 508 | array( |
@@ -513,12 +513,12 @@ discard block |
||
513 | 513 | ), |
514 | 514 | ) |
515 | 515 | ); |
516 | - $response = $this->server->dispatch( $request ); |
|
516 | + $response = $this->server->dispatch($request); |
|
517 | 517 | $data = $response->get_data(); |
518 | 518 | |
519 | - $this->assertEquals( 400, $response->get_status() ); |
|
520 | - $this->assertEquals( 'woocommerce_rest_invalid_coupon', $data['code'] ); |
|
521 | - $this->assertEquals( 'Coupon "non_existing_coupon" does not exist!', $data['message'] ); |
|
519 | + $this->assertEquals(400, $response->get_status()); |
|
520 | + $this->assertEquals('woocommerce_rest_invalid_coupon', $data['code']); |
|
521 | + $this->assertEquals('Coupon "non_existing_coupon" does not exist!', $data['message']); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | /** |
@@ -527,9 +527,9 @@ discard block |
||
527 | 527 | * @since 3.5.0 |
528 | 528 | */ |
529 | 529 | public function test_update_order_without_permission() { |
530 | - wp_set_current_user( 0 ); |
|
530 | + wp_set_current_user(0); |
|
531 | 531 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
532 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/orders/' . $order->get_id() ); |
|
532 | + $request = new WP_REST_Request('PUT', '/wc/v3/orders/' . $order->get_id()); |
|
533 | 533 | $request->set_body_params( |
534 | 534 | array( |
535 | 535 | 'payment_method' => 'test-update', |
@@ -539,8 +539,8 @@ discard block |
||
539 | 539 | ), |
540 | 540 | ) |
541 | 541 | ); |
542 | - $response = $this->server->dispatch( $request ); |
|
543 | - $this->assertEquals( 401, $response->get_status() ); |
|
542 | + $response = $this->server->dispatch($request); |
|
543 | + $this->assertEquals(401, $response->get_status()); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -549,8 +549,8 @@ discard block |
||
549 | 549 | * @since 3.5.0 |
550 | 550 | */ |
551 | 551 | public function test_update_order_invalid_id() { |
552 | - wp_set_current_user( $this->user ); |
|
553 | - $request = new WP_REST_Request( 'POST', '/wc/v3/orders/999999' ); |
|
552 | + wp_set_current_user($this->user); |
|
553 | + $request = new WP_REST_Request('POST', '/wc/v3/orders/999999'); |
|
554 | 554 | $request->set_body_params( |
555 | 555 | array( |
556 | 556 | 'payment_method' => 'test-update', |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | ), |
561 | 561 | ) |
562 | 562 | ); |
563 | - $response = $this->server->dispatch( $request ); |
|
564 | - $this->assertEquals( 400, $response->get_status() ); |
|
563 | + $response = $this->server->dispatch($request); |
|
564 | + $this->assertEquals(400, $response->get_status()); |
|
565 | 565 | } |
566 | 566 | |
567 | 567 | /** |
@@ -570,13 +570,13 @@ discard block |
||
570 | 570 | * @since 3.5.0 |
571 | 571 | */ |
572 | 572 | public function test_delete_order() { |
573 | - wp_set_current_user( $this->user ); |
|
573 | + wp_set_current_user($this->user); |
|
574 | 574 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
575 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/' . $order->get_id() ); |
|
576 | - $request->set_param( 'force', true ); |
|
577 | - $response = $this->server->dispatch( $request ); |
|
578 | - $this->assertEquals( 200, $response->get_status() ); |
|
579 | - $this->assertEquals( null, get_post( $order->get_id() ) ); |
|
575 | + $request = new WP_REST_Request('DELETE', '/wc/v3/orders/' . $order->get_id()); |
|
576 | + $request->set_param('force', true); |
|
577 | + $response = $this->server->dispatch($request); |
|
578 | + $this->assertEquals(200, $response->get_status()); |
|
579 | + $this->assertEquals(null, get_post($order->get_id())); |
|
580 | 580 | } |
581 | 581 | |
582 | 582 | /** |
@@ -585,12 +585,12 @@ discard block |
||
585 | 585 | * @since 3.5.0 |
586 | 586 | */ |
587 | 587 | public function test_delete_order_without_permission() { |
588 | - wp_set_current_user( 0 ); |
|
588 | + wp_set_current_user(0); |
|
589 | 589 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
590 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/' . $order->get_id() ); |
|
591 | - $request->set_param( 'force', true ); |
|
592 | - $response = $this->server->dispatch( $request ); |
|
593 | - $this->assertEquals( 401, $response->get_status() ); |
|
590 | + $request = new WP_REST_Request('DELETE', '/wc/v3/orders/' . $order->get_id()); |
|
591 | + $request->set_param('force', true); |
|
592 | + $response = $this->server->dispatch($request); |
|
593 | + $this->assertEquals(401, $response->get_status()); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -599,11 +599,11 @@ discard block |
||
599 | 599 | * @since 3.5.0 |
600 | 600 | */ |
601 | 601 | public function test_delete_order_invalid_id() { |
602 | - wp_set_current_user( $this->user ); |
|
603 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/orders/9999999' ); |
|
604 | - $request->set_param( 'force', true ); |
|
605 | - $response = $this->server->dispatch( $request ); |
|
606 | - $this->assertEquals( 404, $response->get_status() ); |
|
602 | + wp_set_current_user($this->user); |
|
603 | + $request = new WP_REST_Request('DELETE', '/wc/v3/orders/9999999'); |
|
604 | + $request->set_param('force', true); |
|
605 | + $response = $this->server->dispatch($request); |
|
606 | + $this->assertEquals(404, $response->get_status()); |
|
607 | 607 | } |
608 | 608 | |
609 | 609 | /** |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | * @since 3.5.0 |
613 | 613 | */ |
614 | 614 | public function test_orders_batch() { |
615 | - wp_set_current_user( $this->user ); |
|
615 | + wp_set_current_user($this->user); |
|
616 | 616 | |
617 | 617 | $order1 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
618 | 618 | $order2 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
619 | 619 | $order3 = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
620 | 620 | |
621 | - $request = new WP_REST_Request( 'POST', '/wc/v3/orders/batch' ); |
|
621 | + $request = new WP_REST_Request('POST', '/wc/v3/orders/batch'); |
|
622 | 622 | $request->set_body_params( |
623 | 623 | array( |
624 | 624 | 'update' => array( |
@@ -633,17 +633,17 @@ discard block |
||
633 | 633 | ), |
634 | 634 | ) |
635 | 635 | ); |
636 | - $response = $this->server->dispatch( $request ); |
|
636 | + $response = $this->server->dispatch($request); |
|
637 | 637 | $data = $response->get_data(); |
638 | 638 | |
639 | - $this->assertEquals( 'updated', $data['update'][0]['payment_method'] ); |
|
640 | - $this->assertEquals( $order2->get_id(), $data['delete'][0]['id'] ); |
|
641 | - $this->assertEquals( $order3->get_id(), $data['delete'][1]['id'] ); |
|
639 | + $this->assertEquals('updated', $data['update'][0]['payment_method']); |
|
640 | + $this->assertEquals($order2->get_id(), $data['delete'][0]['id']); |
|
641 | + $this->assertEquals($order3->get_id(), $data['delete'][1]['id']); |
|
642 | 642 | |
643 | - $request = new WP_REST_Request( 'GET', '/wc/v3/orders' ); |
|
644 | - $response = $this->server->dispatch( $request ); |
|
643 | + $request = new WP_REST_Request('GET', '/wc/v3/orders'); |
|
644 | + $response = $this->server->dispatch($request); |
|
645 | 645 | $data = $response->get_data(); |
646 | - $this->assertEquals( 1, count( $data ) ); |
|
646 | + $this->assertEquals(1, count($data)); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | /** |
@@ -652,14 +652,14 @@ discard block |
||
652 | 652 | * @since 3.5.0 |
653 | 653 | */ |
654 | 654 | public function test_order_schema() { |
655 | - wp_set_current_user( $this->user ); |
|
655 | + wp_set_current_user($this->user); |
|
656 | 656 | $order = \WooCommerce\RestApi\UnitTests\Helpers\OrderHelper::create_order(); |
657 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/orders/' . $order->get_id() ); |
|
658 | - $response = $this->server->dispatch( $request ); |
|
657 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/orders/' . $order->get_id()); |
|
658 | + $response = $this->server->dispatch($request); |
|
659 | 659 | $data = $response->get_data(); |
660 | 660 | $properties = $data['schema']['properties']; |
661 | 661 | |
662 | - $this->assertEquals( 42, count( $properties ) ); |
|
663 | - $this->assertArrayHasKey( 'id', $properties ); |
|
662 | + $this->assertEquals(42, count($properties)); |
|
663 | + $this->assertArrayHasKey('id', $properties); |
|
664 | 664 | } |
665 | 665 | } |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function test_register_routes() { |
29 | 29 | $routes = $this->server->get_routes(); |
30 | - $this->assertArrayHasKey( '/wc/v3/products/reviews', $routes ); |
|
31 | - $this->assertArrayHasKey( '/wc/v3/products/reviews/(?P<id>[\d]+)', $routes ); |
|
32 | - $this->assertArrayHasKey( '/wc/v3/products/reviews/batch', $routes ); |
|
30 | + $this->assertArrayHasKey('/wc/v3/products/reviews', $routes); |
|
31 | + $this->assertArrayHasKey('/wc/v3/products/reviews/(?P<id>[\d]+)', $routes); |
|
32 | + $this->assertArrayHasKey('/wc/v3/products/reviews/batch', $routes); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | * @since 3.5.0 |
39 | 39 | */ |
40 | 40 | public function test_get_product_reviews() { |
41 | - wp_set_current_user( $this->user ); |
|
41 | + wp_set_current_user($this->user); |
|
42 | 42 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
43 | 43 | // Create 10 products reviews for the product |
44 | - for ( $i = 0; $i < 10; $i++ ) { |
|
45 | - $review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
44 | + for ($i = 0; $i < 10; $i++) { |
|
45 | + $review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
46 | 46 | } |
47 | 47 | |
48 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); |
|
48 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews')); |
|
49 | 49 | $product_reviews = $response->get_data(); |
50 | 50 | |
51 | - $this->assertEquals( 200, $response->get_status() ); |
|
52 | - $this->assertEquals( 10, count( $product_reviews ) ); |
|
51 | + $this->assertEquals(200, $response->get_status()); |
|
52 | + $this->assertEquals(10, count($product_reviews)); |
|
53 | 53 | $this->assertContains( |
54 | 54 | array( |
55 | 55 | 'id' => $review_id, |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | '_links' => array( |
67 | 67 | 'self' => array( |
68 | 68 | array( |
69 | - 'href' => rest_url( '/wc/v3/products/reviews/' . $review_id ), |
|
69 | + 'href' => rest_url('/wc/v3/products/reviews/' . $review_id), |
|
70 | 70 | ), |
71 | 71 | ), |
72 | 72 | 'collection' => array( |
73 | 73 | array( |
74 | - 'href' => rest_url( '/wc/v3/products/reviews' ), |
|
74 | + 'href' => rest_url('/wc/v3/products/reviews'), |
|
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | 'up' => array( |
78 | 78 | array( |
79 | - 'href' => rest_url( '/wc/v3/products/' . $product->get_id() ), |
|
79 | + 'href' => rest_url('/wc/v3/products/' . $product->get_id()), |
|
80 | 80 | ), |
81 | 81 | ), |
82 | 82 | ), |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | * @since 3.5.0 |
92 | 92 | */ |
93 | 93 | public function test_get_product_reviews_without_permission() { |
94 | - wp_set_current_user( 0 ); |
|
94 | + wp_set_current_user(0); |
|
95 | 95 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
96 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ) ); |
|
97 | - $this->assertEquals( 401, $response->get_status() ); |
|
96 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews')); |
|
97 | + $this->assertEquals(401, $response->get_status()); |
|
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | * @since 3.5.0 |
104 | 104 | */ |
105 | 105 | public function test_get_product_reviews_invalid_product() { |
106 | - wp_set_current_user( $this->user ); |
|
107 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/0/reviews' ) ); |
|
108 | - $this->assertEquals( 404, $response->get_status() ); |
|
106 | + wp_set_current_user($this->user); |
|
107 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/0/reviews')); |
|
108 | + $this->assertEquals(404, $response->get_status()); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | * @since 3.5.0 |
115 | 115 | */ |
116 | 116 | public function test_get_product_review() { |
117 | - wp_set_current_user( $this->user ); |
|
117 | + wp_set_current_user($this->user); |
|
118 | 118 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
119 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
119 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
120 | 120 | |
121 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); |
|
121 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id)); |
|
122 | 122 | $data = $response->get_data(); |
123 | 123 | |
124 | - $this->assertEquals( 200, $response->get_status() ); |
|
124 | + $this->assertEquals(200, $response->get_status()); |
|
125 | 125 | $this->assertEquals( |
126 | 126 | array( |
127 | 127 | 'id' => $product_review_id, |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | * @since 3.5.0 |
147 | 147 | */ |
148 | 148 | public function test_get_product_review_without_permission() { |
149 | - wp_set_current_user( 0 ); |
|
149 | + wp_set_current_user(0); |
|
150 | 150 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
151 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
152 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); |
|
153 | - $this->assertEquals( 401, $response->get_status() ); |
|
151 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
152 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id)); |
|
153 | + $this->assertEquals(401, $response->get_status()); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | /** |
@@ -159,10 +159,10 @@ discard block |
||
159 | 159 | * @since 3.5.0 |
160 | 160 | */ |
161 | 161 | public function test_get_product_review_invalid_id() { |
162 | - wp_set_current_user( $this->user ); |
|
162 | + wp_set_current_user($this->user); |
|
163 | 163 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
164 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/0' ) ); |
|
165 | - $this->assertEquals( 404, $response->get_status() ); |
|
164 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/0')); |
|
165 | + $this->assertEquals(404, $response->get_status()); |
|
166 | 166 | } |
167 | 167 | |
168 | 168 | /** |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | * @since 3.5.0 |
172 | 172 | */ |
173 | 173 | public function test_create_product_review() { |
174 | - wp_set_current_user( $this->user ); |
|
174 | + wp_set_current_user($this->user); |
|
175 | 175 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
176 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); |
|
176 | + $request = new WP_REST_Request('POST', '/wc/v3/products/reviews'); |
|
177 | 177 | $request->set_body_params( |
178 | 178 | array( |
179 | 179 | 'review' => 'Hello world.', |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | 'product_id' => $product->get_id(), |
184 | 184 | ) |
185 | 185 | ); |
186 | - $response = $this->server->dispatch( $request ); |
|
186 | + $response = $this->server->dispatch($request); |
|
187 | 187 | $data = $response->get_data(); |
188 | 188 | |
189 | - $this->assertEquals( 201, $response->get_status() ); |
|
189 | + $this->assertEquals(201, $response->get_status()); |
|
190 | 190 | $this->assertEquals( |
191 | 191 | array( |
192 | 192 | 'id' => $data['id'], |
@@ -211,47 +211,47 @@ discard block |
||
211 | 211 | * @since 3.5.0 |
212 | 212 | */ |
213 | 213 | public function test_create_product_review_invalid_fields() { |
214 | - wp_set_current_user( $this->user ); |
|
214 | + wp_set_current_user($this->user); |
|
215 | 215 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
216 | 216 | |
217 | 217 | // missing review |
218 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); |
|
218 | + $request = new WP_REST_Request('POST', '/wc/v3/products/reviews'); |
|
219 | 219 | $request->set_body_params( |
220 | 220 | array( |
221 | 221 | 'reviewer' => 'Admin', |
222 | 222 | 'reviewer_email' => '[email protected]', |
223 | 223 | ) |
224 | 224 | ); |
225 | - $response = $this->server->dispatch( $request ); |
|
225 | + $response = $this->server->dispatch($request); |
|
226 | 226 | $data = $response->get_data(); |
227 | 227 | |
228 | - $this->assertEquals( 400, $response->get_status() ); |
|
228 | + $this->assertEquals(400, $response->get_status()); |
|
229 | 229 | |
230 | 230 | // Missing reviewer. |
231 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); |
|
231 | + $request = new WP_REST_Request('POST', '/wc/v3/products/reviews'); |
|
232 | 232 | $request->set_body_params( |
233 | 233 | array( |
234 | 234 | 'review' => 'Hello world.', |
235 | 235 | 'reviewer_email' => '[email protected]', |
236 | 236 | ) |
237 | 237 | ); |
238 | - $response = $this->server->dispatch( $request ); |
|
238 | + $response = $this->server->dispatch($request); |
|
239 | 239 | $data = $response->get_data(); |
240 | 240 | |
241 | - $this->assertEquals( 400, $response->get_status() ); |
|
241 | + $this->assertEquals(400, $response->get_status()); |
|
242 | 242 | |
243 | 243 | // missing reviewer_email |
244 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews' ); |
|
244 | + $request = new WP_REST_Request('POST', '/wc/v3/products/reviews'); |
|
245 | 245 | $request->set_body_params( |
246 | 246 | array( |
247 | 247 | 'review' => 'Hello world.', |
248 | 248 | 'reviewer' => 'Admin', |
249 | 249 | ) |
250 | 250 | ); |
251 | - $response = $this->server->dispatch( $request ); |
|
251 | + $response = $this->server->dispatch($request); |
|
252 | 252 | $data = $response->get_data(); |
253 | 253 | |
254 | - $this->assertEquals( 400, $response->get_status() ); |
|
254 | + $this->assertEquals(400, $response->get_status()); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
@@ -260,18 +260,18 @@ discard block |
||
260 | 260 | * @since 3.5.0 |
261 | 261 | */ |
262 | 262 | public function test_update_product_review() { |
263 | - wp_set_current_user( $this->user ); |
|
263 | + wp_set_current_user($this->user); |
|
264 | 264 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
265 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
265 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
266 | 266 | |
267 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/reviews/' . $product_review_id ) ); |
|
267 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/reviews/' . $product_review_id)); |
|
268 | 268 | $data = $response->get_data(); |
269 | - $this->assertEquals( "<p>Review content here</p>\n", $data['review'] ); |
|
270 | - $this->assertEquals( 'admin', $data['reviewer'] ); |
|
271 | - $this->assertEquals( '[email protected]', $data['reviewer_email'] ); |
|
272 | - $this->assertEquals( 0, $data['rating'] ); |
|
269 | + $this->assertEquals("<p>Review content here</p>\n", $data['review']); |
|
270 | + $this->assertEquals('admin', $data['reviewer']); |
|
271 | + $this->assertEquals('[email protected]', $data['reviewer_email']); |
|
272 | + $this->assertEquals(0, $data['rating']); |
|
273 | 273 | |
274 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); |
|
274 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/' . $product_review_id); |
|
275 | 275 | $request->set_body_params( |
276 | 276 | array( |
277 | 277 | 'review' => 'Hello world - updated.', |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | 'rating' => 3, |
281 | 281 | ) |
282 | 282 | ); |
283 | - $response = $this->server->dispatch( $request ); |
|
283 | + $response = $this->server->dispatch($request); |
|
284 | 284 | $data = $response->get_data(); |
285 | - $this->assertEquals( 'Hello world - updated.', $data['review'] ); |
|
286 | - $this->assertEquals( 'Justin', $data['reviewer'] ); |
|
287 | - $this->assertEquals( '[email protected]', $data['reviewer_email'] ); |
|
288 | - $this->assertEquals( 3, $data['rating'] ); |
|
285 | + $this->assertEquals('Hello world - updated.', $data['review']); |
|
286 | + $this->assertEquals('Justin', $data['reviewer']); |
|
287 | + $this->assertEquals('[email protected]', $data['reviewer_email']); |
|
288 | + $this->assertEquals(3, $data['rating']); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,11 +294,11 @@ discard block |
||
294 | 294 | * @since 3.5.0 |
295 | 295 | */ |
296 | 296 | public function test_update_product_review_without_permission() { |
297 | - wp_set_current_user( 0 ); |
|
297 | + wp_set_current_user(0); |
|
298 | 298 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
299 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
299 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
300 | 300 | |
301 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/' . $product_review_id ); |
|
301 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/' . $product_review_id); |
|
302 | 302 | $request->set_body_params( |
303 | 303 | array( |
304 | 304 | 'review' => 'Hello world.', |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | 'reviewer_email' => '[email protected]', |
307 | 307 | ) |
308 | 308 | ); |
309 | - $response = $this->server->dispatch( $request ); |
|
309 | + $response = $this->server->dispatch($request); |
|
310 | 310 | $data = $response->get_data(); |
311 | 311 | |
312 | - $this->assertEquals( 401, $response->get_status() ); |
|
312 | + $this->assertEquals(401, $response->get_status()); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | /** |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | * @since 3.5.0 |
319 | 319 | */ |
320 | 320 | public function test_update_product_review_invalid_id() { |
321 | - wp_set_current_user( $this->user ); |
|
321 | + wp_set_current_user($this->user); |
|
322 | 322 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
323 | 323 | |
324 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/reviews/0' ); |
|
324 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/reviews/0'); |
|
325 | 325 | $request->set_body_params( |
326 | 326 | array( |
327 | 327 | 'review' => 'Hello world.', |
@@ -329,10 +329,10 @@ discard block |
||
329 | 329 | 'reviewer_email' => '[email protected]', |
330 | 330 | ) |
331 | 331 | ); |
332 | - $response = $this->server->dispatch( $request ); |
|
332 | + $response = $this->server->dispatch($request); |
|
333 | 333 | $data = $response->get_data(); |
334 | 334 | |
335 | - $this->assertEquals( 404, $response->get_status() ); |
|
335 | + $this->assertEquals(404, $response->get_status()); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | /** |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | * @since 3.5.0 |
342 | 342 | */ |
343 | 343 | public function test_delete_product_review() { |
344 | - wp_set_current_user( $this->user ); |
|
344 | + wp_set_current_user($this->user); |
|
345 | 345 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
346 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
346 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
347 | 347 | |
348 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); |
|
349 | - $request->set_param( 'force', true ); |
|
350 | - $response = $this->server->dispatch( $request ); |
|
351 | - $this->assertEquals( 200, $response->get_status() ); |
|
348 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/' . $product_review_id); |
|
349 | + $request->set_param('force', true); |
|
350 | + $response = $this->server->dispatch($request); |
|
351 | + $this->assertEquals(200, $response->get_status()); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -357,14 +357,14 @@ discard block |
||
357 | 357 | * @since 3.5.0 |
358 | 358 | */ |
359 | 359 | public function test_delete_product_without_permission() { |
360 | - wp_set_current_user( 0 ); |
|
360 | + wp_set_current_user(0); |
|
361 | 361 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
362 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
362 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
363 | 363 | |
364 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/' . $product_review_id ); |
|
365 | - $response = $this->server->dispatch( $request ); |
|
364 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/' . $product_review_id); |
|
365 | + $response = $this->server->dispatch($request); |
|
366 | 366 | |
367 | - $this->assertEquals( 401, $response->get_status() ); |
|
367 | + $this->assertEquals(401, $response->get_status()); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | /** |
@@ -373,15 +373,15 @@ discard block |
||
373 | 373 | * @since 3.5.0 |
374 | 374 | */ |
375 | 375 | public function test_delete_product_review_invalid_id() { |
376 | - wp_set_current_user( $this->user ); |
|
376 | + wp_set_current_user($this->user); |
|
377 | 377 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
378 | - $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
378 | + $product_review_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
379 | 379 | |
380 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/reviews/0' ); |
|
381 | - $request->set_param( 'force', true ); |
|
382 | - $response = $this->server->dispatch( $request ); |
|
380 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/reviews/0'); |
|
381 | + $request->set_param('force', true); |
|
382 | + $response = $this->server->dispatch($request); |
|
383 | 383 | |
384 | - $this->assertEquals( 404, $response->get_status() ); |
|
384 | + $this->assertEquals(404, $response->get_status()); |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | /** |
@@ -390,15 +390,15 @@ discard block |
||
390 | 390 | * @since 3.5.0 |
391 | 391 | */ |
392 | 392 | public function test_product_reviews_batch() { |
393 | - wp_set_current_user( $this->user ); |
|
393 | + wp_set_current_user($this->user); |
|
394 | 394 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
395 | 395 | |
396 | - $review_1_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
397 | - $review_2_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
398 | - $review_3_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
399 | - $review_4_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review( $product->get_id() ); |
|
396 | + $review_1_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
397 | + $review_2_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
398 | + $review_3_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
399 | + $review_4_id = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_product_review($product->get_id()); |
|
400 | 400 | |
401 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/reviews/batch' ); |
|
401 | + $request = new WP_REST_Request('POST', '/wc/v3/products/reviews/batch'); |
|
402 | 402 | $request->set_body_params( |
403 | 403 | array( |
404 | 404 | 'update' => array( |
@@ -421,21 +421,21 @@ discard block |
||
421 | 421 | ), |
422 | 422 | ) |
423 | 423 | ); |
424 | - $response = $this->server->dispatch( $request ); |
|
424 | + $response = $this->server->dispatch($request); |
|
425 | 425 | $data = $response->get_data(); |
426 | 426 | |
427 | - $this->assertEquals( 'Updated review.', $data['update'][0]['review'] ); |
|
428 | - $this->assertEquals( 'New review.', $data['create'][0]['review'] ); |
|
429 | - $this->assertEquals( $review_2_id, $data['delete'][0]['previous']['id'] ); |
|
430 | - $this->assertEquals( $review_3_id, $data['delete'][1]['previous']['id'] ); |
|
427 | + $this->assertEquals('Updated review.', $data['update'][0]['review']); |
|
428 | + $this->assertEquals('New review.', $data['create'][0]['review']); |
|
429 | + $this->assertEquals($review_2_id, $data['delete'][0]['previous']['id']); |
|
430 | + $this->assertEquals($review_3_id, $data['delete'][1]['previous']['id']); |
|
431 | 431 | |
432 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products/reviews' ); |
|
433 | - $request->set_param( 'product', $product->get_id() ); |
|
432 | + $request = new WP_REST_Request('GET', '/wc/v3/products/reviews'); |
|
433 | + $request->set_param('product', $product->get_id()); |
|
434 | 434 | |
435 | - $response = $this->server->dispatch( $request ); |
|
435 | + $response = $this->server->dispatch($request); |
|
436 | 436 | $data = $response->get_data(); |
437 | 437 | |
438 | - $this->assertEquals( 3, count( $data ) ); |
|
438 | + $this->assertEquals(3, count($data)); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -444,27 +444,27 @@ discard block |
||
444 | 444 | * @since 3.5.0 |
445 | 445 | */ |
446 | 446 | public function test_product_review_schema() { |
447 | - wp_set_current_user( $this->user ); |
|
447 | + wp_set_current_user($this->user); |
|
448 | 448 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
449 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/reviews' ); |
|
450 | - $response = $this->server->dispatch( $request ); |
|
449 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/products/reviews'); |
|
450 | + $response = $this->server->dispatch($request); |
|
451 | 451 | $data = $response->get_data(); |
452 | 452 | $properties = $data['schema']['properties']; |
453 | 453 | |
454 | - $this->assertEquals( 11, count( $properties ) ); |
|
455 | - $this->assertArrayHasKey( 'id', $properties ); |
|
456 | - $this->assertArrayHasKey( 'date_created', $properties ); |
|
457 | - $this->assertArrayHasKey( 'date_created_gmt', $properties ); |
|
458 | - $this->assertArrayHasKey( 'product_id', $properties ); |
|
459 | - $this->assertArrayHasKey( 'status', $properties ); |
|
460 | - $this->assertArrayHasKey( 'reviewer', $properties ); |
|
461 | - $this->assertArrayHasKey( 'reviewer_email', $properties ); |
|
462 | - $this->assertArrayHasKey( 'review', $properties ); |
|
463 | - $this->assertArrayHasKey( 'rating', $properties ); |
|
464 | - $this->assertArrayHasKey( 'verified', $properties ); |
|
465 | - |
|
466 | - if ( get_option( 'show_avatars' ) ) { |
|
467 | - $this->assertArrayHasKey( 'reviewer_avatar_urls', $properties ); |
|
454 | + $this->assertEquals(11, count($properties)); |
|
455 | + $this->assertArrayHasKey('id', $properties); |
|
456 | + $this->assertArrayHasKey('date_created', $properties); |
|
457 | + $this->assertArrayHasKey('date_created_gmt', $properties); |
|
458 | + $this->assertArrayHasKey('product_id', $properties); |
|
459 | + $this->assertArrayHasKey('status', $properties); |
|
460 | + $this->assertArrayHasKey('reviewer', $properties); |
|
461 | + $this->assertArrayHasKey('reviewer_email', $properties); |
|
462 | + $this->assertArrayHasKey('review', $properties); |
|
463 | + $this->assertArrayHasKey('rating', $properties); |
|
464 | + $this->assertArrayHasKey('verified', $properties); |
|
465 | + |
|
466 | + if (get_option('show_avatars')) { |
|
467 | + $this->assertArrayHasKey('reviewer_avatar_urls', $properties); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | } |