/** * @group coupon */ public function testCartCouponBogoHalf() { $term = new Term(1); $term->setOld(12.0); $term->setPrice(12.0); $product = new ProductDomain(); $product->setId('.com'); $product->setTitle('.com Registration'); $product->getBilling()->addTerm($term); $catalog = $this->getCatalog(); $catalog->addProduct($product); $item = $catalog->getCartItem($product, null, ['domain' => 'example.com']); $item_2 = $catalog->getCartItem($product, null, ['domain' => 'example-2.com']); $item_3 = $catalog->getCartItem($product, null, ['domain' => 'example-3.com']); $cart = $this->getCart(); $cart->add($item); $cart->add($item_2); $cart->add($item_3); $coupons = $this->getCouponsCollection(); $coupon = $coupons->getCoupon('BUY_ONE_GET_ONE_HALF'); $coupon->calculateDiscount($cart); $items = $cart->all(); $this->assertEquals(0, $items[0]->getDiscount()); $this->assertEquals(6, $items[1]->getDiscount()); $this->assertEquals(0, $items[2]->getDiscount()); }
public function testIsArrayable() { $p = new ProductDomain(); $p->setId(1); $p->setTitle('Domain registration'); $p->setDescription('Domain registration'); $this->assertInternalType('array', $p->toArray()); }
/** * @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()); }