This commit is contained in:
Almira Krdzic
2018-09-19 10:52:59 +02:00
parent cae148ebce
commit 85deb1d9f8
11 changed files with 798 additions and 14 deletions

View File

@@ -8,15 +8,22 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
*/
function setUp() {
parent::setUp();
wp_set_current_user(1);
# Setup Gravity info since options table is deleted after each test
gf_upgrade()->install();
WC_PB_Install::install();
wiaas_db_update_setup_gravity();
wiaas_db_update_enable_orders_access_management();
Wiaas_Countries::register_product_countries_taxonomy();
Wiaas_Product_Category::register_product_categories();
Wiaas_Package_Type::register_package_type_taxonomy();
define('WP_TEST_IN_PROGRESS',true);
}
@@ -25,7 +32,7 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
parent::tearDown();
}
function insertNewProduct() {
function create_new_product($price = 10, $is_recurring = false, $pay_period = 0) {
$post_id = wp_insert_post(array(
'post_type' => 'product',
'post_status' => 'publish',
@@ -35,10 +42,16 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
'post_excerpt' => 'Product'
), true);
return new WC_Product_Simple($post_id);
$product = new WC_Product_Simple($post_id);
Wiaas_Product_Pricing::set_product_price($product, $price, $is_recurring, $pay_period);
$product->save();
return $product;
}
function insertNewPackage() {
function create_new_package() {
$post_id = wp_insert_post(array(
'post_type' => 'product',
'post_status' => 'publish',
@@ -50,4 +63,26 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
return new WC_Product_Bundle($post_id);
}
function add_product_category($product, $name) {
wp_set_object_terms($product->get_id(), $name, 'product_cat', false);
clean_object_term_cache( $product->get_id(), 'product_cat' );
}
function add_products_to_package($package, $products) {
$bundled_data = array();
foreach ($products as $product) {
$bundled_data[] = array(
'product_id' => $product->get_id(),
'quantity_min' => 1,
'quantity_max' => 1,
'priced_individually' => true
);
}
$package->set_bundled_data_items($bundled_data);
$package->sync(true);
}
}