@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | public function setUp() { |
35 | 35 | parent::setUp(); |
36 | 36 | |
37 | - $this->wc_stripe_subs_compat = $this->getMockBuilder( 'WC_Stripe_Subs_Compat' ) |
|
37 | + $this->wc_stripe_subs_compat = $this->getMockBuilder('WC_Stripe_Subs_Compat') |
|
38 | 38 | ->disableOriginalConstructor() |
39 | - ->setMethods( array( 'prepare_order_source', 'has_subscription', 'ensure_subscription_has_customer_id' ) ) |
|
39 | + ->setMethods(array('prepare_order_source', 'has_subscription', 'ensure_subscription_has_customer_id')) |
|
40 | 40 | ->getMock(); |
41 | 41 | |
42 | 42 | // Mocked in order to get metadata[payment_type] = recurring in the HTTP request. |
43 | 43 | $this->wc_stripe_subs_compat |
44 | - ->expects( $this->any() ) |
|
45 | - ->method( 'has_subscription' ) |
|
44 | + ->expects($this->any()) |
|
45 | + ->method('has_subscription') |
|
46 | 46 | ->will( |
47 | - $this->returnValue( true ) |
|
47 | + $this->returnValue(true) |
|
48 | 48 | ); |
49 | 49 | |
50 | 50 | $this->statement_descriptor = 'This is a statement descriptor.'; |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | public function tearDown() { |
63 | 63 | parent::tearDown(); |
64 | 64 | |
65 | - delete_option( 'woocommerce_stripe_settings' ); |
|
65 | + delete_option('woocommerce_stripe_settings'); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -79,22 +79,22 @@ discard block |
||
79 | 79 | // Arrange: Some variables we'll use later. |
80 | 80 | $renewal_order = WC_Helper_Order::create_order(); |
81 | 81 | $amount = 20; // WC Subs sends an amount to be used, instead of using the order amount. |
82 | - $stripe_amount = WC_Stripe_Helper::get_stripe_amount( $amount ); |
|
83 | - $currency = strtolower( $renewal_order->get_currency() ); |
|
82 | + $stripe_amount = WC_Stripe_Helper::get_stripe_amount($amount); |
|
83 | + $currency = strtolower($renewal_order->get_currency()); |
|
84 | 84 | $customer = 'cus_123abc'; |
85 | 85 | $source = 'src_123abc'; |
86 | - $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor( $this->statement_descriptor ); |
|
86 | + $statement_descriptor = WC_Stripe_Helper::clean_statement_descriptor($this->statement_descriptor); |
|
87 | 87 | $should_retry = false; |
88 | 88 | $previous_error = false; |
89 | 89 | $payments_intents_api_endpoint = 'https://api.stripe.com/v1/payment_intents'; |
90 | 90 | $urls_used = array(); |
91 | 91 | |
92 | - $renewal_order->set_payment_method( 'stripe' ); |
|
92 | + $renewal_order->set_payment_method('stripe'); |
|
93 | 93 | |
94 | 94 | // Arrange: Mock prepare_order_source() so that we have a customer and source. |
95 | 95 | $this->wc_stripe_subs_compat |
96 | - ->expects( $this->any() ) |
|
97 | - ->method( 'prepare_order_source' ) |
|
96 | + ->expects($this->any()) |
|
97 | + ->method('prepare_order_source') |
|
98 | 98 | ->will( |
99 | 99 | $this->returnValue( |
100 | 100 | (object) array( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | // Arrange: Add filter that will return a mocked HTTP response for the payment_intent call. |
110 | 110 | // Note: There are assertions in the callback function. |
111 | - $pre_http_request_response_callback = function( $preempt, $request_args, $url ) use ( |
|
111 | + $pre_http_request_response_callback = function($preempt, $request_args, $url) use ( |
|
112 | 112 | $renewal_order, |
113 | 113 | $stripe_amount, |
114 | 114 | $currency, |
@@ -119,35 +119,35 @@ discard block |
||
119 | 119 | &$urls_used |
120 | 120 | ) { |
121 | 121 | // Add all urls to array so we can later make assertions about which endpoints were used. |
122 | - array_push( $urls_used, $url ); |
|
122 | + array_push($urls_used, $url); |
|
123 | 123 | |
124 | 124 | // Continue without mocking the request if it's not the endpoint we care about. |
125 | - if ( $payments_intents_api_endpoint !== $url ) { |
|
125 | + if ($payments_intents_api_endpoint !== $url) { |
|
126 | 126 | return false; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // Assert: the request method is POST. |
130 | - $this->assertArrayHasKey( 'method', $request_args ); |
|
131 | - $this->assertSame( 'POST', $request_args['method'] ); |
|
130 | + $this->assertArrayHasKey('method', $request_args); |
|
131 | + $this->assertSame('POST', $request_args['method']); |
|
132 | 132 | |
133 | 133 | // Assert: the request has a body. |
134 | - $this->assertArrayHasKey( 'body', $request_args ); |
|
134 | + $this->assertArrayHasKey('body', $request_args); |
|
135 | 135 | |
136 | 136 | // Assert: the request body contains these values. |
137 | 137 | $expected_request_body_values = array( |
138 | 138 | 'source' => $source, |
139 | 139 | 'amount' => $stripe_amount, |
140 | 140 | 'currency' => $currency, |
141 | - 'payment_method_types' => array( 'card' ), |
|
141 | + 'payment_method_types' => array('card'), |
|
142 | 142 | 'customer' => $customer, |
143 | 143 | 'off_session' => 'true', |
144 | 144 | 'confirm' => 'true', |
145 | 145 | 'confirmation_method' => 'automatic', |
146 | 146 | 'statement_descriptor' => $statement_descriptor, |
147 | 147 | ); |
148 | - foreach ( $expected_request_body_values as $key => $value ) { |
|
149 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
150 | - $this->assertSame( $value, $request_args['body'][ $key ] ); |
|
148 | + foreach ($expected_request_body_values as $key => $value) { |
|
149 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
150 | + $this->assertSame($value, $request_args['body'][$key]); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // Assert: the request body contains these keys, without checking for their value. |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | 'description', |
156 | 156 | 'metadata', |
157 | 157 | ); |
158 | - foreach ( $expected_request_body_keys as $key ) { |
|
159 | - $this->assertArrayHasKey( $key, $request_args['body'] ); |
|
158 | + foreach ($expected_request_body_keys as $key) { |
|
159 | + $this->assertArrayHasKey($key, $request_args['body']); |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // Assert: the body metadata has these values. |
@@ -165,9 +165,9 @@ discard block |
||
165 | 165 | 'order_id' => $order_id, |
166 | 166 | 'payment_type' => 'recurring', |
167 | 167 | ); |
168 | - foreach ( $expected_metadata_values as $key => $value ) { |
|
169 | - $this->assertArrayHasKey( $key, $request_args['body']['metadata'] ); |
|
170 | - $this->assertSame( $value, $request_args['body']['metadata'][ $key ] ); |
|
168 | + foreach ($expected_metadata_values as $key => $value) { |
|
169 | + $this->assertArrayHasKey($key, $request_args['body']['metadata']); |
|
170 | + $this->assertSame($value, $request_args['body']['metadata'][$key]); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | // Assert: the body metadata has these keys, without checking for their value. |
@@ -176,8 +176,8 @@ discard block |
||
176 | 176 | 'customer_email', |
177 | 177 | 'site_url', |
178 | 178 | ); |
179 | - foreach ( $expected_metadata_keys as $key ) { |
|
180 | - $this->assertArrayHasKey( $key, $request_args['body']['metadata'] ); |
|
179 | + foreach ($expected_metadata_keys as $key) { |
|
180 | + $this->assertArrayHasKey($key, $request_args['body']['metadata']); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Assert: the request body does not contains these keys. |
@@ -186,15 +186,15 @@ discard block |
||
186 | 186 | 'capture_method', // The default ('automatic') is what we want in this case, so we leave it off. |
187 | 187 | 'expand[]', |
188 | 188 | ); |
189 | - foreach ( $expected_missing_request_body_keys as $key ) { |
|
190 | - $this->assertArrayNotHasKey( $key, $request_args['body'] ); |
|
189 | + foreach ($expected_missing_request_body_keys as $key) { |
|
190 | + $this->assertArrayNotHasKey($key, $request_args['body']); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Arrange: return dummy content as the response. |
194 | 194 | return array( |
195 | 195 | 'headers' => array(), |
196 | 196 | // Too bad we aren't dynamically setting things 'cus_123abc' when using this file. |
197 | - 'body' => file_get_contents( 'tests/phpunit/dummy-data/subscription_renewal_response_success.json' ), |
|
197 | + 'body' => file_get_contents('tests/phpunit/dummy-data/subscription_renewal_response_success.json'), |
|
198 | 198 | 'response' => array( |
199 | 199 | 'code' => 200, |
200 | 200 | 'message' => 'OK', |
@@ -204,48 +204,48 @@ discard block |
||
204 | 204 | ); |
205 | 205 | }; |
206 | 206 | |
207 | - add_filter( 'pre_http_request', $pre_http_request_response_callback, 10, 3 ); |
|
207 | + add_filter('pre_http_request', $pre_http_request_response_callback, 10, 3); |
|
208 | 208 | |
209 | 209 | // Arrange: Make sure to check that an action we care about was called |
210 | 210 | // by hooking into it. |
211 | 211 | $mock_action_process_payment = new MockAction(); |
212 | 212 | add_action( |
213 | 213 | 'wc_gateway_stripe_process_payment', |
214 | - [ &$mock_action_process_payment, 'action' ] |
|
214 | + [&$mock_action_process_payment, 'action'] |
|
215 | 215 | ); |
216 | 216 | |
217 | 217 | // Act: call process_subscription_payment(). |
218 | 218 | // We need to use `wc_stripe_subs_compat` here because we mocked this class earlier. |
219 | - $result = $this->wc_stripe_subs_compat->process_subscription_payment( 20, $renewal_order, $should_retry, $previous_error ); |
|
219 | + $result = $this->wc_stripe_subs_compat->process_subscription_payment(20, $renewal_order, $should_retry, $previous_error); |
|
220 | 220 | |
221 | 221 | // Assert: nothing was returned. |
222 | - $this->assertEquals( $result, null ); |
|
222 | + $this->assertEquals($result, null); |
|
223 | 223 | |
224 | 224 | // Assert that we saved the payment intent to the order. |
225 | - $order = wc_get_order( $renewal_order->get_id() ); |
|
226 | - $this->assertNotFalse( $order ); |
|
227 | - $order_data = $order->get_meta( '_stripe_intent_id' ); |
|
225 | + $order = wc_get_order($renewal_order->get_id()); |
|
226 | + $this->assertNotFalse($order); |
|
227 | + $order_data = $order->get_meta('_stripe_intent_id'); |
|
228 | 228 | |
229 | - $this->assertEquals( $order_data, 'pi_123abc' ); |
|
229 | + $this->assertEquals($order_data, 'pi_123abc'); |
|
230 | 230 | |
231 | 231 | // Transaction ID was saved to order. |
232 | 232 | $order_transaction_id = $order->get_transaction_id(); |
233 | - $this->assertEquals( $order_transaction_id, 'ch_123abc' ); |
|
233 | + $this->assertEquals($order_transaction_id, 'ch_123abc'); |
|
234 | 234 | |
235 | 235 | // Assert: the order was marked as processing (this is done in process_response()). |
236 | - $this->assertEquals( $order->get_status(), 'processing' ); |
|
236 | + $this->assertEquals($order->get_status(), 'processing'); |
|
237 | 237 | |
238 | 238 | // Assert: called payment intents. |
239 | - $this->assertTrue( in_array( $payments_intents_api_endpoint, $urls_used ) ); |
|
239 | + $this->assertTrue(in_array($payments_intents_api_endpoint, $urls_used)); |
|
240 | 240 | |
241 | 241 | // Assert: Our hook was called once. |
242 | - $this->assertEquals( 1, $mock_action_process_payment->get_call_count() ); |
|
242 | + $this->assertEquals(1, $mock_action_process_payment->get_call_count()); |
|
243 | 243 | |
244 | 244 | // Assert: Only our hook was called. |
245 | - $this->assertEquals( array( 'wc_gateway_stripe_process_payment' ), $mock_action_process_payment->get_tags() ); |
|
245 | + $this->assertEquals(array('wc_gateway_stripe_process_payment'), $mock_action_process_payment->get_tags()); |
|
246 | 246 | |
247 | 247 | // Clean up. |
248 | - remove_filter( 'pre_http_request', array( $this, 'pre_http_request_response_success' ) ); |
|
248 | + remove_filter('pre_http_request', array($this, 'pre_http_request_response_success')); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | // Arrange: Some variables we'll use later. |
263 | 263 | $renewal_order = WC_Helper_Order::create_order(); |
264 | 264 | $amount = 20; |
265 | - $stripe_amount = WC_Stripe_Helper::get_stripe_amount( $amount ); |
|
266 | - $currency = strtolower( $renewal_order->get_currency() ); |
|
265 | + $stripe_amount = WC_Stripe_Helper::get_stripe_amount($amount); |
|
266 | + $currency = strtolower($renewal_order->get_currency()); |
|
267 | 267 | $customer = 'cus_123abc'; |
268 | 268 | $source = 'src_123abc'; |
269 | 269 | $should_retry = false; |
@@ -273,8 +273,8 @@ discard block |
||
273 | 273 | |
274 | 274 | // Arrange: Mock prepare_order_source() so that we have a customer and source. |
275 | 275 | $this->wc_stripe_subs_compat |
276 | - ->expects( $this->any() ) |
|
277 | - ->method( 'prepare_order_source' ) |
|
276 | + ->expects($this->any()) |
|
277 | + ->method('prepare_order_source') |
|
278 | 278 | ->will( |
279 | 279 | $this->returnValue( |
280 | 280 | (object) array( |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | ); |
288 | 288 | |
289 | 289 | // Arrange: Add filter that will return a mocked HTTP response for the payment_intent call. |
290 | - $pre_http_request_response_callback = function( $preempt, $request_args, $url ) use ( |
|
290 | + $pre_http_request_response_callback = function($preempt, $request_args, $url) use ( |
|
291 | 291 | $renewal_order, |
292 | 292 | $stripe_amount, |
293 | 293 | $currency, |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | &$urls_used |
298 | 298 | ) { |
299 | 299 | // Add all urls to array so we can later make assertions about which endpoints were used. |
300 | - array_push( $urls_used, $url ); |
|
300 | + array_push($urls_used, $url); |
|
301 | 301 | |
302 | 302 | // Continue without mocking the request if it's not the endpoint we care about. |
303 | - if ( $payments_intents_api_endpoint !== $url ) { |
|
303 | + if ($payments_intents_api_endpoint !== $url) { |
|
304 | 304 | return false; |
305 | 305 | } |
306 | 306 | |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | return array( |
309 | 309 | 'headers' => array(), |
310 | 310 | // Too bad we aren't dynamically setting things 'cus_123abc' when using this file. |
311 | - 'body' => file_get_contents( 'tests/phpunit/dummy-data/subscription_renewal_response_authentication_required.json' ), |
|
311 | + 'body' => file_get_contents('tests/phpunit/dummy-data/subscription_renewal_response_authentication_required.json'), |
|
312 | 312 | 'response' => array( |
313 | 313 | 'code' => 402, |
314 | 314 | 'message' => 'Payment Required', |
@@ -317,48 +317,48 @@ discard block |
||
317 | 317 | 'filename' => null, |
318 | 318 | ); |
319 | 319 | }; |
320 | - add_filter( 'pre_http_request', $pre_http_request_response_callback, 10, 3 ); |
|
320 | + add_filter('pre_http_request', $pre_http_request_response_callback, 10, 3); |
|
321 | 321 | |
322 | 322 | // Arrange: Make sure to check that an action we care about was called |
323 | 323 | // by hooking into it. |
324 | 324 | $mock_action_process_payment = new MockAction(); |
325 | 325 | add_action( |
326 | 326 | 'wc_gateway_stripe_process_payment_authentication_required', |
327 | - [ &$mock_action_process_payment, 'action' ] |
|
327 | + [&$mock_action_process_payment, 'action'] |
|
328 | 328 | ); |
329 | 329 | |
330 | 330 | // Act: call process_subscription_payment(). |
331 | 331 | // We need to use `wc_stripe_subs_compat` here because we mocked this class earlier. |
332 | - $result = $this->wc_stripe_subs_compat->process_subscription_payment( 20, $renewal_order, $should_retry, $previous_error ); |
|
332 | + $result = $this->wc_stripe_subs_compat->process_subscription_payment(20, $renewal_order, $should_retry, $previous_error); |
|
333 | 333 | |
334 | 334 | // Assert: nothing was returned. |
335 | - $this->assertEquals( $result, null ); |
|
335 | + $this->assertEquals($result, null); |
|
336 | 336 | |
337 | 337 | // Assert that we saved the payment intent to the order. |
338 | - $order = wc_get_order( $renewal_order->get_id() ); |
|
339 | - $this->assertNotFalse( $order ); |
|
340 | - $order_data = $order->get_meta( '_stripe_intent_id' ); |
|
338 | + $order = wc_get_order($renewal_order->get_id()); |
|
339 | + $this->assertNotFalse($order); |
|
340 | + $order_data = $order->get_meta('_stripe_intent_id'); |
|
341 | 341 | $order_transaction_id = $order->get_transaction_id(); |
342 | 342 | |
343 | 343 | // Intent was saved to order even though there was an error in the response body. |
344 | - $this->assertEquals( $order_data, 'pi_123abc' ); |
|
344 | + $this->assertEquals($order_data, 'pi_123abc'); |
|
345 | 345 | |
346 | 346 | // Transaction ID was saved to order. |
347 | - $this->assertEquals( $order_transaction_id, 'ch_123abc' ); |
|
347 | + $this->assertEquals($order_transaction_id, 'ch_123abc'); |
|
348 | 348 | |
349 | 349 | // Assert: the order was marked as failed. |
350 | - $this->assertEquals( $order->get_status(), 'failed' ); |
|
350 | + $this->assertEquals($order->get_status(), 'failed'); |
|
351 | 351 | |
352 | 352 | // Assert: called payment intents. |
353 | - $this->assertTrue( in_array( $payments_intents_api_endpoint, $urls_used ) ); |
|
353 | + $this->assertTrue(in_array($payments_intents_api_endpoint, $urls_used)); |
|
354 | 354 | |
355 | 355 | // Assert: Our hook was called once. |
356 | - $this->assertEquals( 1, $mock_action_process_payment->get_call_count() ); |
|
356 | + $this->assertEquals(1, $mock_action_process_payment->get_call_count()); |
|
357 | 357 | |
358 | 358 | // Assert: Only our hook was called. |
359 | - $this->assertEquals( array( 'wc_gateway_stripe_process_payment_authentication_required' ), $mock_action_process_payment->get_tags() ); |
|
359 | + $this->assertEquals(array('wc_gateway_stripe_process_payment_authentication_required'), $mock_action_process_payment->get_tags()); |
|
360 | 360 | |
361 | 361 | // Clean up. |
362 | - remove_filter( 'pre_http_request', array( $this, 'pre_http_request_response_success' ) ); |
|
362 | + remove_filter('pre_http_request', array($this, 'pre_http_request_response_success')); |
|
363 | 363 | } |
364 | 364 | } |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @param int $product_id ID to delete. |
19 | 19 | */ |
20 | - public static function delete_product( $product_id ) { |
|
21 | - $product = wc_get_product( $product_id ); |
|
22 | - if ( $product ) { |
|
23 | - $product->delete( true ); |
|
20 | + public static function delete_product($product_id) { |
|
21 | + $product = wc_get_product($product_id); |
|
22 | + if ($product) { |
|
23 | + $product->delete(true); |
|
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * @param bool $save Save or return object. |
32 | 32 | * @return WC_Product_Simple |
33 | 33 | */ |
34 | - public static function create_simple_product( $save = true ) { |
|
34 | + public static function create_simple_product($save = true) { |
|
35 | 35 | $product = new WC_Product_Simple(); |
36 | 36 | $product->set_props( |
37 | 37 | [ |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | ] |
49 | 49 | ); |
50 | 50 | |
51 | - if ( $save ) { |
|
51 | + if ($save) { |
|
52 | 52 | $product->save(); |
53 | - return wc_get_product( $product->get_id() ); |
|
53 | + return wc_get_product($product->get_id()); |
|
54 | 54 | } else { |
55 | 55 | return $product; |
56 | 56 | } |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | ); |
76 | 76 | $product->save(); |
77 | 77 | |
78 | - return wc_get_product( $product->get_id() ); |
|
78 | + return wc_get_product($product->get_id()); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -94,10 +94,10 @@ discard block |
||
94 | 94 | 'sku' => 'DUMMY GROUPED SKU', |
95 | 95 | ] |
96 | 96 | ); |
97 | - $product->set_children( [ $simple_product_1->get_id(), $simple_product_2->get_id() ] ); |
|
97 | + $product->set_children([$simple_product_1->get_id(), $simple_product_2->get_id()]); |
|
98 | 98 | $product->save(); |
99 | 99 | |
100 | - return wc_get_product( $product->get_id() ); |
|
100 | + return wc_get_product($product->get_id()); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -119,36 +119,36 @@ discard block |
||
119 | 119 | $attributes = []; |
120 | 120 | |
121 | 121 | $attribute = new WC_Product_Attribute(); |
122 | - $attribute_data = self::create_attribute( 'size', [ 'small', 'large', 'huge' ] ); |
|
123 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
124 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
125 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
126 | - $attribute->set_position( 1 ); |
|
127 | - $attribute->set_visible( true ); |
|
128 | - $attribute->set_variation( true ); |
|
122 | + $attribute_data = self::create_attribute('size', ['small', 'large', 'huge']); |
|
123 | + $attribute->set_id($attribute_data['attribute_id']); |
|
124 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
125 | + $attribute->set_options($attribute_data['term_ids']); |
|
126 | + $attribute->set_position(1); |
|
127 | + $attribute->set_visible(true); |
|
128 | + $attribute->set_variation(true); |
|
129 | 129 | $attributes[] = $attribute; |
130 | 130 | |
131 | 131 | $attribute = new WC_Product_Attribute(); |
132 | - $attribute_data = self::create_attribute( 'colour', [ 'red', 'blue' ] ); |
|
133 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
134 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
135 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
136 | - $attribute->set_position( 1 ); |
|
137 | - $attribute->set_visible( true ); |
|
138 | - $attribute->set_variation( true ); |
|
132 | + $attribute_data = self::create_attribute('colour', ['red', 'blue']); |
|
133 | + $attribute->set_id($attribute_data['attribute_id']); |
|
134 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
135 | + $attribute->set_options($attribute_data['term_ids']); |
|
136 | + $attribute->set_position(1); |
|
137 | + $attribute->set_visible(true); |
|
138 | + $attribute->set_variation(true); |
|
139 | 139 | $attributes[] = $attribute; |
140 | 140 | |
141 | 141 | $attribute = new WC_Product_Attribute(); |
142 | - $attribute_data = self::create_attribute( 'number', [ '0', '1', '2' ] ); |
|
143 | - $attribute->set_id( $attribute_data['attribute_id'] ); |
|
144 | - $attribute->set_name( $attribute_data['attribute_taxonomy'] ); |
|
145 | - $attribute->set_options( $attribute_data['term_ids'] ); |
|
146 | - $attribute->set_position( 1 ); |
|
147 | - $attribute->set_visible( true ); |
|
148 | - $attribute->set_variation( true ); |
|
142 | + $attribute_data = self::create_attribute('number', ['0', '1', '2']); |
|
143 | + $attribute->set_id($attribute_data['attribute_id']); |
|
144 | + $attribute->set_name($attribute_data['attribute_taxonomy']); |
|
145 | + $attribute->set_options($attribute_data['term_ids']); |
|
146 | + $attribute->set_position(1); |
|
147 | + $attribute->set_visible(true); |
|
148 | + $attribute->set_variation(true); |
|
149 | 149 | $attributes[] = $attribute; |
150 | 150 | |
151 | - $product->set_attributes( $attributes ); |
|
151 | + $product->set_attributes($attributes); |
|
152 | 152 | $product->save(); |
153 | 153 | |
154 | 154 | $variation_1 = new WC_Product_Variation(); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'regular_price' => 10, |
160 | 160 | ] |
161 | 161 | ); |
162 | - $variation_1->set_attributes( [ 'pa_size' => 'small' ] ); |
|
162 | + $variation_1->set_attributes(['pa_size' => 'small']); |
|
163 | 163 | $variation_1->save(); |
164 | 164 | |
165 | 165 | $variation_2 = new WC_Product_Variation(); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | 'regular_price' => 15, |
171 | 171 | ] |
172 | 172 | ); |
173 | - $variation_2->set_attributes( [ 'pa_size' => 'large' ] ); |
|
173 | + $variation_2->set_attributes(['pa_size' => 'large']); |
|
174 | 174 | $variation_2->save(); |
175 | 175 | |
176 | 176 | $variation_3 = new WC_Product_Variation(); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | ); |
208 | 208 | $variation_4->save(); |
209 | 209 | |
210 | - return wc_get_product( $product->get_id() ); |
|
210 | + return wc_get_product($product->get_id()); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -219,30 +219,30 @@ discard block |
||
219 | 219 | * @param array(string) $terms Terms to create for the attribute. |
220 | 220 | * @return array |
221 | 221 | */ |
222 | - public static function create_attribute( $raw_name = 'size', $terms = [ 'small' ] ) { |
|
222 | + public static function create_attribute($raw_name = 'size', $terms = ['small']) { |
|
223 | 223 | global $wpdb, $wc_product_attributes; |
224 | 224 | |
225 | 225 | // Make sure caches are clean. |
226 | - delete_transient( 'wc_attribute_taxonomies' ); |
|
227 | - if ( is_callable( [ 'WC_Cache_Helper', 'invalidate_cache_group' ] ) ) { |
|
226 | + delete_transient('wc_attribute_taxonomies'); |
|
227 | + if (is_callable(['WC_Cache_Helper', 'invalidate_cache_group'])) { |
|
228 | 228 | WC_Cache_Helper::invalidate_cache_group('woocommerce-attributes'); |
229 | 229 | } |
230 | 230 | |
231 | 231 | // These are exported as labels, so convert the label to a name if possible first. |
232 | - $attribute_labels = wp_list_pluck( wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name' ); |
|
233 | - $attribute_name = array_search( $raw_name, $attribute_labels, true ); |
|
232 | + $attribute_labels = wp_list_pluck(wc_get_attribute_taxonomies(), 'attribute_label', 'attribute_name'); |
|
233 | + $attribute_name = array_search($raw_name, $attribute_labels, true); |
|
234 | 234 | |
235 | - if ( ! $attribute_name ) { |
|
236 | - $attribute_name = wc_sanitize_taxonomy_name( $raw_name ); |
|
235 | + if ( ! $attribute_name) { |
|
236 | + $attribute_name = wc_sanitize_taxonomy_name($raw_name); |
|
237 | 237 | } |
238 | 238 | |
239 | - $attribute_id = wc_attribute_taxonomy_id_by_name( $attribute_name ); |
|
239 | + $attribute_id = wc_attribute_taxonomy_id_by_name($attribute_name); |
|
240 | 240 | |
241 | - if ( ! $attribute_id ) { |
|
242 | - $taxonomy_name = wc_attribute_taxonomy_name( $attribute_name ); |
|
241 | + if ( ! $attribute_id) { |
|
242 | + $taxonomy_name = wc_attribute_taxonomy_name($attribute_name); |
|
243 | 243 | |
244 | 244 | // Degister taxonomy which other tests may have created... |
245 | - unregister_taxonomy( $taxonomy_name ); |
|
245 | + unregister_taxonomy($taxonomy_name); |
|
246 | 246 | |
247 | 247 | $attribute_id = wc_create_attribute( |
248 | 248 | [ |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | // Register as taxonomy. |
258 | 258 | register_taxonomy( |
259 | 259 | $taxonomy_name, |
260 | - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, [ 'product' ] ), |
|
260 | + apply_filters('woocommerce_taxonomy_objects_' . $taxonomy_name, ['product']), |
|
261 | 261 | apply_filters( |
262 | 262 | 'woocommerce_taxonomy_args_' . $taxonomy_name, |
263 | 263 | [ |
@@ -275,12 +275,12 @@ discard block |
||
275 | 275 | // Set product attributes global. |
276 | 276 | $wc_product_attributes = []; |
277 | 277 | |
278 | - foreach ( wc_get_attribute_taxonomies() as $taxonomy ) { |
|
279 | - $wc_product_attributes[ wc_attribute_taxonomy_name( $taxonomy->attribute_name ) ] = $taxonomy; |
|
278 | + foreach (wc_get_attribute_taxonomies() as $taxonomy) { |
|
279 | + $wc_product_attributes[wc_attribute_taxonomy_name($taxonomy->attribute_name)] = $taxonomy; |
|
280 | 280 | } |
281 | 281 | } |
282 | 282 | |
283 | - $attribute = wc_get_attribute( $attribute_id ); |
|
283 | + $attribute = wc_get_attribute($attribute_id); |
|
284 | 284 | $return = [ |
285 | 285 | 'attribute_name' => $attribute->name, |
286 | 286 | 'attribute_taxonomy' => $attribute->slug, |
@@ -288,11 +288,11 @@ discard block |
||
288 | 288 | 'term_ids' => [], |
289 | 289 | ]; |
290 | 290 | |
291 | - foreach ( $terms as $term ) { |
|
292 | - $result = term_exists( $term, $attribute->slug ); |
|
291 | + foreach ($terms as $term) { |
|
292 | + $result = term_exists($term, $attribute->slug); |
|
293 | 293 | |
294 | - if ( ! $result ) { |
|
295 | - $result = wp_insert_term( $term, $attribute->slug ); |
|
294 | + if ( ! $result) { |
|
295 | + $result = wp_insert_term($term, $attribute->slug); |
|
296 | 296 | $return['term_ids'][] = $result['term_id']; |
297 | 297 | } else { |
298 | 298 | $return['term_ids'][] = $result['term_id']; |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | * |
310 | 310 | * @since 2.3 |
311 | 311 | */ |
312 | - public static function delete_attribute( $attribute_id ) { |
|
312 | + public static function delete_attribute($attribute_id) { |
|
313 | 313 | global $wpdb; |
314 | 314 | |
315 | - $attribute_id = absint( $attribute_id ); |
|
315 | + $attribute_id = absint($attribute_id); |
|
316 | 316 | |
317 | 317 | $wpdb->query( |
318 | - $wpdb->prepare( "DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d", $attribute_id ) |
|
318 | + $wpdb->prepare("DELETE FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_id = %d", $attribute_id) |
|
319 | 319 | ); |
320 | 320 | } |
321 | 321 | |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | * @param string $review_content string Content to use for the product review. |
328 | 328 | * @return integer Product Review ID. |
329 | 329 | */ |
330 | - public static function create_product_review( $product_id, $review_content = 'Review content here' ) { |
|
330 | + public static function create_product_review($product_id, $review_content = 'Review content here') { |
|
331 | 331 | $data = [ |
332 | 332 | 'comment_post_ID' => $product_id, |
333 | 333 | 'comment_author' => 'admin', |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | 'comment_approved' => 1, |
339 | 339 | 'comment_type' => 'review', |
340 | 340 | ]; |
341 | - return wp_insert_comment( $data ); |
|
341 | + return wp_insert_comment($data); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @param int $id ID to update. |
349 | 349 | */ |
350 | - public static function save_post_test_update_meta_data_direct( $id ) { |
|
351 | - update_post_meta( $id, '_test2', 'world' ); |
|
350 | + public static function save_post_test_update_meta_data_direct($id) { |
|
351 | + update_post_meta($id, '_test2', 'world'); |
|
352 | 352 | } |
353 | 353 | } |