@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | parent::setUp(); |
| 34 | 34 | |
| 35 | 35 | // Callback used by WP_HTTP_TestCase to decide whether to perform HTTP requests or to provide a mocked response. |
| 36 | - $this->http_responder = array( $this, 'mock_http_responses' ); |
|
| 36 | + $this->http_responder = array($this, 'mock_http_responses'); |
|
| 37 | 37 | |
| 38 | 38 | $upload_dir_info = wp_upload_dir(); |
| 39 | 39 | $this->upload_dir_path = $upload_dir_info['path']; |
@@ -50,8 +50,8 @@ discard block |
||
| 50 | 50 | // remove files created in the wc_rest_upload_image_from_url() tests. |
| 51 | 51 | $file_path = $this->upload_dir_path . '/' . $this->file_name; |
| 52 | 52 | |
| 53 | - if ( file_exists( $file_path ) ) { |
|
| 54 | - unlink( $file_path ); |
|
| 53 | + if (file_exists($file_path)) { |
|
| 54 | + unlink($file_path); |
|
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | 57 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @since 2.6.0 |
| 62 | 62 | */ |
| 63 | 63 | public function test_wc_rest_prepare_date_response() { |
| 64 | - $this->assertEquals( '2016-06-06T06:06:06', wc_rest_prepare_date_response( '2016-06-06 06:06:06' ) ); |
|
| 64 | + $this->assertEquals('2016-06-06T06:06:06', wc_rest_prepare_date_response('2016-06-06 06:06:06')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function test_wc_rest_upload_image_from_url_should_return_error_when_unable_to_download_image() { |
| 71 | 71 | $expected_error_message = 'Error getting remote image http://somedomain.com/nonexistent-image.png. Error: Not found.'; |
| 72 | - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/nonexistent-image.png' ); |
|
| 72 | + $result = wc_rest_upload_image_from_url('http://somedomain.com/nonexistent-image.png'); |
|
| 73 | 73 | |
| 74 | - $this->assertIsWPError( $result ); |
|
| 75 | - $this->assertEquals( $expected_error_message, $result->get_error_message() ); |
|
| 74 | + $this->assertIsWPError($result); |
|
| 75 | + $this->assertEquals($expected_error_message, $result->get_error_message()); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | public function test_wc_rest_upload_image_from_url_should_return_error_when_invalid_image_is_passed() { |
| 84 | 84 | // empty file. |
| 85 | 85 | $expected_error_message = 'Invalid image: File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini.'; |
| 86 | - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-1.png' ); |
|
| 86 | + $result = wc_rest_upload_image_from_url('http://somedomain.com/invalid-image-1.png'); |
|
| 87 | 87 | |
| 88 | - $this->assertIsWPError( $result ); |
|
| 89 | - $this->assertEquals( $expected_error_message, $result->get_error_message() ); |
|
| 88 | + $this->assertIsWPError($result); |
|
| 89 | + $this->assertEquals($expected_error_message, $result->get_error_message()); |
|
| 90 | 90 | |
| 91 | 91 | // unsupported mime type. |
| 92 | 92 | $expected_error_message = 'Invalid image: Sorry, this file type is not permitted for security reasons.'; |
| 93 | - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/invalid-image-2.png' ); |
|
| 93 | + $result = wc_rest_upload_image_from_url('http://somedomain.com/invalid-image-2.png'); |
|
| 94 | 94 | |
| 95 | - $this->assertIsWPError( $result ); |
|
| 96 | - $this->assertEquals( $expected_error_message, $result->get_error_message() ); |
|
| 95 | + $this->assertIsWPError($result); |
|
| 96 | + $this->assertEquals($expected_error_message, $result->get_error_message()); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -108,9 +108,9 @@ discard block |
||
| 108 | 108 | 'url' => $this->upload_dir_url . '/' . $this->file_name, |
| 109 | 109 | 'type' => 'image/png', |
| 110 | 110 | ); |
| 111 | - $result = wc_rest_upload_image_from_url( 'http://somedomain.com/' . $this->file_name ); |
|
| 111 | + $result = wc_rest_upload_image_from_url('http://somedomain.com/' . $this->file_name); |
|
| 112 | 112 | |
| 113 | - $this->assertEquals( $expected_result, $result ); |
|
| 113 | + $this->assertEquals($expected_result, $result); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -150,11 +150,11 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | 152 | // Success. |
| 153 | - $this->assertTrue( wc_rest_validate_reports_request_arg( '2016-06-06', $request, 'date' ) ); |
|
| 153 | + $this->assertTrue(wc_rest_validate_reports_request_arg('2016-06-06', $request, 'date')); |
|
| 154 | 154 | |
| 155 | 155 | // Error. |
| 156 | - $error = wc_rest_validate_reports_request_arg( 'foo', $request, 'date' ); |
|
| 157 | - $this->assertEquals( 'The date you provided is invalid.', $error->get_error_message() ); |
|
| 156 | + $error = wc_rest_validate_reports_request_arg('foo', $request, 'date'); |
|
| 157 | + $this->assertEquals('The date you provided is invalid.', $error->get_error_message()); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | * @since 2.6.0 |
| 164 | 164 | */ |
| 165 | 165 | public function test_wc_rest_urlencode_rfc3986() { |
| 166 | - $this->assertEquals( 'https%3A%2F%2Fwoocommerce.com%2F', wc_rest_urlencode_rfc3986( 'https://woocommerce.com/' ) ); |
|
| 166 | + $this->assertEquals('https%3A%2F%2Fwoocommerce.com%2F', wc_rest_urlencode_rfc3986('https://woocommerce.com/')); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @since 2.6.0 |
| 173 | 173 | */ |
| 174 | 174 | public function test_wc_rest_check_post_permissions() { |
| 175 | - $this->assertFalse( wc_rest_check_post_permissions( 'shop_order' ) ); |
|
| 175 | + $this->assertFalse(wc_rest_check_post_permissions('shop_order')); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @since 2.6.0 |
| 182 | 182 | */ |
| 183 | 183 | public function test_wc_rest_check_user_permissions() { |
| 184 | - $this->assertFalse( wc_rest_check_user_permissions() ); |
|
| 184 | + $this->assertFalse(wc_rest_check_user_permissions()); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | * @since 2.6.0 |
| 191 | 191 | */ |
| 192 | 192 | public function test_wc_rest_check_product_term_permissions() { |
| 193 | - $this->assertFalse( wc_rest_check_product_term_permissions( 'product_cat' ) ); |
|
| 193 | + $this->assertFalse(wc_rest_check_product_term_permissions('product_cat')); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @since 2.6.0 |
| 200 | 200 | */ |
| 201 | 201 | public function test_wc_rest_check_manager_permissions() { |
| 202 | - $this->assertFalse( wc_rest_check_manager_permissions( 'reports' ) ); |
|
| 202 | + $this->assertFalse(wc_rest_check_manager_permissions('reports')); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -214,35 +214,35 @@ discard block |
||
| 214 | 214 | * |
| 215 | 215 | * @return array|false mocked response or false to let WP perform a regular request. |
| 216 | 216 | */ |
| 217 | - protected function mock_http_responses( $request, $url ) { |
|
| 217 | + protected function mock_http_responses($request, $url) { |
|
| 218 | 218 | $mocked_response = false; |
| 219 | 219 | |
| 220 | - if ( 'http://somedomain.com/nonexistent-image.png' === $url ) { |
|
| 220 | + if ('http://somedomain.com/nonexistent-image.png' === $url) { |
|
| 221 | 221 | $mocked_response = array( |
| 222 | 222 | 'response' => array( |
| 223 | 223 | 'code' => 404, |
| 224 | 224 | 'message' => 'Not found.', |
| 225 | 225 | ), |
| 226 | 226 | ); |
| 227 | - } elseif ( 'http://somedomain.com/invalid-image-1.png' === $url ) { |
|
| 227 | + } elseif ('http://somedomain.com/invalid-image-1.png' === $url) { |
|
| 228 | 228 | // empty image. |
| 229 | 229 | $mocked_response = array( |
| 230 | - 'response' => array( 'code' => 200 ), |
|
| 230 | + 'response' => array('code' => 200), |
|
| 231 | 231 | ); |
| 232 | - } elseif ( 'http://somedomain.com/invalid-image-2.png' === $url ) { |
|
| 232 | + } elseif ('http://somedomain.com/invalid-image-2.png' === $url) { |
|
| 233 | 233 | // image with an unsupported mime type. |
| 234 | 234 | // we need to manually copy the file as we are mocking the request. without this an empty file is created. |
| 235 | - copy( WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/file.txt', $request['filename'] ); |
|
| 235 | + copy(WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/file.txt', $request['filename']); |
|
| 236 | 236 | |
| 237 | 237 | $mocked_response = array( |
| 238 | - 'response' => array( 'code' => 200 ), |
|
| 238 | + 'response' => array('code' => 200), |
|
| 239 | 239 | ); |
| 240 | - } elseif ( 'http://somedomain.com/' . $this->file_name === $url ) { |
|
| 240 | + } elseif ('http://somedomain.com/' . $this->file_name === $url) { |
|
| 241 | 241 | // we need to manually copy the file as we are mocking the request. without this an empty file is created. |
| 242 | - copy( WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/Dr1Bczxq4q.png', $request['filename'] ); |
|
| 242 | + copy(WooCommerce\RestApi\UnitTests\Bootstrap::instance()->get_dir() . '/data/Dr1Bczxq4q.png', $request['filename']); |
|
| 243 | 243 | |
| 244 | 244 | $mocked_response = array( |
| 245 | - 'response' => array( 'code' => 200 ), |
|
| 245 | + 'response' => array('code' => 200), |
|
| 246 | 246 | ); |
| 247 | 247 | } |
| 248 | 248 | |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function test_register_routes() { |
| 33 | 33 | $routes = $this->server->get_routes(); |
| 34 | - $this->assertArrayHasKey( '/wc/v3/products', $routes ); |
|
| 35 | - $this->assertArrayHasKey( '/wc/v3/products/(?P<id>[\d]+)', $routes ); |
|
| 36 | - $this->assertArrayHasKey( '/wc/v3/products/batch', $routes ); |
|
| 34 | + $this->assertArrayHasKey('/wc/v3/products', $routes); |
|
| 35 | + $this->assertArrayHasKey('/wc/v3/products/(?P<id>[\d]+)', $routes); |
|
| 36 | + $this->assertArrayHasKey('/wc/v3/products/batch', $routes); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -42,20 +42,20 @@ discard block |
||
| 42 | 42 | * @since 3.5.0 |
| 43 | 43 | */ |
| 44 | 44 | public function test_get_products() { |
| 45 | - wp_set_current_user( $this->user ); |
|
| 45 | + wp_set_current_user($this->user); |
|
| 46 | 46 | \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); |
| 47 | - sleep( 1 ); // So both products have different timestamps. |
|
| 47 | + sleep(1); // So both products have different timestamps. |
|
| 48 | 48 | \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 49 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); |
|
| 49 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products')); |
|
| 50 | 50 | $products = $response->get_data(); |
| 51 | 51 | |
| 52 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 52 | + $this->assertEquals(200, $response->get_status()); |
|
| 53 | 53 | |
| 54 | - $this->assertEquals( 2, count( $products ) ); |
|
| 55 | - $this->assertEquals( 'Dummy Product', $products[0]['name'] ); |
|
| 56 | - $this->assertEquals( 'DUMMY SKU', $products[0]['sku'] ); |
|
| 57 | - $this->assertEquals( 'Dummy External Product', $products[1]['name'] ); |
|
| 58 | - $this->assertEquals( 'DUMMY EXTERNAL SKU', $products[1]['sku'] ); |
|
| 54 | + $this->assertEquals(2, count($products)); |
|
| 55 | + $this->assertEquals('Dummy Product', $products[0]['name']); |
|
| 56 | + $this->assertEquals('DUMMY SKU', $products[0]['sku']); |
|
| 57 | + $this->assertEquals('Dummy External Product', $products[1]['name']); |
|
| 58 | + $this->assertEquals('DUMMY EXTERNAL SKU', $products[1]['sku']); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | * @since 3.5.0 |
| 65 | 65 | */ |
| 66 | 66 | public function test_get_products_without_permission() { |
| 67 | - wp_set_current_user( 0 ); |
|
| 67 | + wp_set_current_user(0); |
|
| 68 | 68 | \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 69 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); |
|
| 70 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 69 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products')); |
|
| 70 | + $this->assertEquals(401, $response->get_status()); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | * @since 3.5.0 |
| 77 | 77 | */ |
| 78 | 78 | public function test_get_product() { |
| 79 | - wp_set_current_user( $this->user ); |
|
| 79 | + wp_set_current_user($this->user); |
|
| 80 | 80 | $simple = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); |
| 81 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $simple->get_id() ) ); |
|
| 81 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $simple->get_id())); |
|
| 82 | 82 | $product = $response->get_data(); |
| 83 | 83 | |
| 84 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 84 | + $this->assertEquals(200, $response->get_status()); |
|
| 85 | 85 | $this->assertContains( |
| 86 | 86 | array( |
| 87 | 87 | 'id' => $simple->get_id(), |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | * @since 3.5.0 |
| 102 | 102 | */ |
| 103 | 103 | public function test_get_product_without_permission() { |
| 104 | - wp_set_current_user( 0 ); |
|
| 104 | + wp_set_current_user(0); |
|
| 105 | 105 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 106 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); |
|
| 107 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 106 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id())); |
|
| 107 | + $this->assertEquals(401, $response->get_status()); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -113,17 +113,17 @@ discard block |
||
| 113 | 113 | * @since 3.5.0 |
| 114 | 114 | */ |
| 115 | 115 | public function test_delete_product() { |
| 116 | - wp_set_current_user( $this->user ); |
|
| 116 | + wp_set_current_user($this->user); |
|
| 117 | 117 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 118 | 118 | |
| 119 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() ); |
|
| 120 | - $request->set_param( 'force', true ); |
|
| 121 | - $response = $this->server->dispatch( $request ); |
|
| 122 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 119 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/' . $product->get_id()); |
|
| 120 | + $request->set_param('force', true); |
|
| 121 | + $response = $this->server->dispatch($request); |
|
| 122 | + $this->assertEquals(200, $response->get_status()); |
|
| 123 | 123 | |
| 124 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); |
|
| 124 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products')); |
|
| 125 | 125 | $variations = $response->get_data(); |
| 126 | - $this->assertEquals( 0, count( $variations ) ); |
|
| 126 | + $this->assertEquals(0, count($variations)); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -132,12 +132,12 @@ discard block |
||
| 132 | 132 | * @since 3.5.0 |
| 133 | 133 | */ |
| 134 | 134 | public function test_delete_product_without_permission() { |
| 135 | - wp_set_current_user( 0 ); |
|
| 135 | + wp_set_current_user(0); |
|
| 136 | 136 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 137 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/' . $product->get_id() ); |
|
| 138 | - $request->set_param( 'force', true ); |
|
| 139 | - $response = $this->server->dispatch( $request ); |
|
| 140 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 137 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/' . $product->get_id()); |
|
| 138 | + $request->set_param('force', true); |
|
| 139 | + $response = $this->server->dispatch($request); |
|
| 140 | + $this->assertEquals(401, $response->get_status()); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -146,11 +146,11 @@ discard block |
||
| 146 | 146 | * @since 3.5.0 |
| 147 | 147 | */ |
| 148 | 148 | public function test_delete_product_with_invalid_id() { |
| 149 | - wp_set_current_user( 0 ); |
|
| 150 | - $request = new WP_REST_Request( 'DELETE', '/wc/v3/products/0' ); |
|
| 151 | - $request->set_param( 'force', true ); |
|
| 152 | - $response = $this->server->dispatch( $request ); |
|
| 153 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 149 | + wp_set_current_user(0); |
|
| 150 | + $request = new WP_REST_Request('DELETE', '/wc/v3/products/0'); |
|
| 151 | + $request->set_param('force', true); |
|
| 152 | + $response = $this->server->dispatch($request); |
|
| 153 | + $this->assertEquals(404, $response->get_status()); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -159,19 +159,19 @@ discard block |
||
| 159 | 159 | * @since 3.5.0 |
| 160 | 160 | */ |
| 161 | 161 | public function test_update_product() { |
| 162 | - wp_set_current_user( $this->user ); |
|
| 162 | + wp_set_current_user($this->user); |
|
| 163 | 163 | |
| 164 | 164 | // test simple products. |
| 165 | 165 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 166 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); |
|
| 166 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id())); |
|
| 167 | 167 | $data = $response->get_data(); |
| 168 | - $date_created = date( 'Y-m-d\TH:i:s', current_time( 'timestamp' ) ); |
|
| 168 | + $date_created = date('Y-m-d\TH:i:s', current_time('timestamp')); |
|
| 169 | 169 | |
| 170 | - $this->assertEquals( 'DUMMY SKU', $data['sku'] ); |
|
| 171 | - $this->assertEquals( 10, $data['regular_price'] ); |
|
| 172 | - $this->assertEmpty( $data['sale_price'] ); |
|
| 170 | + $this->assertEquals('DUMMY SKU', $data['sku']); |
|
| 171 | + $this->assertEquals(10, $data['regular_price']); |
|
| 172 | + $this->assertEmpty($data['sale_price']); |
|
| 173 | 173 | |
| 174 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); |
|
| 174 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id()); |
|
| 175 | 175 | $request->set_body_params( |
| 176 | 176 | array( |
| 177 | 177 | 'sku' => 'FIXED-SKU', |
@@ -187,29 +187,29 @@ discard block |
||
| 187 | 187 | ), |
| 188 | 188 | ) |
| 189 | 189 | ); |
| 190 | - $response = $this->server->dispatch( $request ); |
|
| 190 | + $response = $this->server->dispatch($request); |
|
| 191 | 191 | $data = $response->get_data(); |
| 192 | 192 | |
| 193 | - $this->assertContains( 'Testing', $data['description'] ); |
|
| 194 | - $this->assertEquals( '8', $data['price'] ); |
|
| 195 | - $this->assertEquals( '8', $data['sale_price'] ); |
|
| 196 | - $this->assertEquals( '10', $data['regular_price'] ); |
|
| 197 | - $this->assertEquals( 'FIXED-SKU', $data['sku'] ); |
|
| 198 | - $this->assertEquals( $date_created, $data['date_created'] ); |
|
| 199 | - $this->assertContains( 'Dr1Bczxq4q', $data['images'][0]['src'] ); |
|
| 200 | - $this->assertContains( 'test upload image', $data['images'][0]['alt'] ); |
|
| 201 | - $product->delete( true ); |
|
| 193 | + $this->assertContains('Testing', $data['description']); |
|
| 194 | + $this->assertEquals('8', $data['price']); |
|
| 195 | + $this->assertEquals('8', $data['sale_price']); |
|
| 196 | + $this->assertEquals('10', $data['regular_price']); |
|
| 197 | + $this->assertEquals('FIXED-SKU', $data['sku']); |
|
| 198 | + $this->assertEquals($date_created, $data['date_created']); |
|
| 199 | + $this->assertContains('Dr1Bczxq4q', $data['images'][0]['src']); |
|
| 200 | + $this->assertContains('test upload image', $data['images'][0]['alt']); |
|
| 201 | + $product->delete(true); |
|
| 202 | 202 | |
| 203 | 203 | // test variable product (variations are tested in product-variations.php). |
| 204 | 204 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
| 205 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); |
|
| 205 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id())); |
|
| 206 | 206 | $data = $response->get_data(); |
| 207 | 207 | |
| 208 | - foreach ( array( 'small', 'large' ) as $term_name ) { |
|
| 209 | - $this->assertContains( $term_name, $data['attributes'][0]['options'] ); |
|
| 208 | + foreach (array('small', 'large') as $term_name) { |
|
| 209 | + $this->assertContains($term_name, $data['attributes'][0]['options']); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); |
|
| 212 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id()); |
|
| 213 | 213 | $request->set_body_params( |
| 214 | 214 | array( |
| 215 | 215 | 'attributes' => array( |
@@ -235,37 +235,37 @@ discard block |
||
| 235 | 235 | ), |
| 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( array( 'small' ), $data['attributes'][0]['options'] ); |
|
| 241 | + $this->assertEquals(array('small'), $data['attributes'][0]['options']); |
|
| 242 | 242 | |
| 243 | - foreach ( array( 'red', 'yellow' ) as $term_name ) { |
|
| 244 | - $this->assertContains( $term_name, $data['attributes'][1]['options'] ); |
|
| 243 | + foreach (array('red', 'yellow') as $term_name) { |
|
| 244 | + $this->assertContains($term_name, $data['attributes'][1]['options']); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - $product->delete( true ); |
|
| 247 | + $product->delete(true); |
|
| 248 | 248 | |
| 249 | 249 | // test external product. |
| 250 | 250 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); |
| 251 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products/' . $product->get_id() ) ); |
|
| 251 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products/' . $product->get_id())); |
|
| 252 | 252 | $data = $response->get_data(); |
| 253 | 253 | |
| 254 | - $this->assertEquals( 'Buy external product', $data['button_text'] ); |
|
| 255 | - $this->assertEquals( 'http://woocommerce.com', $data['external_url'] ); |
|
| 254 | + $this->assertEquals('Buy external product', $data['button_text']); |
|
| 255 | + $this->assertEquals('http://woocommerce.com', $data['external_url']); |
|
| 256 | 256 | |
| 257 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); |
|
| 257 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id()); |
|
| 258 | 258 | $request->set_body_params( |
| 259 | 259 | array( |
| 260 | 260 | 'button_text' => 'Test API Update', |
| 261 | 261 | 'external_url' => 'http://automattic.com', |
| 262 | 262 | ) |
| 263 | 263 | ); |
| 264 | - $response = $this->server->dispatch( $request ); |
|
| 264 | + $response = $this->server->dispatch($request); |
|
| 265 | 265 | $data = $response->get_data(); |
| 266 | 266 | |
| 267 | - $this->assertEquals( 'Test API Update', $data['button_text'] ); |
|
| 268 | - $this->assertEquals( 'http://automattic.com', $data['external_url'] ); |
|
| 267 | + $this->assertEquals('Test API Update', $data['button_text']); |
|
| 268 | + $this->assertEquals('http://automattic.com', $data['external_url']); |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | * @since 3.5.0 |
| 275 | 275 | */ |
| 276 | 276 | public function test_update_product_without_permission() { |
| 277 | - wp_set_current_user( 0 ); |
|
| 277 | + wp_set_current_user(0); |
|
| 278 | 278 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 279 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/products/' . $product->get_id() ); |
|
| 279 | + $request = new WP_REST_Request('PUT', '/wc/v3/products/' . $product->get_id()); |
|
| 280 | 280 | $request->set_body_params( |
| 281 | 281 | array( |
| 282 | 282 | 'sku' => 'FIXED-SKU-NO-PERMISSION', |
| 283 | 283 | ) |
| 284 | 284 | ); |
| 285 | - $response = $this->server->dispatch( $request ); |
|
| 286 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 285 | + $response = $this->server->dispatch($request); |
|
| 286 | + $this->assertEquals(401, $response->get_status()); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -292,15 +292,15 @@ discard block |
||
| 292 | 292 | * @since 3.5.0 |
| 293 | 293 | */ |
| 294 | 294 | public function test_update_product_with_invalid_id() { |
| 295 | - wp_set_current_user( $this->user ); |
|
| 296 | - $request = new WP_REST_Request( 'PUT', '/wc/v2/products/0' ); |
|
| 295 | + wp_set_current_user($this->user); |
|
| 296 | + $request = new WP_REST_Request('PUT', '/wc/v2/products/0'); |
|
| 297 | 297 | $request->set_body_params( |
| 298 | 298 | array( |
| 299 | 299 | 'sku' => 'FIXED-SKU-INVALID-ID', |
| 300 | 300 | ) |
| 301 | 301 | ); |
| 302 | - $response = $this->server->dispatch( $request ); |
|
| 303 | - $this->assertEquals( 400, $response->get_status() ); |
|
| 302 | + $response = $this->server->dispatch($request); |
|
| 303 | + $this->assertEquals(400, $response->get_status()); |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -309,20 +309,20 @@ discard block |
||
| 309 | 309 | * @since 3.5.0 |
| 310 | 310 | */ |
| 311 | 311 | public function test_create_product() { |
| 312 | - wp_set_current_user( $this->user ); |
|
| 312 | + wp_set_current_user($this->user); |
|
| 313 | 313 | |
| 314 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/shipping_classes' ); |
|
| 314 | + $request = new WP_REST_Request('POST', '/wc/v3/products/shipping_classes'); |
|
| 315 | 315 | $request->set_body_params( |
| 316 | 316 | array( |
| 317 | 317 | 'name' => 'Test', |
| 318 | 318 | ) |
| 319 | 319 | ); |
| 320 | - $response = $this->server->dispatch( $request ); |
|
| 320 | + $response = $this->server->dispatch($request); |
|
| 321 | 321 | $data = $response->get_data(); |
| 322 | 322 | $shipping_class_id = $data['id']; |
| 323 | 323 | |
| 324 | 324 | // Create simple. |
| 325 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); |
|
| 325 | + $request = new WP_REST_Request('POST', '/wc/v3/products'); |
|
| 326 | 326 | $request->set_body_params( |
| 327 | 327 | array( |
| 328 | 328 | 'type' => 'simple', |
@@ -332,19 +332,19 @@ discard block |
||
| 332 | 332 | 'shipping_class' => 'test', |
| 333 | 333 | ) |
| 334 | 334 | ); |
| 335 | - $response = $this->server->dispatch( $request ); |
|
| 335 | + $response = $this->server->dispatch($request); |
|
| 336 | 336 | $data = $response->get_data(); |
| 337 | 337 | |
| 338 | - $this->assertEquals( '10', $data['price'] ); |
|
| 339 | - $this->assertEquals( '10', $data['regular_price'] ); |
|
| 340 | - $this->assertTrue( $data['purchasable'] ); |
|
| 341 | - $this->assertEquals( 'DUMMY SKU SIMPLE API', $data['sku'] ); |
|
| 342 | - $this->assertEquals( 'Test Simple Product', $data['name'] ); |
|
| 343 | - $this->assertEquals( 'simple', $data['type'] ); |
|
| 344 | - $this->assertEquals( $shipping_class_id, $data['shipping_class_id'] ); |
|
| 338 | + $this->assertEquals('10', $data['price']); |
|
| 339 | + $this->assertEquals('10', $data['regular_price']); |
|
| 340 | + $this->assertTrue($data['purchasable']); |
|
| 341 | + $this->assertEquals('DUMMY SKU SIMPLE API', $data['sku']); |
|
| 342 | + $this->assertEquals('Test Simple Product', $data['name']); |
|
| 343 | + $this->assertEquals('simple', $data['type']); |
|
| 344 | + $this->assertEquals($shipping_class_id, $data['shipping_class_id']); |
|
| 345 | 345 | |
| 346 | 346 | // Create external. |
| 347 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); |
|
| 347 | + $request = new WP_REST_Request('POST', '/wc/v3/products'); |
|
| 348 | 348 | $request->set_body_params( |
| 349 | 349 | array( |
| 350 | 350 | 'type' => 'external', |
@@ -355,20 +355,20 @@ discard block |
||
| 355 | 355 | 'external_url' => 'https://wordpress.org', |
| 356 | 356 | ) |
| 357 | 357 | ); |
| 358 | - $response = $this->server->dispatch( $request ); |
|
| 358 | + $response = $this->server->dispatch($request); |
|
| 359 | 359 | $data = $response->get_data(); |
| 360 | 360 | |
| 361 | - $this->assertEquals( '10', $data['price'] ); |
|
| 362 | - $this->assertEquals( '10', $data['regular_price'] ); |
|
| 363 | - $this->assertFalse( $data['purchasable'] ); |
|
| 364 | - $this->assertEquals( 'DUMMY SKU EXTERNAL API', $data['sku'] ); |
|
| 365 | - $this->assertEquals( 'Test External Product', $data['name'] ); |
|
| 366 | - $this->assertEquals( 'external', $data['type'] ); |
|
| 367 | - $this->assertEquals( 'Test Button', $data['button_text'] ); |
|
| 368 | - $this->assertEquals( 'https://wordpress.org', $data['external_url'] ); |
|
| 361 | + $this->assertEquals('10', $data['price']); |
|
| 362 | + $this->assertEquals('10', $data['regular_price']); |
|
| 363 | + $this->assertFalse($data['purchasable']); |
|
| 364 | + $this->assertEquals('DUMMY SKU EXTERNAL API', $data['sku']); |
|
| 365 | + $this->assertEquals('Test External Product', $data['name']); |
|
| 366 | + $this->assertEquals('external', $data['type']); |
|
| 367 | + $this->assertEquals('Test Button', $data['button_text']); |
|
| 368 | + $this->assertEquals('https://wordpress.org', $data['external_url']); |
|
| 369 | 369 | |
| 370 | 370 | // Create variable. |
| 371 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); |
|
| 371 | + $request = new WP_REST_Request('POST', '/wc/v3/products'); |
|
| 372 | 372 | $request->set_body_params( |
| 373 | 373 | array( |
| 374 | 374 | 'type' => 'variable', |
@@ -388,17 +388,17 @@ discard block |
||
| 388 | 388 | ), |
| 389 | 389 | ) |
| 390 | 390 | ); |
| 391 | - $response = $this->server->dispatch( $request ); |
|
| 391 | + $response = $this->server->dispatch($request); |
|
| 392 | 392 | $data = $response->get_data(); |
| 393 | 393 | |
| 394 | - $this->assertEquals( 'DUMMY SKU VARIABLE API', $data['sku'] ); |
|
| 395 | - $this->assertEquals( 'Test Variable Product', $data['name'] ); |
|
| 396 | - $this->assertEquals( 'variable', $data['type'] ); |
|
| 397 | - $this->assertEquals( array( 'small', 'medium' ), $data['attributes'][0]['options'] ); |
|
| 394 | + $this->assertEquals('DUMMY SKU VARIABLE API', $data['sku']); |
|
| 395 | + $this->assertEquals('Test Variable Product', $data['name']); |
|
| 396 | + $this->assertEquals('variable', $data['type']); |
|
| 397 | + $this->assertEquals(array('small', 'medium'), $data['attributes'][0]['options']); |
|
| 398 | 398 | |
| 399 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/products' ) ); |
|
| 399 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/products')); |
|
| 400 | 400 | $products = $response->get_data(); |
| 401 | - $this->assertEquals( 3, count( $products ) ); |
|
| 401 | + $this->assertEquals(3, count($products)); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | /** |
@@ -407,17 +407,17 @@ discard block |
||
| 407 | 407 | * @since 3.5.0 |
| 408 | 408 | */ |
| 409 | 409 | public function test_create_product_without_permission() { |
| 410 | - wp_set_current_user( 0 ); |
|
| 410 | + wp_set_current_user(0); |
|
| 411 | 411 | |
| 412 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products' ); |
|
| 412 | + $request = new WP_REST_Request('POST', '/wc/v3/products'); |
|
| 413 | 413 | $request->set_body_params( |
| 414 | 414 | array( |
| 415 | 415 | 'name' => 'Test Product', |
| 416 | 416 | 'regular_price' => '12', |
| 417 | 417 | ) |
| 418 | 418 | ); |
| 419 | - $response = $this->server->dispatch( $request ); |
|
| 420 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 419 | + $response = $this->server->dispatch($request); |
|
| 420 | + $this->assertEquals(401, $response->get_status()); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -426,10 +426,10 @@ discard block |
||
| 426 | 426 | * @since 3.5.0 |
| 427 | 427 | */ |
| 428 | 428 | public function test_products_batch() { |
| 429 | - wp_set_current_user( $this->user ); |
|
| 429 | + wp_set_current_user($this->user); |
|
| 430 | 430 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 431 | 431 | $product_2 = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 432 | - $request = new WP_REST_Request( 'POST', '/wc/v3/products/batch' ); |
|
| 432 | + $request = new WP_REST_Request('POST', '/wc/v3/products/batch'); |
|
| 433 | 433 | $request->set_body_params( |
| 434 | 434 | array( |
| 435 | 435 | 'update' => array( |
@@ -458,22 +458,22 @@ discard block |
||
| 458 | 458 | ), |
| 459 | 459 | ) |
| 460 | 460 | ); |
| 461 | - $response = $this->server->dispatch( $request ); |
|
| 461 | + $response = $this->server->dispatch($request); |
|
| 462 | 462 | $data = $response->get_data(); |
| 463 | 463 | |
| 464 | - $this->assertContains( 'Updated description.', $data['update'][0]['description'] ); |
|
| 465 | - $this->assertEquals( 'DUMMY SKU BATCH TEST 1', $data['create'][0]['sku'] ); |
|
| 466 | - $this->assertEquals( 'DUMMY SKU BATCH TEST 2', $data['create'][1]['sku'] ); |
|
| 467 | - $this->assertEquals( 'Test Button', $data['create'][0]['button_text'] ); |
|
| 468 | - $this->assertEquals( 'external', $data['create'][0]['type'] ); |
|
| 469 | - $this->assertEquals( 'simple', $data['create'][1]['type'] ); |
|
| 470 | - $this->assertEquals( $product_2->get_id(), $data['delete'][0]['id'] ); |
|
| 464 | + $this->assertContains('Updated description.', $data['update'][0]['description']); |
|
| 465 | + $this->assertEquals('DUMMY SKU BATCH TEST 1', $data['create'][0]['sku']); |
|
| 466 | + $this->assertEquals('DUMMY SKU BATCH TEST 2', $data['create'][1]['sku']); |
|
| 467 | + $this->assertEquals('Test Button', $data['create'][0]['button_text']); |
|
| 468 | + $this->assertEquals('external', $data['create'][0]['type']); |
|
| 469 | + $this->assertEquals('simple', $data['create'][1]['type']); |
|
| 470 | + $this->assertEquals($product_2->get_id(), $data['delete'][0]['id']); |
|
| 471 | 471 | |
| 472 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); |
|
| 473 | - $response = $this->server->dispatch( $request ); |
|
| 472 | + $request = new WP_REST_Request('GET', '/wc/v3/products'); |
|
| 473 | + $response = $this->server->dispatch($request); |
|
| 474 | 474 | $data = $response->get_data(); |
| 475 | 475 | |
| 476 | - $this->assertEquals( 3, count( $data ) ); |
|
| 476 | + $this->assertEquals(3, count($data)); |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -483,10 +483,10 @@ discard block |
||
| 483 | 483 | * @since 3.5.0 |
| 484 | 484 | */ |
| 485 | 485 | public function test_products_filter_post_status() { |
| 486 | - wp_set_current_user( $this->user ); |
|
| 487 | - for ( $i = 0; $i < 8; $i++ ) { |
|
| 486 | + wp_set_current_user($this->user); |
|
| 487 | + for ($i = 0; $i < 8; $i++) { |
|
| 488 | 488 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 489 | - if ( 0 === $i % 2 ) { |
|
| 489 | + if (0 === $i % 2) { |
|
| 490 | 490 | wp_update_post( |
| 491 | 491 | array( |
| 492 | 492 | 'ID' => $product->get_id(), |
@@ -497,33 +497,33 @@ discard block |
||
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Test filtering with status=publish. |
| 500 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); |
|
| 501 | - $request->set_param( 'status', 'publish' ); |
|
| 502 | - $response = $this->server->dispatch( $request ); |
|
| 500 | + $request = new WP_REST_Request('GET', '/wc/v3/products'); |
|
| 501 | + $request->set_param('status', 'publish'); |
|
| 502 | + $response = $this->server->dispatch($request); |
|
| 503 | 503 | $products = $response->get_data(); |
| 504 | 504 | |
| 505 | - $this->assertEquals( 4, count( $products ) ); |
|
| 506 | - foreach ( $products as $product ) { |
|
| 507 | - $this->assertEquals( 'publish', $product['status'] ); |
|
| 505 | + $this->assertEquals(4, count($products)); |
|
| 506 | + foreach ($products as $product) { |
|
| 507 | + $this->assertEquals('publish', $product['status']); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | // Test filtering with status=draft. |
| 511 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); |
|
| 512 | - $request->set_param( 'status', 'draft' ); |
|
| 513 | - $response = $this->server->dispatch( $request ); |
|
| 511 | + $request = new WP_REST_Request('GET', '/wc/v3/products'); |
|
| 512 | + $request->set_param('status', 'draft'); |
|
| 513 | + $response = $this->server->dispatch($request); |
|
| 514 | 514 | $products = $response->get_data(); |
| 515 | 515 | |
| 516 | - $this->assertEquals( 4, count( $products ) ); |
|
| 517 | - foreach ( $products as $product ) { |
|
| 518 | - $this->assertEquals( 'draft', $product['status'] ); |
|
| 516 | + $this->assertEquals(4, count($products)); |
|
| 517 | + foreach ($products as $product) { |
|
| 518 | + $this->assertEquals('draft', $product['status']); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // Test filtering with no filters - which should return 'any' (all 8). |
| 522 | - $request = new WP_REST_Request( 'GET', '/wc/v3/products' ); |
|
| 523 | - $response = $this->server->dispatch( $request ); |
|
| 522 | + $request = new WP_REST_Request('GET', '/wc/v3/products'); |
|
| 523 | + $response = $this->server->dispatch($request); |
|
| 524 | 524 | $products = $response->get_data(); |
| 525 | 525 | |
| 526 | - $this->assertEquals( 8, count( $products ) ); |
|
| 526 | + $this->assertEquals(8, count($products)); |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -532,13 +532,13 @@ discard block |
||
| 532 | 532 | * @since 3.5.0 |
| 533 | 533 | */ |
| 534 | 534 | public function test_product_schema() { |
| 535 | - wp_set_current_user( $this->user ); |
|
| 535 | + wp_set_current_user($this->user); |
|
| 536 | 536 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 537 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/products/' . $product->get_id() ); |
|
| 538 | - $response = $this->server->dispatch( $request ); |
|
| 537 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/products/' . $product->get_id()); |
|
| 538 | + $response = $this->server->dispatch($request); |
|
| 539 | 539 | $data = $response->get_data(); |
| 540 | 540 | $properties = $data['schema']['properties']; |
| 541 | - $this->assertEquals( 65, count( $properties ) ); |
|
| 541 | + $this->assertEquals(65, count($properties)); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -547,13 +547,13 @@ discard block |
||
| 547 | 547 | * @since 3.5.0 |
| 548 | 548 | */ |
| 549 | 549 | public function test_get_products_by_category() { |
| 550 | - wp_set_current_user( $this->user ); |
|
| 550 | + wp_set_current_user($this->user); |
|
| 551 | 551 | |
| 552 | 552 | // Create one product with a category. |
| 553 | - $category = wp_insert_term( 'Some Category', 'product_cat' ); |
|
| 553 | + $category = wp_insert_term('Some Category', 'product_cat'); |
|
| 554 | 554 | |
| 555 | 555 | $product = new WC_Product_Simple(); |
| 556 | - $product->set_category_ids( array( $category['term_id'] ) ); |
|
| 556 | + $product->set_category_ids(array($category['term_id'])); |
|
| 557 | 557 | $product->save(); |
| 558 | 558 | |
| 559 | 559 | // Create one product without category, i.e. Uncategorized. |
@@ -564,25 +564,25 @@ discard block |
||
| 564 | 564 | $query_params = array( |
| 565 | 565 | 'category' => (string) $category['term_id'], |
| 566 | 566 | ); |
| 567 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 568 | - $request->set_query_params( $query_params ); |
|
| 569 | - $response = $this->server->dispatch( $request ); |
|
| 567 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 568 | + $request->set_query_params($query_params); |
|
| 569 | + $response = $this->server->dispatch($request); |
|
| 570 | 570 | $response_products = $response->get_data(); |
| 571 | 571 | |
| 572 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 573 | - foreach ( $response_products as $response_product ) { |
|
| 574 | - $this->assertEquals( $product->get_id(), $response_product['id'] ); |
|
| 575 | - $this->assertEquals( $product->get_category_ids(), wp_list_pluck( $response_product['categories'], 'id' ) ); |
|
| 572 | + $this->assertEquals(200, $response->get_status()); |
|
| 573 | + foreach ($response_products as $response_product) { |
|
| 574 | + $this->assertEquals($product->get_id(), $response_product['id']); |
|
| 575 | + $this->assertEquals($product->get_category_ids(), wp_list_pluck($response_product['categories'], 'id')); |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | // Test product without categories. |
| 579 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products/' . $product_2->get_id() ); |
|
| 580 | - $response = $this->server->dispatch( $request ); |
|
| 579 | + $request = new WP_REST_Request('GET', '/wc/v2/products/' . $product_2->get_id()); |
|
| 580 | + $response = $this->server->dispatch($request); |
|
| 581 | 581 | $response_product = $response->get_data(); |
| 582 | 582 | |
| 583 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 584 | - $this->assertCount( 1, $response_product['categories'], print_r( $response_product, true ) ); |
|
| 585 | - $this->assertEquals( 'uncategorized', $response_product['categories'][0]['slug'] ); |
|
| 583 | + $this->assertEquals(200, $response->get_status()); |
|
| 584 | + $this->assertCount(1, $response_product['categories'], print_r($response_product, true)); |
|
| 585 | + $this->assertEquals('uncategorized', $response_product['categories'][0]['slug']); |
|
| 586 | 586 | |
| 587 | 587 | } |
| 588 | 588 | |
@@ -592,7 +592,7 @@ discard block |
||
| 592 | 592 | * @since 3.5.0 |
| 593 | 593 | */ |
| 594 | 594 | public function test_get_products_by_type() { |
| 595 | - wp_set_current_user( $this->user ); |
|
| 595 | + wp_set_current_user($this->user); |
|
| 596 | 596 | |
| 597 | 597 | $simple = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 598 | 598 | $external = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_external_product(); |
@@ -600,29 +600,29 @@ discard block |
||
| 600 | 600 | $variable = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
| 601 | 601 | |
| 602 | 602 | $product_ids_for_type = array( |
| 603 | - 'simple' => array( $simple->get_id() ), |
|
| 604 | - 'external' => array( $external->get_id() ), |
|
| 605 | - 'grouped' => array( $grouped->get_id() ), |
|
| 606 | - 'variable' => array( $variable->get_id() ), |
|
| 603 | + 'simple' => array($simple->get_id()), |
|
| 604 | + 'external' => array($external->get_id()), |
|
| 605 | + 'grouped' => array($grouped->get_id()), |
|
| 606 | + 'variable' => array($variable->get_id()), |
|
| 607 | 607 | ); |
| 608 | 608 | |
| 609 | - foreach ( $grouped->get_children() as $additional_product ) { |
|
| 609 | + foreach ($grouped->get_children() as $additional_product) { |
|
| 610 | 610 | $product_ids_for_type['simple'][] = $additional_product; |
| 611 | 611 | } |
| 612 | 612 | |
| 613 | - foreach ( $product_ids_for_type as $product_type => $product_ids ) { |
|
| 613 | + foreach ($product_ids_for_type as $product_type => $product_ids) { |
|
| 614 | 614 | $query_params = array( |
| 615 | 615 | 'type' => $product_type, |
| 616 | 616 | ); |
| 617 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 618 | - $request->set_query_params( $query_params ); |
|
| 619 | - $response = $this->server->dispatch( $request ); |
|
| 617 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 618 | + $request->set_query_params($query_params); |
|
| 619 | + $response = $this->server->dispatch($request); |
|
| 620 | 620 | $response_products = $response->get_data(); |
| 621 | 621 | |
| 622 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 623 | - $this->assertEquals( count( $product_ids ), count( $response_products ) ); |
|
| 624 | - foreach ( $response_products as $response_product ) { |
|
| 625 | - $this->assertContains( $response_product['id'], $product_ids_for_type[ $product_type ], 'REST API: ' . $product_type . ' not found correctly' ); |
|
| 622 | + $this->assertEquals(200, $response->get_status()); |
|
| 623 | + $this->assertEquals(count($product_ids), count($response_products)); |
|
| 624 | + foreach ($response_products as $response_product) { |
|
| 625 | + $this->assertContains($response_product['id'], $product_ids_for_type[$product_type], 'REST API: ' . $product_type . ' not found correctly'); |
|
| 626 | 626 | } |
| 627 | 627 | } |
| 628 | 628 | } |
@@ -633,11 +633,11 @@ discard block |
||
| 633 | 633 | * @since 3.5.0 |
| 634 | 634 | */ |
| 635 | 635 | public function test_get_featured_products() { |
| 636 | - wp_set_current_user( $this->user ); |
|
| 636 | + wp_set_current_user($this->user); |
|
| 637 | 637 | |
| 638 | 638 | // Create a featured product. |
| 639 | 639 | $feat_product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 640 | - $feat_product->set_featured( true ); |
|
| 640 | + $feat_product->set_featured(true); |
|
| 641 | 641 | $feat_product->save(); |
| 642 | 642 | |
| 643 | 643 | // Create a non-featured product. |
@@ -647,27 +647,27 @@ discard block |
||
| 647 | 647 | $query_params = array( |
| 648 | 648 | 'featured' => 'true', |
| 649 | 649 | ); |
| 650 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 651 | - $request->set_query_params( $query_params ); |
|
| 652 | - $response = $this->server->dispatch( $request ); |
|
| 650 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 651 | + $request->set_query_params($query_params); |
|
| 652 | + $response = $this->server->dispatch($request); |
|
| 653 | 653 | $response_products = $response->get_data(); |
| 654 | 654 | |
| 655 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 656 | - foreach ( $response_products as $response_product ) { |
|
| 657 | - $this->assertEquals( $feat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' ); |
|
| 655 | + $this->assertEquals(200, $response->get_status()); |
|
| 656 | + foreach ($response_products as $response_product) { |
|
| 657 | + $this->assertEquals($feat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly'); |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | $query_params = array( |
| 661 | 661 | 'featured' => 'false', |
| 662 | 662 | ); |
| 663 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 664 | - $request->set_query_params( $query_params ); |
|
| 665 | - $response = $this->server->dispatch( $request ); |
|
| 663 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 664 | + $request->set_query_params($query_params); |
|
| 665 | + $response = $this->server->dispatch($request); |
|
| 666 | 666 | $response_products = $response->get_data(); |
| 667 | 667 | |
| 668 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 669 | - foreach ( $response_products as $response_product ) { |
|
| 670 | - $this->assertEquals( $nonfeat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly' ); |
|
| 668 | + $this->assertEquals(200, $response->get_status()); |
|
| 669 | + foreach ($response_products as $response_product) { |
|
| 670 | + $this->assertEquals($nonfeat_product->get_id(), $response_product['id'], 'REST API: Featured product not found correctly'); |
|
| 671 | 671 | } |
| 672 | 672 | } |
| 673 | 673 | |
@@ -677,25 +677,25 @@ discard block |
||
| 677 | 677 | * @since 3.5.0 |
| 678 | 678 | */ |
| 679 | 679 | public function test_get_products_by_shipping_class() { |
| 680 | - wp_set_current_user( $this->user ); |
|
| 680 | + wp_set_current_user($this->user); |
|
| 681 | 681 | |
| 682 | - $shipping_class_1 = wp_insert_term( 'Bulky', 'product_shipping_class' ); |
|
| 682 | + $shipping_class_1 = wp_insert_term('Bulky', 'product_shipping_class'); |
|
| 683 | 683 | |
| 684 | 684 | $product_1 = new WC_Product_Simple(); |
| 685 | - $product_1->set_shipping_class_id( $shipping_class_1['term_id'] ); |
|
| 685 | + $product_1->set_shipping_class_id($shipping_class_1['term_id']); |
|
| 686 | 686 | $product_1->save(); |
| 687 | 687 | |
| 688 | 688 | $query_params = array( |
| 689 | 689 | 'shipping_class' => (string) $shipping_class_1['term_id'], |
| 690 | 690 | ); |
| 691 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 692 | - $request->set_query_params( $query_params ); |
|
| 693 | - $response = $this->server->dispatch( $request ); |
|
| 691 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 692 | + $request->set_query_params($query_params); |
|
| 693 | + $response = $this->server->dispatch($request); |
|
| 694 | 694 | $response_products = $response->get_data(); |
| 695 | 695 | |
| 696 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 697 | - foreach ( $response_products as $response_product ) { |
|
| 698 | - $this->assertEquals( $product_1->get_id(), $response_product['id'] ); |
|
| 696 | + $this->assertEquals(200, $response->get_status()); |
|
| 697 | + foreach ($response_products as $response_product) { |
|
| 698 | + $this->assertEquals($product_1->get_id(), $response_product['id']); |
|
| 699 | 699 | } |
| 700 | 700 | } |
| 701 | 701 | |
@@ -705,13 +705,13 @@ discard block |
||
| 705 | 705 | * @since 3.5.0 |
| 706 | 706 | */ |
| 707 | 707 | public function test_get_products_by_tag() { |
| 708 | - wp_set_current_user( $this->user ); |
|
| 708 | + wp_set_current_user($this->user); |
|
| 709 | 709 | |
| 710 | - $test_tag_1 = wp_insert_term( 'Tag 1', 'product_tag' ); |
|
| 710 | + $test_tag_1 = wp_insert_term('Tag 1', 'product_tag'); |
|
| 711 | 711 | |
| 712 | 712 | // Product with a tag. |
| 713 | 713 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 714 | - $product->set_tag_ids( array( $test_tag_1['term_id'] ) ); |
|
| 714 | + $product->set_tag_ids(array($test_tag_1['term_id'])); |
|
| 715 | 715 | $product->save(); |
| 716 | 716 | |
| 717 | 717 | // Product without a tag. |
@@ -720,14 +720,14 @@ discard block |
||
| 720 | 720 | $query_params = array( |
| 721 | 721 | 'tag' => (string) $test_tag_1['term_id'], |
| 722 | 722 | ); |
| 723 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 724 | - $request->set_query_params( $query_params ); |
|
| 725 | - $response = $this->server->dispatch( $request ); |
|
| 723 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 724 | + $request->set_query_params($query_params); |
|
| 725 | + $response = $this->server->dispatch($request); |
|
| 726 | 726 | $response_products = $response->get_data(); |
| 727 | 727 | |
| 728 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 729 | - foreach ( $response_products as $response_product ) { |
|
| 730 | - $this->assertEquals( $product->get_id(), $response_product['id'] ); |
|
| 728 | + $this->assertEquals(200, $response->get_status()); |
|
| 729 | + foreach ($response_products as $response_product) { |
|
| 730 | + $this->assertEquals($product->get_id(), $response_product['id']); |
|
| 731 | 731 | } |
| 732 | 732 | } |
| 733 | 733 | |
@@ -738,21 +738,21 @@ discard block |
||
| 738 | 738 | */ |
| 739 | 739 | public function test_get_products_by_attribute() { |
| 740 | 740 | global $wpdb; |
| 741 | - wp_set_current_user( $this->user ); |
|
| 741 | + wp_set_current_user($this->user); |
|
| 742 | 742 | |
| 743 | 743 | // Variable product with 2 different variations. |
| 744 | 744 | $variable_product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_variation_product(); |
| 745 | 745 | |
| 746 | 746 | // Terms created by variable product. |
| 747 | - $term_large = get_term_by( 'slug', 'large', 'pa_size' ); |
|
| 748 | - $term_small = get_term_by( 'slug', 'small', 'pa_size' ); |
|
| 747 | + $term_large = get_term_by('slug', 'large', 'pa_size'); |
|
| 748 | + $term_small = get_term_by('slug', 'small', 'pa_size'); |
|
| 749 | 749 | |
| 750 | 750 | // Simple product without attribute. |
| 751 | 751 | $product_1 = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 752 | 752 | |
| 753 | 753 | // Simple product with attribute size = large. |
| 754 | 754 | $product_2 = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 755 | - $product_2->set_attributes( array( 'pa_size' => 'large' ) ); |
|
| 755 | + $product_2->set_attributes(array('pa_size' => 'large')); |
|
| 756 | 756 | $product_2->save(); |
| 757 | 757 | |
| 758 | 758 | // Link the product to the term. |
@@ -770,19 +770,19 @@ discard block |
||
| 770 | 770 | $variable_product->get_id(), |
| 771 | 771 | $product_2->get_id(), |
| 772 | 772 | ); |
| 773 | - $query_params = array( |
|
| 773 | + $query_params = array( |
|
| 774 | 774 | 'attribute' => 'pa_size', |
| 775 | 775 | 'attribute_term' => (string) $term_large->term_id, |
| 776 | 776 | ); |
| 777 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 778 | - $request->set_query_params( $query_params ); |
|
| 779 | - $response = $this->server->dispatch( $request ); |
|
| 777 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 778 | + $request->set_query_params($query_params); |
|
| 779 | + $response = $this->server->dispatch($request); |
|
| 780 | 780 | $response_products = $response->get_data(); |
| 781 | 781 | |
| 782 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 783 | - $this->assertEquals( count( $expected_product_ids ), count( $response_products ) ); |
|
| 784 | - foreach ( $response_products as $response_product ) { |
|
| 785 | - $this->assertContains( $response_product['id'], $expected_product_ids ); |
|
| 782 | + $this->assertEquals(200, $response->get_status()); |
|
| 783 | + $this->assertEquals(count($expected_product_ids), count($response_products)); |
|
| 784 | + foreach ($response_products as $response_product) { |
|
| 785 | + $this->assertContains($response_product['id'], $expected_product_ids); |
|
| 786 | 786 | } |
| 787 | 787 | |
| 788 | 788 | // Products with attribute size == small. |
@@ -793,15 +793,15 @@ discard block |
||
| 793 | 793 | 'attribute' => 'pa_size', |
| 794 | 794 | 'attribute_term' => (string) $term_small->term_id, |
| 795 | 795 | ); |
| 796 | - $request = new WP_REST_Request( 'GET', '/wc/v2/products' ); |
|
| 797 | - $request->set_query_params( $query_params ); |
|
| 798 | - $response = $this->server->dispatch( $request ); |
|
| 796 | + $request = new WP_REST_Request('GET', '/wc/v2/products'); |
|
| 797 | + $request->set_query_params($query_params); |
|
| 798 | + $response = $this->server->dispatch($request); |
|
| 799 | 799 | $response_products = $response->get_data(); |
| 800 | 800 | |
| 801 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 802 | - $this->assertEquals( count( $expected_product_ids ), count( $response_products ) ); |
|
| 803 | - foreach ( $response_products as $response_product ) { |
|
| 804 | - $this->assertContains( $response_product['id'], $expected_product_ids ); |
|
| 801 | + $this->assertEquals(200, $response->get_status()); |
|
| 802 | + $this->assertEquals(count($expected_product_ids), count($response_products)); |
|
| 803 | + foreach ($response_products as $response_product) { |
|
| 804 | + $this->assertContains($response_product['id'], $expected_product_ids); |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | } |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function test_register_routes() { |
| 30 | 30 | $routes = $this->server->get_routes(); |
| 31 | - $this->assertArrayHasKey( '/wc/v3/payment_gateways', $routes ); |
|
| 32 | - $this->assertArrayHasKey( '/wc/v3/payment_gateways/(?P<id>[\w-]+)', $routes ); |
|
| 31 | + $this->assertArrayHasKey('/wc/v3/payment_gateways', $routes); |
|
| 32 | + $this->assertArrayHasKey('/wc/v3/payment_gateways/(?P<id>[\w-]+)', $routes); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | * @since 3.5.0 |
| 39 | 39 | */ |
| 40 | 40 | public function test_get_payment_gateways() { |
| 41 | - wp_set_current_user( $this->user ); |
|
| 41 | + wp_set_current_user($this->user); |
|
| 42 | 42 | |
| 43 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways' ) ); |
|
| 43 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways')); |
|
| 44 | 44 | $gateways = $response->get_data(); |
| 45 | 45 | |
| 46 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 46 | + $this->assertEquals(200, $response->get_status()); |
|
| 47 | 47 | $this->assertContains( |
| 48 | 48 | array( |
| 49 | 49 | 'id' => 'cheque', |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | 'products', |
| 58 | 58 | ), |
| 59 | 59 | 'settings' => array_diff_key( |
| 60 | - $this->get_settings( 'WC_Gateway_Cheque' ), |
|
| 60 | + $this->get_settings('WC_Gateway_Cheque'), |
|
| 61 | 61 | array( |
| 62 | 62 | 'enabled' => false, |
| 63 | 63 | 'description' => false, |
@@ -66,12 +66,12 @@ discard block |
||
| 66 | 66 | '_links' => array( |
| 67 | 67 | 'self' => array( |
| 68 | 68 | array( |
| 69 | - 'href' => rest_url( '/wc/v3/payment_gateways/cheque' ), |
|
| 69 | + 'href' => rest_url('/wc/v3/payment_gateways/cheque'), |
|
| 70 | 70 | ), |
| 71 | 71 | ), |
| 72 | 72 | 'collection' => array( |
| 73 | 73 | array( |
| 74 | - 'href' => rest_url( '/wc/v3/payment_gateways' ), |
|
| 74 | + 'href' => rest_url('/wc/v3/payment_gateways'), |
|
| 75 | 75 | ), |
| 76 | 76 | ), |
| 77 | 77 | ), |
@@ -86,9 +86,9 @@ discard block |
||
| 86 | 86 | * @since 3.5.0 |
| 87 | 87 | */ |
| 88 | 88 | public function test_get_payment_gateways_without_permission() { |
| 89 | - wp_set_current_user( 0 ); |
|
| 90 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways' ) ); |
|
| 91 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 89 | + wp_set_current_user(0); |
|
| 90 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways')); |
|
| 91 | + $this->assertEquals(401, $response->get_status()); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -97,12 +97,12 @@ discard block |
||
| 97 | 97 | * @since 3.5.0 |
| 98 | 98 | */ |
| 99 | 99 | public function test_get_payment_gateway() { |
| 100 | - wp_set_current_user( $this->user ); |
|
| 100 | + wp_set_current_user($this->user); |
|
| 101 | 101 | |
| 102 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); |
|
| 102 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways/paypal')); |
|
| 103 | 103 | $paypal = $response->get_data(); |
| 104 | 104 | |
| 105 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 105 | + $this->assertEquals(200, $response->get_status()); |
|
| 106 | 106 | $this->assertEquals( |
| 107 | 107 | array( |
| 108 | 108 | 'id' => 'paypal', |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | 'refunds', |
| 118 | 118 | ), |
| 119 | 119 | 'settings' => array_diff_key( |
| 120 | - $this->get_settings( 'WC_Gateway_Paypal' ), |
|
| 120 | + $this->get_settings('WC_Gateway_Paypal'), |
|
| 121 | 121 | array( |
| 122 | 122 | 'enabled' => false, |
| 123 | 123 | 'description' => false, |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | * @since 3.5.0 |
| 135 | 135 | */ |
| 136 | 136 | public function test_get_payment_gateway_without_permission() { |
| 137 | - wp_set_current_user( 0 ); |
|
| 138 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); |
|
| 139 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 137 | + wp_set_current_user(0); |
|
| 138 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways/paypal')); |
|
| 139 | + $this->assertEquals(401, $response->get_status()); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | * @since 3.5.0 |
| 146 | 146 | */ |
| 147 | 147 | public function test_get_payment_gateway_invalid_id() { |
| 148 | - wp_set_current_user( $this->user ); |
|
| 149 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/totally_fake_method' ) ); |
|
| 150 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 148 | + wp_set_current_user($this->user); |
|
| 149 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways/totally_fake_method')); |
|
| 150 | + $this->assertEquals(404, $response->get_status()); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -156,18 +156,18 @@ discard block |
||
| 156 | 156 | * @since 3.5.0 |
| 157 | 157 | */ |
| 158 | 158 | public function test_update_payment_gateway() { |
| 159 | - wp_set_current_user( $this->user ); |
|
| 159 | + wp_set_current_user($this->user); |
|
| 160 | 160 | |
| 161 | 161 | // Test defaults |
| 162 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/payment_gateways/paypal' ) ); |
|
| 162 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/payment_gateways/paypal')); |
|
| 163 | 163 | $paypal = $response->get_data(); |
| 164 | 164 | |
| 165 | - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); |
|
| 166 | - $this->assertEquals( '[email protected]', $paypal['settings']['email']['value'] ); |
|
| 167 | - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); |
|
| 165 | + $this->assertEquals('PayPal', $paypal['settings']['title']['value']); |
|
| 166 | + $this->assertEquals('[email protected]', $paypal['settings']['email']['value']); |
|
| 167 | + $this->assertEquals('no', $paypal['settings']['testmode']['value']); |
|
| 168 | 168 | |
| 169 | 169 | // test updating single setting |
| 170 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 170 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 171 | 171 | $request->set_body_params( |
| 172 | 172 | array( |
| 173 | 173 | 'settings' => array( |
@@ -175,16 +175,16 @@ discard block |
||
| 175 | 175 | ), |
| 176 | 176 | ) |
| 177 | 177 | ); |
| 178 | - $response = $this->server->dispatch( $request ); |
|
| 178 | + $response = $this->server->dispatch($request); |
|
| 179 | 179 | $paypal = $response->get_data(); |
| 180 | 180 | |
| 181 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 182 | - $this->assertEquals( 'PayPal', $paypal['settings']['title']['value'] ); |
|
| 183 | - $this->assertEquals( '[email protected]', $paypal['settings']['email']['value'] ); |
|
| 184 | - $this->assertEquals( 'no', $paypal['settings']['testmode']['value'] ); |
|
| 181 | + $this->assertEquals(200, $response->get_status()); |
|
| 182 | + $this->assertEquals('PayPal', $paypal['settings']['title']['value']); |
|
| 183 | + $this->assertEquals('[email protected]', $paypal['settings']['email']['value']); |
|
| 184 | + $this->assertEquals('no', $paypal['settings']['testmode']['value']); |
|
| 185 | 185 | |
| 186 | 186 | // test updating multiple settings |
| 187 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 187 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 188 | 188 | $request->set_body_params( |
| 189 | 189 | array( |
| 190 | 190 | 'settings' => array( |
@@ -193,33 +193,33 @@ discard block |
||
| 193 | 193 | ), |
| 194 | 194 | ) |
| 195 | 195 | ); |
| 196 | - $response = $this->server->dispatch( $request ); |
|
| 196 | + $response = $this->server->dispatch($request); |
|
| 197 | 197 | $paypal = $response->get_data(); |
| 198 | 198 | |
| 199 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 200 | - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); |
|
| 201 | - $this->assertEquals( '[email protected]', $paypal['settings']['email']['value'] ); |
|
| 202 | - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); |
|
| 199 | + $this->assertEquals(200, $response->get_status()); |
|
| 200 | + $this->assertEquals('PayPal - New Title', $paypal['settings']['title']['value']); |
|
| 201 | + $this->assertEquals('[email protected]', $paypal['settings']['email']['value']); |
|
| 202 | + $this->assertEquals('yes', $paypal['settings']['testmode']['value']); |
|
| 203 | 203 | |
| 204 | 204 | // Test other parameters, and recheck settings |
| 205 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 205 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 206 | 206 | $request->set_body_params( |
| 207 | 207 | array( |
| 208 | 208 | 'enabled' => false, |
| 209 | 209 | 'order' => 2, |
| 210 | 210 | ) |
| 211 | 211 | ); |
| 212 | - $response = $this->server->dispatch( $request ); |
|
| 212 | + $response = $this->server->dispatch($request); |
|
| 213 | 213 | $paypal = $response->get_data(); |
| 214 | 214 | |
| 215 | - $this->assertFalse( $paypal['enabled'] ); |
|
| 216 | - $this->assertEquals( 2, $paypal['order'] ); |
|
| 217 | - $this->assertEquals( 'PayPal - New Title', $paypal['settings']['title']['value'] ); |
|
| 218 | - $this->assertEquals( '[email protected]', $paypal['settings']['email']['value'] ); |
|
| 219 | - $this->assertEquals( 'yes', $paypal['settings']['testmode']['value'] ); |
|
| 215 | + $this->assertFalse($paypal['enabled']); |
|
| 216 | + $this->assertEquals(2, $paypal['order']); |
|
| 217 | + $this->assertEquals('PayPal - New Title', $paypal['settings']['title']['value']); |
|
| 218 | + $this->assertEquals('[email protected]', $paypal['settings']['email']['value']); |
|
| 219 | + $this->assertEquals('yes', $paypal['settings']['testmode']['value']); |
|
| 220 | 220 | |
| 221 | 221 | // test bogus |
| 222 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 222 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 223 | 223 | $request->set_body_params( |
| 224 | 224 | array( |
| 225 | 225 | 'settings' => array( |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | ), |
| 228 | 228 | ) |
| 229 | 229 | ); |
| 230 | - $response = $this->server->dispatch( $request ); |
|
| 231 | - $this->assertEquals( 400, $response->get_status() ); |
|
| 230 | + $response = $this->server->dispatch($request); |
|
| 231 | + $this->assertEquals(400, $response->get_status()); |
|
| 232 | 232 | |
| 233 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 233 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 234 | 234 | $request->set_body_params( |
| 235 | 235 | array( |
| 236 | 236 | 'settings' => array( |
@@ -238,9 +238,9 @@ discard block |
||
| 238 | 238 | ), |
| 239 | 239 | ) |
| 240 | 240 | ); |
| 241 | - $response = $this->server->dispatch( $request ); |
|
| 241 | + $response = $this->server->dispatch($request); |
|
| 242 | 242 | $paypal = $response->get_data(); |
| 243 | - $this->assertEquals( 'authorization', $paypal['settings']['paymentaction']['value'] ); |
|
| 243 | + $this->assertEquals('authorization', $paypal['settings']['paymentaction']['value']); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -249,8 +249,8 @@ discard block |
||
| 249 | 249 | * @since 3.5.0 |
| 250 | 250 | */ |
| 251 | 251 | public function test_update_payment_gateway_without_permission() { |
| 252 | - wp_set_current_user( 0 ); |
|
| 253 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/paypal' ); |
|
| 252 | + wp_set_current_user(0); |
|
| 253 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/paypal'); |
|
| 254 | 254 | $request->set_body_params( |
| 255 | 255 | array( |
| 256 | 256 | 'settings' => array( |
@@ -259,8 +259,8 @@ discard block |
||
| 259 | 259 | ), |
| 260 | 260 | ) |
| 261 | 261 | ); |
| 262 | - $response = $this->server->dispatch( $request ); |
|
| 263 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 262 | + $response = $this->server->dispatch($request); |
|
| 263 | + $this->assertEquals(401, $response->get_status()); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -269,15 +269,15 @@ discard block |
||
| 269 | 269 | * @since 3.5.0 |
| 270 | 270 | */ |
| 271 | 271 | public function test_update_payment_gateway_invalid_id() { |
| 272 | - wp_set_current_user( $this->user ); |
|
| 273 | - $request = new WP_REST_Request( 'POST', '/wc/v3/payment_gateways/totally_fake_method' ); |
|
| 272 | + wp_set_current_user($this->user); |
|
| 273 | + $request = new WP_REST_Request('POST', '/wc/v3/payment_gateways/totally_fake_method'); |
|
| 274 | 274 | $request->set_body_params( |
| 275 | 275 | array( |
| 276 | 276 | 'enabled' => true, |
| 277 | 277 | ) |
| 278 | 278 | ); |
| 279 | - $response = $this->server->dispatch( $request ); |
|
| 280 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 279 | + $response = $this->server->dispatch($request); |
|
| 280 | + $this->assertEquals(404, $response->get_status()); |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -286,23 +286,23 @@ discard block |
||
| 286 | 286 | * @since 3.5.0 |
| 287 | 287 | */ |
| 288 | 288 | public function test_payment_gateway_schema() { |
| 289 | - wp_set_current_user( $this->user ); |
|
| 289 | + wp_set_current_user($this->user); |
|
| 290 | 290 | |
| 291 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/payment_gateways' ); |
|
| 292 | - $response = $this->server->dispatch( $request ); |
|
| 291 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/payment_gateways'); |
|
| 292 | + $response = $this->server->dispatch($request); |
|
| 293 | 293 | $data = $response->get_data(); |
| 294 | 294 | $properties = $data['schema']['properties']; |
| 295 | 295 | |
| 296 | - $this->assertEquals( 9, count( $properties ) ); |
|
| 297 | - $this->assertArrayHasKey( 'id', $properties ); |
|
| 298 | - $this->assertArrayHasKey( 'title', $properties ); |
|
| 299 | - $this->assertArrayHasKey( 'description', $properties ); |
|
| 300 | - $this->assertArrayHasKey( 'order', $properties ); |
|
| 301 | - $this->assertArrayHasKey( 'enabled', $properties ); |
|
| 302 | - $this->assertArrayHasKey( 'method_title', $properties ); |
|
| 303 | - $this->assertArrayHasKey( 'method_description', $properties ); |
|
| 304 | - $this->assertArrayHasKey( 'method_supports', $properties ); |
|
| 305 | - $this->assertArrayHasKey( 'settings', $properties ); |
|
| 296 | + $this->assertEquals(9, count($properties)); |
|
| 297 | + $this->assertArrayHasKey('id', $properties); |
|
| 298 | + $this->assertArrayHasKey('title', $properties); |
|
| 299 | + $this->assertArrayHasKey('description', $properties); |
|
| 300 | + $this->assertArrayHasKey('order', $properties); |
|
| 301 | + $this->assertArrayHasKey('enabled', $properties); |
|
| 302 | + $this->assertArrayHasKey('method_title', $properties); |
|
| 303 | + $this->assertArrayHasKey('method_description', $properties); |
|
| 304 | + $this->assertArrayHasKey('method_supports', $properties); |
|
| 305 | + $this->assertArrayHasKey('settings', $properties); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -311,33 +311,33 @@ discard block |
||
| 311 | 311 | * @since 3.5.0 |
| 312 | 312 | * @param string $gateway_class Name of WC_Payment_Gateway class. |
| 313 | 313 | */ |
| 314 | - private function get_settings( $gateway_class ) { |
|
| 314 | + private function get_settings($gateway_class) { |
|
| 315 | 315 | $gateway = new $gateway_class(); |
| 316 | 316 | $settings = array(); |
| 317 | 317 | $gateway->init_form_fields(); |
| 318 | - foreach ( $gateway->form_fields as $id => $field ) { |
|
| 318 | + foreach ($gateway->form_fields as $id => $field) { |
|
| 319 | 319 | // Make sure we at least have a title and type |
| 320 | - if ( empty( $field['title'] ) || empty( $field['type'] ) ) { |
|
| 320 | + if (empty($field['title']) || empty($field['type'])) { |
|
| 321 | 321 | continue; |
| 322 | 322 | } |
| 323 | 323 | // Ignore 'enabled' and 'description', to be in line with \WC_REST_Payment_Gateways_Controller::get_settings. |
| 324 | - if ( in_array( $id, array( 'enabled', 'description' ), true ) ) { |
|
| 324 | + if (in_array($id, array('enabled', 'description'), true)) { |
|
| 325 | 325 | continue; |
| 326 | 326 | } |
| 327 | 327 | $data = array( |
| 328 | 328 | 'id' => $id, |
| 329 | - 'label' => empty( $field['label'] ) ? $field['title'] : $field['label'], |
|
| 330 | - 'description' => empty( $field['description'] ) ? '' : $field['description'], |
|
| 329 | + 'label' => empty($field['label']) ? $field['title'] : $field['label'], |
|
| 330 | + 'description' => empty($field['description']) ? '' : $field['description'], |
|
| 331 | 331 | 'type' => $field['type'], |
| 332 | - 'value' => $gateway->settings[ $id ], |
|
| 333 | - 'default' => empty( $field['default'] ) ? '' : $field['default'], |
|
| 334 | - 'tip' => empty( $field['description'] ) ? '' : $field['description'], |
|
| 335 | - 'placeholder' => empty( $field['placeholder'] ) ? '' : $field['placeholder'], |
|
| 332 | + 'value' => $gateway->settings[$id], |
|
| 333 | + 'default' => empty($field['default']) ? '' : $field['default'], |
|
| 334 | + 'tip' => empty($field['description']) ? '' : $field['description'], |
|
| 335 | + 'placeholder' => empty($field['placeholder']) ? '' : $field['placeholder'], |
|
| 336 | 336 | ); |
| 337 | - if ( ! empty( $field['options'] ) ) { |
|
| 337 | + if ( ! empty($field['options'])) { |
|
| 338 | 338 | $data['options'] = $field['options']; |
| 339 | 339 | } |
| 340 | - $settings[ $id ] = $data; |
|
| 340 | + $settings[$id] = $data; |
|
| 341 | 341 | } |
| 342 | 342 | return $settings; |
| 343 | 343 | } |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function test_register_routes() { |
| 30 | 30 | $routes = $this->server->get_routes(); |
| 31 | - $this->assertArrayHasKey( '/wc/v3/shipping_methods', $routes ); |
|
| 32 | - $this->assertArrayHasKey( '/wc/v3/shipping_methods/(?P<id>[\w-]+)', $routes ); |
|
| 31 | + $this->assertArrayHasKey('/wc/v3/shipping_methods', $routes); |
|
| 32 | + $this->assertArrayHasKey('/wc/v3/shipping_methods/(?P<id>[\w-]+)', $routes); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -38,12 +38,12 @@ discard block |
||
| 38 | 38 | * @since 3.5.0 |
| 39 | 39 | */ |
| 40 | 40 | public function test_get_shipping_methods() { |
| 41 | - wp_set_current_user( $this->user ); |
|
| 41 | + wp_set_current_user($this->user); |
|
| 42 | 42 | |
| 43 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) ); |
|
| 43 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping_methods')); |
|
| 44 | 44 | $methods = $response->get_data(); |
| 45 | 45 | |
| 46 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 46 | + $this->assertEquals(200, $response->get_status()); |
|
| 47 | 47 | $this->assertContains( |
| 48 | 48 | array( |
| 49 | 49 | 'id' => 'free_shipping', |
@@ -52,12 +52,12 @@ discard block |
||
| 52 | 52 | '_links' => array( |
| 53 | 53 | 'self' => array( |
| 54 | 54 | array( |
| 55 | - 'href' => rest_url( '/wc/v3/shipping_methods/free_shipping' ), |
|
| 55 | + 'href' => rest_url('/wc/v3/shipping_methods/free_shipping'), |
|
| 56 | 56 | ), |
| 57 | 57 | ), |
| 58 | 58 | 'collection' => array( |
| 59 | 59 | array( |
| 60 | - 'href' => rest_url( '/wc/v3/shipping_methods' ), |
|
| 60 | + 'href' => rest_url('/wc/v3/shipping_methods'), |
|
| 61 | 61 | ), |
| 62 | 62 | ), |
| 63 | 63 | ), |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * @since 3.5.0 |
| 73 | 73 | */ |
| 74 | 74 | public function test_get_shipping_methods_without_permission() { |
| 75 | - wp_set_current_user( 0 ); |
|
| 76 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods' ) ); |
|
| 77 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 75 | + wp_set_current_user(0); |
|
| 76 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping_methods')); |
|
| 77 | + $this->assertEquals(401, $response->get_status()); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | * @since 3.5.0 |
| 84 | 84 | */ |
| 85 | 85 | public function test_get_shipping_method() { |
| 86 | - wp_set_current_user( $this->user ); |
|
| 86 | + wp_set_current_user($this->user); |
|
| 87 | 87 | |
| 88 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/local_pickup' ) ); |
|
| 88 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping_methods/local_pickup')); |
|
| 89 | 89 | $method = $response->get_data(); |
| 90 | 90 | |
| 91 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 91 | + $this->assertEquals(200, $response->get_status()); |
|
| 92 | 92 | $this->assertEquals( |
| 93 | 93 | array( |
| 94 | 94 | 'id' => 'local_pickup', |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | * @since 3.5.0 |
| 106 | 106 | */ |
| 107 | 107 | public function test_get_shipping_method_without_permission() { |
| 108 | - wp_set_current_user( 0 ); |
|
| 108 | + wp_set_current_user(0); |
|
| 109 | 109 | |
| 110 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/local_pickup' ) ); |
|
| 111 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 110 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping_methods/local_pickup')); |
|
| 111 | + $this->assertEquals(401, $response->get_status()); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -117,9 +117,9 @@ discard block |
||
| 117 | 117 | * @since 3.5.0 |
| 118 | 118 | */ |
| 119 | 119 | public function test_get_shipping_method_invalid_id() { |
| 120 | - wp_set_current_user( $this->user ); |
|
| 121 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/shipping_methods/fake_method' ) ); |
|
| 122 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 120 | + wp_set_current_user($this->user); |
|
| 121 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/shipping_methods/fake_method')); |
|
| 122 | + $this->assertEquals(404, $response->get_status()); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * @since 3.5.0 |
| 129 | 129 | */ |
| 130 | 130 | public function test_shipping_method_schema() { |
| 131 | - wp_set_current_user( $this->user ); |
|
| 131 | + wp_set_current_user($this->user); |
|
| 132 | 132 | |
| 133 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/shipping_methods' ); |
|
| 134 | - $response = $this->server->dispatch( $request ); |
|
| 133 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/shipping_methods'); |
|
| 134 | + $response = $this->server->dispatch($request); |
|
| 135 | 135 | $data = $response->get_data(); |
| 136 | 136 | $properties = $data['schema']['properties']; |
| 137 | 137 | |
| 138 | - $this->assertEquals( 3, count( $properties ) ); |
|
| 139 | - $this->assertArrayHasKey( 'id', $properties ); |
|
| 140 | - $this->assertArrayHasKey( 'title', $properties ); |
|
| 141 | - $this->assertArrayHasKey( 'description', $properties ); |
|
| 138 | + $this->assertEquals(3, count($properties)); |
|
| 139 | + $this->assertArrayHasKey('id', $properties); |
|
| 140 | + $this->assertArrayHasKey('title', $properties); |
|
| 141 | + $this->assertArrayHasKey('description', $properties); |
|
| 142 | 142 | } |
| 143 | 143 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | ); |
| 27 | 27 | |
| 28 | 28 | // Callback used by WP_HTTP_TestCase to decide whether to perform HTTP requests or to provide a mocked response. |
| 29 | - $this->http_responder = array( $this, 'mock_http_responses' ); |
|
| 29 | + $this->http_responder = array($this, 'mock_http_responses'); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -34,9 +34,9 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | public function test_register_routes() { |
| 36 | 36 | $routes = $this->server->get_routes(); |
| 37 | - $this->assertArrayHasKey( '/wc/v3/system_status', $routes ); |
|
| 38 | - $this->assertArrayHasKey( '/wc/v3/system_status/tools', $routes ); |
|
| 39 | - $this->assertArrayHasKey( '/wc/v3/system_status/tools/(?P<id>[\w-]+)', $routes ); |
|
| 37 | + $this->assertArrayHasKey('/wc/v3/system_status', $routes); |
|
| 38 | + $this->assertArrayHasKey('/wc/v3/system_status/tools', $routes); |
|
| 39 | + $this->assertArrayHasKey('/wc/v3/system_status/tools/(?P<id>[\w-]+)', $routes); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -45,9 +45,9 @@ discard block |
||
| 45 | 45 | * @since 3.5.0 |
| 46 | 46 | */ |
| 47 | 47 | public function test_get_system_status_info_without_permission() { |
| 48 | - wp_set_current_user( 0 ); |
|
| 49 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 50 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 48 | + wp_set_current_user(0); |
|
| 49 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 50 | + $this->assertEquals(401, $response->get_status()); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -57,17 +57,17 @@ discard block |
||
| 57 | 57 | * @since 3.5.0 |
| 58 | 58 | */ |
| 59 | 59 | public function test_get_system_status_info_returns_root_properties() { |
| 60 | - wp_set_current_user( $this->user ); |
|
| 61 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 60 | + wp_set_current_user($this->user); |
|
| 61 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 62 | 62 | $data = $response->get_data(); |
| 63 | 63 | |
| 64 | - $this->assertArrayHasKey( 'environment', $data ); |
|
| 65 | - $this->assertArrayHasKey( 'database', $data ); |
|
| 66 | - $this->assertArrayHasKey( 'active_plugins', $data ); |
|
| 67 | - $this->assertArrayHasKey( 'theme', $data ); |
|
| 68 | - $this->assertArrayHasKey( 'settings', $data ); |
|
| 69 | - $this->assertArrayHasKey( 'security', $data ); |
|
| 70 | - $this->assertArrayHasKey( 'pages', $data ); |
|
| 64 | + $this->assertArrayHasKey('environment', $data); |
|
| 65 | + $this->assertArrayHasKey('database', $data); |
|
| 66 | + $this->assertArrayHasKey('active_plugins', $data); |
|
| 67 | + $this->assertArrayHasKey('theme', $data); |
|
| 68 | + $this->assertArrayHasKey('settings', $data); |
|
| 69 | + $this->assertArrayHasKey('security', $data); |
|
| 70 | + $this->assertArrayHasKey('pages', $data); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,18 +76,18 @@ discard block |
||
| 76 | 76 | * @since 3.5.0 |
| 77 | 77 | */ |
| 78 | 78 | public function test_get_system_status_info_environment() { |
| 79 | - wp_set_current_user( $this->user ); |
|
| 80 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 79 | + wp_set_current_user($this->user); |
|
| 80 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 81 | 81 | $data = $response->get_data(); |
| 82 | 82 | $environment = (array) $data['environment']; |
| 83 | 83 | |
| 84 | 84 | // Make sure all expected data is present. |
| 85 | - $this->assertEquals( 32, count( $environment ) ); |
|
| 85 | + $this->assertEquals(32, count($environment)); |
|
| 86 | 86 | |
| 87 | 87 | // Test some responses to make sure they match up. |
| 88 | - $this->assertEquals( get_option( 'home' ), $environment['home_url'] ); |
|
| 89 | - $this->assertEquals( get_option( 'siteurl' ), $environment['site_url'] ); |
|
| 90 | - $this->assertEquals( WC()->version, $environment['version'] ); |
|
| 88 | + $this->assertEquals(get_option('home'), $environment['home_url']); |
|
| 89 | + $this->assertEquals(get_option('siteurl'), $environment['site_url']); |
|
| 90 | + $this->assertEquals(WC()->version, $environment['version']); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | /** |
@@ -97,16 +97,16 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | public function test_get_system_status_info_database() { |
| 99 | 99 | global $wpdb; |
| 100 | - wp_set_current_user( $this->user ); |
|
| 101 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 100 | + wp_set_current_user($this->user); |
|
| 101 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 102 | 102 | $data = $response->get_data(); |
| 103 | 103 | $database = (array) $data['database']; |
| 104 | 104 | |
| 105 | - $this->assertEquals( get_option( 'woocommerce_db_version' ), $database['wc_database_version'] ); |
|
| 106 | - $this->assertEquals( $wpdb->prefix, $database['database_prefix'] ); |
|
| 107 | - $this->assertEquals( WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database'] ); |
|
| 108 | - $this->assertArrayHasKey( 'woocommerce', $database['database_tables'], wc_print_r( $database, true ) ); |
|
| 109 | - $this->assertArrayHasKey( $wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r( $database, true ) ); |
|
| 105 | + $this->assertEquals(get_option('woocommerce_db_version'), $database['wc_database_version']); |
|
| 106 | + $this->assertEquals($wpdb->prefix, $database['database_prefix']); |
|
| 107 | + $this->assertEquals(WC_Geolocation::get_local_database_path(), $database['maxmind_geoip_database']); |
|
| 108 | + $this->assertArrayHasKey('woocommerce', $database['database_tables'], wc_print_r($database, true)); |
|
| 109 | + $this->assertArrayHasKey($wpdb->prefix . 'woocommerce_payment_tokens', $database['database_tables']['woocommerce'], wc_print_r($database, true)); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,18 +115,18 @@ discard block |
||
| 115 | 115 | * @since 3.5.0 |
| 116 | 116 | */ |
| 117 | 117 | public function test_get_system_status_info_active_plugins() { |
| 118 | - wp_set_current_user( $this->user ); |
|
| 118 | + wp_set_current_user($this->user); |
|
| 119 | 119 | |
| 120 | - $actual_plugins = array( 'hello.php' ); |
|
| 121 | - update_option( 'active_plugins', $actual_plugins ); |
|
| 122 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 123 | - update_option( 'active_plugins', array() ); |
|
| 120 | + $actual_plugins = array('hello.php'); |
|
| 121 | + update_option('active_plugins', $actual_plugins); |
|
| 122 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 123 | + update_option('active_plugins', array()); |
|
| 124 | 124 | |
| 125 | 125 | $data = $response->get_data(); |
| 126 | 126 | $plugins = (array) $data['active_plugins']; |
| 127 | 127 | |
| 128 | - $this->assertEquals( 1, count( $plugins ) ); |
|
| 129 | - $this->assertEquals( 'Hello Dolly', $plugins[0]['name'] ); |
|
| 128 | + $this->assertEquals(1, count($plugins)); |
|
| 129 | + $this->assertEquals('Hello Dolly', $plugins[0]['name']); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -135,15 +135,15 @@ discard block |
||
| 135 | 135 | * @since 3.5.0 |
| 136 | 136 | */ |
| 137 | 137 | public function test_get_system_status_info_theme() { |
| 138 | - wp_set_current_user( $this->user ); |
|
| 138 | + wp_set_current_user($this->user); |
|
| 139 | 139 | $active_theme = wp_get_theme(); |
| 140 | 140 | |
| 141 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 141 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 142 | 142 | $data = $response->get_data(); |
| 143 | 143 | $theme = (array) $data['theme']; |
| 144 | 144 | |
| 145 | - $this->assertEquals( 13, count( $theme ) ); |
|
| 146 | - $this->assertEquals( $active_theme->Name, $theme['name'] ); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar |
|
| 145 | + $this->assertEquals(13, count($theme)); |
|
| 146 | + $this->assertEquals($active_theme->Name, $theme['name']); // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -152,22 +152,22 @@ discard block |
||
| 152 | 152 | * @since 3.5.0 |
| 153 | 153 | */ |
| 154 | 154 | public function test_get_system_status_info_settings() { |
| 155 | - wp_set_current_user( $this->user ); |
|
| 155 | + wp_set_current_user($this->user); |
|
| 156 | 156 | |
| 157 | 157 | $term_response = array(); |
| 158 | - $terms = get_terms( 'product_type', array( 'hide_empty' => 0 ) ); |
|
| 159 | - foreach ( $terms as $term ) { |
|
| 160 | - $term_response[ $term->slug ] = strtolower( $term->name ); |
|
| 158 | + $terms = get_terms('product_type', array('hide_empty' => 0)); |
|
| 159 | + foreach ($terms as $term) { |
|
| 160 | + $term_response[$term->slug] = strtolower($term->name); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 163 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 164 | 164 | $data = $response->get_data(); |
| 165 | 165 | $settings = (array) $data['settings']; |
| 166 | 166 | |
| 167 | - $this->assertEquals( 12, count( $settings ) ); |
|
| 168 | - $this->assertEquals( ( 'yes' === get_option( 'woocommerce_api_enabled' ) ), $settings['api_enabled'] ); |
|
| 169 | - $this->assertEquals( get_woocommerce_currency(), $settings['currency'] ); |
|
| 170 | - $this->assertEquals( $term_response, $settings['taxonomies'] ); |
|
| 167 | + $this->assertEquals(12, count($settings)); |
|
| 168 | + $this->assertEquals(('yes' === get_option('woocommerce_api_enabled')), $settings['api_enabled']); |
|
| 169 | + $this->assertEquals(get_woocommerce_currency(), $settings['currency']); |
|
| 170 | + $this->assertEquals($term_response, $settings['taxonomies']); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -176,15 +176,15 @@ discard block |
||
| 176 | 176 | * @since 3.5.0 |
| 177 | 177 | */ |
| 178 | 178 | public function test_get_system_status_info_security() { |
| 179 | - wp_set_current_user( $this->user ); |
|
| 179 | + wp_set_current_user($this->user); |
|
| 180 | 180 | |
| 181 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 181 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 182 | 182 | $data = $response->get_data(); |
| 183 | 183 | $settings = (array) $data['security']; |
| 184 | 184 | |
| 185 | - $this->assertEquals( 2, count( $settings ) ); |
|
| 186 | - $this->assertEquals( 'https' === substr( wc_get_page_permalink( 'shop' ), 0, 5 ), $settings['secure_connection'] ); |
|
| 187 | - $this->assertEquals( ! ( defined( 'WP_DEBUG' ) && defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG && WP_DEBUG_DISPLAY ) || 0 === intval( ini_get( 'display_errors' ) ), $settings['hide_errors'] ); |
|
| 185 | + $this->assertEquals(2, count($settings)); |
|
| 186 | + $this->assertEquals('https' === substr(wc_get_page_permalink('shop'), 0, 5), $settings['secure_connection']); |
|
| 187 | + $this->assertEquals( ! (defined('WP_DEBUG') && defined('WP_DEBUG_DISPLAY') && WP_DEBUG && WP_DEBUG_DISPLAY) || 0 === intval(ini_get('display_errors')), $settings['hide_errors']); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -193,11 +193,11 @@ discard block |
||
| 193 | 193 | * @since 3.5.0 |
| 194 | 194 | */ |
| 195 | 195 | public function test_get_system_status_info_pages() { |
| 196 | - wp_set_current_user( $this->user ); |
|
| 197 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status' ) ); |
|
| 196 | + wp_set_current_user($this->user); |
|
| 197 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status')); |
|
| 198 | 198 | $data = $response->get_data(); |
| 199 | 199 | $pages = $data['pages']; |
| 200 | - $this->assertEquals( 5, count( $pages ) ); |
|
| 200 | + $this->assertEquals(5, count($pages)); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -206,18 +206,18 @@ discard block |
||
| 206 | 206 | * @since 3.5.0 |
| 207 | 207 | */ |
| 208 | 208 | public function test_system_status_schema() { |
| 209 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/system_status' ); |
|
| 210 | - $response = $this->server->dispatch( $request ); |
|
| 209 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/system_status'); |
|
| 210 | + $response = $this->server->dispatch($request); |
|
| 211 | 211 | $data = $response->get_data(); |
| 212 | 212 | $properties = $data['schema']['properties']; |
| 213 | - $this->assertEquals( 9, count( $properties ) ); |
|
| 214 | - $this->assertArrayHasKey( 'environment', $properties ); |
|
| 215 | - $this->assertArrayHasKey( 'database', $properties ); |
|
| 216 | - $this->assertArrayHasKey( 'active_plugins', $properties ); |
|
| 217 | - $this->assertArrayHasKey( 'theme', $properties ); |
|
| 218 | - $this->assertArrayHasKey( 'settings', $properties ); |
|
| 219 | - $this->assertArrayHasKey( 'security', $properties ); |
|
| 220 | - $this->assertArrayHasKey( 'pages', $properties ); |
|
| 213 | + $this->assertEquals(9, count($properties)); |
|
| 214 | + $this->assertArrayHasKey('environment', $properties); |
|
| 215 | + $this->assertArrayHasKey('database', $properties); |
|
| 216 | + $this->assertArrayHasKey('active_plugins', $properties); |
|
| 217 | + $this->assertArrayHasKey('theme', $properties); |
|
| 218 | + $this->assertArrayHasKey('settings', $properties); |
|
| 219 | + $this->assertArrayHasKey('security', $properties); |
|
| 220 | + $this->assertArrayHasKey('pages', $properties); |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | * @since 3.5.0 |
| 227 | 227 | */ |
| 228 | 228 | public function test_get_system_tools() { |
| 229 | - wp_set_current_user( $this->user ); |
|
| 229 | + wp_set_current_user($this->user); |
|
| 230 | 230 | |
| 231 | 231 | $tools_controller = new WC_REST_System_Status_Tools_Controller(); |
| 232 | 232 | $raw_tools = $tools_controller->get_tools(); |
| 233 | 233 | |
| 234 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ) ); |
|
| 234 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status/tools')); |
|
| 235 | 235 | $data = $response->get_data(); |
| 236 | 236 | |
| 237 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 238 | - $this->assertEquals( count( $raw_tools ), count( $data ) ); |
|
| 237 | + $this->assertEquals(200, $response->get_status()); |
|
| 238 | + $this->assertEquals(count($raw_tools), count($data)); |
|
| 239 | 239 | $this->assertContains( |
| 240 | 240 | array( |
| 241 | 241 | 'id' => 'regenerate_thumbnails', |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | '_links' => array( |
| 246 | 246 | 'item' => array( |
| 247 | 247 | array( |
| 248 | - 'href' => rest_url( '/wc/v3/system_status/tools/regenerate_thumbnails' ), |
|
| 248 | + 'href' => rest_url('/wc/v3/system_status/tools/regenerate_thumbnails'), |
|
| 249 | 249 | 'embeddable' => 1, |
| 250 | 250 | ), |
| 251 | 251 | ), |
@@ -257,13 +257,13 @@ discard block |
||
| 257 | 257 | $query_params = array( |
| 258 | 258 | '_fields' => 'id,name,nonexisting', |
| 259 | 259 | ); |
| 260 | - $request = new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ); |
|
| 261 | - $request->set_query_params( $query_params ); |
|
| 262 | - $response = $this->server->dispatch( $request ); |
|
| 260 | + $request = new WP_REST_Request('GET', '/wc/v3/system_status/tools'); |
|
| 261 | + $request->set_query_params($query_params); |
|
| 262 | + $response = $this->server->dispatch($request); |
|
| 263 | 263 | $data = $response->get_data(); |
| 264 | 264 | |
| 265 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 266 | - $this->assertEquals( count( $raw_tools ), count( $data ) ); |
|
| 265 | + $this->assertEquals(200, $response->get_status()); |
|
| 266 | + $this->assertEquals(count($raw_tools), count($data)); |
|
| 267 | 267 | $this->assertContains( |
| 268 | 268 | array( |
| 269 | 269 | 'id' => 'regenerate_thumbnails', |
@@ -271,19 +271,19 @@ discard block |
||
| 271 | 271 | ), |
| 272 | 272 | $data |
| 273 | 273 | ); |
| 274 | - foreach ( $data as $item ) { |
|
| 274 | + foreach ($data as $item) { |
|
| 275 | 275 | // Fields that are not requested are not returned in response. |
| 276 | - $this->assertArrayNotHasKey( 'action', $item ); |
|
| 277 | - $this->assertArrayNotHasKey( 'description', $item ); |
|
| 276 | + $this->assertArrayNotHasKey('action', $item); |
|
| 277 | + $this->assertArrayNotHasKey('description', $item); |
|
| 278 | 278 | // Links are part of data in collections, so excluded if not explicitly requested. |
| 279 | - $this->assertArrayNotHasKey( '_links', $item ); |
|
| 279 | + $this->assertArrayNotHasKey('_links', $item); |
|
| 280 | 280 | // Non existing field is ignored. |
| 281 | - $this->assertArrayNotHasKey( 'nonexisting', $item ); |
|
| 281 | + $this->assertArrayNotHasKey('nonexisting', $item); |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | // Links are part of data, not links in collections. |
| 285 | 285 | $links = $response->get_links(); |
| 286 | - $this->assertEquals( 0, count( $links ) ); |
|
| 286 | + $this->assertEquals(0, count($links)); |
|
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | /** |
@@ -292,9 +292,9 @@ discard block |
||
| 292 | 292 | * @since 3.5.0 |
| 293 | 293 | */ |
| 294 | 294 | public function test_get_system_status_tools_without_permission() { |
| 295 | - wp_set_current_user( 0 ); |
|
| 296 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools' ) ); |
|
| 297 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 295 | + wp_set_current_user(0); |
|
| 296 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status/tools')); |
|
| 297 | + $this->assertEquals(401, $response->get_status()); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -303,43 +303,43 @@ discard block |
||
| 303 | 303 | * @since 3.5.0 |
| 304 | 304 | */ |
| 305 | 305 | public function test_get_system_tool() { |
| 306 | - wp_set_current_user( $this->user ); |
|
| 306 | + wp_set_current_user($this->user); |
|
| 307 | 307 | |
| 308 | 308 | $tools_controller = new WC_REST_System_Status_Tools_Controller(); |
| 309 | 309 | $raw_tools = $tools_controller->get_tools(); |
| 310 | 310 | $raw_tool = $raw_tools['recount_terms']; |
| 311 | 311 | |
| 312 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ) ); |
|
| 312 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status/tools/recount_terms')); |
|
| 313 | 313 | $data = $response->get_data(); |
| 314 | 314 | |
| 315 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 315 | + $this->assertEquals(200, $response->get_status()); |
|
| 316 | 316 | |
| 317 | - $this->assertEquals( 'recount_terms', $data['id'] ); |
|
| 318 | - $this->assertEquals( 'Term counts', $data['name'] ); |
|
| 319 | - $this->assertEquals( 'Recount terms', $data['action'] ); |
|
| 320 | - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); |
|
| 317 | + $this->assertEquals('recount_terms', $data['id']); |
|
| 318 | + $this->assertEquals('Term counts', $data['name']); |
|
| 319 | + $this->assertEquals('Recount terms', $data['action']); |
|
| 320 | + $this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']); |
|
| 321 | 321 | |
| 322 | 322 | // Test for _fields query parameter. |
| 323 | 323 | $query_params = array( |
| 324 | 324 | '_fields' => 'id,name,nonexisting', |
| 325 | 325 | ); |
| 326 | - $request = new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ); |
|
| 327 | - $request->set_query_params( $query_params ); |
|
| 328 | - $response = $this->server->dispatch( $request ); |
|
| 326 | + $request = new WP_REST_Request('GET', '/wc/v3/system_status/tools/recount_terms'); |
|
| 327 | + $request->set_query_params($query_params); |
|
| 328 | + $response = $this->server->dispatch($request); |
|
| 329 | 329 | $data = $response->get_data(); |
| 330 | 330 | |
| 331 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 331 | + $this->assertEquals(200, $response->get_status()); |
|
| 332 | 332 | |
| 333 | - $this->assertEquals( 'recount_terms', $data['id'] ); |
|
| 334 | - $this->assertEquals( 'Term counts', $data['name'] ); |
|
| 335 | - $this->assertArrayNotHasKey( 'action', $data ); |
|
| 336 | - $this->assertArrayNotHasKey( 'description', $data ); |
|
| 333 | + $this->assertEquals('recount_terms', $data['id']); |
|
| 334 | + $this->assertEquals('Term counts', $data['name']); |
|
| 335 | + $this->assertArrayNotHasKey('action', $data); |
|
| 336 | + $this->assertArrayNotHasKey('description', $data); |
|
| 337 | 337 | // Links are part of links, not data in single items. |
| 338 | - $this->assertArrayNotHasKey( '_links', $data ); |
|
| 338 | + $this->assertArrayNotHasKey('_links', $data); |
|
| 339 | 339 | |
| 340 | 340 | // Links are part of links, not data in single item response. |
| 341 | 341 | $links = $response->get_links(); |
| 342 | - $this->assertEquals( 1, count( $links ) ); |
|
| 342 | + $this->assertEquals(1, count($links)); |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | /** |
@@ -348,9 +348,9 @@ discard block |
||
| 348 | 348 | * @since 3.5.0 |
| 349 | 349 | */ |
| 350 | 350 | public function test_get_system_status_tool_without_permission() { |
| 351 | - wp_set_current_user( 0 ); |
|
| 352 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/system_status/tools/recount_terms' ) ); |
|
| 353 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 351 | + wp_set_current_user(0); |
|
| 352 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/system_status/tools/recount_terms')); |
|
| 353 | + $this->assertEquals(401, $response->get_status()); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -359,50 +359,50 @@ discard block |
||
| 359 | 359 | * @since 3.5.0 |
| 360 | 360 | */ |
| 361 | 361 | public function test_execute_system_tool() { |
| 362 | - wp_set_current_user( $this->user ); |
|
| 362 | + wp_set_current_user($this->user); |
|
| 363 | 363 | |
| 364 | 364 | $tools_controller = new WC_REST_System_Status_Tools_Controller(); |
| 365 | 365 | $raw_tools = $tools_controller->get_tools(); |
| 366 | 366 | $raw_tool = $raw_tools['recount_terms']; |
| 367 | 367 | |
| 368 | - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/recount_terms' ) ); |
|
| 368 | + $response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v3/system_status/tools/recount_terms')); |
|
| 369 | 369 | $data = $response->get_data(); |
| 370 | 370 | |
| 371 | - $this->assertEquals( 'recount_terms', $data['id'] ); |
|
| 372 | - $this->assertEquals( 'Term counts', $data['name'] ); |
|
| 373 | - $this->assertEquals( 'Recount terms', $data['action'] ); |
|
| 374 | - $this->assertEquals( 'This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description'] ); |
|
| 375 | - $this->assertTrue( $data['success'] ); |
|
| 376 | - $this->assertEquals( 1, did_action( 'woocommerce_rest_insert_system_status_tool' ) ); |
|
| 371 | + $this->assertEquals('recount_terms', $data['id']); |
|
| 372 | + $this->assertEquals('Term counts', $data['name']); |
|
| 373 | + $this->assertEquals('Recount terms', $data['action']); |
|
| 374 | + $this->assertEquals('This tool will recount product terms - useful when changing your settings in a way which hides products from the catalog.', $data['description']); |
|
| 375 | + $this->assertTrue($data['success']); |
|
| 376 | + $this->assertEquals(1, did_action('woocommerce_rest_insert_system_status_tool')); |
|
| 377 | 377 | |
| 378 | - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/not_a_real_tool' ) ); |
|
| 379 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 378 | + $response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v3/system_status/tools/not_a_real_tool')); |
|
| 379 | + $this->assertEquals(404, $response->get_status()); |
|
| 380 | 380 | |
| 381 | 381 | // Test _fields for execute system tool request. |
| 382 | 382 | $query_params = array( |
| 383 | 383 | '_fields' => 'id,success,nonexisting', |
| 384 | 384 | ); |
| 385 | - $request = new WP_REST_Request( 'PUT', '/wc/v3/system_status/tools/recount_terms' ); |
|
| 386 | - $request->set_query_params( $query_params ); |
|
| 387 | - $response = $this->server->dispatch( $request ); |
|
| 385 | + $request = new WP_REST_Request('PUT', '/wc/v3/system_status/tools/recount_terms'); |
|
| 386 | + $request->set_query_params($query_params); |
|
| 387 | + $response = $this->server->dispatch($request); |
|
| 388 | 388 | $data = $response->get_data(); |
| 389 | 389 | |
| 390 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 391 | - $this->assertEquals( 'recount_terms', $data['id'] ); |
|
| 392 | - $this->assertTrue( $data['success'] ); |
|
| 390 | + $this->assertEquals(200, $response->get_status()); |
|
| 391 | + $this->assertEquals('recount_terms', $data['id']); |
|
| 392 | + $this->assertTrue($data['success']); |
|
| 393 | 393 | |
| 394 | 394 | // Fields that are not requested are not returned in response. |
| 395 | - $this->assertArrayNotHasKey( 'action', $data ); |
|
| 396 | - $this->assertArrayNotHasKey( 'name', $data ); |
|
| 397 | - $this->assertArrayNotHasKey( 'description', $data ); |
|
| 395 | + $this->assertArrayNotHasKey('action', $data); |
|
| 396 | + $this->assertArrayNotHasKey('name', $data); |
|
| 397 | + $this->assertArrayNotHasKey('description', $data); |
|
| 398 | 398 | // Links are part of links, not data in single item response. |
| 399 | - $this->assertArrayNotHasKey( '_links', $data ); |
|
| 399 | + $this->assertArrayNotHasKey('_links', $data); |
|
| 400 | 400 | // Non existing field is ignored. |
| 401 | - $this->assertArrayNotHasKey( 'nonexisting', $data ); |
|
| 401 | + $this->assertArrayNotHasKey('nonexisting', $data); |
|
| 402 | 402 | |
| 403 | 403 | // Links are part of links, not data in single item response. |
| 404 | 404 | $links = $response->get_links(); |
| 405 | - $this->assertEquals( 1, count( $links ) ); |
|
| 405 | + $this->assertEquals(1, count($links)); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | /** |
@@ -411,9 +411,9 @@ discard block |
||
| 411 | 411 | * @since 3.5.0 |
| 412 | 412 | */ |
| 413 | 413 | public function test_execute_system_status_tool_without_permission() { |
| 414 | - wp_set_current_user( 0 ); |
|
| 415 | - $response = $this->server->dispatch( new WP_REST_Request( 'POST', '/wc/v3/system_status/tools/recount_terms' ) ); |
|
| 416 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 414 | + wp_set_current_user(0); |
|
| 415 | + $response = $this->server->dispatch(new WP_REST_Request('POST', '/wc/v3/system_status/tools/recount_terms')); |
|
| 416 | + $this->assertEquals(401, $response->get_status()); |
|
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | /** |
@@ -422,18 +422,18 @@ discard block |
||
| 422 | 422 | * @since 3.5.0 |
| 423 | 423 | */ |
| 424 | 424 | public function test_system_status_tool_schema() { |
| 425 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/system_status/tools' ); |
|
| 426 | - $response = $this->server->dispatch( $request ); |
|
| 425 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/system_status/tools'); |
|
| 426 | + $response = $this->server->dispatch($request); |
|
| 427 | 427 | $data = $response->get_data(); |
| 428 | 428 | $properties = $data['schema']['properties']; |
| 429 | 429 | |
| 430 | - $this->assertEquals( 6, count( $properties ) ); |
|
| 431 | - $this->assertArrayHasKey( 'id', $properties ); |
|
| 432 | - $this->assertArrayHasKey( 'name', $properties ); |
|
| 433 | - $this->assertArrayHasKey( 'action', $properties ); |
|
| 434 | - $this->assertArrayHasKey( 'description', $properties ); |
|
| 435 | - $this->assertArrayHasKey( 'success', $properties ); |
|
| 436 | - $this->assertArrayHasKey( 'message', $properties ); |
|
| 430 | + $this->assertEquals(6, count($properties)); |
|
| 431 | + $this->assertArrayHasKey('id', $properties); |
|
| 432 | + $this->assertArrayHasKey('name', $properties); |
|
| 433 | + $this->assertArrayHasKey('action', $properties); |
|
| 434 | + $this->assertArrayHasKey('description', $properties); |
|
| 435 | + $this->assertArrayHasKey('success', $properties); |
|
| 436 | + $this->assertArrayHasKey('message', $properties); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -448,17 +448,17 @@ discard block |
||
| 448 | 448 | * |
| 449 | 449 | * @return array|false mocked response or false to let WP perform a regular request. |
| 450 | 450 | */ |
| 451 | - protected function mock_http_responses( $request, $url ) { |
|
| 451 | + protected function mock_http_responses($request, $url) { |
|
| 452 | 452 | $mocked_response = false; |
| 453 | 453 | |
| 454 | - if ( in_array( $url, array( 'https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0' ), true ) ) { |
|
| 454 | + if (in_array($url, array('https://www.paypal.com/cgi-bin/webscr', 'https://woocommerce.com/wc-api/product-key-api?request=ping&network=0'), true)) { |
|
| 455 | 455 | $mocked_response = array( |
| 456 | - 'response' => array( 'code' => 200 ), |
|
| 456 | + 'response' => array('code' => 200), |
|
| 457 | 457 | ); |
| 458 | - } elseif ( 'https://api.wordpress.org/themes/info/1.0/' === $url ) { |
|
| 458 | + } elseif ('https://api.wordpress.org/themes/info/1.0/' === $url) { |
|
| 459 | 459 | $mocked_response = array( |
| 460 | 460 | 'body' => 'O:8:"stdClass":12:{s:4:"name";s:7:"Default";s:4:"slug";s:7:"default";s:7:"version";s:5:"1.7.2";s:11:"preview_url";s:29:"https://wp-themes.com/default";s:6:"author";s:15:"wordpressdotorg";s:14:"screenshot_url";s:61:"//ts.w.org/wp-content/themes/default/screenshot.png?ver=1.7.2";s:6:"rating";d:100;s:11:"num_ratings";s:1:"3";s:10:"downloaded";i:296618;s:12:"last_updated";s:10:"2010-06-14";s:8:"homepage";s:37:"https://wordpress.org/themes/default/";s:13:"download_link";s:55:"https://downloads.wordpress.org/theme/default.1.7.2.zip";}', |
| 461 | - 'response' => array( 'code' => 200 ), |
|
| 461 | + 'response' => array('code' => 200), |
|
| 462 | 462 | ); |
| 463 | 463 | } |
| 464 | 464 | |
@@ -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/reviews/totals', $routes ); |
|
| 30 | + $this->assertArrayHasKey('/wc/v3/reports/reviews/totals', $routes); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,9 +37,9 @@ 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/reviews/totals' ) ); |
|
| 42 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/reviews/totals')); |
|
| 43 | 43 | $report = $response->get_data(); |
| 44 | 44 | $data = array(); |
| 45 | 45 | |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | 'meta_value' => '', // WPCS: slow query ok. |
| 51 | 51 | ); |
| 52 | 52 | |
| 53 | - for ( $i = 1; $i <= 5; $i++ ) { |
|
| 53 | + for ($i = 1; $i <= 5; $i++) { |
|
| 54 | 54 | $query_data['meta_value'] = $i; |
| 55 | 55 | |
| 56 | 56 | $data[] = array( |
| 57 | 57 | 'slug' => 'rated_' . $i . '_out_of_5', |
| 58 | 58 | /* translators: %s: average rating */ |
| 59 | - 'name' => sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $i ), |
|
| 60 | - 'total' => (int) get_comments( $query_data ), |
|
| 59 | + 'name' => sprintf(__('Rated %s out of 5', 'woocommerce'), $i), |
|
| 60 | + 'total' => (int) get_comments($query_data), |
|
| 61 | 61 | ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 65 | - $this->assertEquals( count( $data ), count( $report ) ); |
|
| 66 | - $this->assertEquals( $data, $report ); |
|
| 64 | + $this->assertEquals(200, $response->get_status()); |
|
| 65 | + $this->assertEquals(count($data), count($report)); |
|
| 66 | + $this->assertEquals($data, $report); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -72,9 +72,9 @@ discard block |
||
| 72 | 72 | * @since 3.5.0 |
| 73 | 73 | */ |
| 74 | 74 | public function test_get_reports_without_permission() { |
| 75 | - wp_set_current_user( 0 ); |
|
| 76 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/reviews/totals' ) ); |
|
| 77 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 75 | + wp_set_current_user(0); |
|
| 76 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/reviews/totals')); |
|
| 77 | + $this->assertEquals(401, $response->get_status()); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,16 +83,16 @@ discard block |
||
| 83 | 83 | * @since 3.5.0 |
| 84 | 84 | */ |
| 85 | 85 | public function test_product_review_schema() { |
| 86 | - wp_set_current_user( $this->user ); |
|
| 86 | + wp_set_current_user($this->user); |
|
| 87 | 87 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 88 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/reviews/totals' ); |
|
| 89 | - $response = $this->server->dispatch( $request ); |
|
| 88 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/reports/reviews/totals'); |
|
| 89 | + $response = $this->server->dispatch($request); |
|
| 90 | 90 | $data = $response->get_data(); |
| 91 | 91 | $properties = $data['schema']['properties']; |
| 92 | 92 | |
| 93 | - $this->assertEquals( 3, count( $properties ) ); |
|
| 94 | - $this->assertArrayHasKey( 'slug', $properties ); |
|
| 95 | - $this->assertArrayHasKey( 'name', $properties ); |
|
| 96 | - $this->assertArrayHasKey( 'total', $properties ); |
|
| 93 | + $this->assertEquals(3, count($properties)); |
|
| 94 | + $this->assertArrayHasKey('slug', $properties); |
|
| 95 | + $this->assertArrayHasKey('name', $properties); |
|
| 96 | + $this->assertArrayHasKey('total', $properties); |
|
| 97 | 97 | } |
| 98 | 98 | } |
@@ -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/customers/totals', $routes ); |
|
| 30 | + $this->assertArrayHasKey('/wc/v3/reports/customers/totals', $routes); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -36,15 +36,15 @@ 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/customers/totals' ) ); |
|
| 41 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/customers/totals')); |
|
| 42 | 42 | $report = $response->get_data(); |
| 43 | 43 | $users_count = count_users(); |
| 44 | 44 | $total_customers = 0; |
| 45 | 45 | |
| 46 | - foreach ( $users_count['avail_roles'] as $role => $total ) { |
|
| 47 | - if ( in_array( $role, array( 'administrator', 'shop_manager' ), true ) ) { |
|
| 46 | + foreach ($users_count['avail_roles'] as $role => $total) { |
|
| 47 | + if (in_array($role, array('administrator', 'shop_manager'), true)) { |
|
| 48 | 48 | continue; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | $customers_query = new WP_User_Query( |
| 55 | 55 | array( |
| 56 | - 'role__not_in' => array( 'administrator', 'shop_manager' ), |
|
| 56 | + 'role__not_in' => array('administrator', 'shop_manager'), |
|
| 57 | 57 | 'number' => 0, |
| 58 | 58 | 'fields' => 'ID', |
| 59 | 59 | 'count_total' => true, |
@@ -72,19 +72,19 @@ discard block |
||
| 72 | 72 | $data = array( |
| 73 | 73 | array( |
| 74 | 74 | 'slug' => 'paying', |
| 75 | - 'name' => __( 'Paying customer', 'woocommerce' ), |
|
| 75 | + 'name' => __('Paying customer', 'woocommerce'), |
|
| 76 | 76 | 'total' => $total_paying, |
| 77 | 77 | ), |
| 78 | 78 | array( |
| 79 | 79 | 'slug' => 'non_paying', |
| 80 | - 'name' => __( 'Non-paying customer', 'woocommerce' ), |
|
| 80 | + 'name' => __('Non-paying customer', 'woocommerce'), |
|
| 81 | 81 | 'total' => $total_customers - $total_paying, |
| 82 | 82 | ), |
| 83 | 83 | ); |
| 84 | 84 | |
| 85 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 86 | - $this->assertEquals( 2, count( $report ) ); |
|
| 87 | - $this->assertEquals( $data, $report ); |
|
| 85 | + $this->assertEquals(200, $response->get_status()); |
|
| 86 | + $this->assertEquals(2, count($report)); |
|
| 87 | + $this->assertEquals($data, $report); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -93,9 +93,9 @@ discard block |
||
| 93 | 93 | * @since 3.5.0 |
| 94 | 94 | */ |
| 95 | 95 | public function test_get_reports_without_permission() { |
| 96 | - wp_set_current_user( 0 ); |
|
| 97 | - $response = $this->server->dispatch( new WP_REST_Request( 'GET', '/wc/v3/reports/customers/totals' ) ); |
|
| 98 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 96 | + wp_set_current_user(0); |
|
| 97 | + $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v3/reports/customers/totals')); |
|
| 98 | + $this->assertEquals(401, $response->get_status()); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -104,16 +104,16 @@ discard block |
||
| 104 | 104 | * @since 3.5.0 |
| 105 | 105 | */ |
| 106 | 106 | public function test_product_review_schema() { |
| 107 | - wp_set_current_user( $this->user ); |
|
| 107 | + wp_set_current_user($this->user); |
|
| 108 | 108 | $product = \WooCommerce\RestApi\UnitTests\Helpers\ProductHelper::create_simple_product(); |
| 109 | - $request = new WP_REST_Request( 'OPTIONS', '/wc/v3/reports/customers/totals' ); |
|
| 110 | - $response = $this->server->dispatch( $request ); |
|
| 109 | + $request = new WP_REST_Request('OPTIONS', '/wc/v3/reports/customers/totals'); |
|
| 110 | + $response = $this->server->dispatch($request); |
|
| 111 | 111 | $data = $response->get_data(); |
| 112 | 112 | $properties = $data['schema']['properties']; |
| 113 | 113 | |
| 114 | - $this->assertEquals( 3, count( $properties ) ); |
|
| 115 | - $this->assertArrayHasKey( 'slug', $properties ); |
|
| 116 | - $this->assertArrayHasKey( 'name', $properties ); |
|
| 117 | - $this->assertArrayHasKey( 'total', $properties ); |
|
| 114 | + $this->assertEquals(3, count($properties)); |
|
| 115 | + $this->assertArrayHasKey('slug', $properties); |
|
| 116 | + $this->assertArrayHasKey('name', $properties); |
|
| 117 | + $this->assertArrayHasKey('total', $properties); |
|
| 118 | 118 | } |
| 119 | 119 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | use \WP_REST_Request; |
| 11 | 11 | use \WC_REST_Unit_Test_Case; |
@@ -46,8 +46,8 @@ discard block |
||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | // Create 2 product attributes with terms. |
| 49 | - $this->attr_color = ProductHelper::create_attribute( 'color', array( 'red', 'yellow', 'blue' ) ); |
|
| 50 | - $this->attr_size = ProductHelper::create_attribute( 'size', array( 'small', 'medium', 'large', 'xlarge' ) ); |
|
| 49 | + $this->attr_color = ProductHelper::create_attribute('color', array('red', 'yellow', 'blue')); |
|
| 50 | + $this->attr_size = ProductHelper::create_attribute('size', array('small', 'medium', 'large', 'xlarge')); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | /** |
@@ -56,18 +56,18 @@ discard block |
||
| 56 | 56 | * @since 3.6.0 |
| 57 | 57 | */ |
| 58 | 58 | public function test_get_attributes() { |
| 59 | - wp_set_current_user( $this->user ); |
|
| 60 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes' ); |
|
| 59 | + wp_set_current_user($this->user); |
|
| 60 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/attributes'); |
|
| 61 | 61 | |
| 62 | - $response = $this->server->dispatch( $request ); |
|
| 62 | + $response = $this->server->dispatch($request); |
|
| 63 | 63 | $response_attributes = $response->get_data(); |
| 64 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 65 | - $this->assertEquals( 2, count( $response_attributes ) ); |
|
| 64 | + $this->assertEquals(200, $response->get_status()); |
|
| 65 | + $this->assertEquals(2, count($response_attributes)); |
|
| 66 | 66 | $attribute = $response_attributes[0]; |
| 67 | - $this->assertArrayHasKey( 'id', $attribute ); |
|
| 68 | - $this->assertArrayHasKey( 'name', $attribute ); |
|
| 69 | - $this->assertArrayHasKey( 'slug', $attribute ); |
|
| 70 | - $this->assertArrayHasKey( 'count', $attribute ); |
|
| 67 | + $this->assertArrayHasKey('id', $attribute); |
|
| 68 | + $this->assertArrayHasKey('name', $attribute); |
|
| 69 | + $this->assertArrayHasKey('slug', $attribute); |
|
| 70 | + $this->assertArrayHasKey('count', $attribute); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | * @since 3.6.0 |
| 77 | 77 | */ |
| 78 | 78 | public function test_get_invalid_attribute() { |
| 79 | - wp_set_current_user( $this->user ); |
|
| 80 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes/11111' ); |
|
| 79 | + wp_set_current_user($this->user); |
|
| 80 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/attributes/11111'); |
|
| 81 | 81 | |
| 82 | - $response = $this->server->dispatch( $request ); |
|
| 83 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 82 | + $response = $this->server->dispatch($request); |
|
| 83 | + $this->assertEquals(404, $response->get_status()); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | * @since 3.6.0 |
| 90 | 90 | */ |
| 91 | 91 | public function test_get_unauthed_attribute() { |
| 92 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id'] ); |
|
| 92 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id']); |
|
| 93 | 93 | |
| 94 | - $response = $this->server->dispatch( $request ); |
|
| 95 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 94 | + $response = $this->server->dispatch($request); |
|
| 95 | + $this->assertEquals(401, $response->get_status()); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * @since 3.6.0 |
| 102 | 102 | */ |
| 103 | 103 | public function test_get_attribute_contributor() { |
| 104 | - wp_set_current_user( $this->contributor ); |
|
| 105 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id'] ); |
|
| 104 | + wp_set_current_user($this->contributor); |
|
| 105 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/attributes/' . $this->attr_size['attribute_id']); |
|
| 106 | 106 | |
| 107 | - $response = $this->server->dispatch( $request ); |
|
| 107 | + $response = $this->server->dispatch($request); |
|
| 108 | 108 | $attribute = $response->get_data(); |
| 109 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 110 | - $this->assertEquals( $this->attr_size['attribute_id'], $attribute['id'] ); |
|
| 111 | - $this->assertEquals( $this->attr_size['attribute_name'], $attribute['name'] ); |
|
| 109 | + $this->assertEquals(200, $response->get_status()); |
|
| 110 | + $this->assertEquals($this->attr_size['attribute_id'], $attribute['id']); |
|
| 111 | + $this->assertEquals($this->attr_size['attribute_name'], $attribute['name']); |
|
| 112 | 112 | } |
| 113 | 113 | } |
@@ -5,7 +5,7 @@ discard block |
||
| 5 | 5 | |
| 6 | 6 | namespace WooCommerce\RestApi\UnitTests\Tests\Blocks; |
| 7 | 7 | |
| 8 | -defined( 'ABSPATH' ) || exit; |
|
| 8 | +defined('ABSPATH') || exit; |
|
| 9 | 9 | |
| 10 | 10 | use \WP_REST_Request; |
| 11 | 11 | use \WC_REST_Unit_Test_Case; |
@@ -46,13 +46,13 @@ discard block |
||
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | 48 | // Create 3 product categories. |
| 49 | - $parent = wp_insert_term( 'Parent Category', 'product_cat' ); |
|
| 49 | + $parent = wp_insert_term('Parent Category', 'product_cat'); |
|
| 50 | 50 | $child = wp_insert_term( |
| 51 | 51 | 'Child Category', |
| 52 | 52 | 'product_cat', |
| 53 | - array( 'parent' => $parent['term_id'] ) |
|
| 53 | + array('parent' => $parent['term_id']) |
|
| 54 | 54 | ); |
| 55 | - $single = wp_insert_term( 'Standalone Category', 'product_cat' ); |
|
| 55 | + $single = wp_insert_term('Standalone Category', 'product_cat'); |
|
| 56 | 56 | $this->categories = array( |
| 57 | 57 | 'parent' => $parent, |
| 58 | 58 | 'child' => $child, |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | // Create two products for the parent category. |
| 63 | 63 | $this->products = array(); |
| 64 | - $this->products[0] = ProductHelper::create_simple_product( false ); |
|
| 65 | - $this->products[0]->set_category_ids( array( $parent['term_id'] ) ); |
|
| 64 | + $this->products[0] = ProductHelper::create_simple_product(false); |
|
| 65 | + $this->products[0]->set_category_ids(array($parent['term_id'])); |
|
| 66 | 66 | $this->products[0]->save(); |
| 67 | 67 | |
| 68 | - $this->products[3] = ProductHelper::create_simple_product( false ); |
|
| 69 | - $this->products[3]->set_category_ids( array( $parent['term_id'], $single['term_id'] ) ); |
|
| 68 | + $this->products[3] = ProductHelper::create_simple_product(false); |
|
| 69 | + $this->products[3]->set_category_ids(array($parent['term_id'], $single['term_id'])); |
|
| 70 | 70 | $this->products[3]->save(); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -76,13 +76,13 @@ discard block |
||
| 76 | 76 | * @since 3.6.0 |
| 77 | 77 | */ |
| 78 | 78 | public function test_get_product_categories() { |
| 79 | - wp_set_current_user( $this->user ); |
|
| 80 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/categories' ); |
|
| 79 | + wp_set_current_user($this->user); |
|
| 80 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/categories'); |
|
| 81 | 81 | |
| 82 | - $response = $this->server->dispatch( $request ); |
|
| 82 | + $response = $this->server->dispatch($request); |
|
| 83 | 83 | $categories = $response->get_data(); |
| 84 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 85 | - $this->assertEquals( 4, count( $categories ) ); // Three created and `uncategorized`. |
|
| 84 | + $this->assertEquals(200, $response->get_status()); |
|
| 85 | + $this->assertEquals(4, count($categories)); // Three created and `uncategorized`. |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,11 +91,11 @@ discard block |
||
| 91 | 91 | * @since 3.6.0 |
| 92 | 92 | */ |
| 93 | 93 | public function test_get_invalid_product_category() { |
| 94 | - wp_set_current_user( $this->user ); |
|
| 95 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/categories/007' ); |
|
| 94 | + wp_set_current_user($this->user); |
|
| 95 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/categories/007'); |
|
| 96 | 96 | |
| 97 | - $response = $this->server->dispatch( $request ); |
|
| 98 | - $this->assertEquals( 404, $response->get_status() ); |
|
| 97 | + $response = $this->server->dispatch($request); |
|
| 98 | + $this->assertEquals(404, $response->get_status()); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | /** |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | * @since 3.6.0 |
| 105 | 105 | */ |
| 106 | 106 | public function test_get_unauthed_product_category() { |
| 107 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/categories/' . $this->categories['parent']['term_id'] ); |
|
| 107 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/categories/' . $this->categories['parent']['term_id']); |
|
| 108 | 108 | |
| 109 | - $response = $this->server->dispatch( $request ); |
|
| 110 | - $this->assertEquals( 401, $response->get_status() ); |
|
| 109 | + $response = $this->server->dispatch($request); |
|
| 110 | + $this->assertEquals(401, $response->get_status()); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -116,14 +116,14 @@ discard block |
||
| 116 | 116 | * @since 3.6.0 |
| 117 | 117 | */ |
| 118 | 118 | public function test_get_attribute_terms_contributor() { |
| 119 | - wp_set_current_user( $this->contributor ); |
|
| 120 | - $request = new WP_REST_Request( 'GET', $this->endpoint . '/products/categories/' . $this->categories['parent']['term_id'] ); |
|
| 119 | + wp_set_current_user($this->contributor); |
|
| 120 | + $request = new WP_REST_Request('GET', $this->endpoint . '/products/categories/' . $this->categories['parent']['term_id']); |
|
| 121 | 121 | |
| 122 | - $response = $this->server->dispatch( $request ); |
|
| 122 | + $response = $this->server->dispatch($request); |
|
| 123 | 123 | $category = $response->get_data(); |
| 124 | - $this->assertEquals( 200, $response->get_status() ); |
|
| 125 | - $this->assertEquals( $category['name'], 'Parent Category' ); |
|
| 126 | - $this->assertEquals( $category['parent'], 0 ); |
|
| 127 | - $this->assertEquals( $category['count'], 2 ); |
|
| 124 | + $this->assertEquals(200, $response->get_status()); |
|
| 125 | + $this->assertEquals($category['name'], 'Parent Category'); |
|
| 126 | + $this->assertEquals($category['parent'], 0); |
|
| 127 | + $this->assertEquals($category['count'], 2); |
|
| 128 | 128 | } |
| 129 | 129 | } |