<?php

class Wiaas_Product_Pricing_Test extends Wiaas_Unit_Test_Case {

	/**
	 * @covers Wiaas_Product_Pricing::set_product_price()
	 * @covers Wiaas_Product_Pricing::get_product_price()
	 */
	function test_adding_product_price() {
		$product = $this->create_new_product(10, true, 2);

		$configured_price = Wiaas_Product_Pricing::get_product_price($product);

		$this->assertNotNull($configured_price);

		$this->assertArrayHasKey('price', $configured_price);
		$this->assertArrayHasKey('is_recurring', $configured_price);
		$this->assertArrayHasKey('pay_period', $configured_price);

		$this->assertEquals($configured_price['price'], 10);
		$this->assertEquals($configured_price['is_recurring'], true);
		$this->assertEquals($configured_price['pay_period'], 2);
	}

	/**
	 * @covers Wiaas_Product_Pricing::get_product_price_html()
	 */
	function test_get_product_fixed_price_html() {
		$product = $this->create_new_product();

		$original_price_html = $product->get_price_html();

		$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);

		$this->assertEquals($price_html, $original_price_html);
	}

	/**
	 * @covers Wiaas_Product_Pricing::get_product_price_html()
	 */
	function test_get_product_recurrent_price_html() {
		$product = $this->create_new_product(10, true, 1);

		$original_price_html = $product->get_price_html();

		$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);

		$this->assertEquals($price_html, $original_price_html . ' / month');
	}

	/**
	 * @covers Wiaas_Product_Pricing::get_product_fixed_price()
	 */
	function test_get_fixed_price_for_fixed_product() {
		$product = $this->create_new_product();

		$original_price = $product->get_price();

		$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($original_price, $product);

		$this->assertEquals($fixed_price, $original_price);
	}

	/**
	 * @covers Wiaas_Product_Pricing::get_product_fixed_price()
	 */
	function test_get_fixed_price_for_recurring_product() {
		$product = $this->create_new_product(10, true, 1);

		$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($product->get_price(), $product);

		$this->assertEquals($fixed_price, 0);
	}
}