Ejemplo n.º 1
0
 public function testTryToSaveInvalidDataShouldFailWithErrors()
 {
     $validatorClass = 'Magento\\MediaStorage\\Model\\File\\Validator\\AvailablePath';
     $helperClass = 'Magento\\Sitemap\\Helper\\Data';
     $validPaths = [];
     $messages = ['message1', 'message2'];
     $sessionClass = 'Magento\\Backend\\Model\\Session';
     $data = ['sitemap_filename' => 'sitemap_filename', 'sitemap_path' => '/sitemap_path'];
     $siteMapId = 1;
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->requestMock->expects($this->once())->method('getParam')->with('sitemap_id')->willReturn($siteMapId);
     $validator = $this->getMock($validatorClass, [], [], '', false);
     $validator->expects($this->once())->method('setPaths')->with($validPaths)->willReturnSelf();
     $validator->expects($this->once())->method('isValid')->with('/sitemap_path/sitemap_filename')->willReturn(false);
     $validator->expects($this->once())->method('getMessages')->willReturn($messages);
     $helper = $this->getMock($helperClass, [], [], '', false);
     $helper->expects($this->once())->method('getValidPaths')->willReturn($validPaths);
     $session = $this->getMock($sessionClass, ['setFormData'], [], '', false);
     $session->expects($this->once())->method('setFormData')->with($data)->willReturnSelf();
     $this->objectManagerMock->expects($this->once())->method('create')->with($validatorClass)->willReturn($validator);
     $this->objectManagerMock->expects($this->any())->method('get')->willReturnMap([[$helperClass, $helper], [$sessionClass, $session]]);
     $this->messageManagerMock->expects($this->at(0))->method('addError')->withConsecutive([$messages[0]], [$messages[1]])->willReturnSelf();
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('adminhtml/*/edit', ['sitemap_id' => $siteMapId])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->saveController->execute());
 }
Ejemplo n.º 2
0
 public function testExecuteNotPost()
 {
     $this->validatorMock->expects($this->once())->method('validate')->willReturn(false);
     $this->request->expects($this->once())->method('isPost')->willReturn(false);
     $this->messageManager->expects($this->once())->method('addError')->with('You have not canceled the item.');
     $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->assertEquals($this->resultRedirect, $this->controller->execute());
 }
Ejemplo n.º 3
0
 public function testDeleteActionNoId()
 {
     $this->requestMock->expects($this->once())->method('getParam')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('We can\'t find a synonym group to delete.'));
     $this->messageManagerMock->expects($this->never())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->deleteController->execute());
 }
 public function testExecute()
 {
     $path = '*/*';
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($this->resultRedirect);
     $this->messageManager->expects($this->once())->method('addSuccess')->with(__('We updated lifetime statistic.'));
     $this->objectManager->expects($this->any())->method('create')->with('Magento\\Sales\\Model\\Resource\\Report\\Order')->willReturn($this->order);
     $this->resultRedirect->expects($this->once())->method('setPath')->with($path)->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->refreshStatisticsController->execute());
 }
Ejemplo n.º 5
0
 /**
  * @param string $exceptionType
  * @return void
  * @dataProvider exceptionTypeDataProvider
  */
 public function testExecuteSetsProductDataToSessionAndRedirectsToNewActionOnError($exceptionType)
 {
     $productData = ['product' => ['name' => 'test-name']];
     $this->request->expects($this->any())->method('getPostValue')->willReturn($productData);
     $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($this->product);
     $this->product->expects($this->any())->method('getSku')->willThrowException(new $exceptionType(__('message')));
     $this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/new');
     $this->action->execute();
 }
Ejemplo n.º 6
0
 public function testExecuteEmptyQuery()
 {
     $url = 'some url';
     $searchString = '';
     $this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString));
     $this->url->expects($this->once())->method('getBaseUrl')->willReturn($url);
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }
Ejemplo n.º 7
0
 public function testExecute()
 {
     $ids = [1, 2];
     $this->request->expects($this->once())->method('getParam')->with('search')->will($this->returnValue($ids));
     $this->createQuery(0, 1);
     $this->createQuery(1, 2);
     $this->messageManager->expects($this->once())->method('addSuccess')->will($this->returnSelf());
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('search/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->controller->execute());
 }
Ejemplo n.º 8
0
 public function testEditActionBlockNoExists()
 {
     $blockId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with('block_id')->willReturn($blockId);
     $this->blockMock->expects($this->once())->method('load')->with($blockId);
     $this->blockMock->expects($this->once())->method('getId')->willReturn(null);
     $this->messageManagerMock->expects($this->once())->method('addError')->with(__('This block no longer exists.'));
     $this->resultRedirectFactoryMock->expects($this->atLeastOnce())->method('create')->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*/')->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->editController->execute());
 }
Ejemplo n.º 9
0
 public function testDelete()
 {
     $categoryId = 5;
     $parentId = 7;
     $this->request->expects($this->any())->method('getParam')->with('id')->willReturn($categoryId);
     $category = $this->getMock('Magento\\Catalog\\Model\\Category', ['getParentId', 'getPath'], [], '', false);
     $category->expects($this->once())->method('getParentId')->willReturn($parentId);
     $category->expects($this->once())->method('getPath')->willReturn('category-path');
     $this->categoryRepository->expects($this->once())->method('get')->with($categoryId)->willReturn($category);
     $this->authStorage->expects($this->once())->method('setDeletedPath')->with('category-path');
     $this->resultRedirect->expects($this->once())->method('setPath')->with('catalog/*/', ['_current' => true, 'id' => $parentId]);
     $this->unit->execute();
 }
Ejemplo n.º 10
0
 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());
 }
Ejemplo n.º 11
0
    /**
     * @return void
     */
    public function testExecute()
    {
        $creditmemoId = '111';

        $this->requestMock->expects($this->once())
            ->method('getParam')
            ->with('creditmemo_id')
            ->willReturn($creditmemoId);
        $this->objectManagerMock->expects($this->once())
            ->method('create')
            ->with('Magento\Sales\Api\CreditmemoManagementInterface')
            ->willReturn($this->creditmemoManagementMock);
        $this->creditmemoManagementMock->expects($this->once())
            ->method('cancel')
            ->with($creditmemoId);
        $this->messageManagerMock->expects($this->once())
            ->method('addSuccess')
            ->with('The credit memo has been canceled.');
        $this->resultRedirectFactoryMock->expects($this->once())
            ->method('create')
            ->willReturn($this->resultRedirectMock);
        $this->resultRedirectMock->expects($this->once())
            ->method('setPath')
            ->with('sales/*/view', ['creditmemo_id' => $creditmemoId])
            ->willReturnSelf();

        $this->assertInstanceOf(
            'Magento\Backend\Model\View\Result\Redirect',
            $this->controller->executeInternal()
        );
    }
Ejemplo n.º 12
0
    public function testEmailNoOrderId()
    {
        $this->request->expects($this->once())
            ->method('getParam')
            ->with('order_id')
            ->will($this->returnValue(null));
        $this->orderRepositoryMock->expects($this->once())
            ->method('get')
            ->with(null)
            ->willThrowException(
                new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist'))
            );
        $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->executeInternal()
        );
    }
 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->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId);
     $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
     $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('update');
     $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true);
     $this->messageManagerMock->expects($this->once())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf();
     $result = $this->reviewPayment->execute();
     $this->assertEquals($this->resultRedirectMock, $result);
 }
Ejemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function renderResult(\Magento\Framework\App\ResponseInterface $response)
 {
     $pluginInfo = $this->pluginList->getNext($this->subjectType, 'renderResult');
     if (!$pluginInfo) {
         return parent::renderResult($response);
     } else {
         return $this->___callPlugins('renderResult', func_get_args(), $pluginInfo);
     }
 }
Ejemplo n.º 15
0
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'))->will($this->returnValue($customerId));
     $this->authenticationMock->expects($this->once())->method('unlock')->with($customerId);
     $this->messageManagerMock->expects($this->once())->method('addSuccess');
     $this->redirectMock->expects($this->once())->method('setPath')->with($this->equalTo('customer/index/edit'))->willReturnSelf();
     $this->assertInstanceOf('\\Magento\\Backend\\Model\\View\\Result\\Redirect', $this->controller->execute());
 }
Ejemplo n.º 16
0
 public function testExecute()
 {
     $customersIds = [10, 11, 12];
     $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
     $this->customerRepositoryMock->expects($this->any())->method('deleteById')->willReturnMap([[10, true], [11, true], [12, true]]);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('A total of %1 record(s) were deleted.', count($customersIds)));
     $this->resultRedirectMock->expects($this->any())->method('setPath')->with('customer/*/index')->willReturnSelf();
     $this->massAction->execute();
 }
Ejemplo n.º 17
0
 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);
 }
Ejemplo n.º 18
0
 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());
 }
Ejemplo n.º 19
0
 /**
  * @param int $cmId
  */
 protected function prepareRedirect($cmId)
 {
     $this->resultRedirectFactoryMock->expects($this->once())
         ->method('create')
         ->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())
         ->method('setPath')
         ->with('sales/order_creditmemo/view', ['creditmemo_id' => $cmId])
         ->willReturnSelf();
 }
 public function testExecute()
 {
     $customersIds = [10, 11, 12];
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMockForAbstractClass();
     $this->customerCollectionMock->expects($this->any())->method('getAllIds')->willReturn($customersIds);
     $this->customerRepositoryMock->expects($this->any())->method('getById')->willReturnMap([[10, $customerMock], [11, $customerMock], [12, $customerMock]]);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('A total of %1 record(s) were updated.', count($customersIds)));
     $this->resultRedirectMock->expects($this->any())->method('setPath')->with('customer/*/index')->willReturnSelf();
     $this->massAction->execute();
 }
Ejemplo n.º 21
0
    public function testEmail()
    {
        $invoiceId = 10000031;
        $orderId = 100000030;
        $invoiceClassName = 'Magento\Sales\Model\Order\Invoice';
        $cmNotifierClassName = 'Magento\Sales\Api\InvoiceManagementInterface';
        $invoice = $this->getMock($invoiceClassName, [], [], '', false);
        $invoice->expects($this->once())
            ->method('getEntityId')
            ->willReturn($invoiceId);
        $order = $this->getMock('Magento\Sales\Model\Order', [], [], '', false);
        $order->expects($this->once())
            ->method('getId')
            ->willReturn($orderId);

        $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($invoice);
        $this->objectManager->expects($this->at(0))
            ->method('create')
            ->with('Magento\Sales\Api\InvoiceRepositoryInterface')
            ->willReturn($invoiceRepository);

        $invoice->expects($this->once())
            ->method('getOrder')
            ->willReturn($order);
        $this->objectManager->expects($this->at(1))
            ->method('create')
            ->with($cmNotifierClassName)
            ->willReturn($this->invoiceManagement);

        $this->invoiceManagement->expects($this->once())
            ->method('notify')
            ->with($invoiceId)
            ->willReturn(true);
        $this->messageManager->expects($this->once())
            ->method('addSuccess')
            ->with('You sent the message.');

        $this->resultRedirectFactory->expects($this->atLeastOnce())
            ->method('create')
            ->willReturn($this->resultRedirect);
        $this->resultRedirect->expects($this->once())
            ->method('setPath')
            ->with('sales/invoice/view', ['order_id' => $orderId, 'invoice_id' => $invoiceId])
            ->willReturnSelf();
        $this->assertInstanceOf('Magento\Backend\Model\View\Result\Redirect', $this->invoiceEmail->executeInternal());
    }
Ejemplo n.º 22
0
 /**
  * @covers \Magento\Backup\Controller\Adminhtml\Index\Download::execute
  * @param int $time
  * @param bool $exists
  * @param int $existsCount
  * @dataProvider executeBackupNotFoundDataProvider
  */
 public function testExecuteBackupNotFound($time, $exists, $existsCount)
 {
     $type = 'db';
     $this->backupModelMock->expects($this->atLeastOnce())->method('getTime')->willReturn($time);
     $this->backupModelMock->expects($this->exactly($existsCount))->method('exists')->willReturn($exists);
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['time', null, $time], ['type', null, $type]]);
     $this->backupModelFactoryMock->expects($this->once())->method('create')->with($time, $type)->willReturn($this->backupModelMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('backup/*');
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->assertSame($this->resultRedirectMock, $this->downloadController->execute());
 }
 /**
  * @return void
  */
 public function testExecute()
 {
     $customerId = 1;
     $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo('customer_id'))->will($this->returnValue($customerId));
     $this->customerRepositoryMock->expects($this->once())->method('getById')->with($customerId)->willReturn($this->customerDataMock);
     $this->accountManagementHelperMock->expects($this->once())->method('processUnlockData')->with($customerId);
     $this->customerRepositoryMock->expects($this->once())->method('save')->with($this->customerDataMock);
     $this->messageManagerMock->expects($this->once())->method('addSuccess');
     $this->redirectMock->expects($this->once())->method('setPath')->with($this->equalTo('customer/index/edit'))->willReturnSelf();
     $this->assertInstanceOf('\\Magento\\Backend\\Model\\View\\Result\\Redirect', $this->controller->execute());
 }
Ejemplo n.º 24
0
 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());
 }
Ejemplo n.º 25
0
 public function testExecuteException()
 {
     $queryId = 1;
     $queryText = 'search';
     $this->mockGetRequestData($queryText, $queryId);
     $this->request->expects($this->at(4))->method('getPost')->with('store_id', false)->willReturn(1);
     $this->query->expects($this->once())->method('setStoreId');
     $this->query->expects($this->once())->method('loadByQueryText')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addException');
     $this->session->expects($this->once())->method('setPageData');
     $this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
     $this->assertSame($this->redirect, $this->controller->execute());
 }
Ejemplo n.º 26
0
 public function testExecuteNoReleasedOrderFromHold()
 {
     $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orders = [$order1, $order2];
     $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn($orders);
     $order1->expects($this->once())->method('canUnhold')->willReturn(false);
     $this->orderCollectionMock->expects($this->once())->method('count')->willReturn(count($orders));
     $order2->expects($this->once())->method('canUnhold')->willReturn(false);
     $this->messageManagerMock->expects($this->once())->method('addError')->with('No order(s) were released from on hold status.');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->massAction->execute();
 }
Ejemplo n.º 27
0
 /**
  * @param string $path
  * @param array $arguments
  * @param int $index
  */
 protected function prepareRedirect($path, $arguments, $index)
 {
     $this->actionFlag->expects($this->any())
         ->method('get')
         ->with('', 'check_url_settings')
         ->will($this->returnValue(true));
     $this->session->expects($this->any())
         ->method('setIsUrlNotice')
         ->with(true);
     $this->resultRedirect->expects($this->at($index))
         ->method('setPath')
         ->with($path, ['shipment_id' => $arguments['shipment_id']]);
 }
Ejemplo n.º 28
0
 public function testExecute()
 {
     $data = ['new_attribute_set_name' => 'Test attribute set name', 'frontend_input' => 'test_frontend_input'];
     $this->requestMock->expects($this->once())->method('getPostValue')->willReturn($data);
     $this->resultFactoryMock->expects($this->once())->method('create')->willReturn($this->redirectMock);
     $this->redirectMock->expects($this->any())->method('setPath')->willReturnSelf();
     $this->builderMock->expects($this->once())->method('setEntityTypeId')->willReturnSelf();
     $this->builderMock->expects($this->once())->method('setSkeletonId')->willReturnSelf();
     $this->builderMock->expects($this->once())->method('setName')->willReturnSelf();
     $this->builderMock->expects($this->once())->method('getAttributeSet')->willReturn($this->attributeSetMock);
     $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['set', null, 1], ['attribute_code', null, 'test_attribute_code']]);
     $this->inputTypeValidatorMock->expects($this->once())->method('getMessages')->willReturn([]);
     $this->assertInstanceOf(ResultRedirect::class, $this->getModel()->execute());
 }
Ejemplo n.º 29
0
 /**
  * Test for excluded orders
  * Two orders could't be canceled
  */
 public function testExcludedCannotCancelOrders()
 {
     $order1 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $order2 = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $orders = [$order1, $order2];
     $countOrders = count($orders);
     $this->orderCollectionMock->expects($this->any())->method('getItems')->willReturn([$order1, $order2]);
     $order1->expects($this->once())->method('canCancel')->willReturn(false);
     $this->orderCollectionMock->expects($this->once())->method('count')->willReturn($countOrders);
     $order2->expects($this->once())->method('canCancel')->willReturn(false);
     $this->messageManagerMock->expects($this->once())->method('addError')->with('You cannot cancel the order(s).');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/')->willReturnSelf();
     $this->massAction->execute();
 }
Ejemplo n.º 30
0
 /**
  * Test saveAction when was credit memo total is not positive
  */
 public function testSaveActionWithNegativeCreditmemo()
 {
     $data = ['comment_text' => ''];
     $this->_requestMock->expects($this->once())->method('getPost')->with('creditmemo')->will($this->returnValue($data));
     $this->_requestMock->expects($this->any())->method('getParam')->will($this->returnValue(null));
     $creditmemoMock = $this->getMock('Magento\\Sales\\Model\\Order\\Creditmemo', ['load', 'getGrandTotal', 'getAllowZeroGrandTotal', '__wakeup'], [], '', false);
     $creditmemoMock->expects($this->once())->method('getGrandTotal')->will($this->returnValue('0'));
     $creditmemoMock->expects($this->once())->method('getAllowZeroGrandTotal')->will($this->returnValue(false));
     $this->memoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($creditmemoMock));
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/*/new', ['_current' => true])->willReturnSelf();
     $this->_setSaveActionExpectationForMageCoreException($data, 'The credit memo\'s total must be positive.');
     $this->_controller->execute();
 }