Пример #1
0
 public function testtoApiArray()
 {
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->setMethods(array('getAddonsApiArray', 'getStartingFromPrice', 'getUpgradablePairs', 'toProductPaymentApiArray'))->getMock();
     $serviceMock->expects($this->any())->method('getAddonsApiArray');
     $serviceMock->expects($this->atLeastOnce())->method('getStartingFromPrice');
     $serviceMock->expects($this->atLeastOnce())->method('getUpgradablePairs');
     $productPaymentArray = array('type' => 'free', \Model_ProductPayment::FREE => array('price' => 0, 'setup' => 0), \Model_ProductPayment::ONCE => array('price' => 1, 'setup' => 10), \Model_ProductPayment::RECURRENT => array());
     $serviceMock->expects($this->atLeastOnce())->method('toProductPaymentApiArray')->will($this->returnValue($productPaymentArray));
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $model->product_category_id = 1;
     $model->product_payment_id = 2;
     $model->config = '{}';
     $modelProductCategory = new \Model_ProductCategory();
     $modelProductCategory->loadBean(new \RedBeanPHP\OODBBean());
     $modelProductCategory->type = 'free';
     $modelProductPayment = new \Model_ProductPayment();
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('load')->will($this->onConsecutiveCalls($modelProductPayment, $modelProductCategory));
     $toolsMock = $this->getMockBuilder('\\Box_Tools')->getMock();
     $toolsMock->expects($this->atLeastOnce())->method('decodeJ')->will($this->returnValue(array()));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['tools'] = $toolsMock;
     $di['mod_service'] = $di->protect(function () use($serviceMock) {
         return $serviceMock;
     });
     $model->setDi($di);
     $serviceMock->setDi($di);
     $result = $serviceMock->toApiArray($model, true, new \Model_Admin());
     $this->assertInternalType('array', $result);
 }
Пример #2
0
 public function testaddItemm_TypeCustom()
 {
     $cartModel = new \Model_Cart();
     $cartModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->type = 'custom';
     $data = array();
     $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventMock->expects($this->atLeastOnce())->method('fire');
     $serviceCustomServiceMock = $this->getMockBuilder('\\Box\\Mod\\Servicecustom\\Service')->getMock();
     $serviceCustomServiceMock->expects($this->atLeastOnce())->method('validateCustomForm')->will($this->returnValue(array()));
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('isRecurrentPricing', 'isStockAvailable'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('isRecurrentPricing')->will($this->returnValue(false));
     $serviceMock->expects($this->atLeastOnce())->method('isStockAvailable')->will($this->returnValue(true));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('toArray')->will($this->returnValue(array()));
     $cartProduct = new \Model_CartProduct();
     $cartProduct->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($cartProduct));
     $dbMock->expects($this->atLeastOnce())->method('store');
     $di = new \Box_Di();
     $di['events_manager'] = $eventMock;
     $di['mod_service'] = $di->protect(function ($name) use($serviceCustomServiceMock) {
         return $serviceCustomServiceMock;
     });
     $di['logger'] = new \Box_Log();
     $di['db'] = $dbMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $serviceMock->setDi($di);
     $productModel->setDi($di);
     $result = $serviceMock->addItem($cartModel, $productModel, $data);
     $this->assertTrue($result);
 }