コード例 #1
0
 /**
  * Prepare required values
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_request = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->_response = $this->getMockBuilder('Magento\\Framework\\App\\Response\\Http')->disableOriginalConstructor()->setMethods(array('setRedirect', 'getHeader'))->getMock();
     $this->_response->expects($this->any())->method('getHeader')->with($this->equalTo('X-Frame-Options'))->will($this->returnValue(true));
     $this->_objectManager = $this->getMockBuilder('Magento\\Framework\\App\\ObjectManager')->disableOriginalConstructor()->setMethods(array('get', 'create'))->getMock();
     $frontControllerMock = $this->getMockBuilder('Magento\\Framework\\App\\FrontController')->disableOriginalConstructor()->getMock();
     $actionFlagMock = $this->getMockBuilder('Magento\\Framework\\App\\ActionFlag')->disableOriginalConstructor()->getMock();
     $this->_session = $this->getMockBuilder('Magento\\Backend\\Model\\Session')->disableOriginalConstructor()->setMethods(array('setIsUrlNotice', '__wakeup'))->getMock();
     $this->_session->expects($this->any())->method('setIsUrlNotice');
     $this->_helper = $this->getMockBuilder('Magento\\Backend\\Helper\\Data')->disableOriginalConstructor()->setMethods(array('getUrl'))->getMock();
     $this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\Manager')->disableOriginalConstructor()->setMethods(array('addSuccess', 'addMessage', 'addException'))->getMock();
     $contextArgs = array('getHelper', 'getSession', 'getAuthorization', 'getTranslator', 'getObjectManager', 'getFrontController', 'getActionFlag', 'getMessageManager', 'getLayoutFactory', 'getEventManager', 'getRequest', 'getResponse', 'getTitle', 'getView');
     $contextMock = $this->getMockBuilder('\\Magento\\Backend\\App\\Action\\Context')->disableOriginalConstructor()->setMethods($contextArgs)->getMock();
     $contextMock->expects($this->any())->method('getRequest')->will($this->returnValue($this->_request));
     $contextMock->expects($this->any())->method('getResponse')->will($this->returnValue($this->_response));
     $contextMock->expects($this->any())->method('getObjectManager')->will($this->returnValue($this->_objectManager));
     $contextMock->expects($this->any())->method('getFrontController')->will($this->returnValue($frontControllerMock));
     $contextMock->expects($this->any())->method('getActionFlag')->will($this->returnValue($actionFlagMock));
     $contextMock->expects($this->any())->method('getHelper')->will($this->returnValue($this->_helper));
     $contextMock->expects($this->any())->method('getSession')->will($this->returnValue($this->_session));
     $contextMock->expects($this->any())->method('getMessageManager')->will($this->returnValue($this->messageManager));
     $titleMock = $this->getMockBuilder('\\Magento\\Framework\\App\\Action\\Title')->getMock();
     $contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($titleMock));
     $viewMock = $this->getMockBuilder('\\Magento\\Framework\\App\\ViewInterface')->getMock();
     $viewMock->expects($this->any())->method('loadLayout')->will($this->returnSelf());
     $contextMock->expects($this->any())->method('getView')->will($this->returnValue($viewMock));
     $this->_acctServiceMock = $this->getMockBuilder('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface')->getMock();
     $args = array('context' => $contextMock, 'accountService' => $this->_acctServiceMock);
     $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_testedObject = $helperObjectManager->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Newsletter', $args);
 }
コード例 #2
0
ファイル: RawTest.php プロジェクト: pradeep-wagento/magento2
 public function testRender()
 {
     $content = '<content>test</content>';
     $this->raw->setContents($content);
     $this->response->expects($this->once())->method('setBody')->with($content);
     $this->assertSame($this->raw, $this->raw->renderResult($this->response));
 }
コード例 #3
0
 public function testExecuteEmptyQuery()
 {
     $searchString = "";
     $this->request->expects($this->once())->method('getParam')->with('q')->will($this->returnValue($searchString));
     $this->url->expects($this->once())->method('getBaseUrl');
     $this->response->expects($this->once())->method('setRedirect');
     $this->controller->execute();
 }
コード例 #4
0
ファイル: IndexTest.php プロジェクト: nblair/magescotch
 public function testIndexActionException()
 {
     $this->request->expects($this->once())->method('isPost')->will($this->returnValue(true));
     $exception = new \Exception();
     $this->request->expects($this->once())->method('getPostValue')->will($this->throwException($exception));
     $this->logger->expects($this->once())->method('critical')->with($this->identicalTo($exception));
     $this->response->expects($this->once())->method('setHttpResponseCode')->with(500);
     $this->model->executeInternal();
 }
コード例 #5
0
ファイル: Install.php プロジェクト: aiesh/magento2
 /**
  * Dispatch request
  *
  * @param \Magento\Framework\App\Action\Action $subject
  * @param callable $proceed
  * @param \Magento\Framework\App\RequestInterface $request
  * @return \Magento\Framework\App\ResponseInterface
  */
 public function aroundDispatch(\Magento\Framework\App\Action\Action $subject, \Closure $proceed, \Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_appState->isInstalled()) {
         $this->_actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
         $this->_response->setRedirect($this->_url->getUrl('install'));
         return $this->_response;
     }
     return $proceed($request);
 }
コード例 #6
0
 /**
  * Log out user and redirect him to new admin custom url
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
         return;
     }
     $this->_authSession->destroy();
     $route = $this->_backendData->getAreaFrontName();
     $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
     exit(0);
 }
コード例 #7
0
 /**
  * Log out user and redirect him to new admin custom url
  *
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function afterCustomUrlChanged()
 {
     if (is_null($this->_coreRegistry->registry('custom_admin_path_redirect'))) {
         return;
     }
     $this->_authSession->destroy();
     $route = $this->_backendData->getAreaFrontName();
     $this->_response->setRedirect($this->_storeManager->getStore()->getBaseUrl() . $route)->sendResponse();
     exit(0);
 }
コード例 #8
0
 /**
  * Log out user and redirect to new admin custom url
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.ExitExpression)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if ($this->_coreRegistry->registry('custom_admin_path_redirect') === null) {
         return;
     }
     $this->_authSession->destroy();
     $adminUrl = $this->_backendData->getHomePageUrl();
     $this->_response->setRedirect($adminUrl)->sendResponse();
     exit(0);
 }
コード例 #9
0
ファイル: Options.php プロジェクト: aiesh/magento2
 /**
  * Fetches and outputs file to user browser
  * $info is array with following indexes:
  *  - 'path' - full file path
  *  - 'type' - mime type of file
  *  - 'size' - size of file
  *  - 'title' - user-friendly name of file (usually - original name as uploaded in Magento)
  *
  * @param \Magento\Framework\App\ResponseInterface $response
  * @param string $filePath
  * @param array $info
  * @return bool
  */
 public function downloadFileOption($response, $filePath, $info)
 {
     try {
         $response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $info['type'], true)->setHeader('Content-Length', $info['size'])->setHeader('Content-Disposition', 'inline' . '; filename=' . $info['title'])->clearBody();
         $response->sendHeaders();
         echo $this->directory->readFile($this->directory->getRelativePath($filePath));
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
コード例 #10
0
 public function testExecuteRandom()
 {
     $newKey = 'RSASHA9000VERYSECURESUPERMANKEY';
     $this->requestMock->expects($this->at(0))->method('getPost')->with($this->equalTo('generate_random'))->willReturn(1);
     $this->changeMock->expects($this->once())->method('changeEncryptionKey')->willReturn($newKey);
     $this->managerMock->expects($this->once())->method('addSuccessMessage');
     $this->managerMock->expects($this->once())->method('addNoticeMessage');
     $this->cacheMock->expects($this->once())->method('clean');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->model->execute();
 }
コード例 #11
0
ファイル: RemoveItemTest.php プロジェクト: nblair/magescotch
 public function testExecuteWithException()
 {
     $this->requestMock->expects($this->once())->method('getParam')->with('item_id', null)->willReturn('1');
     $exception = new \Exception('Error message!');
     $this->sidebarMock->expects($this->once())->method('checkQuoteItem')->with(1)->willThrowException($exception);
     $this->loggerMock->expects($this->once())->method('critical')->with($exception)->willReturn(null);
     $this->sidebarMock->expects($this->once())->method('getResponseData')->with('Error message!')->willReturn(['success' => false, 'error_message' => 'Error message!']);
     $this->jsonHelperMock->expects($this->once())->method('jsonEncode')->with(['success' => false, 'error_message' => 'Error message!'])->willReturn('json encoded');
     $this->responseMock->expects($this->once())->method('representJson')->with('json encoded')->willReturn('json represented');
     $this->assertEquals('json represented', $this->removeItem->executeInternal());
 }
コード例 #12
0
ファイル: GridTest.php プロジェクト: nja78/magento2
 public function testExecute()
 {
     $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
     $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle\\Option\\Search\\Grid')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
     $this->response->expects($this->once())->method('setBody')->willReturnSelf();
     $this->request->expects($this->once())->method('getParam')->with('index')->willReturn('index');
     $this->view->expects($this->once())->method('getLayout')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->willReturn($block);
     $block->expects($this->once())->method('setIndex')->willReturnSelf();
     $block->expects($this->once())->method('toHtml')->willReturnSelf();
     $this->assertEquals($this->response, $this->controller->execute());
 }
コード例 #13
0
 /**
  * @return void
  */
 public function testExecute()
 {
     $successMessage = 'All other open sessions for this account were terminated.';
     $this->sessionsManager->expects($this->once())->method('logoutOtherUserSessions');
     $this->messageManager->expects($this->once())->method('addSuccess')->with($successMessage);
     $this->messageManager->expects($this->never())->method('addError');
     $this->messageManager->expects($this->never())->method('addException');
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->actionFlagMock->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED);
     $this->backendHelperMock->expects($this->once())->method('getUrl');
     $this->controller->execute();
 }
コード例 #14
0
ファイル: ViewTest.php プロジェクト: imbrj/magento2-samples
 public function testExecute()
 {
     $type = 'sampleType';
     $feed = $this->getMockBuilder('Magento\\SampleServiceContractNew\\API\\Data\\FeedInterface')->getMockForAbstractClass();
     $xml = 'xmlDataString';
     $this->request->expects($this->once())->method('getParam')->with('type')->willReturn($type);
     $this->feedRepository->expects($this->once())->method('getById')->with($type)->willReturn($feed);
     $this->response->expects($this->once())->method('setHeader')->with('Content-type', 'text/xml; charset=UTF-8')->willReturnSelf();
     $this->feedTransformer->expects($this->once())->method('toXml')->with($feed)->willReturn($xml);
     $this->response->expects($this->once())->method('setBody')->with($xml)->willReturnSelf();
     $this->controller->execute();
 }
コード例 #15
0
 public function testExecute()
 {
     $product = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->setMethods(['_wakeup', 'getId'])->getMock();
     $layout = $this->getMock('\\Magento\\Framework\\View\\LayoutInterface');
     $block = $this->getMockBuilder('Magento\\Bundle\\Block\\Adminhtml\\Catalog\\Product\\Edit\\Tab\\Bundle')->disableOriginalConstructor()->setMethods(['setIndex', 'toHtml'])->getMock();
     $this->productBuilder->expects($this->once())->method('build')->with($this->request)->willReturn($product);
     $this->initializationHelper->expects($this->any())->method('initialize')->willReturn($product);
     $this->response->expects($this->once())->method('setBody')->willReturnSelf();
     $this->view->expects($this->once())->method('getLayout')->willReturn($layout);
     $layout->expects($this->once())->method('createBlock')->willReturn($block);
     $block->expects($this->once())->method('toHtml')->willReturnSelf();
     $this->controller->execute();
 }
コード例 #16
0
 /**
  * @param ResponseInterface $response
  * @return $this
  */
 protected function applyHttpHeaders(ResponseInterface $response)
 {
     if (!empty($this->httpResponseCode)) {
         $response->setHttpResponseCode($this->httpResponseCode);
     }
     if ($this->statusHeaderCode) {
         $response->setStatusHeader($this->statusHeaderCode, $this->statusHeaderVersion, $this->statusHeaderPhrase);
     }
     if (!empty($this->headers)) {
         foreach ($this->headers as $headerData) {
             $response->setHeader($headerData['name'], $headerData['value'], $headerData['replace']);
         }
     }
     return $this;
 }
コード例 #17
0
ファイル: Router.php プロジェクト: aiesh/magento2
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  *
  * @SuppressWarnings(PHPMD.ExitExpression)
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     if (!$this->_appState->isInstalled()) {
         $this->_response->setRedirect($this->_url->getUrl('install'))->sendResponse();
         exit;
     }
     $identifier = trim($request->getPathInfo(), '/');
     $condition = new \Magento\Framework\Object(array('identifier' => $identifier, 'continue' => true));
     $this->_eventManager->dispatch('cms_controller_router_match_before', array('router' => $this, 'condition' => $condition));
     $identifier = $condition->getIdentifier();
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     if (!$condition->getContinue()) {
         return null;
     }
     /** @var \Magento\Cms\Model\Page $page */
     $page = $this->_pageFactory->create();
     $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());
     if (!$pageId) {
         return null;
     }
     $request->setModuleName('cms')->setControllerName('page')->setActionName('view')->setParam('page_id', $pageId);
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
コード例 #18
0
 /**
  * Render current layout
  *
  * @param ResponseInterface $response
  * @return $this
  */
 public function renderResult(ResponseInterface $response)
 {
     $layout = $this->getLayout();
     $output = $layout->getOutput();
     $response->appendBody($output);
     return $this;
 }
コード例 #19
0
ファイル: Router.php プロジェクト: prachicis/test_res
 /**
  * Validate and Match Blog Pages and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return bool
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $_identifier = trim($request->getPathInfo(), '/');
     if (strpos($_identifier, 'blog') !== 0) {
         return;
     }
     $identifier = str_replace(array('blog/', 'blog'), '', $_identifier);
     $condition = new \Magento\Framework\DataObject(['identifier' => $identifier, 'continue' => true]);
     $this->_eventManager->dispatch('magefan_blog_controller_router_match_before', ['router' => $this, 'condition' => $condition]);
     if ($condition->getRedirectUrl()) {
         $this->_response->setRedirect($condition->getRedirectUrl());
         $request->setDispatched(true);
         return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Redirect', ['request' => $request]);
     }
     if (!$condition->getContinue()) {
         return null;
     }
     $identifier = $condition->getIdentifier();
     $success = false;
     $info = explode('/', $identifier);
     if (!$identifier) {
         $request->setModuleName('blog')->setControllerName('index')->setActionName('index');
         $success = true;
     } elseif (count($info) > 1) {
         $store = $this->_storeManager->getStore()->getId();
         switch ($info[0]) {
             case 'post':
                 $post = $this->_postFactory->create();
                 $postId = $post->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$postId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('post')->setActionName('view')->setParam('id', $postId);
                 $success = true;
                 break;
             case 'category':
                 $category = $this->_categoryFactory->create();
                 $categoryId = $category->checkIdentifier($info[1], $this->_storeManager->getStore()->getId());
                 if (!$categoryId) {
                     return null;
                 }
                 $request->setModuleName('blog')->setControllerName('category')->setActionName('view')->setParam('id', $categoryId);
                 $success = true;
                 break;
             case 'archive':
                 $request->setModuleName('blog')->setControllerName('archive')->setActionName('view')->setParam('date', $info[1]);
                 $success = true;
                 break;
             case 'search':
                 $request->setModuleName('blog')->setControllerName('search')->setActionName('index')->setParam('q', $info[1]);
                 $success = true;
                 break;
         }
     }
     if (!$success) {
         return null;
     }
     $request->setAlias(\Magento\Framework\Url::REWRITE_REQUEST_PATH_ALIAS, $_identifier);
     return $this->actionFactory->create('Magento\\Framework\\App\\Action\\Forward', ['request' => $request]);
 }
コード例 #20
0
ファイル: SaveTest.php プロジェクト: pradeep-wagento/magento2
 public function testExecute()
 {
     $firstElement = 'firstElement';
     $symbolsDataArray = [$firstElement];
     $redirectUrl = 'redirectUrl';
     $this->requestMock->expects($this->once())->method('getParam')->with('custom_currency_symbol')->willReturn($symbolsDataArray);
     $this->helperMock->expects($this->once())->method('getUrl')->with('*');
     $this->redirectMock->expects($this->once())->method('getRedirectUrl')->willReturn($redirectUrl);
     $this->currencySymbolMock->expects($this->once())->method('setCurrencySymbolsData')->with($symbolsDataArray);
     $this->responseMock->expects($this->once())->method('setRedirect');
     $this->filterManagerMock->expects($this->once())->method('stripTags')->with($firstElement)->willReturn($firstElement);
     $this->objectManagerMock->expects($this->once())->method('create')->with('Magento\\CurrencySymbol\\Model\\System\\Currencysymbol')->willReturn($this->currencySymbolMock);
     $this->objectManagerMock->expects($this->once())->method('get')->with('Magento\\Framework\\Filter\\FilterManager')->willReturn($this->filterManagerMock);
     $this->messageManagerMock->expects($this->once())->method('addSuccess')->with(__('You applied the custom currency symbols.'));
     $this->action->execute();
 }
コード例 #21
0
 public function testExecute()
 {
     $carrier = 'carrier';
     $number = 'number';
     $title = 'title';
     $shipmentId = 1000012;
     $orderId = 10003;
     $tracking = [];
     $shipmentData = ['items' => [], 'send_email' => ''];
     $shipment = $this->getMock('Magento\\Sales\\Model\\Order\\Shipment', ['addTrack', '__wakeup'], [], '', false);
     $this->request->expects($this->any())->method('getParam')->will($this->returnValueMap([['order_id', null, $orderId], ['shipment_id', null, $shipmentId], ['shipment', null, $shipmentData], ['tracking', null, $tracking]]));
     $this->request->expects($this->any())->method('getPost')->will($this->returnValueMap([['carrier', $carrier], ['number', $number], ['title', $title]]));
     $this->shipmentLoader->expects($this->any())->method('setShipmentId')->with($shipmentId);
     $this->shipmentLoader->expects($this->any())->method('setOrderId')->with($orderId);
     $this->shipmentLoader->expects($this->any())->method('setShipment')->with($shipmentData);
     $this->shipmentLoader->expects($this->any())->method('setTracking')->with($tracking);
     $this->shipmentLoader->expects($this->once())->method('load')->will($this->returnValue($shipment));
     $this->title->expects($this->any())->method('add')->with('Shipments')->will($this->returnSelf());
     $track = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Shipment\\Track')->disableOriginalConstructor()->setMethods(['__wakeup', 'setNumber', 'setCarrierCode', 'setTitle'])->getMock();
     $this->objectManager->expects($this->atLeastOnce())->method('create')->with('Magento\\Sales\\Model\\Order\\Shipment\\Track')->will($this->returnValue($track));
     $track->expects($this->once())->method('setNumber')->with($number)->will($this->returnSelf());
     $track->expects($this->once())->method('setCarrierCode')->with($carrier)->will($this->returnSelf());
     $track->expects($this->once())->method('setTitle')->with($title)->will($this->returnSelf());
     $this->view->expects($this->once())->method('loadLayout')->will($this->returnSelf());
     $layout = $this->getMock('Magento\\Framework\\View\\Layout\\Element\\Layout', ['getBlock'], [], '', false);
     $menuBlock = $this->getMock('Magento\\Framework\\View\\Element\\BlockInterface', ['toHtml'], [], '', false);
     $html = 'html string';
     $this->view->expects($this->once())->method('getLayout')->will($this->returnValue($layout));
     $layout->expects($this->once())->method('getBlock')->with('shipment_tracking')->will($this->returnValue($menuBlock));
     $menuBlock->expects($this->once())->method('toHtml')->will($this->returnValue($html));
     $shipment->expects($this->once())->method('addTrack')->with($this->equalTo($track))->will($this->returnSelf());
     $shipment->expects($this->any())->method('save')->will($this->returnSelf());
     $this->response->expects($this->once())->method('setBody')->with($html);
     $this->assertNull($this->controller->execute());
 }
コード例 #22
0
 /**
  * @param array $indexerIds
  * @param \Exception $exception
  * @param array $expectsExceptionValues
  * @dataProvider executeDataProvider
  */
 public function testExecute($indexerIds, $exception, $expectsExceptionValues)
 {
     $this->model = new \Magento\Indexer\Controller\Adminhtml\Indexer\MassChangelog($this->contextMock);
     $this->request->expects($this->any())->method('getParam')->with('indexer_ids')->will($this->returnValue($indexerIds));
     if (!is_array($indexerIds)) {
         $this->messageManager->expects($this->once())->method('addError')->with(__('Please select indexers.'))->will($this->returnValue(1));
     } else {
         $this->objectManager->expects($this->any())->method('get')->with('Magento\\Framework\\Indexer\\IndexerRegistry')->will($this->returnValue($this->indexReg));
         $indexerInterface = $this->getMockForAbstractClass('Magento\\Framework\\Indexer\\IndexerInterface', ['setScheduled'], '', false);
         $this->indexReg->expects($this->any())->method('get')->with(1)->will($this->returnValue($indexerInterface));
         if ($exception !== null) {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->throwException($exception));
         } else {
             $indexerInterface->expects($this->any())->method('setScheduled')->with(true)->will($this->returnValue(1));
         }
         $this->messageManager->expects($this->any())->method('addSuccess')->will($this->returnValue(1));
         if ($exception !== null) {
             $this->messageManager->expects($this->exactly($expectsExceptionValues[2]))->method('addError')->with($exception->getMessage());
             $this->messageManager->expects($this->exactly($expectsExceptionValues[1]))->method('addException')->with($exception, "We couldn't change indexer(s)' mode because of an error.");
         }
     }
     $this->helper->expects($this->any())->method("getUrl")->willReturn("magento.com");
     $this->response->expects($this->any())->method("setRedirect")->willReturn(1);
     $this->model->executeInternal();
 }
コード例 #23
0
ファイル: Router.php プロジェクト: pavelnovitsky/magento2
 /**
  * Validate and Match Cms Page and modify request
  *
  * @param \Magento\Framework\App\RequestInterface $request
  * @return mixed
  */
 public function match(\Magento\Framework\App\RequestInterface $request)
 {
     $identifier = trim($request->getPathInfo(), '/');
     $urlRewrite = $this->urlMatcher->match($identifier, $this->storeManager->getStore()->getId());
     if ($urlRewrite === null) {
         return null;
     }
     $redirectType = $urlRewrite->getRedirectType();
     if ($redirectType) {
         $redirectCode = $redirectType == \Magento\UrlRedirect\Model\OptionProvider::PERMANENT ? 301 : 302;
         $this->response->setRedirect($urlRewrite->getTargetPath(), $redirectCode);
         $request->setDispatched(true);
         return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Redirect', array('request' => $request));
     }
     $request->setPathInfo('/' . $urlRewrite->getTargetPath());
     return $this->actionFactory->createController('Magento\\Framework\\App\\Action\\Forward', array('request' => $request));
 }
コード例 #24
0
 /**
  * @param $cacheState
  * @param $layoutIsCacheable
  * @param $expectedTags
  * @param $configCacheType
  * @param $ttl
  * @dataProvider afterGetOutputDataProvider
  */
 public function testAfterGetOutput($cacheState, $layoutIsCacheable, $expectedTags, $configCacheType, $ttl)
 {
     $html = 'html';
     $this->configMock->expects($this->any())->method('isEnabled')->will($this->returnValue($cacheState));
     $blockStub = $this->getMock('Magento\\PageCache\\Test\\Unit\\Block\\Controller\\StubBlock', null, [], '', false);
     $blockStub->setTtl($ttl);
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue($layoutIsCacheable));
     $this->layoutMock->expects($this->any())->method('getAllBlocks')->will($this->returnValue([$blockStub]));
     $this->configMock->expects($this->any())->method('getType')->will($this->returnValue($configCacheType));
     if ($layoutIsCacheable && $cacheState) {
         $this->responseMock->expects($this->once())->method('setHeader')->with('X-Magento-Tags', $expectedTags);
     } else {
         $this->responseMock->expects($this->never())->method('setHeader');
     }
     $output = $this->model->afterGetOutput($this->layoutMock, $html);
     $this->assertSame($output, $html);
 }
コード例 #25
0
ファイル: OrderLoader.php プロジェクト: aiesh/magento2
 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return bool
  */
 public function load(RequestInterface $request, ResponseInterface $response)
 {
     $orderId = (int) $request->getParam('order_id');
     if (!$orderId) {
         $request->initForward();
         $request->setActionName('noroute');
         $request->setDispatched(false);
         return false;
     }
     $order = $this->orderFactory->create()->load($orderId);
     if ($this->orderAuthorization->canView($order)) {
         $this->registry->register('current_order', $order);
         return true;
     }
     $response->setRedirect($this->url->getUrl('*/*/history'));
     return false;
 }
コード例 #26
0
ファイル: Save.php プロジェクト: rustamveer/magento2
 protected function _sendUploadResponse($fileName, $content, $contentType = 'application/octet-stream')
 {
     $this->_response->setHttpResponseCode(200)->setHeader('Pragma', 'public', true)->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)->setHeader('Content-type', $contentType, true)->setHeader('Content-Length', strlen($content))->setHeader('Content-Disposition', 'attachment; filename="' . $fileName . '"', true)->setHeader('Last-Modified', date('r'), true);
     $this->_response->setBody($content);
     $this->_response->sendResponse();
     die;
     return $this->_response;
 }
コード例 #27
0
 /**
  * @param int $cmId
  */
 protected function prepareRedirect($cmId)
 {
     $this->actionFlag->expects($this->once())->method('get')->with('', 'check_url_settings')->will($this->returnValue(true));
     $this->session->expects($this->once())->method('setIsUrlNotice')->with(true);
     $path = 'sales/order_creditmemo/view';
     $this->response->expects($this->once())->method('setRedirect')->with($path . '/' . $cmId);
     $this->helper->expects($this->atLeastOnce())->method('getUrl')->with($path, ['creditmemo_id' => $cmId])->will($this->returnValue($path . '/' . $cmId));
 }
コード例 #28
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);
     $url = $path . '/' . (!empty($arguments) ? $arguments['shipment_id'] : '');
     $this->helper->expects($this->at($index))->method('getUrl')->with($path, $arguments)->will($this->returnValue($url));
     $this->response->expects($this->at($index))->method('setRedirect')->with($url);
 }
コード例 #29
0
 /**
  * Test the basic Request action.
  */
 public function testRequestAction()
 {
     $this->request->expects($this->any())->method('getMethod')->willReturn('GET');
     $this->helperMock->expects($this->once())->method('getRequestUrl');
     $this->helperMock->expects($this->once())->method('prepareRequest');
     $this->frameworkOauthSvcMock->expects($this->once())->method('getRequestToken')->willReturn(['response']);
     $this->response->expects($this->once())->method('setBody');
     $this->requestAction->execute();
 }
コード例 #30
0
 public function testExecute()
 {
     $type = 'Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product|attribute_set_id';
     $this->request->expects($this->at(0))->method('getParam')->with('id')->will($this->returnValue('1--1'));
     $this->request->expects($this->at(1))->method('getParam')->with('type')->will($this->returnValue($type));
     $this->request->expects($this->at(2))->method('getParam')->with('form')->will($this->returnValue('request_form_param_value'));
     $condition = $this->getMockBuilder('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->setMethods(['setId', 'setType', 'setRule', 'setPrefix', 'setAttribute', 'asHtmlRecursive', 'setJsFormObject'])->disableOriginalConstructor()->getMock();
     $condition->expects($this->once())->method('setId')->with('1--1')->will($this->returnSelf());
     $condition->expects($this->once())->method('setType')->with('Magento\\CatalogWidget\\Model\\Rule\\Condition\\Product')->will($this->returnSelf());
     $condition->expects($this->once())->method('setRule')->with($this->rule)->will($this->returnSelf());
     $condition->expects($this->once())->method('setPrefix')->with('conditions')->will($this->returnSelf());
     $condition->expects($this->once())->method('setJsFormObject')->with('request_form_param_value')->will($this->returnSelf());
     $condition->expects($this->once())->method('setAttribute')->with('attribute_set_id')->will($this->returnSelf());
     $condition->expects($this->once())->method('asHtmlRecursive')->will($this->returnValue('<some_html>'));
     $this->objectManager->expects($this->once())->method('create')->will($this->returnValue($condition));
     $this->response->expects($this->once())->method('setBody')->with('<some_html>')->will($this->returnSelf());
     $this->controller->execute();
 }