Пример #1
0
 /**
  * Set up test
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->contextMock = $this->getMock('Magento\\Backend\\App\\Action\\Context', ['getAuthorization', 'getSession', 'getActionFlag', 'getAuth', 'getView', 'getHelper', 'getBackendUrl', 'getFormKeyValidator', 'getLocaleResolver', 'getCanUseBaseUrl', 'getRequest', 'getResponse', 'getObjectManager', 'getMessageManager'], [], '', false);
     $this->response = $this->getMock('Magento\\Framework\\App\\ResponseInterface', ['setRedirect', 'sendResponse'], [], '', false);
     $this->view = $this->getMock('\\Magento\\Framework\\App\\ViewInterface', ['loadLayout', 'getPage', 'getConfig', 'getTitle', 'renderLayout', 'loadLayoutUpdates', 'getDefaultLayoutHandle', 'addPageLayoutHandles', 'generateLayoutBlocks', 'generateLayoutXml', 'getLayout', 'addActionLayoutHandles', 'setIsLayoutLoaded', 'isLayoutLoaded'], [], '', false);
     $this->session = $this->getMock('\\Magento\\Backend\\Model\\Session', ['setIsUrlNotice'], [], '', false);
     $this->session->expects($this->any())->method('setIsUrlNotice')->willReturn($this->objectManager);
     $this->actionFlag = $this->getMock('\\Magento\\Framework\\App\\ActionFlag', ['get'], [], '', false);
     $this->actionFlag->expects($this->any())->method("get")->willReturn($this->objectManager);
     $this->objectManager = $this->getMock('Magento\\Framework\\TestFramework\\Unit\\Helper\\ObjectManager', ['get'], [], '', false);
     $this->request = $this->getMockForAbstractClass('\\Magento\\Framework\\App\\RequestInterface', ['getParam', 'getRequest'], '', false);
     $this->response->expects($this->any())->method("setRedirect")->willReturn(1);
     $this->page = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', [], [], '', false);
     $this->config = $this->getMock('\\Magento\\Framework\\View\\Result\\Page', [], [], '', false);
     $this->title = $this->getMock('\\Magento\\Framework\\View\\Page\\Title', [], [], '', false);
     $this->messageManager = $this->getMockForAbstractClass('\\Magento\\Framework\\Message\\ManagerInterface', ['addError', 'addSuccess'], '', false);
     $this->indexReg = $this->getMock('Magento\\Framework\\Indexer\\IndexerRegistry', ['get', 'setScheduled'], [], '', false);
     $this->helper = $this->getMock('\\Magento\\Backend\\Helper\\Data', ['getUrl'], [], '', false);
     $this->contextMock->expects($this->any())->method("getObjectManager")->willReturn($this->objectManager);
     $this->contextMock->expects($this->any())->method("getRequest")->willReturn($this->request);
     $this->contextMock->expects($this->any())->method("getResponse")->willReturn($this->response);
     $this->contextMock->expects($this->any())->method("getMessageManager")->willReturn($this->messageManager);
     $this->contextMock->expects($this->any())->method("getSession")->willReturn($this->session);
     $this->contextMock->expects($this->any())->method("getActionFlag")->willReturn($this->actionFlag);
     $this->contextMock->expects($this->any())->method("getHelper")->willReturn($this->helper);
 }
Пример #2
0
 public function execute()
 {
     $id = $this->getRequest()->getParam('author_id');
     /** @var \Sample\News\Model\Author $author */
     $author = $this->initAuthor();
     /** @var \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setActiveMenu('Sample_News::author');
     $resultPage->getConfig()->getTitle()->set(__('Authors'));
     if ($id) {
         $author->load($id);
         if (!$author->getId()) {
             $this->messageManager->addError(__('This author no longer exists.'));
             $resultRedirect = $this->resultRedirectFactory->create();
             $resultRedirect->setPath('sample_news/*/edit', ['author_id' => $author->getId(), '_current' => true]);
             return $resultRedirect;
         }
     }
     $title = $author->getId() ? $author->getName() : __('New Author');
     $resultPage->getConfig()->getTitle()->append($title);
     $data = $this->backendSession->getData('sample_news_author_data', true);
     if (!empty($data)) {
         $author->setData($data);
     }
     return $resultPage;
 }
Пример #3
0
 /**
  * Switch backend locale according to locale code
  *
  * @param string $localeCode
  * @return $this
  */
 public function switchBackendInterfaceLocale($localeCode)
 {
     $this->_session->setSessionLocale(null);
     $this->_authSession->getUser()->setInterfaceLocale($localeCode);
     $this->_translator->setLocale($localeCode)->loadData(null, true);
     return $this;
 }
Пример #4
0
 /**
  * @param string $locale
  * @dataProvider switchBackendInterfaceLocaleDataProvider
  * @covers \Magento\Backend\Model\Locale\Manager::switchBackendInterfaceLocale
  */
 public function testSwitchBackendInterfaceLocale($locale)
 {
     $this->_model->switchBackendInterfaceLocale($locale);
     $userInterfaceLocale = $this->_authSession->getUser()->getInterfaceLocale();
     $this->assertEquals($userInterfaceLocale, $locale);
     $sessionLocale = $this->_session->getSessionLocale();
     $this->assertEquals($sessionLocale, null);
 }
Пример #5
0
 /**
  * Bind locale
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function bindLocale($observer)
 {
     $locale = $observer->getEvent()->getLocale();
     if ($locale) {
         $selectedLocale = $this->_backendSession->getLocale();
         if ($selectedLocale) {
             $locale->setLocaleCode($selectedLocale);
         }
     }
     return $this;
 }
Пример #6
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDataFixture Magento/Core/_files/second_third_store.php
  * @magentoConfigFixture current_store customer/account_share/scope 0
  */
 public function testToHtmlEmptyGlobalShareAndSessionData()
 {
     $this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
     $customer = $this->customerAccountService->getCustomer(1);
     $this->backendSession->setCustomerData(array('account' => $customer->__toArray()));
     $block = $this->layout->createBlock('Magento\\Customer\\Block\\Adminhtml\\Edit\\Tab\\View\\Accordion');
     $html = $block->toHtml();
     $this->assertContains('Wishlist - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Main Website - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Second Website - 0 item(s)', $html);
     $this->assertContains('Shopping Cart of Third Website - 0 item(s)', $html);
 }
Пример #7
0
 /**
  * @covers \Magento\Customer\Controller\Adminhtml\Index\Index::execute
  */
 public function testExecute()
 {
     $this->prepareExecute();
     $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Customer::customer_manage');
     $this->resultPageMock->expects($this->once())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->pageConfigMock->expects($this->once())->method('getTitle')->willReturn($this->pageTitleMock);
     $this->pageTitleMock->expects($this->once())->method('prepend')->with('Customers');
     $this->resultPageMock->expects($this->atLeastOnce())->method('addBreadcrumb')->withConsecutive(['Customers', 'Customers'], ['Manage Customers', 'Manage Customers']);
     $this->sessionMock->expects($this->once())->method('unsCustomerData');
     $this->assertInstanceOf('Magento\\Framework\\View\\Result\\Page', $this->indexController->execute());
 }
Пример #8
0
 /**
  * Set locale
  *
  * @param string $locale
  * @return $this
  */
 public function setLocale($locale = null)
 {
     $forceLocale = $this->_request->getParam('locale', null);
     if (!$this->_localeValidator->isValid($forceLocale)) {
         $forceLocale = false;
     }
     $sessionLocale = $this->_session->getSessionLocale();
     $userLocale = $this->_localeManager->getUserInterfaceLocale();
     $localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
     if (count($localeCodes)) {
         $locale = reset($localeCodes);
     }
     return parent::setLocale($locale);
 }
Пример #9
0
 /**
  * @return \Magento\Backend\Model\View\Result\Page|\Magento\Backend\Model\View\Result\Redirect|\Magento\Framework\View\Result\Page
  */
 public function execute()
 {
     $id = $this->getRequest()->getParam('post_id');
     /** @var \Mageplaza\Blog\Model\Post $post */
     $post = $this->initPost();
     /** @var \Magento\Backend\Model\View\Result\Page|\Magento\Framework\View\Result\Page $resultPage */
     $resultPage = $this->resultPageFactory->create();
     $resultPage->setActiveMenu('Mageplaza_Blog::post');
     $resultPage->getConfig()->getTitle()->set(__('Posts'));
     if ($id) {
         $post->load($id);
         if (!$post->getId()) {
             $this->messageManager->addError(__('This Post no longer exists.'));
             $resultRedirect = $this->resultRedirectFactory->create();
             $resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
             return $resultRedirect;
         }
     }
     $title = $post->getId() ? $post->getName() : __('New Post');
     $resultPage->getConfig()->getTitle()->prepend($title);
     $data = $this->backendSession->getData('mageplaza_blog_post_data', true);
     if (!empty($data)) {
         $post->setData($data);
     }
     return $resultPage;
 }
Пример #10
0
 /**
  * Register module
  *
  * @param        $module
  * @param        $version
  * @param string $type
  */
 public function register($module, $version, $type = 'install')
 {
     if (null === $module || null === $version) {
         return;
     }
     $sessionDataKey = 'is_registered_' . $module;
     if ($this->session->getData($sessionDataKey)) {
         return;
     }
     $curl = new \Magento\Framework\HTTP\Client\Curl();
     try {
         $curl->post(self::EXTENSION_REGISTER_URL, ['module' => $module, 'version' => $version, 'site_url' => $this->getAllUrls(), 'type' => $type]);
         $this->session->setData($sessionDataKey, true);
     } catch (Exception $e) {
     }
 }
 /**
  * Force admin to change password
  *
  * @param EventObserver $observer
  * @return void
  */
 public function execute(EventObserver $observer)
 {
     if (!$this->observerConfig->isPasswordChangeForced()) {
         return;
     }
     if (!$this->authSession->isLoggedIn()) {
         return;
     }
     $actionList = ['adminhtml_system_account_index', 'adminhtml_system_account_save', 'adminhtml_auth_logout'];
     /** @var \Magento\Framework\App\Action\Action $controller */
     $controller = $observer->getEvent()->getControllerAction();
     /** @var \Magento\Framework\App\RequestInterface $request */
     $request = $observer->getEvent()->getRequest();
     if ($this->authSession->getPciAdminUserIsPasswordExpired()) {
         if (!in_array($request->getFullActionName(), $actionList)) {
             if ($this->authorization->isAllowed('Magento_Backend::myaccount')) {
                 $controller->getResponse()->setRedirect($this->url->getUrl('adminhtml/system_account/'));
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
                 $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_POST_DISPATCH, true);
             } else {
                 /*
                  * if admin password is expired and access to 'My Account' page is denied
                  * than we need to do force logout with error message
                  */
                 $this->authSession->clearStorage();
                 $this->session->clearStorage();
                 $this->messageManager->addErrorMessage(__('Your password has expired; please contact your administrator.'));
                 $controller->getRequest()->setDispatched(false);
             }
         }
     }
 }
Пример #12
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(['setRedirect', 'getHeader', '__wakeup'])->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(['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(['setIsUrlNotice', '__wakeup'])->getMock();
     $this->_session->expects($this->any())->method('setIsUrlNotice');
     $this->_helper = $this->getMockBuilder('Magento\\Backend\\Helper\\Data')->disableOriginalConstructor()->setMethods(['getUrl'])->getMock();
     $this->messageManager = $this->getMockBuilder('Magento\\Framework\\Message\\Manager')->disableOriginalConstructor()->setMethods(['addSuccess', 'addMessage', 'addException'])->getMock();
     $contextArgs = ['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));
     $this->titleMock = $this->getMockBuilder('\\Magento\\Framework\\View\\Page\\Title')->disableOriginalConstructor()->getMock();
     $contextMock->expects($this->any())->method('getTitle')->will($this->returnValue($this->titleMock));
     $this->viewInterfaceMock = $this->getMockBuilder('\\Magento\\Framework\\App\\ViewInterface')->disableOriginalConstructor()->getMock();
     $this->viewInterfaceMock->expects($this->any())->method('loadLayout')->will($this->returnSelf());
     $contextMock->expects($this->any())->method('getView')->will($this->returnValue($this->viewInterfaceMock));
     $this->resultLayoutMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\Layout')->disableOriginalConstructor()->getMock();
     $this->pageConfigMock = $this->getMockBuilder('Magento\\Framework\\View\\Page\\Config')->disableOriginalConstructor()->getMock();
     $this->customerAccountManagement = $this->getMockBuilder('Magento\\Customer\\Api\\AccountManagementInterface')->getMock();
     $this->resultLayoutFactoryMock = $this->getMockBuilder('Magento\\Framework\\View\\Result\\LayoutFactory')->disableOriginalConstructor()->getMock();
     $args = ['context' => $contextMock, 'customerAccountManagement' => $this->customerAccountManagement, 'resultLayoutFactory' => $this->resultLayoutFactoryMock];
     $helperObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_testedObject = $helperObjectManager->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Newsletter', $args);
 }
Пример #13
0
 /**
  * Return array of selected product ids from post or session
  *
  * @return array|null
  */
 public function getProductIds()
 {
     if ($this->_getRequest()->isPost() && $this->_getRequest()->getActionName() == 'edit') {
         $this->_session->setProductIds($this->_getRequest()->getParam('product', null));
     }
     return $this->_session->getProductIds();
 }
Пример #14
0
 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());
 }
Пример #15
0
 /**
  * Redirect into response section
  *
  * @return void
  */
 protected function redirectSection()
 {
     $this->actionFlag->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED)->will($this->returnValue(true));
     $this->sessionMock->expects($this->once())->method('setIsUrlNotice')->with(true);
     $this->helperMock->expects($this->once())->method('getUrl')->will($this->returnValue('redirect-path'));
     $this->responseMock->expects($this->once())->method('setRedirect');
 }
 /**
  * Run test execute method
  *
  * @param int|bool $categoryId
  * @param int $storeId
  * @return void
  *
  * @dataProvider dataProviderExecute
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testExecute($categoryId, $storeId)
 {
     $rootCategoryId = 2;
     $this->requestMock->expects($this->atLeastOnce())->method('getParam')->will($this->returnValueMap([['id', false, $categoryId], ['store', null, $storeId]]));
     $this->requestMock->expects($this->atLeastOnce())->method('getQuery')->with('isAjax')->will($this->returnValue(false));
     $this->mockInitCategoryCall();
     $this->sessionMock->expects($this->once())->method('__call')->will($this->returnValue([]));
     if (!$categoryId) {
         if ($storeId) {
             $this->storeManagerInterfaceMock->expects($this->once())->method('getStore')->with($storeId)->will($this->returnSelf());
         } else {
             $this->storeManagerInterfaceMock->expects($this->once())->method('getDefaultStoreView')->will($this->returnSelf());
         }
         $this->storeManagerInterfaceMock->expects($this->once())->method('getRootCategoryId')->will($this->returnValue($rootCategoryId));
         $categoryId = $rootCategoryId;
     }
     $this->requestMock->expects($this->atLeastOnce())->method('setParam')->with('id', $categoryId)->will($this->returnValue(true));
     $this->categoryMock->expects($this->atLeastOnce())->method('getId')->will($this->returnValue($categoryId));
     /**
      * @var \Magento\Framework\View\Element\Template
      * |\PHPUnit_Framework_MockObject_MockObject $blockMock
      */
     $blockMock = $this->getMock('Magento\\Framework\\View\\Element\\Template', ['setStoreId'], [], '', false);
     $blockMock->expects($this->once())->method('setStoreId')->with($storeId);
     $this->resultPageMock->expects($this->once())->method('getLayout')->will($this->returnSelf());
     $this->resultPageMock->expects($this->once())->method('getBlock')->willReturn($blockMock);
     $this->edit->execute();
 }
Пример #17
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));
 }
Пример #18
0
 /**
  * Run test execute method (fail print)
  */
 public function testExecuteFail()
 {
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue(false));
     $this->shipmentLoaderMock->expects($this->once())->method('load')->will($this->returnValue(false));
     $this->actionFlag->expects($this->once())->method('get')->with('', \Magento\Backend\App\AbstractAction::FLAG_IS_URLS_CHECKED)->will($this->returnValue(true));
     $this->sessionMock->expects($this->once())->method('setIsUrlNotice')->with(true);
     $this->assertNull($this->controller->execute());
 }
Пример #19
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);
 }
Пример #20
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testNewCustomer()
 {
     $customerBuilder = $this->objectManager->get('\\Magento\\Customer\\Service\\V1\\Data\\CustomerBuilder');
     $this->backendSession->setCustomerData(array('customer_id' => 0, 'account' => $customerBuilder->create()->__toArray()));
     $result = $this->accountBlock->initForm()->toHtml();
     // Contains send email controls
     $this->assertContains('<input id="_accountsendemail"', $result);
     $this->assertContains('<select id="_accountsendemail_store_id"', $result);
 }
Пример #21
0
 public function testExecute()
 {
     $data = ['tmp_name' => 'tmp_name', 'path' => 'path', 'file' => 'file'];
     $uploader = $this->getMockBuilder('Magento\\MediaStorage\\Model\\File\\Uploader')->disableOriginalConstructor()->getMock();
     $resultJson = $this->getMockBuilder('Magento\\Framework\\Controller\\Result\\Json')->disableOriginalConstructor()->setMethods(['setData'])->getMock();
     $this->request->expects($this->once())->method('getParam')->with('type')->willReturn('samples');
     $this->sample->expects($this->once())->method('getBaseTmpPath')->willReturn('base_tmp_path');
     $this->uploaderFactory->expects($this->once())->method('create')->willReturn($uploader);
     $this->fileHelper->expects($this->once())->method('uploadFromTmp')->willReturn($data);
     $this->storageDatabase->expects($this->once())->method('saveFile');
     $this->session->expects($this->once())->method('getName')->willReturn('Name');
     $this->session->expects($this->once())->method('getSessionId')->willReturn('SessionId');
     $this->session->expects($this->once())->method('getCookieLifetime')->willReturn('CookieLifetime');
     $this->session->expects($this->once())->method('getCookiePath')->willReturn('CookiePath');
     $this->session->expects($this->once())->method('getCookieDomain')->willReturn('CookieDomain');
     $this->resultFactory->expects($this->once())->method('create')->willReturn($resultJson);
     $resultJson->expects($this->once())->method('setData')->willReturnSelf();
     $this->assertEquals($resultJson, $this->upload->execute());
 }
Пример #22
0
 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testNewCustomer()
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterfaceFactory $customerFactory */
     $customerFactory = $this->objectManager->get('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory');
     $customerData = $this->dataObjectProcessor->buildOutputDataArray($customerFactory->create(), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->backendSession->setCustomerData(['customer_id' => 0, 'account' => $customerData]);
     $result = $this->accountBlock->initForm()->toHtml();
     // Contains send email controls
     $this->assertContains('<input id="_accountsendemail"', $result);
     $this->assertContains('<select id="_accountsendemail_store_id"', $result);
 }
Пример #23
0
 /**
  * run the action
  *
  * @return \Magento\Backend\Model\View\Result\Redirect
  */
 public function execute()
 {
     $data = $this->getRequest()->getPost('post');
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($data) {
         $post = $this->initPost();
         $post->setData($data);
         $image = $this->uploadModel->uploadFileAndGetName('image', $this->imageModel->getBaseDir(), $data);
         if ($image) {
             $post->setImage('mageplaza/blog/post/image' . $image);
         }
         $tags = $this->getRequest()->getPost('tags', -1);
         if ($tags != -1) {
             $post->setTagsData($this->jsHelper->decodeGridSerializedInput($tags));
         }
         $topics = $this->getRequest()->getPost('topics', -1);
         if ($topics != -1) {
             $post->setTopicsData($this->jsHelper->decodeGridSerializedInput($topics));
         }
         if (!isset($data['categories_ids'])) {
             $post->setCategoriesIds([]);
         }
         $this->_eventManager->dispatch('mageplaza_blog_post_prepare_save', ['post' => $post, 'request' => $this->getRequest()]);
         try {
             $post->save();
             $trafficModel = $this->trafficFactory->create()->load($post->getId(), 'post_id');
             if (!$trafficModel->getId()) {
                 $trafficData = ['post_id' => $post->getId(), 'numbers_view' => '0'];
                 $trafficModel->setData($trafficData);
                 $trafficModel->save();
             }
             $this->messageManager->addSuccess(__('The Post has been saved.'));
             $this->backendSession->setMageplazaBlogPostData(false);
             if ($this->getRequest()->getParam('back')) {
                 $resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
                 return $resultRedirect;
             }
             $resultRedirect->setPath('mageplaza_blog/*/');
             return $resultRedirect;
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\RuntimeException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('Something went wrong while saving the Post.'));
         }
         $this->_getSession()->setMageplazaBlogPostData($data);
         $resultRedirect->setPath('mageplaza_blog/*/edit', ['post_id' => $post->getId(), '_current' => true]);
         return $resultRedirect;
     }
     $resultRedirect->setPath('mageplaza_blog/*/');
     return $resultRedirect;
 }
Пример #24
0
 public function testUpdateNavigationMode()
 {
     $this->_setAdditionalExpectations();
     $request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $request->expects($this->once())->method('getPathInfo')->will($this->returnValue('/'));
     $this->_backendSession->expects($this->at(0))->method('setData')->with('vde_current_url', '/');
     $this->_backendSession->expects($this->at(1))->method('setData')->with('vde_current_mode', \Magento\DesignEditor\Model\State::MODE_NAVIGATION);
     $this->_urlModelFactory->expects($this->once())->method('replaceClassName')->with(self::URL_MODEL_NAVIGATION_MODE_CLASS_NAME);
     $this->_areaEmulator->expects($this->once())->method('emulateLayoutArea')->with(self::AREA_CODE);
     $controller = $this->getMock('Magento\\Backend\\App\\Action', [], [], '', false);
     $this->_model->update(self::AREA_CODE, $request, $controller);
 }
Пример #25
0
 public function testExecuteException()
 {
     $queryId = 1;
     $queryText = 'search';
     $this->mockGetRequestData($queryText, $queryId);
     $this->request->expects($this->at(4))->method('getPost')->with('store_id', false)->willReturn(1);
     $this->query->expects($this->once())->method('setStoreId');
     $this->query->expects($this->once())->method('loadByQueryText')->willThrowException(new \Exception());
     $this->messageManager->expects($this->once())->method('addException');
     $this->session->expects($this->once())->method('setPageData');
     $this->redirect->expects($this->once())->method('setPath')->willReturnSelf();
     $this->assertSame($this->redirect, $this->controller->execute());
 }
Пример #26
0
 /**
  * @param string $path
  * @param array $arguments
  * @param int $index
  */
 protected function prepareRedirect($path, $arguments, $index)
 {
     $this->actionFlag->expects($this->any())
         ->method('get')
         ->with('', 'check_url_settings')
         ->will($this->returnValue(true));
     $this->session->expects($this->any())
         ->method('setIsUrlNotice')
         ->with(true);
     $this->resultRedirect->expects($this->at($index))
         ->method('setPath')
         ->with($path, ['shipment_id' => $arguments['shipment_id']]);
 }
Пример #27
0
 /**
  * Get requested items qtys and return to stock flags
  *
  * @return array
  */
 protected function _getItemData()
 {
     $data = $this->getCreditmemo();
     if (!$data) {
         $data = $this->backendSession->getFormData(true);
     }
     if (isset($data['items'])) {
         $qtys = $data['items'];
     } else {
         $qtys = [];
     }
     return $qtys;
 }
Пример #28
0
 /**
  * Get requested items qtys and return to stock flags
  *
  * @param RequestInterface $request
  * @return array
  */
 protected function _getItemData(RequestInterface $request)
 {
     $data = $request->getParam('creditmemo');
     if (!$data) {
         $data = $this->backendSession->getFormData(true);
     }
     if (isset($data['items'])) {
         $qtys = $data['items'];
     } else {
         $qtys = array();
     }
     return $qtys;
 }
Пример #29
0
 /**
  * Put existing customer data into the backend session
  */
 protected function setupExistingCustomerData()
 {
     /** @var Customer $customer */
     $customer = $this->_customerAccountService->getCustomer(1);
     $this->_customerData = array('customer_id' => $customer->getId(), 'account' => \Magento\Framework\Service\ExtensibleDataObjectConverter::toFlatArray($customer));
     $this->_customerData['account']['id'] = $customer->getId();
     /** @var Address[] $addresses */
     $addresses = $this->_addressService->getAddresses(1);
     foreach ($addresses as $addressData) {
         $this->_customerData['address'][$addressData->getId()] = AddressConverter::toFlatArray($addressData);
         $this->_customerData['address'][$addressData->getId()]['id'] = $addressData->getId();
     }
     $this->_backendSession->setCustomerData($this->_customerData);
 }
Пример #30
0
 /**
  * Put existing customer data into the backend session
  */
 protected function setupExistingCustomerData()
 {
     /** @var \Magento\Customer\Api\Data\CustomerInterface $customer */
     $customer = $this->_customerRepository->getById(1);
     $this->_customerData = ['customer_id' => $customer->getId(), 'account' => $this->customerMapper->toFlatArray($customer)];
     $this->_customerData['account']['id'] = $customer->getId();
     /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
     $addresses = $customer->getAddresses();
     foreach ($addresses as $addressData) {
         $this->_customerData['address'][$addressData->getId()] = $this->addressMapper->toFlatArray($addressData);
         $this->_customerData['address'][$addressData->getId()]['id'] = $addressData->getId();
     }
     $this->_backendSession->setCustomerData($this->_customerData);
 }