88 lines
2.1 KiB
PHP
88 lines
2.1 KiB
PHP
<?php
|
|
|
|
class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Executes any db migrations that are done to
|
|
* `wp_options` table since it is deleted on every execution
|
|
*/
|
|
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);
|
|
}
|
|
|
|
function tearDown() {
|
|
parent::tearDown();
|
|
}
|
|
|
|
function create_new_product($price = 10, $is_recurring = false, $pay_period = 0) {
|
|
$post_id = wp_insert_post(array(
|
|
'post_type' => 'product',
|
|
'post_status' => 'publish',
|
|
'post_name' => 'product',
|
|
'post_title' => 'Product',
|
|
'post_content' => 'Product',
|
|
'post_excerpt' => 'Product'
|
|
), true);
|
|
|
|
$product = new WC_Product_Simple($post_id);
|
|
|
|
Wiaas_Product_Pricing::set_product_price($product, $price, $is_recurring, $pay_period);
|
|
|
|
$product->save();
|
|
|
|
return $product;
|
|
}
|
|
|
|
function create_new_package() {
|
|
$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_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);
|
|
}
|
|
} |