From 5bd2190ff5692a4f8b11d9a676e4d64d29e0c667 Mon Sep 17 00:00:00 2001 From: vendidero Date: Mon, 23 Sep 2024 17:43:46 +0200 Subject: [PATCH] tests --- tests/framework/helpers/class-wc-gzd-helper-product.php | 8 +++++--- tests/unit-tests/api/products.php | 5 +---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/framework/helpers/class-wc-gzd-helper-product.php b/tests/framework/helpers/class-wc-gzd-helper-product.php index d118576b..f98df349 100644 --- a/tests/framework/helpers/class-wc-gzd-helper-product.php +++ b/tests/framework/helpers/class-wc-gzd-helper-product.php @@ -69,7 +69,7 @@ public static function create_allergen() { return $term; } - public static function create_attachment( $name = 'woocommerce-placeholder', $file_type = '' ) { + public static function create_attachment( $name = 'woocommerce-placeholder' ) { $attachment = get_page_by_path( $name, 'OBJECT', 'attachment' ); if ( ! is_a( $attachment, 'WP_Post' ) ) { @@ -81,7 +81,7 @@ public static function create_attachment( $name = 'woocommerce-placeholder', $fi copy( $source, $filename ); // @codingStandardsIgnoreLine. } - $filetype = empty( $file_type ) ? wp_check_filetype( basename( $filename ), null ) : $file_type; + $filetype = wp_check_filetype( basename( $filename ), null ); $attachment = array( 'guid' => $upload_dir['url'] . '/' . basename( $filename ), 'post_mime_type' => $filetype, @@ -106,7 +106,7 @@ public static function create_simple_product() { $allergen = self::create_allergen(); $nutrient = self::create_nutrient(); $manufacturer = self::create_manufacturer(); - // $attachment = self::create_attachment(); + $attachment = self::create_attachment(); $product = WC_Helper_Product::create_simple_product(); @@ -140,6 +140,8 @@ public static function create_simple_product() { ), '_is_food' => 'yes', '_manufacturer_slug' => $manufacturer->slug, + '_product_safety_attachments' => array( $attachment ), + '_product_warranty_pdf' => $attachment, '_deposit_type' => $deposit_type->slug, '_deposit_quantity' => 5, '_ingredients' => 'Hazelnut, Fish', diff --git a/tests/unit-tests/api/products.php b/tests/unit-tests/api/products.php index de5ba0e0..e100c28a 100644 --- a/tests/unit-tests/api/products.php +++ b/tests/unit-tests/api/products.php @@ -61,9 +61,6 @@ public function test_get_product() { $this->assertEquals( true, $product['free_shipping'] ); $this->assertEquals( true, $product['is_food'] ); - // $this->assertEquals( true, ! empty( $product['safety_attachment_ids'] ) ); - // $this->assertEquals( true, ! empty( $product['warranty_attachment_id'] ) ); - $nutrient = get_term_by( 'slug', 'energy', 'product_nutrient' ); $allergen = get_term_by( 'slug', 'hazelnut', 'product_allergen' ); @@ -101,7 +98,7 @@ public function test_create_product() { $nutrient = wp_insert_term( 'Salt', 'product_nutrient', array( 'slug' => 'salt' ) ); $nutrient_2 = wp_insert_term( 'Natrium', 'product_nutrient', array( 'slug' => 'natrium' ) ); $allergen = wp_insert_term( 'Nut', 'product_allergen', array( 'slug' => 'nut' ) ); - // $attachment_id = WC_GZD_Helper_Product::create_attachment( 'test' ); + $attachment_id = WC_GZD_Helper_Product::create_attachment( 'test' ); // Create simple. $request = new WP_REST_Request( 'POST', '/wc/v3/products' );