public function testcategory_delete() { $data = array('id' => 1); $model = new \Model_ProductCategory(); $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('removeProductCategory')->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->category_delete($data); $this->assertInternalType('bool', $result); $this->assertTrue($result); }
public function testcategory_get_list() { $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock(); $serviceMock->expects($this->atLeastOnce())->method('getProductCategorySearchQuery')->will($this->returnValue(array('sqlString', array()))); $serviceMock->expects($this->atLeastOnce())->method('toProductCategoryApiArray')->will($this->returnValue(array())); $pager = array('list' => array(0 => array('id' => 1))); $pagerMock = $this->getMockBuilder('\\Box_Pagination')->getMock(); $pagerMock->expects($this->atLeastOnce())->method('getAdvancedResultSet')->will($this->returnValue($pager)); $modelProductCategory = new \Model_ProductCategory(); $modelProductCategory->loadBean(new \RedBeanPHP\OODBBean()); $dbMock = $this->getMockBuilder('\\Box_Database')->getMock(); $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($modelProductCategory)); $di = new \Box_Di(); $di['db'] = $dbMock; $di['pager'] = $pagerMock; $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) { return isset($array[$key]) ? $array[$key] : $default; }); $this->api->setService($serviceMock); $this->api->setDi($di); $result = $this->api->category_get_list(array()); $this->assertInternalType('array', $result); }
public function testgetCategoryProducts() { $productCategoryModel = new \Model_ProductCategory(); $productCategoryModel->loadBean(new \RedBeanPHP\OODBBean()); $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; $this->service->setDi($di); $result = $this->service->getCategoryProducts($productCategoryModel); $this->assertInternalType('array', $result); }
public static function exist($product_id, $category_id) { $query = Model_ProductCategory::query()->where(array('product_id' => $product_id, 'category_id' => $category_id)); return $query->count() > 0; }