Files
old-new-wiaas/backend/app/plugins/wiaas/tests/unit-tests/test-wiaas-countries.php
2018-12-02 22:18:09 +01:00

72 lines
1.8 KiB
PHP

<?php
/**
* Class Wiaas_Countries_Test
*/
class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
var $product, $package, $current_country = 'se';
public function setUp() {
parent::setUp();
# set admin as current user
wp_set_current_user(1);
$this->product = $this->factory->product->create_simple_product(array( 'country' => $this->current_country ));
$this->package = $this->factory->product->create_product_bundle(array( 'country' => $this->current_country ));
}
/**
* @covers Wiaas_Countries::register_product_countries_taxonomy()
*/
function test_available_countries_created() {
// test taxonomy is available
$taxonomy = get_taxonomy('product_country');
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
$countries = get_terms(
array(
'taxonomy' => 'product_country',
'hide_empty' => false,
'fields' => 'id=>slug'
)
);
$country_codes = array_values($countries);
$this->assertNotEmpty($country_codes);
$this->assertContains('se', $country_codes);
$this->assertContains('fi', $country_codes);
$this->assertContains('dk', $country_codes);
}
/**
* @covers Wiaas_Countries::get_product_country()
*/
function test_get_product_country() {
$retrieved_country = Wiaas_Countries::get_product_country($this->product);
$this->assertNotNull($retrieved_country, 'Product has not country!');
$this->assertEquals($retrieved_country['code'], $this->current_country, 'Retrieved product country is incorrect!');
}
/**
* @covers Wiaas_Countries::get_package_country()
*/
function test_get_package_country() {
$retrieved_country = Wiaas_Countries::get_package_country($this->package);
$this->assertNotNull($retrieved_country, 'Package has not country!');
$this->assertEquals($retrieved_country['code'], $this->current_country, 'Retrieved package country is incorrect!');
}
}