<?php

class Wiaas_Product_Category_Test extends Wiaas_Unit_Test_Case {

	/**
	 * @covers Wiaas_Product_Category::register_product_categories()
	 */
	function test_available_product_categories_created() {
		$taxonomy = get_taxonomy('product_cat');

		$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);

		$category_names = array_map(function($term) {
			return $term->name;
		}, get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => false )));

		$this->assertNotEmpty($category_names);

		$this->assertTrue(in_array('hardware', $category_names));
		$this->assertTrue(in_array('software', $category_names));
		$this->assertTrue(in_array('service', $category_names));
		$this->assertTrue(in_array('installation', $category_names));
	}

	/**
	 * @covers Wiaas_Product_Category::get_category()
	 */
	function test_get_category() {
		$product = $this->create_new_product();
		$this->add_product_category($product, 'hardware');

		$product_category = Wiaas_Product_Category::get_category($product);

		$this->assertNotNull($product_category);
		$this->assertEquals($product_category, 'hardware');
	}

	/**
	 * @covers Wiaas_Product_Category::is_service()
	 */
	function test_is_service_negative() {
		$product = $this->create_new_product();
		$this->add_product_category($product, 'hardware');

		$this->assertFalse(Wiaas_Product_Category::is_service($product));
	}

	/**
	 * @covers Wiaas_Product_Category::is_service()
	 */
	function test_is_service_positive() {
		$product = $this->create_new_product();
		$this->add_product_category($product, 'service');

		$this->assertTrue(Wiaas_Product_Category::is_service($product));
	}

	/**
	 * @covers Wiaas_Product_Category::is_installation()
	 */
	function test_is_installation_negative() {
		$product = $this->create_new_product();
		$this->add_product_category($product, 'hardware');

		$this->assertFalse(Wiaas_Product_Category::is_installation($product));
	}

	/**
	 * @covers Wiaas_Product_Category::is_installation()
	 */
	function test_is_installation_positive() {
		$product = $this->create_new_product();
		$this->add_product_category($product, 'installation');

		$this->assertTrue(Wiaas_Product_Category::is_installation($product));
	}

}