Пример #1
0
 public function testattachOrderConfig()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->config = '["hello", "world"]';
     $data = array('testing' => 'phase');
     $expected = array_merge(json_decode($productModel->config, 1), $data);
     $result = $this->service->attachOrderConfig($productModel, $data);
     $this->assertInternalType('array', $result);
     $this->assertEquals($expected, $result);
 }
Пример #2
0
 public function testfree_tlds_ProductTypeIsNotHosting()
 {
     $di = new \Box_Di();
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null));
     $di['validator'] = $validatorMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $di['db'] = $dbMock;
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicehosting\\Service')->getMock();
     $serviceMock->expects($this->never())->method('getFreeTlds');
     $this->api->setService($serviceMock);
     $this->api->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'Product type is invalid');
     $this->api->free_tlds(array('product_id' => 1));
 }
Пример #3
0
 public function testActionCreate()
 {
     $order = new \Model_ClientOrder();
     $order->loadBean(new \RedBeanPHP\OODBBean());
     $order->product_id = rand(1, 100);
     $order->client_id = rand(1, 100);
     $order->config = 'config';
     $product = new \Model_Product();
     $product->loadBean(new \RedBeanPHP\OODBBean());
     $product->plugin = 'plugin';
     $product->plugin_config = 'plugin_config';
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue(rand(1, 100)));
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($product));
     $serviceCustomModel = new \Model_ServiceCustom();
     $serviceCustomModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($serviceCustomModel));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $result = $this->service->action_create($order);
     $this->assertInstanceOf('Model_ServiceCustom', $result);
 }
Пример #4
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);
 }
Пример #5
0
 public function testdelete()
 {
     $data = array('id' => 1);
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('deleteProduct')->will($this->returnValue(true));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null));
     $di['validator'] = $validatorMock;
     $this->api->setService($serviceMock);
     $this->api->setDi($di);
     $result = $this->api->delete($data);
     $this->assertInternalType('bool', $result);
     $this->assertTrue($result);
 }
Пример #6
0
 public function testuploadProductFile()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $successfullyUploadedFileCount = 1;
     $file = array('name' => 'test', 'tmp_name' => '12345');
     $fileMock = new \Box_RequestFile($file);
     $requestMock = $this->getMockBuilder('\\Box_Request')->getMock();
     $requestMock->expects($this->atLeastOnce())->method('hasFiles')->will($this->returnValue($successfullyUploadedFileCount));
     $requestMock->expects($this->atLeastOnce())->method('getUploadedFiles')->will($this->returnValue(array($fileMock)));
     $productServiceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock();
     $productServiceMock->expects($this->atLeastOnce())->method('getSavePath');
     $productServiceMock->expects($this->atLeastOnce())->method('removeOldFile');
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store');
     $di = new \Box_Di();
     $di['mod_service'] = $di->protect(function () use($productServiceMock) {
         return $productServiceMock;
     });
     $di['db'] = $dbMock;
     $di['logger'] = new \Box_Log();
     $di['request'] = $requestMock;
     $this->service->setDi($di);
     $result = $this->service->uploadProductFile($productModel);
     $this->assertInternalType('bool', $result);
     $this->assertTrue($result);
 }
Пример #7
0
 public function teststockSale()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->stock_control = 1;
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store')->with($productModel);
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $result = $this->service->stockSale($productModel, 2);
     $this->assertTrue($result);
 }
Пример #8
0
 public function testcheckLimits_LimitAndResultRowsEqual()
 {
     $modelName = 'Model_Product';
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $findResult = array(array($model), array($model), array($model), array($model), array($model), array($model));
     $limit = count($findResult);
     $licenseMock = $this->getMockBuilder('\\Box_License')->getMock();
     $licenseMock->expects($this->atLeastOnce())->method('isPro')->willReturn(false);
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->once())->method('find')->willReturn($findResult);
     $di = new \Box_Di();
     $di['license'] = $licenseMock;
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'You have reached free version limit. Upgrade to PRO version of BoxBilling if you want this limit removed.', 875);
     $this->service->checkLimits($modelName, $limit);
 }
Пример #9
0
 public function testcanUpgradeTo_SameProducts()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->id = 1;
     $newProductModel = new \Model_Product();
     $newProductModel->loadBean(new \RedBeanPHP\OODBBean());
     $newProductModel->id = 1;
     $result = $this->service->canUpgradeTo($productModel, $newProductModel);
     $this->assertFalse($result);
 }
Пример #10
0
 public function testget_sliderJsonFormat()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('find')->will($this->returnValue(array($productModel)));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $this->api->setDi($di);
     $arr = array('id' => 1, 'slug' => '/', 'title' => 'New Item', 'pricing' => '1W', 'config' => array());
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('toApiArray')->will($this->returnValue($arr));
     $this->api->setService($serviceMock);
     $result = $this->api->get_slider(array());
     $this->assertInternalType('array', $result);
     $result = $this->api->get_slider(array('format' => 'json'));
     $this->assertInternalType('string', $result);
     $this->assertInternalType('array', json_decode($result, 1));
 }
Пример #11
0
 public function testgetFreeTlds()
 {
     $config = array('free_tlds' => array('.com'));
     $di = new \Box_Di();
     $toolsMock = $this->getMockBuilder('\\Box_Tools')->getMock();
     $toolsMock->expects($this->atLeastOnce())->method('decodeJ')->willReturn($config);
     $di['tools'] = $toolsMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $this->service->setDi($di);
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $result = $this->service->getFreeTlds($model);
     $this->assertInternalType('array', $result);
     $this->assertNotEmpty($result);
 }
Пример #12
0
 public function testUpgradables()
 {
     $order = new Model_ClientOrder();
     $order->loadBean(new \RedBeanPHP\OODBBean());
     $apiMock = $this->getMockBuilder('\\Box\\Mod\\Order\\Api\\Client')->setMethods(array('_getOrder'))->disableOriginalConstructor()->getMock();
     $apiMock->expects($this->atLeastOnce())->method('_getOrder')->will($this->returnValue($order));
     $productServiceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->setMethods(array('getUpgradablePairs'))->getMock();
     $productServiceMock->expects($this->atLeastOnce())->method("getUpgradablePairs")->will($this->returnValue(array()));
     $product = new Model_Product();
     $product->loadBean(new RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->disableOriginalConstructor()->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($product));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $di['mod_service'] = $di->protect(function () use($productServiceMock) {
         return $productServiceMock;
     });
     $apiMock->setDi($di);
     $data = array();
     $result = $apiMock->upgradables($data);
     $this->assertInternalType('array', $result);
 }