/**
  * @dataProvider logDataProvider
  */
 public function testLog($logLevel, $method)
 {
     $message = 'Error message';
     $this->request->expects($this->once())->method('getRequestUri')->willReturn($this->requestUri);
     $this->psrLogger->expects($this->once())->method($method)->with($message . ' ' . $this->requestUri);
     $this->logger->log($message, $logLevel);
 }
Example #2
0
 public function testDispatchPostDispatch()
 {
     $this->_requestMock->expects($this->exactly(3))->method('getFullActionName')->will($this->returnValue(self::FULL_ACTION_NAME));
     $this->_requestMock->expects($this->exactly(2))->method('getRouteName')->will($this->returnValue(self::ROUTE_NAME));
     $expectedEventParameters = ['controller_action' => $this->action, 'request' => $this->_requestMock];
     $this->_eventManagerMock->expects($this->at(0))->method('dispatch')->with('controller_action_predispatch', $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(1))->method('dispatch')->with('controller_action_predispatch_' . self::ROUTE_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(2))->method('dispatch')->with('controller_action_predispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
     $this->_requestMock->expects($this->once())->method('isDispatched')->will($this->returnValue(true));
     $this->_actionFlagMock->expects($this->at(0))->method('get')->with('', Action::FLAG_NO_DISPATCH)->will($this->returnValue(false));
     // _forward expectations
     $this->_requestMock->expects($this->once())->method('initForward');
     $this->_requestMock->expects($this->once())->method('setParams')->with(self::$actionParams);
     $this->_requestMock->expects($this->once())->method('setControllerName')->with(self::CONTROLLER_NAME);
     $this->_requestMock->expects($this->once())->method('setModuleName')->with(self::MODULE_NAME);
     $this->_requestMock->expects($this->once())->method('setActionName')->with(self::ACTION_NAME);
     $this->_requestMock->expects($this->once())->method('setDispatched')->with(false);
     // _redirect expectations
     $this->_redirectMock->expects($this->once())->method('redirect')->with($this->_responseMock, self::FULL_ACTION_NAME, self::$actionParams);
     $this->_actionFlagMock->expects($this->at(1))->method('get')->with('', Action::FLAG_NO_POST_DISPATCH)->will($this->returnValue(false));
     $this->_eventManagerMock->expects($this->at(3))->method('dispatch')->with('controller_action_postdispatch_' . self::FULL_ACTION_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(4))->method('dispatch')->with('controller_action_postdispatch_' . self::ROUTE_NAME, $expectedEventParameters);
     $this->_eventManagerMock->expects($this->at(5))->method('dispatch')->with('controller_action_postdispatch', $expectedEventParameters);
     $this->assertEquals($this->_responseMock, $this->action->dispatch($this->_requestMock));
 }
 protected function setUp()
 {
     $orderId = 1;
     $shipmentId = 1;
     $shipment = [];
     $tracking = [];
     $this->shipmentLoaderMock = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false);
     $this->requestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface');
     $this->responseMock = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $this->sessionMock = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
     $this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false);
     $this->shipmentMock = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['__wakeup'], [], '', false);
     $this->fileFactoryMock = $this->getMock('Magento\\Framework\\App\\Response\\Http\\FileFactory', ['create'], [], '', false);
     $contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getObjectManager', 'getResponse', 'getSession', 'getActionFlag'], [], '', false);
     $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock));
     $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock));
     $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->responseMock));
     $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->sessionMock));
     $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($this->actionFlag));
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
     $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
     $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
     $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
     $this->controller = new \Magento\Shipping\Controller\Adminhtml\Order\Shipment\PrintPackage($contextMock, $this->shipmentLoaderMock, $this->fileFactoryMock);
 }
Example #4
0
 /**
  * Run test execute method
  */
 public function testExecute()
 {
     $orderId = 1;
     $shipmentId = 1;
     $shipment = [];
     $tracking = [];
     $result = 'result-html';
     $layoutMock = $this->getMock('Magento\\Framework\\View\\Layout', ['createBlock'], [], '', false);
     $gridMock = $this->getMock('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid', ['setIndex', 'toHtml'], [], '', false);
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
     $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
     $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
     $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
     $this->shipmentLoaderMock->expects($this->once())->method('load');
     $layoutMock->expects($this->once())->method('createBlock')->with('Magento\\Shipping\\Block\\Adminhtml\\Order\\Packaging\\Grid')->will($this->returnValue($gridMock));
     $this->viewMock->expects($this->once())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->responseMock->expects($this->once())->method('setBody')->with($result)->will($this->returnSelf());
     $this->requestMock->expects($this->at(4))->method('getParam')->with('index');
     $gridMock->expects($this->once())->method('setIndex')->will($this->returnSelf());
     $gridMock->expects($this->once())->method('toHtml')->will($this->returnValue($result));
     $this->assertNotEmpty('result-html', $this->controller->execute());
 }
Example #5
0
    /**
     * @dataProvider processProvider
     * @param bool $isPost
     */
    public function testProcess($isPost)
    {
        $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
        if ($isPost) {
            $publicCookieMetadataMock = $this->getMock('Magento\Framework\Stdlib\Cookie\PublicCookieMetadata');
            $publicCookieMetadataMock->expects($this->once())
                ->method('setPath')
                ->with('/')
                ->will($this->returnSelf());

            $publicCookieMetadataMock->expects($this->once())
                ->method('setDuration')
                ->with(Version::COOKIE_PERIOD)
                ->will($this->returnSelf());

            $publicCookieMetadataMock->expects($this->once())
                ->method('setHttpOnly')
                ->with(false)
                ->will($this->returnSelf());

            $this->cookieMetadataFactoryMock->expects($this->once())
                ->method('createPublicCookieMetadata')
                ->with()
                ->will(
                    $this->returnValue($publicCookieMetadataMock)
                );

            $this->cookieManagerMock->expects($this->once())
                ->method('setPublicCookie');
        }
        $this->version->process();
    }
Example #6
0
 /**
  * @dataProvider processProvider
  * @param bool $isPost
  */
 public function testProcess($isPost)
 {
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     if ($isPost) {
         $this->cookieMock->expects($this->once())->method('set');
     }
     $this->version->process();
 }
 /**
  * @param string $userAgent
  * @param bool $useConfig
  * @param bool|string $result
  * @param array $expressions
  * @dataProvider getThemeByRequestDataProvider
  */
 public function testGetThemeByRequest($userAgent, $useConfig, $result, $expressions = [])
 {
     $this->requestMock->expects($this->once())->method('getServer')->with($this->equalTo('HTTP_USER_AGENT'))->will($this->returnValue($userAgent));
     if ($useConfig) {
         $this->scopeConfigMock->expects($this->once())->method('getValue')->with($this->equalTo($this->exceptionConfigPath), $this->equalTo($this->scopeType))->will($this->returnValue(serialize($expressions)));
     }
     $this->assertSame($result, $this->designExceptions->getThemeByRequest($this->requestMock));
 }
 public function testGetScopeTitleDefault()
 {
     $scope = 'default';
     $scopeId = 0;
     $scopeTypeName = 'Default';
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->assertEquals($scopeTypeName, $this->block->getScopeTitle()->render());
 }
 /**
  * @param bool $isSecure
  * @dataProvider getViewFileUrlDataProvider
  */
 public function testGetViewFileUrl($isSecure)
 {
     $this->request->expects($this->once())->method('isSecure')->will($this->returnValue($isSecure));
     $this->assetRepo->expects($this->once())->method('getUrlWithParams')->with('some file', $this->callback(function ($value) use($isSecure) {
         return isset($value['_secure']) && $value['_secure'] === $isSecure;
     }))->will($this->returnValue('result url'));
     $this->assertEquals('result url', $this->model->getViewFileUrl('some file'));
 }
 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());
 }
Example #11
0
 /**
  * @param boolean $clean
  * @param string $expectedValue
  *
  * @dataProvider getRequestUriDataProvider
  */
 public function testGetRequestUri($clean, $expectedValue)
 {
     $this->_request->expects($this->once())->method('getRequestUri')->will($this->returnValue('value'));
     $this->_prepareCleanString($clean);
     $headerObject = $this->_objectManager->getObject('Magento\\Framework\\HTTP\\Header', ['httpRequest' => $this->_request, 'converter' => $this->_converter]);
     $result = $headerObject->getRequestUri($clean);
     $this->assertEquals($expectedValue, $result);
 }
Example #12
0
 public function testPathDifferentiator()
 {
     $this->requestMock->method('isSecure')->willReturn(true);
     $this->requestMock->expects($this->at(1))->method('getUriString')->willReturn('http://example.com/path/');
     $this->requestMock->expects($this->at(4))->method('getUriString')->willReturn('http://example.com/path1/');
     $this->contextMock->method('getVaryString')->willReturn(self::VARY);
     $valuePath1 = $this->model->getValue();
     $valuePath2 = $this->model->getValue();
     $this->assertNotEquals($valuePath1, $valuePath2);
 }
Example #13
0
 public function testExecuteWithWishlist()
 {
     $wishlist = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock();
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->willReturn($wishlist);
     $this->request->expects($this->once())->method('getParam')->with('qty')->will($this->returnValue(2));
     $this->itemCarrier->expects($this->once())->method('moveAllToCart')->with($wishlist, 2)->will($this->returnValue('http://redirect-url.com'));
     $this->response->expects($this->once())->method('setRedirect')->will($this->returnValue('http://redirect-url.com'));
     $controller = $this->getController();
     $controller->execute();
 }
Example #14
0
 public function testExecutePageDirectAccess()
 {
     $this->request->expects($this->any())->method('getParam')->with('filters')->willReturn(null);
     $this->request->expects($this->any())->method('getParams')->willReturn([]);
     $this->attributeHelper->expects($this->any())->method('getProductIds')->willReturn(null);
     $resultRedirect = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->setMethods(['setPath'])->disableOriginalConstructor()->getMock();
     $resultRedirect->expects($this->any())->method('setPath')->with('catalog/product/', ['_current' => true])->willReturnSelf();
     $this->resultRedirectFactory->expects($this->any())->method('create')->willReturn($resultRedirect);
     $this->assertSame($resultRedirect, $this->object->execute());
 }
 public function testExecuteWithWishlist()
 {
     $url = 'http://redirect-url.com';
     $quantity = 2;
     $this->wishlistProviderMock->expects($this->once())->method('getWishlist')->willReturn($this->wishlistMock);
     $this->requestMock->expects($this->any())->method('getParam')->with('qty')->willReturn($quantity);
     $this->itemCarrierMock->expects($this->once())->method('moveAllToCart')->with($this->wishlistMock, 2)->willReturn($url);
     $this->resultRedirectMock->expects($this->once())->method('setUrl')->with($url)->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->allcartController->execute());
 }
 /**
  * @param bool $isPost
  * @param int $numOfCalls
  * @dataProvider afterDispatchTestDataProvider
  */
 public function testAfterDispatch($isPost, $numOfCalls)
 {
     $this->messageManagerMock->expects($this->exactly($numOfCalls))->method('hasMessages')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue($isPost));
     $this->cookieMetadataFactoryMock->expects($this->exactly($numOfCalls))->method('createPublicCookieMetadata')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setDuration')->with(MessageBox::COOKIE_PERIOD)->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setPath')->with('/')->will($this->returnValue($this->publicCookieMetadataMock));
     $this->publicCookieMetadataMock->expects($this->exactly($numOfCalls))->method('setHttpOnly')->with(false)->will($this->returnValue($this->publicCookieMetadataMock));
     $this->cookieManagerMock->expects($this->exactly($numOfCalls))->method('setPublicCookie')->with(MessageBox::COOKIE_NAME, 1, $this->publicCookieMetadataMock);
     $this->assertSame($this->responseMock, $this->msgBox->afterDispatch($this->objectMock, $this->responseMock));
 }
 public function testProcessNoDefault()
 {
     // Default path from config
     $this->configMock->expects($this->once())->method('getValue')->with('web/default/no_route', 'default')->willReturn(null);
     // Set expectations
     $this->requestMock->expects($this->once())->method('setModuleName')->with('core')->willReturnSelf();
     $this->requestMock->expects($this->once())->method('setControllerName')->with('index')->willReturnSelf();
     $this->requestMock->expects($this->once())->method('setActionName')->with('index')->willReturnSelf();
     // Test
     $this->assertTrue($this->model->process($this->requestMock));
 }
 /**
  * @dataProvider dataForTest
  */
 public function testBeforeGetImage($expected)
 {
     $this->productMock->expects($this->once())->method('getTypeId')->willReturn('configurable');
     $this->requestMock->expects($this->once())->method('getParams')->willReturn($expected['getParams']);
     $this->getFilterArray($expected);
     $this->canReplaceImageWithSwatch($expected);
     $this->swatchesHelperMock->expects($this->exactly($expected['loadVariationByFallback_count']))->method('loadVariationByFallback')->willReturn($expected['product']);
     $productImageMock = $this->getMock('Magento\\Catalog\\Block\\Product\\AbstractProduct', [], [], '', false);
     $result = $this->pluginModel->beforeGetImage($productImageMock, $this->productMock, $expected['page_handle']);
     $this->assertEquals([$this->productMock, $expected['page_handle'], []], $result);
 }
Example #19
0
 /**
  * Executes the controller action and asserts non exception logic
  */
 public function testExecuteLocalizedException()
 {
     $phrase = new \Magento\Framework\Phrase('Something went wrong while processing.');
     $objectManager = new ObjectManager($this);
     $this->vault->expects($this->once())->method('generatePaymentMethodToken')->willThrowException(new LocalizedException($phrase));
     $this->resultJson->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => 'Something went wrong while processing.']);
     $this->resultFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $this->messageManager->expects($this->once())->method('addError')->with($phrase);
     $this->request->expects($this->any())->method('getParam')->willReturn(true);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Generate', ['request' => $this->request, 'resultFactory' => $this->resultFactory, 'vault' => $this->vault, 'messageManager' => $this->messageManager]);
     $this->assertSame($this->resultJson, $notification->execute());
 }
 /**
  * @param array $requestResult
  * @param bool $moduleManagerResult
  * @param bool $cacheConfigResult
  * @param bool $layoutResult
  * @param bool $can Depersonalize
  * @dataProvider checkIfDepersonalizeDataProvider
  */
 public function testCheckIfDepersonalize(array $requestResult, $moduleManagerResult, $cacheConfigResult, $layoutResult, $canDepersonalize)
 {
     $this->requestMock->expects($this->any())->method('isAjax')->willReturn($requestResult['ajax']);
     $this->requestMock->expects($this->any())->method('isGet')->willReturn($requestResult['get']);
     $this->requestMock->expects($this->any())->method('isHead')->willReturn($requestResult['head']);
     $this->moduleManagerMock->expects($this->any())->method('isEnabled')->with('Magento_PageCache')->willReturn($moduleManagerResult);
     $this->cacheConfigMock->expects($this->any())->method('isEnabled')->willReturn($cacheConfigResult);
     $layoutMock = $this->getMockForAbstractClass('Magento\\Framework\\View\\LayoutInterface', [], '', false);
     $layoutMock->expects($this->any())->method('isCacheable')->willReturn($layoutResult);
     $object = new DepersonalizeChecker($this->requestMock, $this->moduleManagerMock, $this->cacheConfigMock);
     $this->assertEquals($canDepersonalize, $object->checkIfDepersonalize($layoutMock));
 }
 /**
  * @param string $scope
  * @param string $scopeId
  * @param string $showFallbackReset
  * @dataProvider dataProviderGetData
  */
 public function testGetData($scope, $scopeId, $showFallbackReset)
 {
     $this->request->expects($this->exactly(2))->method('getParam')->willReturnMap([['scope', null, $scope], ['scope_id', null, $scopeId]]);
     $this->scopeFallbackResolver->expects($this->atLeastOnce())->method('getFallbackScope')->with($scope, $scopeId)->willReturn([$scope, $scopeId]);
     $this->storeManager->expects($this->once())->method('isSingleStoreMode')->willReturn(false);
     $this->designConfigRepository->expects($this->once())->method('getByScope')->with($scope, $scopeId)->willReturn($this->designConfig);
     $this->designConfig->expects($this->once())->method('getExtensionAttributes')->willReturn($this->designConfigExtension);
     $this->designConfigExtension->expects($this->once())->method('getDesignConfigData')->willReturn([$this->designConfigData]);
     $this->designConfigData->expects($this->atLeastOnce())->method('getFieldConfig')->willReturn(['field' => 'field', 'fieldset' => 'fieldset1']);
     $this->designConfigData->expects($this->once())->method('getValue')->willReturn('value');
     $result = $this->model->getData();
     $expected = ['fieldset1' => ['children' => ['field' => ['arguments' => ['data' => ['config' => ['default' => 'value', 'showFallbackReset' => $showFallbackReset]]]]]]];
     $this->assertEquals($expected, $result);
 }
 /**
  * @return void
  */
 public function testBeforeExecute()
 {
     $logoutReasonCode = 2;
     $uri = '/uri/';
     $errorMessage = 'Error Message';
     $this->securityCookieHelperMock->expects($this->once())->method('getLogoutReasonCookie')->willReturn($logoutReasonCode);
     $this->backendControllerAuthLoginMock->expects($this->once())->method('getRequest')->willReturn($this->requestMock);
     $this->requestMock->expects($this->once())->method('getUri')->willReturn($uri);
     $this->backendControllerAuthLoginMock->expects($this->once())->method('getUrl')->willReturn($uri);
     $this->adminSessionsManagerMock->expects($this->once())->method('getLogoutReasonMessageByStatus')->with($logoutReasonCode)->willReturn($errorMessage);
     $this->messageManagerMock->expects($this->once())->method('addError')->with($errorMessage);
     $this->securityCookieHelperMock->expects($this->once())->method('deleteLogoutReasonCookie')->willReturnSelf();
     $this->controller->beforeExecute($this->backendControllerAuthLoginMock);
 }
Example #23
0
 /**
  * Executes the controller action
  */
 public function testExecute()
 {
     $objectManager = new ObjectManagerHelper($this);
     $phrase = new \Magento\Framework\Phrase('There was error during saving card data');
     $this->request->expects($this->any())->method('getParam')->willReturn('token');
     $this->resultRedirectFactory->expects($this->once())->method('create')->willReturn($this->resultRedirect);
     $this->resultRedirect->expects($this->once())->method('setPath')->willReturnSelf();
     /**
      * @var \Magento\Framework\Message\ManagerInterface $messageManager
      */
     $messageManager = $this->getMockBuilder('\\Magento\\Framework\\Message\\ManagerInterface')->getMock();
     $messageManager->expects($this->once())->method('addError')->with($phrase);
     $notification = $objectManager->getObject('Magento\\Braintree\\Controller\\Creditcard\\Save', ['request' => $this->request, 'resultRedirectFactory' => $this->resultRedirectFactory, 'messageManager' => $messageManager]);
     $this->assertSame($this->resultRedirect, $notification->execute());
 }
Example #24
0
 /**
  * Check if validation throws a localized catched exception in case of incorrect id
  */
 public function testExecuteException()
 {
     $taxRateId = 999;
     $exceptionMessage = __('An error occurred while loading this tax rate.');
     $noSuchEntityEx = new \Exception();
     $objectManager = new ObjectManager($this);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValue($taxRateId));
     $this->taxRateRepository->expects($this->any())->method('get')->with($taxRateId)->willThrowException($noSuchEntityEx);
     $jsonObject = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock();
     $jsonObject->expects($this->once())->method('setData')->with(['success' => false, 'error_message' => $exceptionMessage]);
     $this->resultFactory->expects($this->any())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->willReturn($jsonObject);
     $notification = $objectManager->getObject('Magento\\Tax\\Controller\\Adminhtml\\Rate\\AjaxLoad', ['taxRateRepository' => $this->taxRateRepository, 'request' => $this->request, 'resultFactory' => $this->resultFactory]);
     //exception thrown with catch
     $this->assertSame($jsonObject, $notification->execute());
 }
 public function testExecute()
 {
     $this->_getTreeBlock();
     $testCategoryId = 1;
     $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue($testCategoryId));
     $categoryMock = $this->getMock('Magento\\Catalog\\Model\\Category', [], [], '', false);
     $categoryMock->expects($this->once())->method('load')->will($this->returnValue($categoryMock));
     $categoryMock->expects($this->once())->method('getId')->will($this->returnValue($testCategoryId));
     $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Catalog\\Model\\Category'))->will($this->returnValue($categoryMock));
     $this->chooserBlockMock->expects($this->once())->method('setSelectedCategories')->will($this->returnValue($this->chooserBlockMock));
     $testHtml = '<div>Some test html</div>';
     $this->chooserBlockMock->expects($this->once())->method('getTreeJson')->will($this->returnValue($testHtml));
     $this->resultJson->expects($this->once())->method('setJsonData')->with($testHtml)->willReturnSelf();
     $this->controller->execute();
 }
Example #26
0
 /**
  * Load shipment object
  *
  * @return void
  */
 protected function loadShipment()
 {
     $orderId = 1;
     $shipmentId = 1;
     $shipment = [];
     $tracking = [];
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->requestMock->expects($this->at(1))->method('getParam')->with('shipment_id')->will($this->returnValue($shipmentId));
     $this->requestMock->expects($this->at(2))->method('getParam')->with('shipment')->will($this->returnValue($shipment));
     $this->requestMock->expects($this->at(3))->method('getParam')->with('tracking')->will($this->returnValue($tracking));
     $this->shipmentLoaderMock->expects($this->once())->method('setOrderId')->with($orderId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoaderMock->expects($this->once())->method('setShipment')->with($shipment);
     $this->shipmentLoaderMock->expects($this->once())->method('setTracking')->with($tracking);
 }
 /**
  * Test execute add success critical exception
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecuteAddSuccessCriticalException()
 {
     $wishlist = $this->getMock('Magento\\Wishlist\\Model\\Wishlist', [], [], '', false);
     $product = $this->getMock('Magento\\Catalog\\Model\\Product', [], [], '', false);
     $item = $this->getMock('Magento\\Wishlist\\Model\\Item', [], [], '', false);
     $helper = $this->getMock('Magento\\Wishlist\\Helper\\Data', [], [], '', false);
     $logger = $this->getMock('Magento\\Framework\\Logger\\Monolog', [], [], '', false);
     $exception = new \Exception();
     $logger->expects($this->once())->method('critical')->with($exception)->willReturn(true);
     $helper->expects($this->exactly(2))->method('calculate')->willReturn(true);
     $wishlist->expects($this->once())->method('getItem')->with(3)->willReturn($item);
     $wishlist->expects($this->once())->method('updateItem')->with(3, new \Magento\Framework\DataObject([]))->willReturnSelf();
     $wishlist->expects($this->once())->method('save')->willReturn(null);
     $wishlist->expects($this->once())->method('getId')->willReturn(56);
     $product->expects($this->once())->method('isVisibleInCatalog')->willReturn(true);
     $product->expects($this->once())->method('getName')->willReturn('Test name');
     $this->request->expects($this->at(0))->method('getParam')->with('product', null)->willReturn(2);
     $this->request->expects($this->at(1))->method('getParam')->with('id', null)->willReturn(3);
     $this->productRepository->expects($this->once())->method('getById')->with(2)->willReturn($product);
     $item->expects($this->once())->method('load')->with(3)->willReturnSelf();
     $item->expects($this->once())->method('__call')->with('getWishlistId')->willReturn(12);
     $this->wishlistProvider->expects($this->once())->method('getWishlist')->with(12)->willReturn($wishlist);
     $this->om->expects($this->once())->method('create')->with('Magento\\Wishlist\\Model\\Item')->willReturn($item);
     $this->request->expects($this->once())->method('getParams')->willReturn([]);
     $this->om->expects($this->at(1))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(2))->method('get')->with('Magento\\Wishlist\\Helper\\Data')->willReturn($helper);
     $this->om->expects($this->at(3))->method('get')->with('Psr\\Log\\LoggerInterface')->willReturn($logger);
     $this->eventManager->expects($this->once())->method('dispatch')->with('wishlist_update_item', ['wishlist' => $wishlist, 'product' => $product, 'item' => $item])->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('Test name has been updated in your Wish List.', null)->willThrowException($exception);
     $this->messageManager->expects($this->once())->method('addError')->with('We can\'t update your Wish List right now.', null)->willReturn(true);
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('*/*', ['wishlist_id' => 56])->willReturnSelf();
     $this->assertSame($this->resultRedirectMock, $this->getController()->execute());
 }
 /**
  * Set up
  */
 public function setUp()
 {
     $this->sessionMock = $this->getMock('Magento\\Framework\\Session\\Generic', ['getCurrencyCode'], [], '', false);
     $this->httpContextMock = $this->getMock('Magento\\Framework\\App\\Http\\Context', [], [], '', false);
     $this->httpRequestMock = $this->getMock('Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false);
     $this->storeManager = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->storeCookieManager = $this->getMock('Magento\\Store\\Api\\StoreCookieManagerInterface');
     $this->storeMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->currentStoreMock = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $this->websiteMock = $this->getMock('Magento\\Store\\Model\\Website', ['getDefaultStore', '__wakeup'], [], '', false);
     $this->closureMock = function () {
         return 'ExpectedValue';
     };
     $this->subjectMock = $this->getMock('Magento\\Framework\\App\\Action\\Action', [], [], '', false);
     $this->requestMock = $this->getMock('Magento\\Framework\\App\\RequestInterface');
     $this->plugin = (new ObjectManager($this))->getObject('Magento\\Store\\App\\Action\\Plugin\\Context', ['session' => $this->sessionMock, 'httpContext' => $this->httpContextMock, 'httpRequest' => $this->httpRequestMock, 'storeManager' => $this->storeManager, 'storeCookieManager' => $this->storeCookieManager]);
     $this->storeManager->expects($this->once())->method('getWebsite')->will($this->returnValue($this->websiteMock));
     $this->storeManager->method('getDefaultStoreView')->willReturn($this->storeMock);
     $this->storeManager->method('getStore')->willReturn($this->currentStoreMock);
     $this->websiteMock->expects($this->once())->method('getDefaultStore')->will($this->returnValue($this->storeMock));
     $this->storeMock->expects($this->once())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_DEFAULT));
     $this->storeMock->expects($this->once())->method('getCode')->willReturn('default');
     $this->currentStoreMock->expects($this->once())->method('getCode')->willReturn('custom_store');
     $this->storeCookieManager->expects($this->once())->method('getStoreCodeFromCookie')->will($this->returnValue('storeCookie'));
     $this->httpRequestMock->expects($this->once())->method('getParam')->with($this->equalTo('___store'))->will($this->returnValue('default'));
     $this->currentStoreMock->expects($this->any())->method('getDefaultCurrencyCode')->will($this->returnValue(self::CURRENCY_CURRENT_STORE));
 }
 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());
 }
Example #30
0
 /**
  * @expectedException \Magento\Framework\Exception\NotFoundException
  */
 public function testBeforeDispatch()
 {
     $actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', [], [], '', false);
     $indexController = $this->getMock('Magento\\Wishlist\\Controller\\Index\\Index', [], [], '', false);
     $actionFlag->expects($this->once())->method('set')->with('', 'no-dispatch', true)->willReturn(true);
     $indexController->expects($this->once())->method('getActionFlag')->willReturn($actionFlag);
     $this->authenticationState->expects($this->once())->method('isEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('authenticate')->willReturn(false);
     $this->redirector->expects($this->once())->method('getRefererUrl')->willReturn('http://referer-url.com');
     $this->request->expects($this->once())->method('getParams')->willReturn(['product' => 1]);
     $this->customerSession->expects($this->at(1))->method('__call')->with('getBeforeWishlistUrl', [])->willReturn(false);
     $this->customerSession->expects($this->at(2))->method('__call')->with('setBeforeWishlistUrl', ['http://referer-url.com'])->willReturn(false);
     $this->customerSession->expects($this->at(3))->method('__call')->with('setBeforeWishlistRequest', [['product' => 1]])->willReturn(true);
     $this->config->expects($this->once())->method('isSetFlag')->with('wishlist/general/active')->willReturn(false);
     $this->getPlugin()->beforeDispatch($indexController, $this->request);
 }