@@ -308,7 +308,7 @@ public function test_attribute_on_simple_product_does_not_exist() {
308308 *
309309 * @author Stéphane Gillot
310310 */
311- public function test_get_simple_product_dimensions_when_defined (){
311+ public function test_get_simple_product_dimensions_when_defined () {
312312 $ wc_product = WC_Helper_Product::create_simple_product ();
313313 $ wc_product ->set_length ( 5 );
314314 $ wc_product ->set_height ( 10 );
@@ -329,9 +329,9 @@ public function test_get_simple_product_dimensions_when_defined(){
329329 *
330330 * @author Stéphane Gillot
331331 */
332- public function test_get_simple_product_dimensions_when_not_defined (){
332+ public function test_get_simple_product_dimensions_when_not_defined () {
333333 $ wc_product = WC_Helper_Product::create_simple_product ();
334- $ wc_product ->set_length ('' );
334+ $ wc_product ->set_length ( '' );
335335 $ wc_product ->set_height ( '' );
336336 $ wc_product ->set_width ( '' );
337337 $ wc_product ->save ();
@@ -363,7 +363,7 @@ public function test_get_variation_dimensions_when_it_not_defined() {
363363 $ this ->assertEquals ( '' , $ sf_product ->get_width (), 'Product width should be null. ' );
364364 }
365365
366- public function test_get_variation_dimensions_when_it_overrides_parent_dimensions (){
366+ public function test_get_variation_dimensions_when_it_overrides_parent_dimensions () {
367367
368368 // Prepare the variable product object
369369 $ wc_variable_product = new \WC_Product_Variable ();
@@ -374,9 +374,9 @@ public function test_get_variation_dimensions_when_it_overrides_parent_dimension
374374
375375 $ variation = WC_Helper_Product::create_variation_product ();
376376 $ variation ->set_parent_id ( $ wc_variable_product ->get_id () );
377- $ variation ->set_length (20 );
378- $ variation ->set_height (30 );
379- $ variation ->set_width (40 );
377+ $ variation ->set_length ( 20 );
378+ $ variation ->set_height ( 30 );
379+ $ variation ->set_width ( 40 );
380380 $ variation ->save ();
381381
382382
@@ -390,7 +390,7 @@ public function test_get_variation_dimensions_when_it_overrides_parent_dimension
390390 public function test_variation_set_custom_main_image () {
391391 add_filter (
392392 'shopping_feed_variation_main_image ' ,
393- function ( $ image , $ variation , $ product ) {
393+ function ( $ image , $ variation , $ product ) {
394394 return 'https://example.com/image.jpg ' ;
395395 },
396396 10 ,
@@ -399,15 +399,15 @@ function( $image, $variation, $product ) {
399399
400400 $ image_id = $ this ->factory ()->attachment ->create_object (
401401 [
402- 'file ' => codecept_data_dir ( 'images/image1.png ' ),
402+ 'file ' => codecept_data_dir ( 'images/image1.png ' ),
403403 'post_mime_type ' => 'image/png ' ,
404- 'post_title ' => 'Test Image ' ,
405- 'post_content ' => '' ,
406- 'post_status ' => 'inherit ' ,
404+ 'post_title ' => 'Test Image ' ,
405+ 'post_content ' => '' ,
406+ 'post_status ' => 'inherit ' ,
407407 ]
408408 );
409-
410- $ variable_product = new \WC_Product_Variable ();
409+
410+ $ variable_product = new \WC_Product_Variable ();
411411 $ variable_product_id = $ variable_product ->save ();
412412
413413 WC_Helper_Product::create_product_variation_object ( $ variable_product_id , 'variation-1 ' , 10 , [], true );
@@ -419,18 +419,18 @@ function( $image, $variation, $product ) {
419419 }
420420
421421 public function test_variation_use_thumbnail_as_main_image () {
422- $ image_id = $ this ->factory ()->attachment ->create_object (
422+ $ image_id = $ this ->factory ()->attachment ->create_object (
423423 [
424- 'file ' => codecept_data_dir ( 'images/image1.png ' ),
424+ 'file ' => codecept_data_dir ( 'images/image1.png ' ),
425425 'post_mime_type ' => 'image/png ' ,
426- 'post_title ' => 'Test Image ' ,
427- 'post_content ' => '' ,
428- 'post_status ' => 'inherit ' ,
426+ 'post_title ' => 'Test Image ' ,
427+ 'post_content ' => '' ,
428+ 'post_status ' => 'inherit ' ,
429429 ]
430430 );
431431 $ image_url = wp_get_attachment_image_url ( $ image_id , 'full ' );
432-
433- $ variable_product = new \WC_Product_Variable ();
432+
433+ $ variable_product = new \WC_Product_Variable ();
434434 $ variable_product_id = $ variable_product ->save ();
435435
436436 $ variation_product = WC_Helper_Product::create_product_variation_object ( $ variable_product_id , 'variation-1 ' , 10 , [], true );
@@ -446,14 +446,14 @@ public function test_variation_use_thumbnail_as_main_image() {
446446 public function test_variation_empty_main_image_if_no_image_set () {
447447 $ image_id = $ this ->factory ()->attachment ->create_object (
448448 [
449- 'file ' => codecept_data_dir ( 'images/image1.png ' ),
449+ 'file ' => codecept_data_dir ( 'images/image1.png ' ),
450450 'post_mime_type ' => 'image/png ' ,
451- 'post_title ' => 'Test Image ' ,
452- 'post_content ' => '' ,
453- 'post_status ' => 'inherit ' ,
451+ 'post_title ' => 'Test Image ' ,
452+ 'post_content ' => '' ,
453+ 'post_status ' => 'inherit ' ,
454454 ]
455455 );
456-
456+
457457 $ variable_product = new \WC_Product_Variable ();
458458 $ variable_product ->set_image_id ( $ image_id );
459459 $ variable_product_id = $ variable_product ->save ();
@@ -465,4 +465,34 @@ public function test_variation_empty_main_image_if_no_image_set() {
465465 $ this ->assertArrayHasKey ( 'image_main ' , $ sf_product ->get_variations ()[0 ], 'Variation should have an image_main key. ' );
466466 $ this ->assertEquals ( '' , $ sf_product ->get_variations ()[0 ]['image_main ' ], 'Product main image should be empty. ' );
467467 }
468+
469+ /**
470+ * @covers \ShoppingFeed\ShoppingFeedWC\Products\Product::get_variation_extra_fields
471+ */
472+ public function test_variation_extra_fields () {
473+ $ extra_fields = [
474+ 'field1 ' => 'value1 ' ,
475+ 'field2 ' => 'value2 ' ,
476+ ];
477+
478+ add_filter (
479+ 'shopping_feed_variation_extra_fields ' ,
480+ function ( $ fields , $ variation ) use ( $ extra_fields ) {
481+ return $ extra_fields ;
482+ },
483+ 10 ,
484+ 2
485+ );
486+
487+ $ variable_product = new \WC_Product_Variable ();
488+ $ variable_product_id = $ variable_product ->save ();
489+
490+ WC_Helper_Product::create_product_variation_object ( $ variable_product_id , 'variation-1 ' , 10 , [], true );
491+
492+ $ sf_product = new Product ( $ variable_product_id );
493+ $ variations = $ sf_product ->get_variations ();
494+ $ this ->assertCount ( 1 , $ variations , 'Variable product should have 1 variation. ' );
495+ $ this ->assertIsArray ( reset ( $ variations )['extra ' ], 'Variation data should have a key "extra" containing an array. ' );
496+ $ this ->assertEqualSets ( $ extra_fields , reset ( $ variations )['extra ' ] );
497+ }
468498}
0 commit comments