/**
  * Apply the renewal discount.
  *
  * @since 1.0
  *
  * @param string|float $db_base_price
  * @param array        $product
  * @param bool         $format
  *
  * @return string|float
  */
 public function apply_renewal_discount($db_base_price, $product, $format)
 {
     try {
         $product = itelic_get_product($product['product_id']);
     } catch (\Exception $e) {
         return $db_base_price;
     }
     if (!$product->get_feature('licensing')) {
         return $db_base_price;
     }
     $session = $this->get_cache_data();
     if (!isset($session["p" . $product->ID]) || $session["p" . $product->ID] === null) {
         return $db_base_price;
     }
     $key = $session["p" . $product->ID];
     $key = itelic_get_key($key);
     $discount = new Discount($key);
     if (!$discount->is_discount_valid()) {
         return $db_base_price;
     }
     return $discount->get_discount_price($format);
 }
 /**
  * @depends test_get_discount_price_flat
  */
 public function test_get_discount_price_formatted()
 {
     $mock_product = $this->getMockBuilder('\\ITELIC\\Product')->disableOriginalConstructor()->getMock();
     $mock_product->method('get_feature')->will($this->returnValueMap(array(array('licensing-discount', array(), array('amount' => '20', 'type' => Discount::TYPE_FLAT)), array('base-price', array(), '75.00'))));
     $mock_product->ID = 1;
     $mock_txn = $this->getMockBuilder('\\IT_Exchange_Transaction')->disableOriginalConstructor()->getMock();
     $mock_txn->method('get_products')->willReturn(array(array('product_id' => 1, 'product_subtotal' => '100.00')));
     $mock_key = $this->getMockBuilder('\\ITELIC\\Key')->disableOriginalConstructor()->getMock();
     $mock_key->method('get_product')->willReturn($mock_product);
     $mock_key->method('get_transaction')->willReturn($mock_txn);
     WP_Mock::wpFunction('it_exchange_format_price', array('times' => 1, 'args' => array('80.00'), 'return' => function ($price) {
         return '$' . number_format($price, 2);
     }));
     $discount = new Discount($mock_key);
     $this->assertEquals('$80.00', $discount->get_discount_price(true));
 }