From 4c760b12c3ba89a29eb5001c5a38fac88127335d Mon Sep 17 00:00:00 2001 From: Nedim Uka Date: Mon, 1 Oct 2018 17:03:24 +0200 Subject: [PATCH] Added unit tests for templates --- .../class-wiaas-admin-template-selection.php | 2 +- .../tests/unit-tests/test-wiaas-templates.php | 61 +++++++++++++++++++ .../wiaas/tests/wiaas-unit-test-case.php | 15 +++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-templates.php diff --git a/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php b/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php index a052f01..83411b2 100644 --- a/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php +++ b/backend/app/plugins/wiaas/includes/admin/template/class-wiaas-admin-template-selection.php @@ -165,7 +165,7 @@ class Wiaas_Admin_Template_Selection { /** * Get the template categories from bundle products and selected template - * Compare template categories and quantities that are required by the template with those in bundle products + * Compare template categories and quantities that are required by the template with those in bundle products * * Admin error is added if validation is not satisfied * diff --git a/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-templates.php b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-templates.php new file mode 100644 index 0000000..e3f008d --- /dev/null +++ b/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-templates.php @@ -0,0 +1,61 @@ +template_category = wp_create_term('Test', 'template_category'); + $this->template_meta = array( + 'template_category_id' => $this->template_category['term_id'], + 'template_category_title' => 'Test', + 'quantity' => 1 + ); + + $this->template = $this->create_new_wiaas_template(); + $this->product = $this->create_new_product(); + $this->package = $this->create_new_package(); + $this->add_products_to_package($this->package, $this->product); + + + } + + public function test_template_category_taxonomy_created() { + $taxonomy = get_taxonomy('template_category'); + + $this->assertInstanceOf(WP_Taxonomy::class, $taxonomy); + + $template_category_names = array_map(function ($term) { + return $term->name; + }, get_terms(array('taxonomy' => 'template_category', 'hide_empty' => false))); + + $this->assertNotEmpty($template_category_names); + $this->assertContains('Test', $template_category_names); + + } + + function test_adding_template_category_to_template() { + + WC_Product_Template::save_template_product_meta($this->template->get_id(), 'hardware', $this->template_meta); + + $test_template_category = WC_Product_Template::get_template_categories_from_meta( + $this->template->get_id(), '_template_items_hardware'); + + $this->assertEquals($test_template_category['template_category_id'], $this->template_meta['template_category_id']); + $this->assertEquals($test_template_category['template_category_title'], $this->template_meta['template_category_title']); + $this->assertEquals($test_template_category['quantity'], $this->template_meta['quantity']); + } + + function save_bind_package_to_template() { + WC_Product_Template::bind_selected_template_to_product($this->template->get_id(), $this->package->get_id()); + $value = get_post_meta($this->package->get_id(), '_select_template', true); + + $this->assertNotEmpty($value); + } +} \ No newline at end of file diff --git a/backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php b/backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php index 14a5b2f..d4c64b5 100644 --- a/backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php +++ b/backend/app/plugins/wiaas/tests/wiaas-unit-test-case.php @@ -88,6 +88,21 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase { $package->sync(true); } + + function create_new_wiaas_template() { + $post_id = wp_insert_post(array( + 'post_type' => 'product', + 'post_status' => 'publish', + 'post_name' => 'product', + 'post_title' => 'Package', + 'post_content' => 'Package', + 'post_excerpt' => 'Package' + ), true); + + return new WC_Product_Template($post_id); + + } + function create_new_customer($login = 'customer_test', $organization_name = 'test-customer-organization') { $customer_id = wp_insert_user(array( 'user_login' => $login,