public function setUp() { $objectManagerHelper = new ObjectManagerHelper($this); $this->shipmentLoader = $this->getMock('Magento\\Shipping\\Controller\\Adminhtml\\Order\\ShipmentLoader', ['setOrderId', 'setShipmentId', 'setShipment', 'setTracking', 'load'], [], '', false); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getRequest', 'getResponse', 'getMessageManager', 'getRedirect', 'getObjectManager', 'getSession', 'getActionFlag', 'getHelper', 'getResultFactory'], [], '', false); $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false); $this->request = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->setMethods(['isPost', 'getModuleName', 'setModuleName', 'getActionName', 'setActionName', 'getParam', 'getCookie'])->getMockForAbstractClass(); $this->objectManager = $this->getMock('Magento\\Framework\\ObjectManager\\ObjectManager', ['create'], [], '', false); $this->messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', ['addSuccess', 'addError'], [], '', false); $this->session = $this->getMock('Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false); $this->actionFlag = $this->getMock('Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false); $this->helper = $this->getMock('\\Magento\\Backend\\Helper\\Data', ['getUrl'], [], '', false); $this->resultRedirect = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', [], [], '', false); $this->resultFactory = $this->getMock('Magento\\Framework\\Controller\\ResultFactory', ['create'], [], '', false); $this->resultFactory->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($this->resultRedirect); $this->context->expects($this->once())->method('getMessageManager')->willReturn($this->messageManager); $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); $this->context->expects($this->once())->method('getResponse')->willReturn($this->response); $this->context->expects($this->once())->method('getObjectManager')->willReturn($this->objectManager); $this->context->expects($this->once())->method('getSession')->willReturn($this->session); $this->context->expects($this->once())->method('getActionFlag')->willReturn($this->actionFlag); $this->context->expects($this->once())->method('getHelper')->willReturn($this->helper); $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory); $this->shipmentEmail = $objectManagerHelper->getObject('Magento\\Shipping\\Controller\\Adminhtml\\Order\\Shipment\\Email', ['context' => $this->context, 'shipmentLoader' => $this->shipmentLoader, 'request' => $this->request, 'response' => $this->response]); }
protected function setUp() { $this->context = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); $this->wishlistProvider = $this->getMock('Magento\Wishlist\Controller\WishlistProvider', [], [], '', false); $this->itemCarrier = $this->getMock('Magento\Wishlist\Model\ItemCarrier', [], [], '', false); $this->formKeyValidator = $this->getMock('Magento\Framework\Data\Form\FormKey\Validator', [], [], '', false); $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); $this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') ->disableOriginalConstructor() ->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') ->disableOriginalConstructor() ->getMock(); $this->resultForwardMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Forward') ->disableOriginalConstructor() ->getMock(); $this->resultFactoryMock->expects($this->any()) ->method('create') ->willReturnMap( [ [ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], [ResultFactory::TYPE_FORWARD, [], $this->resultForwardMock] ] ); }
protected function setUp() { $this->context = $this->getMock('Magento\Framework\App\Action\Context', [], [], '', false); $this->request = $this->getMock('Magento\Framework\App\Request\Http', [], [], '', false); $this->response = $this->getMock('Magento\Framework\App\Response\Http', [], [], '', false); $this->wishlistProvider = $this->getMock('Magento\Wishlist\Controller\WishlistProvider', [], [], '', false); $this->redirect = $this->getMock('\Magento\Store\App\Response\Redirect', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') ->disableOriginalConstructor() ->getMock(); $this->resultPageMock = $this->getMockBuilder('Magento\Framework\View\Result\Page') ->disableOriginalConstructor() ->getMock(); $this->layoutMock = $this->getMockBuilder('Magento\Framework\View\Layout') ->disableOriginalConstructor() ->getMock(); $this->resultFactoryMock->expects($this->any()) ->method('create') ->with(ResultFactory::TYPE_PAGE, []) ->willReturn($this->resultPageMock); $this->resultPageMock->expects($this->any()) ->method('getLayout') ->willReturn($this->layoutMock); }
public function testExecute() { $product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock(); $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product); $resultLayout = $this->getMock(\Magento\Framework\View\Result\Layout::class, [], [], '', false); $this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_LAYOUT)->willReturn($resultLayout); $this->assertInstanceOf(\Magento\Framework\View\Result\Layout::class, $this->controller->execute()); }
public function testExecute() { $_FILES['test_key'] = []; $result = ['file' => '', 'url' => '']; $resultJson = '{"file": "", "url": ""}'; $this->imageProcessor->expects($this->once())->method('saveToTmp')->with('test_key')->willReturn($result); $this->resultFactory->expects($this->once())->method('create')->with(ResultFactory::TYPE_JSON)->willReturn($this->resultPage); $this->resultPage->expects($this->once())->method('setData')->with($result)->willReturn($resultJson); $this->assertEquals($resultJson, $this->controller->execute()); }
/** * @return \Magento\Backend\Model\View\Result\Page */ public function execute() { if ($this->initModel()) { /* @var \Magento\Backend\Model\View\Result\Page $resultPage */ $resultPage = $this->resultFactory->create(ResultFactory::TYPE_PAGE); return $resultPage; } else { $this->_forward('no_route'); } }
public function setUp() { $this->context = $this->getMock('Magento\\Framework\\App\\Action\\Context', [], [], '', false); $this->wishlistProvider = $this->getMock('Magento\\Wishlist\\Controller\\WishlistProvider', ['getWishlist'], [], '', false); $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', ['getBeforeWishlistRequest', 'unsBeforeWishlistRequest', 'getBeforeWishlistUrl', 'setAddActionReferer', 'setBeforeWishlistUrl'], [], '', false); $this->productRepository = $this->getMock('\\Magento\\Catalog\\Model\\ProductRepository', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); }
protected function setUp() { $this->autocomplete = $this->getMockBuilder('Magento\Search\Model\AutocompleteInterface') ->disableOriginalConstructor() ->setMethods(['getItems']) ->getMockForAbstractClass(); $this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface') ->disableOriginalConstructor() ->setMethods([]) ->getMockForAbstractClass(); $this->url = $this->getMockBuilder('Magento\Framework\UrlInterface') ->disableOriginalConstructor() ->setMethods(['getBaseUrl']) ->getMockForAbstractClass(); $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') ->disableOriginalConstructor() ->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); $this->resultJsonMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Json') ->disableOriginalConstructor() ->getMock(); $this->context = $this->getMockBuilder('Magento\Framework\App\Action\Context') ->disableOriginalConstructor() ->getMock(); $this->context->expects($this->atLeastOnce()) ->method('getRequest') ->will($this->returnValue($this->request)); $this->context->expects($this->any()) ->method('getUrl') ->will($this->returnValue($this->url)); $this->context->expects($this->any()) ->method('getResultFactory') ->willReturn($this->resultFactoryMock); $this->resultFactoryMock->expects($this->any()) ->method('create') ->willReturnMap( [ [ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], [ResultFactory::TYPE_JSON, [], $this->resultJsonMock] ] ); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->controller = $this->objectManagerHelper->getObject( 'Magento\Search\Controller\Ajax\Suggest', [ 'context' => $this->context, 'autocomplete' => $this->autocomplete ] ); }
protected function setUp() { $this->request = $this->getMock('Magento\\Framework\\App\\RequestInterface', [], [], '', false); $this->factory = $this->getMock('Magento\\Catalog\\Model\\ProductFactory', ['create'], [], '', false); $this->registry = $this->getMock('Magento\\Framework\\Registry', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultLayoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Layout')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_LAYOUT, [])->willReturn($this->resultLayoutMock); $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->context = $this->objectManager->getObject('Magento\\Backend\\App\\Action\\Context', ['request' => $this->request, 'resultFactory' => $this->resultFactoryMock]); $this->action = $this->objectManager->getObject('Magento\\GroupedProduct\\Controller\\Adminhtml\\Edit\\Popup', ['context' => $this->context, 'factory' => $this->factory, 'registry' => $this->registry]); }
protected function setUp() { $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); $this->contextMock = $this->getMock('\\Magento\\Backend\\App\\Action\\Context', [], [], '', false); $this->filterMock = $this->getMockBuilder('Magento\\Ui\\Component\\MassAction\\Filter')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); }
protected function setUp() { $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getPostValue'])->getMockForAbstractClass(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManagerInterface')->getMock(); $this->messageManagerMock = $this->getMockBuilder('Magento\\Framework\\Message\\ManagerInterface')->getMock(); $this->resultFactoryMock->expects($this->once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($this->resultRedirectMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->context = $this->objectManagerHelper->getObject('Magento\\Backend\\App\\Action\\Context', ['resultFactory' => $this->resultFactoryMock, 'request' => $this->requestMock, 'messageManager' => $this->messageManagerMock, 'objectManager' => $this->objectManagerMock]); $this->saveController = $this->objectManagerHelper->getObject('Magento\\Sitemap\\Controller\\Adminhtml\\Sitemap\\Save', ['context' => $this->context]); }
protected function setUp() { $this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface') ->disableOriginalConstructor() ->setMethods([]) ->getMockForAbstractClass(); $this->objectManager = $this->getMockBuilder('\Magento\Framework\ObjectManagerInterface') ->disableOriginalConstructor() ->setMethods(['create']) ->getMockForAbstractClass(); $this->messageManager = $this->getMockBuilder('\Magento\Framework\Message\ManagerInterface') ->disableOriginalConstructor() ->setMethods(['addSuccess', 'addError']) ->getMockForAbstractClass(); $this->pageFactory = $this->getMockBuilder('Magento\Framework\View\Result\PageFactory') ->setMethods([]) ->disableOriginalConstructor() ->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\Backend\Model\View\Result\Redirect') ->disableOriginalConstructor() ->getMock(); $this->resultFactoryMock = $this->getMockBuilder('Magento\Framework\Controller\ResultFactory') ->disableOriginalConstructor() ->getMock(); $this->resultFactoryMock->expects($this->any()) ->method('create') ->with(ResultFactory::TYPE_REDIRECT, []) ->willReturn($this->resultRedirectMock); $this->context = $this->getMockBuilder('Magento\Backend\App\Action\Context') ->disableOriginalConstructor() ->getMock(); $this->context->expects($this->atLeastOnce()) ->method('getRequest') ->willReturn($this->request); $this->context->expects($this->any()) ->method('getObjectManager') ->willReturn($this->objectManager); $this->context->expects($this->any()) ->method('getMessageManager') ->willReturn($this->messageManager); $this->context->expects($this->any()) ->method('getResultFactory') ->willReturn($this->resultFactoryMock); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->controller = $this->objectManagerHelper->getObject( 'Magento\Search\Controller\Adminhtml\Term\MassDelete', [ 'context' => $this->context, 'resultPageFactory' => $this->pageFactory, ] ); }
/** * Set up */ protected function setUp() { $this->resultPage = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Page', ['setActiveMenu', 'getConfig', 'getTitle', 'prepend', 'addBreadcrumb'], [], '', false); $this->resultPage->expects($this->any())->method('getConfig')->willReturnSelf(); $this->resultPage->expects($this->any())->method('getTitle')->willReturnSelf(); $this->resultFactory = $this->getMock('Magento\\Framework\\Controller\\ResultFactory', ['create'], [], '', false); $this->resultFactory->expects($this->any())->method('create')->willReturn($this->resultPage); $this->context = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getResultFactory'], [], '', false); $this->context->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactory); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->indexController = $this->objectManagerHelper->getObject('Magento\\ImportExport\\Controller\\Adminhtml\\History\\Index', ['context' => $this->context]); }
protected function setUp() { $this->context = $this->getMock('Magento\\Framework\\App\\Action\\Context', [], [], '', false); $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->wishlistProvider = $this->getMock('Magento\\Wishlist\\Controller\\WishlistProvider', [], [], '', false); $this->redirect = $this->getMock('\\Magento\\Store\\App\\Response\\Redirect', [], [], '', false); $this->om = $this->getMock('Magento\\Framework\\App\\ObjectManager', [], [], '', false); $this->messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false); $this->url = $this->getMock('Magento\\Framework\\Url', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); }
protected function setUp() { $this->wishlistProviderMock = $this->getMockBuilder('Magento\\Wishlist\\Controller\\Shared\\WishlistProvider')->disableOriginalConstructor()->getMock(); $this->itemCarrierMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ItemCarrier')->disableOriginalConstructor()->getMock(); $this->wishlistMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Wishlist')->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultForwardMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->willReturnMap([[ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], [ResultFactory::TYPE_FORWARD, [], $this->resultForwardMock]]); $this->objectManagerHelper = new ObjectManagerHelper($this); $this->context = $this->objectManagerHelper->getObject('Magento\\Framework\\App\\Action\\Context', ['request' => $this->requestMock, 'resultFactory' => $this->resultFactoryMock]); $this->allcartController = $this->objectManagerHelper->getObject('Magento\\Wishlist\\Controller\\Shared\\Allcart', ['context' => $this->context, 'wishlistProvider' => $this->wishlistProviderMock, 'itemCarrier' => $this->itemCarrierMock]); }
/** * Retrieve redirect * * @return ResultRedirect|ResultForward */ public function getRedirect() { $this->updateLastCustomerId(); $this->prepareRedirectUrl(); /** @var ResultRedirect|ResultForward $result */ if ($this->session->getBeforeRequestParams()) { $result = $this->resultFactory->create(ResultFactory::TYPE_FORWARD); $result->setParams($this->session->getBeforeRequestParams())->setModule($this->session->getBeforeModuleName())->setController($this->session->getBeforeControllerName())->forward($this->session->getBeforeAction()); } else { $result = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $result->setUrl($this->session->getBeforeAuthUrl(true)); } return $result; }
/** * Get mock objects for SetUp() */ protected function _prepareMockObjects() { $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock(); $this->objectManagerMock = $this->getMock('Magento\\Framework\\ObjectManagerInterface'); $this->storeManagerMock = $this->getMockForAbstractClass('Magento\\Store\\Model\\StoreManagerInterface'); $this->storeModelMock = $this->getMock('Magento\\Store\\Model\\Store', ['__wakeup', 'getId'], [], '', false); $this->reviewMock = $this->getMock('Magento\\Review\\Model\\Review', ['__wakeup', 'create', 'save', 'getId', 'getResource', 'aggregate'], [], '', false); $this->reviewFactoryMock = $this->getMock('Magento\\Review\\Model\\ReviewFactory', ['create'], [], '', false); $this->ratingMock = $this->getMock('Magento\\Review\\Model\\Rating', ['__wakeup', 'setRatingId', 'setReviewId', 'addOptionVote'], [], '', false); $this->ratingFactoryMock = $this->getMock('Magento\\Review\\Model\\RatingFactory', ['create'], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Backend\\Model\\View\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); }
public function setUp() { $this->mediaGallery = [ 'image' => '/m/a/magento.png', 'small_image' => '/m/a/magento.png', 'thumbnail' => '/m/a/magento.png', 'swatch_image' => '/m/a/magento.png', ]; $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->swatchHelperMock = $this->getMock('\Magento\Swatches\Helper\Data', [], [], '', false); $this->productModelFactoryMock = $this->getMock( '\Magento\Catalog\Model\ProductFactory', ['create'], [], '', false ); $this->productMock = $this->getMock('\Magento\Catalog\Model\Product', [], [], '', false); $this->attributeMock = $this->getMock('\Magento\Catalog\Model\ResourceModel\Eav\Attribute', [], [], '', false); $this->contextMock = $this->getMock('\Magento\Framework\App\Action\Context', [], [], '', false); $this->requestMock = $this->getMock('\Magento\Framework\App\Request', ['getParam'], [], '', false); $this->requestMock->expects($this->any())->method('getParam')->withConsecutive( ['product_id'], ['attributes'], ['additional'] )->willReturnOnConsecutiveCalls( 59, ['size' => 454], ['color' => 43] ); $this->contextMock->method('getRequest')->willReturn($this->requestMock); $this->resultFactory = $this->getMock('\Magento\Framework\Controller\ResultFactory', ['create'], [], '', false); $this->contextMock->method('getResultFactory')->willReturn($this->resultFactory); $this->jsonMock = $this->getMock('\Magento\Framework\Controller\Result\Json', [], [], '', false); $this->resultFactory->expects($this->once())->method('create')->with('json')->willReturn($this->jsonMock); $this->controller = $this->objectManager->getObject( '\Magento\Swatches\Controller\Ajax\Media', [ 'context' => $this->contextMock, 'swatchHelper' => $this->swatchHelperMock, 'productModelFactory' => $this->productModelFactoryMock ] ); }
/** * SetUp method * * @return void */ protected function setUp() { $this->productRepository = $this->getMock('Magento\\Catalog\\Model\\ProductRepository', [], [], '', false); $this->context = $this->getMock('Magento\\Framework\\App\\Action\\Context', [], [], '', false); $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false); $this->wishlistProvider = $this->getMock('Magento\\Wishlist\\Controller\\WishlistProvider', [], [], '', false); $this->om = $this->getMock('Magento\\Framework\\App\\ObjectManager', [], [], '', false); $this->messageManager = $this->getMock('Magento\\Framework\\Message\\Manager', [], [], '', false); $this->url = $this->getMock('Magento\\Framework\\Url', [], [], '', false); $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false); $this->eventManager = $this->getMock('Magento\\Framework\\Event\\Manager', [], [], '', false); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); $this->formKeyValidator = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\FormKey\\Validator')->disableOriginalConstructor()->getMock(); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function setUp() { $this->wishlistProviderMock = $this->getMockBuilder('Magento\\Wishlist\\Controller\\WishlistProviderInterface')->disableOriginalConstructor()->setMethods(['getWishlist'])->getMockForAbstractClass(); $this->quantityProcessorMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\LocaleQuantityProcessor')->disableOriginalConstructor()->getMock(); $this->itemFactoryMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->checkoutCartMock = $this->getMockBuilder('Magento\\Checkout\\Model\\Cart')->disableOriginalConstructor()->setMethods(['save', 'getQuote', 'getShouldRedirectToCart', 'getCartUrl'])->getMock(); $this->optionFactoryMock = $this->getMockBuilder('Magento\\Wishlist\\Model\\Item\\OptionFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock(); $this->productHelperMock = $this->getMockBuilder('Magento\\Catalog\\Helper\\Product')->disableOriginalConstructor()->getMock(); $this->escaperMock = $this->getMockBuilder('Magento\\Framework\\Escaper')->disableOriginalConstructor()->getMock(); $this->helperMock = $this->getMockBuilder('Magento\\Wishlist\\Helper\\Data')->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParams', 'getParam', 'isAjax'])->getMockForAbstractClass(); $this->redirectMock = $this->getMockBuilder('Magento\\Framework\\App\\Response\\RedirectInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->objectManagerMock = $this->getMockBuilder('Magento\\Framework\\ObjectManagerInterface')->disableOriginalConstructor()->getMockForAbstractClass(); $this->messageManagerMock = $this->getMockBuilder('Magento\\Framework\\Message\\ManagerInterface')->disableOriginalConstructor()->setMethods(['addSuccess'])->getMockForAbstractClass(); $this->urlMock = $this->getMockBuilder('Magento\\Framework\\UrlInterface')->disableOriginalConstructor()->setMethods(['getUrl'])->getMockForAbstractClass(); $this->cartHelperMock = $this->getMockBuilder('Magento\\Checkout\\Helper\\Cart')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultJsonMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->getMock(); $this->contextMock = $this->getMockBuilder('Magento\\Framework\\App\\Action\\Context')->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->requestMock)); $this->contextMock->expects($this->any())->method('getRedirect')->will($this->returnValue($this->redirectMock)); $this->contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->objectManagerMock)); $this->contextMock->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->messageManagerMock)); $this->contextMock->expects($this->any())->method('getUrl')->willReturn($this->urlMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); $this->resultFactoryMock->expects($this->any())->method('create')->willReturnMap([[ResultFactory::TYPE_REDIRECT, [], $this->resultRedirectMock], [ResultFactory::TYPE_JSON, [], $this->resultJsonMock]]); $this->model = new Cart($this->contextMock, $this->wishlistProviderMock, $this->quantityProcessorMock, $this->itemFactoryMock, $this->checkoutCartMock, $this->optionFactoryMock, $this->productHelperMock, $this->escaperMock, $this->helperMock, $this->cartHelperMock); }
/** * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function setUp() { $this->redirect = $this->getMock('\\Magento\\Framework\\App\\Response\\RedirectInterface'); $this->request = $this->getMock('\\Magento\\Framework\\App\\Request\\Http', ['getParam'], [], '', false); $this->response = $this->getMock('\\Magento\\Framework\\App\\Response\\Http', ['setRedirect'], [], '', false); $this->formKeyValidator = $this->getMock('Magento\\Framework\\Data\\Form\\FormKey\\Validator', ['validate'], [], '', false); $this->reviewSession = $this->getMock('\\Magento\\Framework\\Session\\Generic', ['getFormData', 'getRedirectUrl'], [], '', false); $this->eventManager = $this->getMock('\\Magento\\Framework\\Event\\ManagerInterface'); $this->productRepository = $this->getMock('\\Magento\\Catalog\\Api\\ProductRepositoryInterface'); $this->coreRegistry = $this->getMock('\\Magento\\Framework\\Registry'); $this->review = $this->getMock('\\Magento\\Review\\Model\\Review', ['setData', 'validate', 'setEntityId', 'getEntityIdByCode', 'setEntityPkValue', 'setStatusId', 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate'], [], '', false, false); $reviewFactory = $this->getMock('\\Magento\\Review\\Model\\ReviewFactory', ['create'], [], '', false, false); $reviewFactory->expects($this->once())->method('create')->willReturn($this->review); $this->customerSession = $this->getMock('\\Magento\\Customer\\Model\\Session', ['getCustomerId'], [], '', false, false); $this->rating = $this->getMock('\\Magento\\Review\\Model\\Rating', ['setRatingId', 'setReviewId', 'setCustomerId', 'addOptionVote'], [], '', false, false); $ratingFactory = $this->getMock('\\Magento\\Review\\Model\\RatingFactory', ['create'], [], '', false, false); $ratingFactory->expects($this->once())->method('create')->willReturn($this->rating); $this->messageManager = $this->getMock('\\Magento\\Framework\\Message\\ManagerInterface'); $this->store = $this->getMock('\\Magento\\Store\\Model\\Store', ['getId'], [], '', false); $storeManager = $this->getMockForAbstractClass('\\Magento\\Store\\Model\\StoreManagerInterface'); $storeManager->expects($this->any())->method('getStore')->willReturn($this->store); $this->resultFactoryMock = $this->getMockBuilder('Magento\\Framework\\Controller\\ResultFactory')->disableOriginalConstructor()->getMock(); $this->resultRedirectMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->any())->method('create')->with(ResultFactory::TYPE_REDIRECT, [])->willReturn($this->resultRedirectMock); $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); $this->context = $objectManagerHelper->getObject('Magento\\Framework\\App\\Action\\Context', ['request' => $this->request, 'resultFactory' => $this->resultFactoryMock, 'messageManager' => $this->messageManager]); $this->model = $objectManagerHelper->getObject('\\Magento\\Review\\Controller\\Product\\Post', ['response' => $this->response, 'redirect' => $this->redirect, 'formKeyValidator' => $this->formKeyValidator, 'reviewSession' => $this->reviewSession, 'eventManager' => $this->eventManager, 'productRepository' => $this->productRepository, 'coreRegistry' => $this->coreRegistry, 'reviewFactory' => $reviewFactory, 'customerSession' => $this->customerSession, 'ratingFactory' => $ratingFactory, 'storeManager' => $storeManager, 'context' => $this->context]); }
public function testExecuteWithoutFormKey() { /** @var \Magento\Framework\Controller\Result\Redirect|\PHPUnit_Framework_MockObject_MockObject $redirectMock */ $redirectMock = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') ->disableOriginalConstructor() ->getMock(); $this->resultFactoryMock->expects($this->once()) ->method('create') ->willReturnMap( [ [\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT, [], $redirectMock], ] ); $this->validatorMock->expects($this->once()) ->method('validate') ->with($this->requestMock) ->willReturn(false); $redirectMock->expects($this->once()) ->method('setPath') ->with('sendfriend/product/send', ['_current' => true]) ->willReturnSelf(); $this->assertEquals($redirectMock, $this->model->executeInternal()); }
/** * @test * @return void */ public function testExecuteLocalizedException() { $path = 'adminhtml/*/'; $themeId = 1; $this->request->expects($this->any()) ->method('getParam') ->willReturnMap( [ ['id', null, $themeId], ['back', false, false], ] ); $redirect = $this->getMockBuilder('Magento\Framework\Controller\Result\Redirect') ->disableOriginalConstructor() ->getMock(); $this->objectManager->expects($this->once()) ->method('create') ->with('Magento\Framework\View\Design\ThemeInterface') ->willThrowException(new \Magento\Framework\Exception\LocalizedException(__('localized exception'))); $this->resultFactory->expects($this->once()) ->method('create') ->with(ResultFactory::TYPE_REDIRECT) ->willReturn($redirect); $redirect->expects($this->once()) ->method('setPath') ->with($path) ->willReturnSelf(); $this->messageManager->expects($this->once()) ->method('addError'); $this->assertInstanceOf('Magento\Framework\Controller\Result\Redirect', $this->controller->executeInternal()); }
/** * Init mocks for tests * @return void */ public function setUp() { $this->objectManager = new ObjectManager($this); $this->contextMock = $this->getMockBuilder('\\Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->getMock(); $this->authenticationMock = $this->getMockBuilder(AuthenticationInterface::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\RequestInterface')->setMethods(['getParam'])->getMockForAbstractClass(); $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface'); $this->resultFactoryMock = $this->getMock('Magento\\Framework\\Controller\\ResultFactory', ['create'], [], '', false); $this->redirectMock = $this->getMock('Magento\\Backend\\Model\\View\\Result\\Redirect', ['setPath'], [], '', false); $this->customerDataMock = $this->getMock('Magento\\Customer\\Model\\Data\\Customer', [], [], '', false); $this->contextMock = $this->getMockBuilder('Magento\\Backend\\App\\Action\\Context')->setMethods(['getObjectManager', 'getResultFactory', 'getMessageManager', 'getRequest'])->disableOriginalConstructor()->getMock(); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->contextMock->expects($this->any())->method('getMessageManager')->willReturn($this->messageManagerMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); $this->resultFactoryMock->expects($this->once())->method('create')->willReturn($this->redirectMock); $this->controller = $this->objectManager->getObject('\\Magento\\Customer\\Controller\\Adminhtml\\Locks\\Unlock', ['context' => $this->contextMock, 'authentication' => $this->authenticationMock]); }
/** * @return \Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\Result\Redirect|null */ public function aroundExecute() { $query = $this->request->getParam('q', false); if (!$query) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); $resultRedirect->setUrl($this->url->getBaseUrl()); return $resultRedirect; } if ($this->bxHelperData->isAutocompleteEnabled()) { $responseData = $this->p13nHelper->autocomplete($query, $this->autocompleteHelper); /** @var \Magento\Framework\Controller\Result\Json $resultJson */ $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); $resultJson->setData($responseData); return $resultJson; } return null; }
public function testExecuteException() { $this->setupCart(); $exceptionMsg = new \Magento\Framework\Phrase('error'); $exception = new \Magento\Framework\Exception\LocalizedException($exceptionMsg); $this->checkoutMock->expects($this->once())->method('place')->with(null)->willThrowException($exception); $this->messageManager->expects($this->once())->method('addError')->with($exceptionMsg); $resultRedirect = $this->getMockBuilder('\\Magento\\Framework\\Controller\\Result\\Redirect')->disableOriginalConstructor()->getMock(); $resultRedirect->expects($this->once())->method('setPath')->with('checkout/cart')->willReturnSelf(); $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirect); $this->assertEquals($resultRedirect, $this->controller->execute()); }
protected function setUp() { $this->objectManager = new ObjectManager($this); $this->contextMock = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock(); $this->resultFactoryMock = $this->getMockBuilder(ResultFactory::class)->disableOriginalConstructor()->getMock(); $this->layoutMock = $this->getMockBuilder(LayoutInterface::class)->disableOriginalConstructor()->getMock(); $this->requestMock = $this->getMockBuilder(RequestInterface::class)->getMockForAbstractClass(); $this->productBuilderMock = $this->getMockBuilder(Builder::class)->disableOriginalConstructor()->getMock(); $this->resultMock = $this->getMockBuilder(ResultInterface::class)->setMethods(['forward', 'setJsonData', 'getLayout'])->getMockForAbstractClass(); $this->productMock = $this->getMockBuilder(ProductInterface::class)->getMockForAbstractClass(); $this->uiComponentMock = $this->getMockBuilder(UiComponent::class)->disableOriginalConstructor()->getMock(); $this->processorMock = $this->getMockBuilder(ProcessorInterface::class)->getMockForAbstractClass(); $this->contextMock->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->resultFactoryMock->expects($this->any())->method('create')->willReturn($this->resultMock); $this->contextMock->expects($this->any())->method('getResultFactory')->willReturn($this->resultFactoryMock); $this->productBuilderMock->expects($this->any())->method('build')->willReturn($this->productMock); $this->layoutMock->expects($this->any())->method('getBlock')->willReturn($this->uiComponentMock); $this->layoutMock->expects($this->any())->method('getUpdate')->willReturn($this->processorMock); $this->resultMock->expects($this->any())->method('getLayout')->willReturn($this->layoutMock); $this->model = $this->objectManager->getObject(Reload::class, ['context' => $this->contextMock, 'productBuilder' => $this->productBuilderMock, 'layout' => $this->layoutMock]); }
public function testExecute() { $selectedCategories = '1'; $isAnchorOnly = true; $hash = '7e6baeca2d76ca0efc3a299986d31bdc9cd796fb'; $content = 'block_content'; $this->request->expects($this->any())->method('getParam')->willReturnMap( [ ['selected', '', $selectedCategories], ['is_anchor_only', 0, $isAnchorOnly] ] ); $this->mathRandom->expects($this->once())->method('getUniqueHash')->with('categories')->willReturn($hash); $this->chooser->expects($this->once())->method('setUseMassaction')->with()->willReturnSelf(); $this->chooser->expects($this->once())->method('setId')->with($hash)->willReturnSelf(); $this->chooser->expects($this->once())->method('setIsAnchorOnly')->with($isAnchorOnly)->willReturnSelf(); $this->chooser->expects($this->once()) ->method('setSelectedCategories') ->with(explode(',', $selectedCategories)) ->willReturnSelf(); $this->chooser->expects($this->once())->method('toHtml')->willReturn($content); $this->layout->expects($this->once()) ->method('createBlock') ->with($this->blockClass) ->willReturn($this->chooser); $this->resultRaw->expects($this->once())->method('setContents')->with($content)->willReturnSelf(); $this->resultFactory->expects($this->once()) ->method('create') ->with(\Magento\Framework\Controller\ResultFactory::TYPE_RAW) ->willReturn($this->resultRaw); $this->context->expects($this->once())->method('getRequest')->willReturn($this->request); $this->context->expects($this->once())->method('getResultFactory')->willReturn($this->resultFactory); /** @var \Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories $controller */ $this->controller = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)) ->getObject( 'Magento\Widget\Controller\Adminhtml\Widget\Instance\Categories', [ 'context' => $this->context, 'mathRandom' => $this->mathRandom, 'layout' => $this->layout ] ); $this->assertSame($this->resultRaw, $this->controller->executeInternal()); }
public function testExecuteWithNonVisibleProduct() { $productId = 11; $this->requestMock->expects($this->once())->method('getParam')->with('id', null)->willReturn($productId); /** @var \Magento\Catalog\Api\Data\ProductInterface|\PHPUnit_Framework_MockObject_MockObject $productMock */ $productMock = $this->getMockBuilder('Magento\\Catalog\\Api\\Data\\ProductInterface')->setMethods(['isVisibleInCatalog'])->getMockForAbstractClass(); $this->productRepositoryMock->expects($this->once())->method('getById')->with($productId, false, null, false)->willReturn($productMock); $productMock->expects($this->once())->method('isVisibleInCatalog')->willReturn(false); /** @var \Magento\Framework\Controller\Result\Forward|\PHPUnit_Framework_MockObject_MockObject $forwardMock */ $forwardMock = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Forward')->disableOriginalConstructor()->getMock(); $this->resultFactoryMock->expects($this->once())->method('create')->with(\Magento\Framework\Controller\ResultFactory::TYPE_FORWARD, [])->willReturn($forwardMock); $forwardMock->expects($this->once())->method('forward')->with('noroute')->willReturnSelf(); $this->assertEquals($forwardMock, $this->model->execute()); }
public function testExecuteException() { $result = '{}'; $quoteMock = $this->getQuoteMock(); $resultRedirectMock = $this->getResultRedirectMock(); $quoteMock->expects(self::once())->method('getItemsCount')->willReturn(1); $this->requestMock->expects(self::once())->method('getPostValue')->with('result', '{}')->willReturn($result); $this->checkoutSessionMock->expects(self::once())->method('getQuote')->willReturn($quoteMock); $this->quoteUpdaterMock->expects(self::never())->method('execute'); $this->messageManagerMock->expects(self::once())->method('addExceptionMessage')->with(self::isInstanceOf('\\InvalidArgumentException'), 'Data of request cannot be empty.'); $this->resultFactoryMock->expects(self::once())->method('create')->with(ResultFactory::TYPE_REDIRECT)->willReturn($resultRedirectMock); $resultRedirectMock->expects(self::once())->method('setPath')->with('checkout/cart')->willReturnSelf(); self::assertEquals($this->review->execute(), $resultRedirectMock); }