/** * @group coupon */ public function testCartCouponFixedPrice() { $period = 10; $term = new Term($period); $term->setOld(12); $term->setPrice(10); $term->setTrial(1); $term2 = new Term($period); $term2->setPrice(2); $product = new ProductSharedHosting(); $product->setId(21); $product->setTitle('Silver'); $product->getBilling()->addTerm($term); $ssl = new ProductSsl(); $ssl->setId(22); $ssl->getBilling()->addTerm($term2); $catalog = $this->getCatalog(); $item = $catalog->getCartItem($product, null, ['plan' => 'silver']); $item_ssl = $catalog->getCartItem($ssl, null, []); $coupons = $this->getCouponsCollection(); $coupon = $coupons->getCoupon('5_DOLLAR_SALE'); $cart = $this->getCart(); $cart->add($item); $cart->add($item_ssl); $coupon->calculateDiscount($cart); $items = $cart->all(); //price should be 5 * $period because fixed $5 coupon is set $this->assertEquals(5 * $period, $items[0]->getPriceWithDiscount()); //price should not be affected because initial price is lower than $5 $this->assertEquals(2 * $period, $items[1]->getPriceWithDiscount()); $this->assertEquals($items[1]->getPrice(), $items[1]->getPriceWithDiscount()); }
/** * @dataProvider testCartCouponFreeAddonAddedFirstProvicer * @group coupon */ public function testCartCouponFreeAddonAddedFirst($termDomain, $termSSL, $isDomainFree, $isSSLFree) { $term = new Term($termDomain); $term->setOld(14.99); $term->setPrice(12.99); $term_ssl = new Term($termSSL); $term_ssl->setTrial(15); $term_ssl->setOld(0); $term_ssl->setPrice(49.0); $product = new ProductDomain(); $product->setId('.com'); $product->setTitle('.com Registration'); $product->getBilling()->addTerm($term); $hosting = new ProductSharedHosting(); $hosting->setId(24); $hosting->setTitle('Premium'); $hosting->getBilling()->addTerm($term); $ssl = new ProductSsl(); $ssl->setId(21); $ssl->setTitle('SSL Certificate'); $ssl->getBilling()->addTerm($term_ssl); $catalog = $this->getCatalog(); $item = $catalog->getCartItem($product, null, ['domain' => 'example.com']); $item_hosting = $catalog->getCartItem($hosting); $item_3 = $catalog->getCartItem($product, null, ['domain' => 'example-3.com']); $item_ssl = $catalog->getCartItem($ssl); $coupons = $this->getCouponsCollection(); $coupon = $coupons->getCoupon('BUY_HOSTING_GET_DOMAIN_AND_SSL_FREE'); $cart = $this->getCart(); $cart->add($item); $cart->add($item_hosting); $cart->add($item_3); $cart->add($item_ssl); $coupon->calculateDiscount($cart); $items = $cart->all(); $expectedDomainDiscount = $isDomainFree ? $items[0]->getPrice() : 0; $expectedSSLDiscount = $isSSLFree ? $items[3]->getPrice() : 0; $this->assertEquals($expectedDomainDiscount, $items[0]->getDiscount()); $this->assertEquals(0, $items[1]->getDiscount()); $this->assertEquals(0, $items[2]->getDiscount()); $this->assertEquals($expectedSSLDiscount, $items[3]->getDiscount()); }
public function testGetCartItem() { $term = new Term(1); $product = new Product(); $product->getBilling()->addTerm($term); $productDomain = new ProductDomain(); $productDomain->getBilling()->addTerm($term); $productSharedHosting = new ProductSharedHosting(); $productSharedHosting->getBilling()->addTerm($term); $productCpanelHosting = new ProductCpanelHosting(); $productCpanelHosting->getBilling()->addTerm($term); $productVps = new ProductVps(); $productVps->getBilling()->addTerm($term); $productSsl = new ProductSsl(); $productSsl->getBilling()->addTerm($term); $catalog = new Catalog(); $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($productCpanelHosting)); $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($productSsl)); $this->assertInstanceOf('\\Cart\\CartItemVps', $catalog->getCartItem($productVps)); $this->assertInstanceOf('\\Cart\\CartItemSharedHosting', $catalog->getCartItem($productSharedHosting)); $this->assertInstanceOf('\\Cart\\CartItemDomain', $catalog->getCartItem($productDomain)); $this->assertInstanceOf('\\Cart\\CartItem', $catalog->getCartItem($product)); }