From be5902580969f3751d0ba8de94fbc001f4c49edd Mon Sep 17 00:00:00 2001 From: aquilax Date: Fri, 29 May 2015 15:42:31 +0200 Subject: [PATCH] Service --- phpunit.xml.dist | 2 +- .../order_fetch.php => FmOrderFetch.php} | 14 +- src/backoffice/FmOutput.php | 30 ++ src/backoffice/FmServiceController.php | 229 ++++++------ src/backoffice/FmUtils.php | 32 -- src/backoffice/includes/shared | 2 +- src/backoffice/models/FmOrder.php | 7 +- src/backoffice/service.php | 2 +- tests/bootstrap.php | 3 + .../backoffice/FmServiceControllerTest.php | 330 +++++++++++++++++- 10 files changed, 479 insertions(+), 172 deletions(-) rename src/backoffice/{models/order_fetch.php => FmOrderFetch.php} (57%) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a296b52..e1faa61 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + tests/src/ diff --git a/src/backoffice/models/order_fetch.php b/src/backoffice/FmOrderFetch.php similarity index 57% rename from src/backoffice/models/order_fetch.php rename to src/backoffice/FmOrderFetch.php index d70e6bd..704d4f4 100644 --- a/src/backoffice/models/order_fetch.php +++ b/src/backoffice/FmOrderFetch.php @@ -3,10 +3,16 @@ class FmOrderFetch extends FyndiqPaginatedFetch { + function __construct($fmConfig, $fmOrder, $fmApiModel){ + $this->fmConfig = $fmConfig; + $this->fmOrder = $fmOrder; + $this->fmApiModel = $fmApiModel; + } + function getInitialPath() { $url = 'orders/'; - $date = FmConfig::get('import_date'); + $date = $this->fmConfig->get('import_date'); if (!empty($date)) { $url .= '?min_date=' . urlencode($date); } @@ -15,15 +21,15 @@ function getInitialPath() function getPageData($path) { - $ret = FmHelpers::callApi('GET', $path); + $ret = $this->fmApiModel->callApi('GET', $path); return $ret['data']; } function processData($data) { foreach ($data as $order) { - if (!FmOrder::orderExists($order->id)) { - FmOrder::create($order); + if (!$this->fmOrder->orderExists($order->id)) { + $this->fmOrder->create($order); } } return true; diff --git a/src/backoffice/FmOutput.php b/src/backoffice/FmOutput.php index 8b06f60..0f5ec21 100644 --- a/src/backoffice/FmOutput.php +++ b/src/backoffice/FmOutput.php @@ -59,6 +59,24 @@ public function renderJSON($data) return true; } + /** + * create a error to be send back to client. + * + * @param $title + * @param $message + */ + public function responseError($title, $message) + { + $response = array( + 'fm-service-status' => 'error', + 'title' => $title, + 'message' => $message, + ); + $json = json_encode($response); + $this->output($json); + return null; + } + public function header($content) { return header($content); @@ -69,4 +87,16 @@ public function output($output) echo $output; return true; } + + public function streamFile($file, $fileName, $contentType) + { + $this->header('Content-Type: ' . $contentType); + $this->header('Content-Disposition: attachment; filename="' . $fileName . '"'); + $this->header('Content-Transfer-Encoding: binary'); + $this->header('Content-Length: ' . filesize($file)); + $this->header('Expires: 0'); + rewind($file); + return fpassthru($file); + } + } diff --git a/src/backoffice/FmServiceController.php b/src/backoffice/FmServiceController.php index 0987db4..658b5f7 100644 --- a/src/backoffice/FmServiceController.php +++ b/src/backoffice/FmServiceController.php @@ -22,79 +22,51 @@ public function handleRequest($params) } $action = $params['action']; $args = isset($params['args']) && is_array($params['args']) ? $params['args'] : array(); - try { + return $this->fmOutput->renderJSON($this->routeRequest($action, $args)); + } + + public function routeRequest($action, $args) { + //try { switch($action) { case 'get_categories': - return $this->fmOutput->renderJSON($this->getCategories($args)); + return $this->getCategories($args); case 'get_products': - return $this->fmOutput->renderJSON($this->getProducts($args)); + return $this->getProducts($args); case 'export_products': - return $this->fmOutput->renderJSON($this->serviceExportProducts($args)); + return $this->exportProducts($args); case 'delete_exported_products': - return $this->fmOutput->renderJSON($this->serviceDeleteExportedProducts($args)); + return $this->deleteExportedProducts($args); case 'update_order_status': - return $this->fmOutput->renderJSON($this->updateOrderStatus($args)); + return $this->updateOrderStatus($args); case 'load_orders': - return $this->fmOutput->renderJSON($this->loadOrders($args)); + return $this->loadOrders($args); case 'get_delivery_notes': - return $this->fmOutput->renderJSON($this->serviceGetDeliveryNotes($args)); + return $this->serviceGetDeliveryNotes($args); case 'import_orders': - return $this->fmOutput->renderJSON($this->serviceImportOrders($args)); + return $this->importOrders($args); case 'update_product_status': - return $this->fmOutput->renderJSON($this->serviceUpdateProductStatus($args)); + return $this->serviceUpdateProductStatus($args); default: - return $this->fmOutput->showError(404, 'Not Found', '404 Not Found'); + return $this->fmOutput->responseError( + 'Not Found', + 'Acion ' . $action . ' con not be found' + ); } - } catch (Exception $e) { - return $this->fmOutput->responseError( - FyndiqTranslation::get('unhandled-error-title'), - FyndiqTranslation::get('unhandled-error-message') . ' (' . $e->getMessage() . ')' - ); - } + // } catch (Exception $e) { + // return $this->fmOutput->responseError( + // FyndiqTranslation::get('unhandled-error-title'), + // FyndiqTranslation::get('unhandled-error-message') . ' (' . $e->getMessage() . ')' + // ); + // } } - /** - * Structure the response back to the client - * - * @param string $data - */ - private function response($data = '') - { - $response = array( - 'fm-service-status' => 'success', - 'data' => $data - ); - $json = json_encode($response); - if (json_last_error() != JSON_ERROR_NONE) { - $this->responseError( - FyndiqTranslation::get('unhandled-error-title'), - FyndiqTranslation::get('unhandled-error-message') - ); - } else { - echo $json; + protected function loadModel($modelName) { + if (class_exists($modelName)) { + return new $modelName($this->fmPrestashop, $this->fmConfig); } + throw new Exception('Model ' . $modelName . ' is not defined'); } - # return an error response - /** - * create a error to be send back to client. - * - * @param $title - * @param $message - */ - private function responseError($title, $message) - { - $response = array( - 'fm-service-status' => 'error', - 'title' => $title, - 'message' => $message, - ); - $json = json_encode($response); - echo $json; - } - - ### views ### - /** * Get the categories. * @@ -103,7 +75,7 @@ private function responseError($title, $message) private function getCategories($args) { $languageId = $this->fmConfig->get('language'); - $fmCategory = new FmCategory($this->fmPrestashop, $this->fmConfig); + $fmCategory = $this->loadModel('FmCategory'); return $fmCategory->getSubcategories($languageId, intval($args['category_id'])); } @@ -115,8 +87,8 @@ private function getCategories($args) private function getProducts($args) { $products = array(); - $fmProduct = new FmProduct($this->fmPrestashop, $this->fmConfig); - $fmProductExport = new FmProductExport($this->fmPrestashop, $this->fmConfig); + $fmProduct = $this->loadModel('FmProduct'); + $fmProductExport = $this->loadModel('FmProductExport'); // get currency $currentCurrency = $this->fmPrestashop->getDefaultCurrency(); @@ -161,7 +133,7 @@ private function getProducts($args) $page = isset($args['page']) ? intval($args['page']) : 1; $total = $fmProduct->getAmount($args['category']); - $result = array( + return array( 'products' => $products, 'pagination' => FyndiqUtils::getPaginationHTML( $total, @@ -170,46 +142,44 @@ private function getProducts($args) FyndiqUtils::PAGINATION_PAGE_FRAME ) ); - $this->response($result); } private function loadOrders($args) { - $page = (isset($args['page']) and $args['page'] > 0) ? $args['page']: 1; - $fmOrder = new FmOrder($this->fmPrestashop, $this->fmConfig); - $orders = $fmOrder->getImportedOrders($page, FyndiqUtils::PAGINATION_ITEMS_PER_PAGE); - - $object = new stdClass(); - $object->orders = $orders; - - // Setup pagination - $page = isset($args['page']) ? intval($args['page']) : 1; - $total = FmOrder::getAmount(); - $object->pagination = FyndiqUtils::getPaginationHTML( - $total, - $page, - FyndiqUtils::PAGINATION_ITEMS_PER_PAGE, - FyndiqUtils::PAGINATION_PAGE_FRAME + $fmOrder = $this->loadModel('FmOrder'); + $total = $fmOrder->getTotal(); + $page = (isset($args['page']) && $args['page'] > 0) ? $args['page']: 1; + return array( + 'orders' => $fmOrder->getImportedOrders($page, FyndiqUtils::PAGINATION_ITEMS_PER_PAGE), + 'pagination' => FyndiqUtils::getPaginationHTML( + $total, + $page, + FyndiqUtils::PAGINATION_ITEMS_PER_PAGE, + FyndiqUtils::PAGINATION_PAGE_FRAME + ) ); - $this->response($object); } private function updateOrderStatus($args) { + $doneStateName = ''; if (isset($args['orders']) && is_array($args['orders'])) { $doneState = ''; $doneState = $this->fmConfig->get('done_state'); - $fmOrder = new FmOrder($this->fmPrestashop, $this->fmConfig); + $fmOrder = $this->loadModel('FmOrder'); foreach ($args['orders'] as $order) { if (is_numeric($order)) { $doneState = $fmOrder->markOrderAsDone($order, $doneState); } } $doneStateName = $this->fmPrestashop->getOrderStateName($doneState); - return $this->response($doneStateName); } - $this->response(false); + return $doneStateName; + } + + protected function getTime() { + return time(); } /** @@ -218,69 +188,82 @@ private function updateOrderStatus($args) * @param $args * @throws PrestaShopException */ - private function import_orders() + private function importOrders() { - try { - $orderFetch = new FmOrderFetch(); - $orderFetch->getAll(); - $newDate = date('Y-m-d H:i:s'); - FmConfig::set('import_date', $newDate); - $time = date('G:i:s', strtotime($newDate)); - $this->response($time); - } catch (Exception $e) { - $this->responseError( - FyndiqTranslation::get('unhandled-error-title'), - FyndiqTranslation::get('unhandled-error-message') . ' (' . $e->getMessage() . ')' - ); - } + $fmOrder = $this->loadModel('FmOrder'); + $orderFetch = new FmOrderFetch($this->fmConfig, $fmOrder, $this->fmApiModel); + $orderFetch->getAll(); + $time = $this->getTime(); + $newDate = date('Y-m-d H:i:s', $time); + $this->fmConfig->set('import_date', $newDate); + return date('G:i:s', $time); } /** * Exporting the products from PrestaShop * - * @param $args + * @param mixed $args */ - private function export_products($args) + private function exportProducts($args) { - // Getting all data - foreach ($args['products'] as $row) { - $product = $row['product']; - - if (FmProductExport::productExist($product['id'])) { - FmProductExport::updateProduct($product['id'], $product['fyndiq_percentage']); - } else { - FmProductExport::addProduct($product['id'], $product['fyndiq_percentage']); + $result = true; + if (isset($args['products']) && is_array($args['products'])) { + $fmProductExport = $this->loadModel('FmProductExport'); + foreach ($args['products'] as $row) { + $product= $row['product']; + if ($fmProductExport->productExist($product['id'])) { + $result &= $fmProductExport->updateProduct($product['id'], $product['fyndiq_percentage']); + continue; + } + $result &= $fmProductExport->addProduct($product['id'], $product['fyndiq_percentage']); } } - $this->response(true); - } - - private function delete_exported_products($args) - { - foreach ($args['products'] as $row) { - $product = $row['product']; - FmProductExport::deleteProduct($product['id']); - } - $this->response(true); + return (bool)$result; } - private function update_product($args) + private function deleteExportedProducts($args) { - $result = false; - if (isset($args['product']) && is_numeric($args['product']) - && isset($args['percentage']) && is_numeric($args['percentage'])) { - $result = FmProductExport::updateProduct($args['product'], $args['percentage']); + $result = true; + if (isset($args['products']) && is_array($args['products'])) { + $fmProductExport = $this->loadModel('FmProductExport'); + foreach ($args['products'] as $row) { + $product = $row['product']; + $fmProductExport->deleteProduct($product['id']); + } } - $this->response($result); + return $result; } private function get_delivery_notes($args) { if (isset($args['orders']) && is_array($args['orders'])) { - echo FmHelpers::streamBackDeliveryNotes($args['orders']); - return; + $orderIds = $args['orders']; + $request = array( + 'orders' => array() + ); + foreach ($orderIds as $orderId) { + $request['orders'][] = array('order' => intval($orderId)); + } + try { + $ret = $this->apiModel->callApi('POST', 'delivery_notes/', $request); + $fileName = 'delivery_notes-' . implode('-', $orderIds) . '.pdf'; + + if ($ret['status'] == 200) { + $file = fopen('php://temp', 'wb+'); + // Saving data to file + fputs($file, $ret['data']); + $this->output->streamFile($file, $fileName, 'application/pdf'); + fclose($file); + return null; + } + return FyndiqTranslation::get('unhandled-error-message'); + } catch (Exception $e) { + $this->output->output($e->getMessage()); + return null; + } } - echo 'Please, pick at least one order'; + $this->output->output('Please, pick at least one order'); + return null; } private function update_product_status() diff --git a/src/backoffice/FmUtils.php b/src/backoffice/FmUtils.php index 9f19b9a..6344826 100644 --- a/src/backoffice/FmUtils.php +++ b/src/backoffice/FmUtils.php @@ -42,38 +42,6 @@ public static function getCurrentShopId() return intval($context->shop->id); } - public static function streamBackDeliveryNotes($orderIds) - { - $request = array( - 'orders' => array() - ); - foreach ($orderIds as $orderId) { - $request['orders'][] = array('order' => $orderId); - } - try { - $ret = self::callApi('POST', 'delivery_notes/', $request, true); - $fileName = 'delivery_notes-' . implode('-', $orderIds) . '.pdf'; - - if ($ret['status'] == 200) { - header('Content-Type: application/pdf'); - header('Content-Disposition: attachment; filename="' . $fileName . '"'); - header('Content-Transfer-Encoding: binary'); - header('Content-Length: ' . strlen($ret['data'])); - header('Expires: 0'); - $fp = fopen('php://temp', 'wb+'); - // Saving data to file - fputs($fp, $ret['data']); - rewind($fp); - fpassthru($fp); - fclose($fp); - die(); - } - return FyndiqTranslation::get('unhandled-error-message'); - } catch (Exception $e) { - return $e->getMessage(); - } - } - public static function getFileWriter($file) { return new FyndiqCSVFeedWriter($file); diff --git a/src/backoffice/includes/shared b/src/backoffice/includes/shared index 35b9b62..aaa3426 160000 --- a/src/backoffice/includes/shared +++ b/src/backoffice/includes/shared @@ -1 +1 @@ -Subproject commit 35b9b6224990bdc2361102f9e3ddb8d228faa991 +Subproject commit aaa3426377b5343bab87eb66e422721203a15603 diff --git a/src/backoffice/models/FmOrder.php b/src/backoffice/models/FmOrder.php index 3047445..46687e8 100644 --- a/src/backoffice/models/FmOrder.php +++ b/src/backoffice/models/FmOrder.php @@ -431,11 +431,10 @@ public function getImportedOrders($page, $perPage) return $return; } - public static function getAmount() + public function getTotal() { - $module = Module::getInstanceByName('fyndiqmerchant'); - $sqlquery = 'SELECT count(id) as amount FROM ' . _DB_PREFIX_ . $module->config_name . '_orders'; - return Db::getInstance()->getValue($sqlquery); + $sqlquery = 'SELECT count(id) as amount FROM ' . $fmPrestashop->getTableName(FmUtils::MODULE_NAME, '_orders'); + return $this->fmPrestashop->dbGetInstance()->getValue($sqlquery); } /** diff --git a/src/backoffice/service.php b/src/backoffice/service.php index 83108e1..09d31dd 100644 --- a/src/backoffice/service.php +++ b/src/backoffice/service.php @@ -12,7 +12,7 @@ require_once('./models/FmApiModel.php'); require_once('./FmConfig.php'); require_once('./models/FmOrder.php'); -require_once('./models/order_fetch.php'); +require_once('./FmOrderFetch.php'); require_once('./FmServiceController.php'); $cookie = new Cookie('psAdmin'); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index d3fd34f..259fe9d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,10 +10,13 @@ require_once(FYNDIQ_ROOT . 'backoffice/FmServiceController.php'); require_once(FYNDIQ_ROOT . 'backoffice/models/FmModel.php'); require_once(FYNDIQ_ROOT . 'backoffice/models/FmApiModel.php'); +require_once(FYNDIQ_ROOT . 'backoffice/models/FmOrder.php'); require_once(FYNDIQ_ROOT . 'backoffice/models/FmCategory.php'); require_once(FYNDIQ_ROOT . 'backoffice/models/FmProduct.php'); require_once(FYNDIQ_ROOT . 'backoffice/models/FmProductExport.php'); require_once(FYNDIQ_ROOT . 'backoffice/includes/shared/src/init.php'); +require_once(FYNDIQ_ROOT . 'backoffice/FmOrderFetch.php'); + // require_once(FYNDIQ_ROOT . 'backoffice/models/config.php'); // require_once(FYNDIQ_ROOT . 'backoffice/includes/fyndiqAPI/fyndiqAPI.php'); diff --git a/tests/src/backoffice/FmServiceControllerTest.php b/tests/src/backoffice/FmServiceControllerTest.php index 0668567..23f8601 100644 --- a/tests/src/backoffice/FmServiceControllerTest.php +++ b/tests/src/backoffice/FmServiceControllerTest.php @@ -17,12 +17,15 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); - $this->controller = new FmServiceController( - $this->fmPrestashop, - $this->fmOutput, - $this->fmConfig, - $this->fmApiModel - ); + $this->controller = $this->getMockBuilder('FmServiceController') + ->setConstructorArgs(array( + $this->fmPrestashop, + $this->fmOutput, + $this->fmConfig, + $this->fmApiModel + )) + ->setMethods(array('loadModel', 'getTime')) + ->getMock(); } public function testHandleRequestNoAction() { @@ -37,4 +40,319 @@ public function testHandleRequestNoAction() { $result = $this->controller->handleRequest(array()); $this->assertTrue($result); } + + public function testRouteRequestGetCategories() { + + $expected = array( + 'category_id' => 3 + ); + + $fmCategory = $this->getMockBuilder('FmCategory') + ->disableOriginalConstructor() + ->getMock(); + + $fmCategory->expects($this->once()) + ->method('getSubcategories') + ->with( + $this->equalTo(1), + $this->equalTo(2) + ) + ->willReturn($expected); + + $this->fmConfig->expects($this->once()) + ->method('get') + ->with( + $this->equalTo('language') + ) + ->willReturn(1); + + $this->controller->expects($this->once()) + ->method('loadModel') + ->willReturn($fmCategory); + + $result = $this->controller->routeRequest( + 'get_categories', + array( + 'category_id' => 2 + ) + ); + $this->assertEquals($expected, $result); + } + + public function testRouteRequestGetProducts() { + $categoryId = 2; + $currency = 'ZAM'; + $fyndiqPercentage = 23; + + $expected = array( + 'pagination' => '', + 'products' => array( + array( + 'price' => 3.33, + 'currency' => $currency, + 'fyndiq_quantity' => 2, + 'fyndiq_status' => 'on', + 'fyndiq_percentage' => 33, + 'expected_price' => '2.23', + 'quantity' => 2, + 'fyndiq_exported' => true, + ), + array( + 'price' => 3.33, + 'currency' => $currency, + 'fyndiq_quantity' => 2, + 'fyndiq_status' => 'pending', + 'fyndiq_percentage' => 44, + 'expected_price' => '1.86', + 'quantity' => 2, + 'fyndiq_exported' => true, + ) + ) + ); + $products = array( + array( + 'id_product' => 1, + ), + array( + 'id_product' => 2, + ), + array( + 'id_product' => 3, + ), + ); + + $this->fmConfig->expects($this->at(0)) + ->method('get') + ->with( + $this->equalTo('price_percentage') + ) + ->willReturn($fyndiqPercentage); + + $this->fmPrestashop->expects($this->once()) + ->method('getDefaultCurrency') + ->willReturn($currency); + + $fmProduct = $this->getMockBuilder('FmProduct') + ->disableOriginalConstructor() + ->getMock(); + + $fmProduct->expects($this->once()) + ->method('getByCategory') + ->with( + $this->equalTo($categoryId), + $this->equalTo(1), + $this->equalTo(FyndiqUtils::PAGINATION_ITEMS_PER_PAGE) + ) + ->willReturn($products); + + $fmProductExport = $this->getMockBuilder('FmProductExport') + ->disableOriginalConstructor() + ->getMock(); + + $fmProductExport->method('getStoreProduct') + ->will($this->onConsecutiveCalls( + array( + 'quantity' => 2, + 'price' => 3.33, + ), + array( + 'quantity' => 2, + 'price' => 3.33, + ), + array() + )); + + $fmProductExport->method('getProduct') + ->will($this->onConsecutiveCalls( + array( + 'exported_price_percentage' => 33, + 'state' => 'FOR_SALE', + ), + array( + 'exported_price_percentage' => 44, + 'state' => 'test', + ) + )); + + $this->controller->expects($this->at(0)) + ->method('loadModel') + ->willReturn($fmProduct); + + $this->controller->expects($this->at(1)) + ->method('loadModel') + ->willReturn($fmProductExport); + + + $result = $this->controller->routeRequest( + 'get_products', + array( + 'category' => $categoryId + ) + ); + $this->assertEquals($expected, $result); + } + + public function testLoadOrders() { + $expected = array( + 'orders' => array( + array(1 => 1) + ), + 'pagination' => '', + ); + + $fmOrder = $this->getMockBuilder('FmOrder') + ->disableOriginalConstructor() + ->getMock(); + + $fmOrder->expects($this->once()) + ->method('getImportedOrders') + ->willReturn(array( + array(1 => 1), + )); + + $this->controller->expects($this->once()) + ->method('loadModel') + ->willReturn($fmOrder); + + $result = $this->controller->routeRequest( + 'load_orders', + array( + ) + ); + $this->assertEquals($expected, $result); + } + + public function testUpdateOrderStatus() { + $doneState = 'test'; + + $fmOrder = $this->getMockBuilder('FmOrder') + ->disableOriginalConstructor() + ->getMock(); + + $fmOrder->method('markOrderAsDone') + ->willReturn(true); + + $this->controller->expects($this->once()) + ->method('loadModel') + ->willReturn($fmOrder); + + $this->fmPrestashop->method('getOrderStateName')->willReturn($doneState); + + $result = $this->controller->routeRequest( + 'update_order_status', + array( + 'orders' => array(1,2) + ) + ); + $this->assertEquals($doneState, $result); + } + + public function testImportOrders() + { + $expected = '21:21:18'; + $this->controller->method('getTime')->willReturn(12345678); + + $result = $this->controller->routeRequest( + 'import_orders', + array() + ); + $this->assertEquals($expected, $result); + } + + public function testExportProducts() + { + + $fmProductExport = $this->getMockBuilder('FmProductExport') + ->disableOriginalConstructor() + ->getMock(); + + $fmProductExport->method('productExist') + ->will($this->onConsecutiveCalls(array( + true, + false, + ))); + + $fmProductExport->method('updateProduct') + ->with( + $this->equalTo(1), + $this->equalTo(11) + ) + ->willReturn(true); + + $fmProductExport->method('addProduct') + ->with( + $this->equalTo(2), + $this->equalTo(22) + ) + ->willReturn(true); + + $this->controller->expects($this->once()) + ->method('loadModel') + ->willReturn($fmProductExport); + + + $result = $this->controller->routeRequest( + 'export_products', + array( + 'products' => array( + array( + 'product' => array( + 'id' => 1, + 'fyndiq_percentage' => 11, + ) + ), + array( + 'product' => array( + 'id' => 2, + 'fyndiq_percentage' => 22, + ) + ), + ) + ) + ); + $this->assertTrue($result); + } + + public function testDeleteExportedProducts() { + + $fmProductExport = $this->getMockBuilder('FmProductExport') + ->disableOriginalConstructor() + ->getMock(); + + $fmProductExport->method('deleteProeduct') + ->willReturn(true); + + $this->controller->expects($this->once()) + ->method('loadModel') + ->willReturn($fmProductExport); + + $result = $this->controller->routeRequest( + 'delete_exported_products', + array( + 'products' => array( + array( + 'product' => array( + 'id' => 1 + ) + ), + array( + 'product' => array( + 'id' => 2 + ) + ), + ) + ) + ); + $this->assertTrue($result); + } + + public function testGetDeliveryNotes() + { + $data = array( + 'orders' => array(1, 2, 3) + ); + + $result = $this->controller->handleRequest('get_delivery_notes', $data); + $this->assertNull($result); + } }