Added unit tests for templates
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Wiaas_Templates_Test extends Wiaas_Unit_Test_Case {
|
||||
|
||||
var $template, $product, $package, $template_category, $template_meta;
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
# set admin as current user
|
||||
wp_set_current_user(1);
|
||||
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user