Ejemplo n.º 1
0
 public function testtoApiArray()
 {
     $cartModel = new \Model_Cart();
     $cartModel->loadBean(new \RedBeanPHP\OODBBean());
     $cartProductModel = new \Model_CartProduct();
     $cartProductModel->loadBean(new \RedBeanPHP\OODBBean());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('getCartProducts', 'cartProductToApiArray'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('getCartProducts')->will($this->returnValue(array($cartProductModel)));
     $cartProductApiArray = array('total' => 1, 'discount' => 0);
     $serviceMock->expects($this->atLeastOnce())->method('cartProductToApiArray')->will($this->returnValue($cartProductApiArray));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $currencyModel = new \Model_Currency();
     $currencyModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($currencyModel));
     $currencyService = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->getMock();
     $currencyService->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue(array()));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($currencyService) {
         return $currencyService;
     });
     $serviceMock->setDi($di);
     $result = $serviceMock->toApiArray($cartModel);
     $expected = array('promocode' => null, 'discount' => 0, 'total' => 1, 'items' => array($cartProductApiArray), 'currency' => array());
     $this->assertInternalType('array', $result);
     $this->assertEquals($expected, $result);
 }
Ejemplo n.º 2
0
 public function testDelete()
 {
     $model = new \Model_Currency();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $model->code = 'EUR';
     $code = 'EUR';
     $service = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->setMethods(array('getByCode', 'rm'))->getMock();
     $service->expects($this->atLeastOnce())->method('getByCode')->will($this->returnValue($model));
     $service->expects($this->atLeastOnce())->method('rm')->will($this->returnValue($model));
     $manager = $this->getMockBuilder('Box_EventManager')->getMock();
     $manager->expects($this->atLeastOnce())->method('fire')->will($this->returnValue(true));
     $di = new \Box_Di();
     $db = $this->getMockBuilder('Box_Database')->getMock();
     $di['logger'] = new \Box_Log();
     $di['db'] = $db;
     $di['events_manager'] = $manager;
     $service->setDi($di);
     $result = $service->deleteCurrencyByCode($code);
     $this->assertInternalType('boolean', $result);
     $this->assertEquals($result, true);
 }
Ejemplo n.º 3
0
 public function testSetDefault()
 {
     $adminApi = new \Box\Mod\Currency\Api\Admin();
     $model = new \Model_Currency();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $model->code = 'EUR';
     $data = array('code' => 'EUR', 'format' => '€{{price}}');
     $service = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->getMock();
     $service->expects($this->atLeastOnce())->method('getByCode')->will($this->returnValue($model));
     $service->expects($this->atLeastOnce())->method('setAsDefault')->will($this->returnValue(true));
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray');
     $di = new \Box_Di();
     $db = $this->getMockBuilder('Box_Database')->getMock();
     $di['db'] = $db;
     $di['validator'] = $validatorMock;
     $adminApi->setDi($di);
     $adminApi->setService($service);
     $result = $adminApi->set_default($data);
     $this->assertInternalType('boolean', $result);
     $this->assertEquals($result, true);
 }
Ejemplo n.º 4
0
 public function testcreateOrder()
 {
     $modelClient = new \Model_Client();
     $modelClient->loadBean(new \RedBeanPHP\OODBBean());
     $modelClient->currency = 'USD';
     $modelProduct = new \Model_Product();
     $modelProduct->loadBean(new \RedBeanPHP\OODBBean());
     $modelProduct->id = 1;
     $modelProduct->type = 'custom';
     $licenseMock = $this->getMockBuilder('\\Box_License')->getMock();
     $licenseMock->expects($this->atLeastOnce())->method('isPro')->willReturn(true);
     $currencyModel = new \Model_Currency();
     $currencyModel->loadBean(new \RedBeanPHP\OODBBean());
     $currencyServiceMock = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->getMock();
     $currencyServiceMock->expects($this->atLeastOnce())->method('getByCode')->willReturn($currencyModel);
     $cartServiceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->getMock();
     $cartServiceMock->expects($this->atLeastOnce())->method('isStockAvailable')->with($modelProduct)->willReturn(true);
     $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventMock->expects($this->atLeastOnce())->method('fire');
     $productServiceMock = $this->getMockBuilder('\\Box\\Mod\\Servicecustom')->getMock();
     $clientOrderModel = new \Model_ClientOrder();
     $clientOrderModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('dispense')->with('ClientOrder')->willReturn($clientOrderModel);
     $newId = 1;
     $dbMock->expects($this->atLeastOnce())->method('store')->with($clientOrderModel)->willReturn($newId);
     $periodMock = $this->getMockBuilder('\\Box_Period')->disableOriginalConstructor()->getMock();
     $periodMock->expects($this->atLeastOnce())->method('getCode')->willReturn('1Y');
     $di = new \Box_Di();
     $di['license'] = $licenseMock;
     $di['mod_service'] = $di->protect(function ($serviceName) use($currencyServiceMock, $cartServiceMock, $productServiceMock) {
         if ($serviceName == 'currency') {
             return $currencyServiceMock;
         }
         if ($serviceName == 'cart') {
             return $cartServiceMock;
         }
         if ($serviceName == 'servicecustom') {
             return $productServiceMock;
         }
     });
     $di['events_manager'] = $eventMock;
     $di['db'] = $dbMock;
     $di['period'] = $di->protect(function () use($periodMock) {
         return $periodMock;
     });
     $di['logger'] = new \Box_Log();
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $this->service->setDi($di);
     $result = $this->service->createOrder($modelClient, $modelProduct, array('period' => '1Y', 'price' => '10', 'notes' => 'test'));
     $this->assertEquals($newId, $result);
 }
Ejemplo n.º 5
0
 public function testprepareInvoiceCurrencyWasNotDefined()
 {
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\Service')->setMethods(array('setInvoiceDefaults'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('setInvoiceDefaults');
     $data = array('gateway_id' => '', 'text_1' => '', 'text_2' => '', 'items' => array(array('id' => 1)), 'approve');
     $clientModel = new \Model_Client();
     $clientModel->loadBean(new \RedBeanPHP\OODBBean());
     $invoiceModel = new \Model_Invoice();
     $invoiceModel->loadBean(new \RedBeanPHP\OODBBean());
     $currencyModel = new \Model_Currency();
     $currencyModel->loadBean(new \RedBeanPHP\OODBBean());
     $currencyService = $this->getMockBuilder('\\Box\\Mod\\Currency\\Service')->getMock();
     $currencyService->expects($this->atLeastOnce())->method('getDefault')->will($this->returnValue($currencyModel));
     $itemInvoiceServiceMock = $this->getMockBuilder('\\Box\\Mod\\Invoice\\ServiceInvoiceItem')->getMock();
     $itemInvoiceServiceMock->expects($this->atLeastOnce())->method('addNew');
     $newRecordId = 1;
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue($newRecordId));
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($invoiceModel));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function ($serviceName, $sub = '') use($currencyService, $itemInvoiceServiceMock) {
         if ($serviceName == 'Currency') {
             return $currencyService;
         }
         if ($sub == 'InvoiceItem') {
             return $itemInvoiceServiceMock;
         }
     });
     $di['logger'] = new \Box_Log();
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $serviceMock->setDi($di);
     $result = $serviceMock->prepareInvoice($clientModel, $data);
     $this->assertInstanceOf('Model_Invoice', $result);
 }