/** * @param $typeId * @param $quantity * @param $infoClass * @param $prices * @dataProvider createPriceInfoDataProvider */ public function testCreate($typeId, $quantity, $infoClass, $prices) { $this->saleableItemMock->expects($this->once())->method('getTypeId')->will($this->returnValue($typeId)); $this->saleableItemMock->expects($this->once())->method('getQty')->will($this->returnValue($quantity)); $this->objectManagerMock->expects($this->exactly(2))->method('create')->will($this->returnValueMap([[$prices, ['saleableItem' => $this->saleableItemMock, 'quantity' => $quantity], $this->pricesMock], [$infoClass, ['saleableItem' => $this->saleableItemMock, 'quantity' => $quantity, 'prices' => $this->pricesMock], $this->priceInfoMock]])); $this->assertEquals($this->priceInfoMock, $this->factory->create($this->saleableItemMock, [])); }
public function testCreate() { $adapterClassName = '\\Migration\\Resource\\Adapter\\Mysql'; $data = ['config' => ['key' => 'value']]; $adapter = $this->getMock($adapterClassName, [], [], '', false); $this->config->expects($this->once())->method('getOption')->with('resource_adapter_class_name')->will($this->returnValue(null)); $this->objectManager->expects($this->once())->method('create')->with('\\Migration\\Resource\\Adapter\\Mysql', $data)->will($this->returnValue($adapter)); $this->assertInstanceOf($adapterClassName, $this->adapterFactory->create($data)); }
/** * @param Object $object * @param string $methodName */ public function methodInjection($object, $methodName, ObjectManager $objectManager) { $parameters = $this->getMethod($object, $methodName); $argumentsToInject = []; foreach ($parameters as $parameter) { $argumentsToInject[] = $objectManager->get($parameter[1]); } call_user_func_array([$object, $methodName], $argumentsToInject); }
public function testDeleteActionThrowsException() { $errorMsg = 'Can\'t delete the page'; $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->pageId); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Page')->willReturn($this->pageMock); $this->pageMock->expects($this->once())->method('load')->with($this->pageId); $this->pageMock->expects($this->once())->method('getTitle')->willReturn($this->title); $this->pageMock->expects($this->once())->method('delete')->willThrowException(new \Exception(__($errorMsg))); $this->eventManagerMock->expects($this->once())->method('dispatch')->with('adminhtml_cmspage_on_delete', ['title' => $this->title, 'status' => 'fail']); $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['page_id' => $this->pageId])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->deleteController->execute()); }
public function testExecute() { $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false); $order = $this->getMock('Magento\\Sales\\Model\\Order', ['setCustomerNoteNotify', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]])); $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData); $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment)); $shipment->expects($this->once())->method('register')->will($this->returnSelf()); $shipment->expects($this->any())->method('getOrder')->will($this->returnValue($order)); $order->expects($this->once())->method('setCustomerNoteNotify')->with(false); $this->labelGenerator->expects($this->any())->method('create')->with($shipment, $this->request)->will($this->returnValue(true)); $saveTransaction = $this->getMockBuilder('Magento\\Framework\\DB\\Transaction')->disableOriginalConstructor()->setMethods([])->getMock(); $saveTransaction->expects($this->at(0))->method('addObject')->with($shipment)->will($this->returnSelf()); $saveTransaction->expects($this->at(1))->method('addObject')->with($order)->will($this->returnSelf()); $saveTransaction->expects($this->at(2))->method('save'); $this->session->expects($this->once())->method('getCommentText')->with(true); $this->objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\DB\\Transaction')->will($this->returnValue($saveTransaction)); $this->objectManager->expects($this->once())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session)); $path = 'sales/order/view'; $arguments = ['order_id' => $orderId]; $shipment->expects($this->once())->method('getOrderId')->will($this->returnValue($orderId)); $this->prepareRedirect($path, $arguments); $this->saveAction->execute(); $this->assertEquals($this->response, $this->saveAction->getResponse()); }
public function testExecute() { $carrier = 'carrier'; $number = 'number'; $title = 'title'; $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['addTrack', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]])); $this->request->expects($this->any())->method('getPost')->will($this->returnValueMap([['carrier', $carrier], ['number', $number], ['title', $title]])); $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData); $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment)); $this->title->expects($this->any())->method('add')->with('Shipments')->will($this->returnSelf()); $track = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->disableOriginalConstructor()->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle'])->getMock(); $this->objectManager->expects($this->atLeastOnce())->method('create')->with('Magento\\Sales\\Model\\Order\\Shipment\\Track')->will($this->returnValue($track)); $track->expects($this->once())->method('setNumber')->with($number)->will($this->returnSelf()); $track->expects($this->once())->method('setCarrierCode')->with($carrier)->will($this->returnSelf()); $track->expects($this->once())->method('setTitle')->with($title)->will($this->returnSelf()); $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false); $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml'], [], '', false); $html = 'html string'; $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $layout->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($menuBlock)); $menuBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html)); $shipment->expects($this->once())->method('addTrack')->with($this->equalTo($track))->will($this->returnSelf()); $shipment->expects($this->any())->method('save')->will($this->returnSelf()); $this->response->expects($this->once())->method('setBody')->with($html); $this->assertNull($this->controller->execute()); }
public function testEmailNoInvoice() { $invoiceId = 10000031; $this->request->expects($this->once()) ->method('getParam') ->with('invoice_id') ->willReturn($invoiceId); $invoiceRepository = $this->getMockBuilder('Magento\Sales\Api\InvoiceRepositoryInterface') ->disableOriginalConstructor() ->getMock(); $invoiceRepository->expects($this->any()) ->method('get') ->willReturn(null); $this->objectManager->expects($this->at(0)) ->method('create') ->with('Magento\Sales\Api\InvoiceRepositoryInterface') ->willReturn($invoiceRepository); $this->resultForwardFactory->expects($this->any()) ->method('create') ->willReturn($this->resultForward); $this->resultForward->expects($this->once()) ->method('forward') ->with('noroute') ->willReturnSelf(); $this->assertInstanceOf('Magento\Backend\Model\View\Result\Forward', $this->invoiceEmail->executeInternal()); }
public function testExecute() { $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipmentData = ['items' => [], 'send_email' => '']; $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', 'register', 'getOrder', 'getOrderId', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]])); $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData); $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment)); $this->session->expects($this->once())->method('getCommentText')->with(true)->will($this->returnValue('')); $this->objectManager->expects($this->atLeastOnce())->method('get')->with('Magento\\Backend\\Model\\Session')->will($this->returnValue($this->session)); $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf()); $this->view->expects($this->once())->method('renderLayout')->will($this->returnSelf()); $this->view->expects($this->any())->method('getPage')->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any())->method('getConfig')->willReturn($this->pageConfigMock); $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->pageTitleMock); $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false); $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml', 'setActive', 'getMenuModel'], [], '', false); $menuModel = $this->getMockBuilder('Magento\\Backend\\Model\\Menu')->disableOriginalConstructor()->getMock(); $itemId = 'Magento_Sales::sales_order'; $parents = [new \Magento\Framework\DataObject(['title' => 'title1']), new \Magento\Framework\DataObject(['title' => 'title2']), new \Magento\Framework\DataObject(['title' => 'title3'])]; $menuModel->expects($this->once())->method('getParentItems')->with($itemId)->will($this->returnValue($parents)); $menuBlock->expects($this->once())->method('setActive')->with($itemId); $menuBlock->expects($this->once())->method('getMenuModel')->will($this->returnValue($menuModel)); $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout)); $layout->expects($this->once())->method('getBlock')->with('menu')->will($this->returnValue($menuBlock)); $this->assertNull($this->newAction->execute()); }
public function testEmail() { $cmId = 10000031; $cmManagement = 'Magento\Sales\Api\CreditmemoManagementInterface'; $cmManagementMock = $this->getMock($cmManagement, [], [], '', false); $this->prepareRedirect($cmId); $this->request->expects($this->once()) ->method('getParam') ->with('creditmemo_id') ->willReturn($cmId); $this->objectManager->expects($this->once()) ->method('create') ->with($cmManagement) ->willReturn($cmManagementMock); $cmManagementMock->expects($this->once()) ->method('notify') ->willReturn(true); $this->messageManager->expects($this->once()) ->method('addSuccess') ->with('You sent the message.'); $this->assertInstanceOf( 'Magento\Backend\Model\View\Result\Redirect', $this->creditmemoEmail->executeInternal() ); $this->assertEquals($this->response, $this->creditmemoEmail->getResponse()); }
public function testEmail() { $shipmentId = 1000012; $orderId = 10003; $tracking = []; $shipment = ['items' => []]; $orderShipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['load', 'save', '__wakeup'], [], '', false); $shipmentNotifierClassName = 'Magento\\Shipping\\Model\\ShipmentNotifier'; $shipmentNotifier = $this->getMock($shipmentNotifierClassName, ['notify', '__wakeup'], [], '', false); $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipment], ['tracking', null, $tracking]])); $this->shipmentLoader->expects($this->once())->method('setShipmentId')->with($shipmentId); $this->shipmentLoader->expects($this->once())->method('setOrderId')->with($orderId); $this->shipmentLoader->expects($this->once())->method('setShipment')->with($shipment); $this->shipmentLoader->expects($this->once())->method('setTracking')->with($tracking); $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($orderShipment)); $orderShipment->expects($this->once())->method('save')->will($this->returnSelf()); $this->objectManager->expects($this->once())->method('create')->with($shipmentNotifierClassName)->will($this->returnValue($shipmentNotifier)); $shipmentNotifier->expects($this->once())->method('notify')->with($orderShipment)->will($this->returnValue(true)); $this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the shipment.'); $path = '*/*/view'; $arguments = ['shipment_id' => $shipmentId]; $this->prepareRedirect($path, $arguments, 0); $this->shipmentEmail->execute(); $this->assertEquals($this->response, $this->shipmentEmail->getResponse()); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { try { /** @var \Magento\Framework\Component\ComponentRegistrar $componentRegistrar */ $componentRegistrar = $this->objectManager->get('Magento\\Framework\\Component\\ComponentRegistrar'); /** @var \Magento\Framework\Component\DirSearch $dirSearch */ $dirSearch = $this->objectManager->get('Magento\\Framework\\Component\\DirSearch'); /** @var \Magento\Framework\View\Design\Theme\ThemePackageList $themePackageList */ $themePackageList = $this->objectManager->get('Magento\\Framework\\View\\Design\\Theme\\ThemePackageList'); Files::setInstance(new Files($componentRegistrar, $dirSearch, $themePackageList)); $this->buildReport($input->getOption(self::INPUT_KEY_OUTPUT)); $output->writeln('<info>Report successfully processed.</info>'); } catch (\Exception $e) { $output->writeln('<error>Please check the path you provided. Dependencies report generator failed with error: ' . $e->getMessage() . '</error>'); } }
public function testExecuteUpdateAction() { $orderId = 30; $action = 'update'; $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId); $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action); $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Order')->willReturn($this->orderMock); $this->orderMock->expects($this->once())->method('load')->with($orderId)->willReturn($this->orderMock); $this->orderMock->expects($this->any())->method('getId')->willReturn($orderId); $this->orderMock->expects($this->once())->method('getPayment')->willReturn($this->paymentMock); $this->orderMock->expects($this->once())->method('save')->willReturnSelf(); $this->messageManagerMock->expects($this->once())->method('addSuccess')->with('The payment update has been made.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->paymentMock->expects($this->once())->method('update'); $result = $this->reviewPayment->execute(); $this->assertEquals($this->resultRedirectMock, $result); }
public function testEmailNoCreditmemo() { $cmId = 10000031; $creditmemoClassName = 'Magento\\Sales\\Model\\Order\\Creditmemo'; $creditmemo = $this->getMock($creditmemoClassName, ['load', '__wakeup'], [], '', false); $this->request->expects($this->once())->method('getParam')->with('creditmemo_id')->will($this->returnValue($cmId)); $this->objectManager->expects($this->at(0))->method('create')->with($creditmemoClassName)->will($this->returnValue($creditmemo)); $creditmemo->expects($this->once())->method('load')->with($cmId)->will($this->returnValue(null)); $this->assertNull($this->creditmemoEmail->execute()); }
public function testDeleteActionThrowsException() { $errorMsg = 'Can\'t create the block'; $this->requestMock->expects($this->once())->method('getParam')->willReturn($this->blockId); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Block')->willThrowException(new \Exception(__($errorMsg))); $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMsg); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf(); $this->assertSame($this->resultRedirectMock, $this->deleteController->execute()); }
protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface', [], [], '', false); $this->coreRegistryMock = $this->getMock('\\Magento\\Framework\\Registry', [], [], '', false); $this->blockMock = $this->getMockBuilder('Magento\\Cms\\Model\\Block')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManager\\ObjectManager')->setMethods(['create', 'get'])->disableOriginalConstructor()->getMock(); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Cms\\Model\\Block')->willReturn($this->blockMock); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultRedirectFactoryMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\RedirectFactory')->disableOriginalConstructor()->getMock(); $this->resultPageFactoryMock = $this->getMock('Magento\\Framework\\View\\Result\\PageFactory', [], [], '', false); $this->requestMock = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, []); $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->contextMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->once())->method('getObjectManager')->willReturn($this->objectManagerMock); $this->contextMock->expects($this->once())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->once())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactoryMock); $this->editController = $this->objectManager->getObject('Magento\\Cms\\Controller\\Adminhtml\\Block\\Edit', ['context' => $this->contextMock, 'coreRegistry' => $this->coreRegistryMock, 'resultPageFactory' => $this->resultPageFactoryMock]); }
public function testSaveAction() { $userId = 1; $requestParams = ['password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**', \Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password']; $testedMessage = 'The account has been saved.'; $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock)); $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf()); $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true)); $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale'); $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock)); $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock)); $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Locale\\Validator'))->will($this->returnValue($this->_validatorMock)); $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock)); $this->_userMock->setUserId($userId); $this->_userMock->expects($this->once())->method('save'); $this->_userMock->expects($this->once())->method('verifyIdentity')->will($this->returnValue(true)); $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail'); $this->_requestMock->setParams($requestParams); $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage)); $this->_controller->execute(); }
public function testEmailNoOrderId() { $orderClassName = 'Magento\\Sales\\Model\\Order'; $order = $this->getMock($orderClassName, ['load', 'getId', '__wakeup'], [], '', false); $this->request->expects($this->once())->method('getParam')->with('order_id')->will($this->returnValue(null)); $this->objectManager->expects($this->at(0))->method('create')->with($orderClassName)->will($this->returnValue($order)); $order->expects($this->once())->method('load')->with(null)->will($this->returnSelf()); $this->messageManager->expects($this->once())->method('addError')->with('This order no longer exists.'); $this->actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->will($this->returnValue(true)); $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->orderEmail->execute()); }
public function testEmailNoInvoice() { $invoiceId = 10000031; $invoiceClassName = 'Magento\\Sales\\Model\\Order\\Invoice'; $invoice = $this->getMock($invoiceClassName, [], [], '', false); $this->request->expects($this->once())->method('getParam')->with('invoice_id')->willReturn($invoiceId); $this->objectManager->expects($this->at(0))->method('create')->with($invoiceClassName)->willReturn($invoice); $invoice->expects($this->once())->method('load')->with($invoiceId)->willReturn(null); $this->resultForwardFactory->expects($this->any())->method('create')->willReturn($this->resultForward); $this->resultForward->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Forward', $this->invoiceEmail->execute()); }
/** * Set up */ protected function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false); $this->request->expects($this->any())->method('getParam')->with('filename')->willReturn('filename'); $this->reportHelper = $this->getMock('Magento\\ImportExport\\Helper\\Report', ['importFileExists', 'getReportSize', 'getReportOutput'], [], '', false); $this->reportHelper->expects($this->any())->method('getReportSize')->willReturn(1); $this->reportHelper->expects($this->any())->method('getReportOutput')->willReturn('output'); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['get'], [], '', false); $this->objectManager->expects($this->any())->method('get')->with('Magento\\ImportExport\\Helper\\Report')->willReturn($this->reportHelper); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResultRedirectFactory'], [], '', false); $this->fileFactory = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false); $this->resultRaw = $this->getMock('Magento\\Framework\\Controller\\Result\\Raw', ['setContents'], [], '', false); $this->resultRawFactory = $this->getMock('\\Magento\\Framework\\Controller\\Result\\RawFactory', ['create'], [], '', false); $this->resultRawFactory->expects($this->any())->method('create')->willReturn($this->resultRaw); $this->redirect = $this->getMock('\\Magento\\Backend\\Model\\View\\Result\\Redirect', ['setPath'], [], '', false); $this->resultRedirectFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\RedirectFactory', ['create'], [], '', false); $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->redirect); $this->context->expects($this->any())->method('getRequest')->willReturn($this->request); $this->context->expects($this->any())->method('getObjectManager')->willReturn($this->objectManager); $this->context->expects($this->any())->method('getResultRedirectFactory')->willReturn($this->resultRedirectFactory); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->downloadController = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Controller\\Adminhtml\\History\\Download', ['context' => $this->context, 'fileFactory' => $this->fileFactory, 'resultRawFactory' => $this->resultRawFactory, 'reportHelper' => $this->reportHelper]); }
/** * @param string $param * @return mixed */ public function wrap($param) { $beforeFunc = __FUNCTION__ . 'Before'; if (isset($this->_pluginList[$beforeFunc])) { foreach ($this->_pluginList[$beforeFunc] as $plugin) { $param = $this->_objectManager->get($plugin)->{$beforeFunc}($param); } } $insteadFunc = __FUNCTION__; if (isset($this->_pluginList[$insteadFunc])) { $first = reset($this->_pluginList[$insteadFunc]); $returnValue = $this->_objectManager->get($first)->{$insteadFunc}(); } else { $returnValue = $this->_getSubject()->wrap($param); } $afterFunc = __FUNCTION__ . 'After'; if (isset($this->_pluginList[$afterFunc])) { foreach (array_reverse($this->_pluginList[$afterFunc]) as $plugin) { $returnValue = $this->_objectManager->get($plugin)->{$afterFunc}($returnValue); } } return $returnValue; }
/** * @param string $messageType * @param string $status * @param string $notice * @dataProvider linkNotAvailableDataProvider */ public function testLinkNotAvailable($messageType, $status, $notice) { $this->objectManager->expects($this->at(0))->method('get')->with('Magento\\Customer\\Model\\Session')->willReturn($this->session); $this->request->expects($this->once())->method('getParam')->with('id', 0)->willReturn('some_id'); $this->objectManager->expects($this->at(1))->method('create')->with('Magento\\Downloadable\\Model\\Link\\Purchased\\Item')->willReturn($this->linkPurchasedItem); $this->linkPurchasedItem->expects($this->once())->method('load')->with('some_id', 'link_hash')->willReturnSelf(); $this->linkPurchasedItem->expects($this->once())->method('getId')->willReturn(5); $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Data')->willReturn($this->helperData); $this->helperData->expects($this->once())->method('getIsShareable')->with($this->linkPurchasedItem)->willReturn(true); $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsBought')->willReturn(10); $this->linkPurchasedItem->expects($this->any())->method('getNumberOfDownloadsUsed')->willReturn(9); $this->linkPurchasedItem->expects($this->once())->method('getStatus')->willReturn($status); $this->messageManager->expects($this->once())->method($messageType)->with($notice)->willReturnSelf(); $this->assertEquals($this->response, $this->link->execute()); }
public function testSaveActionThrowsException() { $this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['block_id' => 1]); $this->requestMock->expects($this->atLeastOnce())->method('getParam')->willReturnMap([['block_id', null, 1], ['back', null, true]]); $this->objectManagerMock->expects($this->atLeastOnce())->method('create')->with($this->equalTo('Magento\\Cms\\Model\\Block'))->willReturn($this->blockMock); $this->blockMock->expects($this->any())->method('load')->willReturnSelf(); $this->blockMock->expects($this->any())->method('getId')->willReturn(true); $this->blockMock->expects($this->once())->method('setData'); $this->blockMock->expects($this->once())->method('save')->willThrowException(new \Exception('Error message.')); $this->messageManagerMock->expects($this->never())->method('addSuccess'); $this->messageManagerMock->expects($this->once())->method('addException'); $this->dataPersistorMock->expects($this->any())->method('set')->with('cms_block', ['block_id' => 1]); $this->resultRedirect->expects($this->atLeastOnce())->method('setPath')->with('*/*/edit', ['block_id' => $this->blockId])->willReturnSelf(); $this->assertSame($this->resultRedirect, $this->saveController->execute()); }
/** * Order throws exception while canceling */ public function testException() { $selected = [1]; $exception = new \Exception('Can not cancel'); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('selected')->willReturn($selected); $this->requestMock->expects($this->at(1))->method('getParam')->with('excluded')->willReturn([]); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Resource\\Order\\Grid\\Collection')->willReturn($this->orderCollectionMock); $this->orderCollectionMock->expects($this->once())->method('addFieldToFilter')->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['in' => $selected]); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1]); $order1->expects($this->once())->method('canCancel')->willReturn(true); $order1->expects($this->once())->method('cancel')->willThrowException($exception); $this->messageManagerMock->expects($this->once())->method('addError')->with('Can not cancel'); $this->massAction->execute(); }
public function testExecuteOneOrderCannotBePutOnHold() { $excluded = [1, 2]; $countOrders = count($excluded); $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $this->requestMock->expects($this->at(0))->method('getParam')->with('selected')->willReturn([]); $this->requestMock->expects($this->at(1))->method('getParam')->with('excluded')->willReturn($excluded); $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\Sales\\Model\\Resource\\Order\\Grid\\Collection')->willReturn($this->orderCollectionMock); $this->orderCollectionMock->expects($this->once())->method('addFieldToFilter')->with(\Magento\Sales\Controller\Adminhtml\Order\MassCancel::ID_FIELD, ['nin' => $excluded]); $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1, $order2]); $order1->expects($this->once())->method('canHold')->willReturn(false); $this->orderCollectionMock->expects($this->once())->method('count')->willReturn($countOrders); $order2->expects($this->once())->method('canHold')->willReturn(false); $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were put on hold.'); $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf(); $this->massAction->execute(); }
public function testExecuteLinkTypeFile() { $sampleMock = $this->getMockBuilder('Magento\\Downloadable\\Model\\Sample')->disableOriginalConstructor()->setMethods(['getId', 'load', 'getSampleType', 'getSampleUrl', 'getBaseSamplePath'])->getMock(); $fileHelperMock = $this->getMockBuilder('Magento\\Downloadable\\Helper\\File')->disableOriginalConstructor()->setMethods(['getFilePath'])->getMock(); $this->request->expects($this->once())->method('getParam')->with('sample_id', 0)->willReturn('some_sample_id'); $this->objectManager->expects($this->at(0))->method('create')->with('Magento\\Downloadable\\Model\\Sample')->willReturn($sampleMock); $sampleMock->expects($this->once())->method('load')->with('some_sample_id')->willReturnSelf(); $sampleMock->expects($this->once())->method('getId')->willReturn('some_sample_id'); $sampleMock->expects($this->any())->method('getSampleType')->willReturn(\Magento\Downloadable\Helper\Download::LINK_TYPE_FILE); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\File')->willReturn($fileHelperMock); $fileHelperMock->expects($this->once())->method('getFilePath')->willReturn('file_path'); $this->objectManager->expects($this->at(2))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->willReturn($this->downloadHelper); $this->response->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf(); $this->response->expects($this->any())->method('setHeader')->willReturnSelf(); $this->downloadHelper->expects($this->once())->method('output')->willThrowException(new \Exception()); $this->messageManager->expects($this->once())->method('addError')->with('Sorry, there was an error getting requested content. Please contact the store owner.')->willReturnSelf(); $this->redirect->expects($this->once())->method('getRedirectUrl')->willReturn('redirect_url'); $this->response->expects($this->once())->method('setRedirect')->with('redirect_url')->willReturnSelf(); $this->assertEquals($this->response, $this->sample->execute()); }
/** * Execute download sample url action */ public function testExecuteUrl() { $this->request->expects($this->at(0))->method('getParam')->with('id', 0)->will($this->returnValue(1)); $this->response->expects($this->once())->method('setHttpResponseCode')->will($this->returnSelf()); $this->response->expects($this->once())->method('clearBody')->will($this->returnSelf()); $this->response->expects($this->any())->method('setHeader')->will($this->returnSelf()); $this->response->expects($this->once())->method('sendHeaders')->will($this->returnSelf()); $this->objectManager->expects($this->at(1))->method('get')->with('Magento\\Downloadable\\Helper\\Download')->will($this->returnValue($this->downloadHelper)); $this->downloadHelper->expects($this->once())->method('setResource')->will($this->returnSelf()); $this->downloadHelper->expects($this->once())->method('getFilename')->will($this->returnValue('sample.jpg')); $this->downloadHelper->expects($this->once())->method('getContentType')->will($this->returnSelf('url')); $this->downloadHelper->expects($this->once())->method('getFileSize')->will($this->returnValue(null)); $this->downloadHelper->expects($this->once())->method('getContentDisposition')->will($this->returnValue(null)); $this->downloadHelper->expects($this->once())->method('output')->will($this->returnSelf()); $this->sampleModel->expects($this->once())->method('load')->will($this->returnSelf()); $this->sampleModel->expects($this->once())->method('getId')->will($this->returnValue('1')); $this->sampleModel->expects($this->any())->method('getSampleType')->will($this->returnValue('url')); $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($this->sampleModel)); $this->sample->execute(); }
/** * @param int $blockId * @param string $label * @param string $title * @dataProvider editActionData */ public function testEditAction($blockId, $label, $title) { $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId); $this->blockMock->expects($this->any())->method('load')->with($blockId); $this->blockMock->expects($this->any())->method('getId')->willReturn($blockId); $this->blockMock->expects($this->any())->method('getTitle')->willReturn('Test title'); $sessionManagerMock = $this->getMock('Magento\\Backend\\Model\\Session', ['getFormData'], [], '', false); $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Backend\\Model\\Session')->willReturn($sessionManagerMock); $sessionManagerMock->expects($this->once())->method('getFormData')->with(true); $this->coreRegistryMock->expects($this->once())->method('register')->with('cms_block', $this->blockMock); $resultPageMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Page', [], [], '', false); $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($resultPageMock); $titleMock = $this->getMock('Magento\\Framework\\View\\Page\\Title', [], [], '', false); $titleMock->expects($this->at(0))->method('prepend')->with(__('Blocks')); $titleMock->expects($this->at(1))->method('prepend')->with($this->getTitle()); $pageConfigMock = $this->getMock('Magento\\Framework\\View\\Page\\Config', [], [], '', false); $pageConfigMock->expects($this->exactly(2))->method('getTitle')->willReturn($titleMock); $resultPageMock->expects($this->once())->method('setActiveMenu')->willReturnSelf(); $resultPageMock->expects($this->any())->method('addBreadcrumb')->willReturnSelf(); $resultPageMock->expects($this->at(3))->method('addBreadcrumb')->with(__($label), __($title))->willReturnSelf(); $resultPageMock->expects($this->exactly(2))->method('getConfig')->willReturn($pageConfigMock); $this->assertSame($resultPageMock, $this->editController->execute()); }
public function testCreate() { $this->_objectManager->expects($this->once())->method('create')->with('Magento\\Framework\\ObjectManager\\Config\\Reader\\Dom')->will($this->returnValue($this->_object)); $this->_factory->create([1]); }
/** * @param FactoryInterface $factory * @param \Magento\Framework\ObjectManager\ConfigInterface $config * @param array $sharedInstances */ public function __construct(FactoryInterface $factory, \Magento\Framework\ObjectManager\ConfigInterface $config, array &$sharedInstances = []) { parent::__construct($factory, $config, $sharedInstances); self::$_instance = $this; }
public function testGetIgnoresFirstSlash() { $this->assertSame($this->_object->get('Magento\\Test\\Di\\Child'), $this->_object->get('Magento\\Test\\Di\\Child')); }