public function testCheckout() { $cart = new \Model_Cart(); $cart->loadBean(new \RedBeanPHP\OODBBean()); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getSessionCart', 'checkoutCart'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSessionCart')->will($this->returnValue($cart)); $checkOutCartResult = array('gateway_id' => 1, 'invoice_hash' => null, 'order_id' => 1, 'orders' => 1); $serviceMock->expects($this->atLeastOnce())->method('checkoutCart')->will($this->returnValue($checkOutCartResult)); $this->clientApi->setService($serviceMock); $client = new \Model_Client(); $client->loadBean(new \RedBeanPHP\OODBBean()); $this->clientApi->setIdentity($client); $data = array('id' => rand(1, 100)); $di = new \Box_Di(); $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->clientApi->setDi($di); $result = $this->clientApi->checkout($data); $this->assertInternalType('array', $result); }
public function testGet_list() { $simpleResultArr = array('list' => array(array('id' => 1))); $paginatorMock = $this->getMockBuilder('\\Box_Pagination')->disableOriginalConstructor()->getMock(); $paginatorMock->expects($this->atLeastOnce())->method('getSimpleResultSet')->will($this->returnValue($simpleResultArr)); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getSearchQuery', 'toApiArray'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSearchQuery')->will($this->returnValue(array('query', array()))); $serviceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array())); $model = new \Model_Cart(); $model->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model)); $di = new \Box_Di(); $di['pager'] = $paginatorMock; $di['db'] = $dbMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->adminApi->setDi($di); $this->adminApi->setService($serviceMock); $data = array(); $result = $this->adminApi->get_list($data); $this->assertInternalType('array', $result); }
public function testgetProductDiscount_ProductQtyIsSetAndFreeSetup() { $cartProductModel = new \Model_CartProduct(); $cartProductModel->loadBean(new \RedBeanPHP\OODBBean()); $modelCart = new \Model_Cart(); $modelCart->loadBean(new \RedBeanPHP\OODBBean()); $modelCart->promo_id = 1; $promoModel = new \Model_Promo(); $promoModel->loadBean(new \RedBeanPHP\OODBBean()); $promoModel->freesetup = 1; $discountPrice = 25; $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('load')->with('Cart')->willReturn($modelCart); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->with('Promo')->willReturn($promoModel); $di = new \Box_Di(); $di['db'] = $dbMock; $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getRelatedItemsDiscount', 'getItemPromoDiscount', 'getItemConfig'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getRelatedItemsDiscount')->willReturn(0); $serviceMock->expects($this->atLeastOnce())->method('getItemPromoDiscount')->willReturn($discountPrice); $serviceMock->setDi($di); $setupPrice = 25; $result = $serviceMock->getProductDiscount($cartProductModel, $setupPrice); $this->assertInternalType('array', $result); $this->assertEquals($discountPrice, $result[0]); $discountSetup = $setupPrice; $this->assertEquals($discountSetup, $result[1]); }
public function testAdd_itemSingle() { $cart = new \Model_Cart(); $cart->loadBean(new \RedBeanPHP\OODBBean()); $cart->currency_id = rand(1, 100); $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getSessionCart', 'addItem'))->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getSessionCart')->will($this->returnValue($cart)); $serviceMock->expects($this->atLeastOnce())->method('addItem')->will($this->returnValue(true)); $apiMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Api\\Guest')->setMethods(array('reset'))->getMock(); $apiMock->expects($this->atLeastOnce())->method('reset')->will($this->returnValue($cart)); $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock(); $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null)); $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue(new \Model_Product())); $di = new \Box_Di(); $di['validator'] = $validatorMock; $di['db'] = $dbMock; $apiMock->setDi($di); $apiMock->setService($serviceMock); $data = array('id' => rand(1, 100), 'multiple' => false); $result = $apiMock->add_item($data); $this->assertTrue($result); }