php Magento-Backend-Model-Session类(方法)实例源码

下面列出了php Magento-Backend-Model-Session 类(方法)源码代码实例,从而了解它的用法。

作者:nblai    项目:magescotc   
/**
  * 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);
 }

作者:nh    项目:Magento2SampleModul   
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;
 }

作者:Doabilit    项目:magento2de   
/**
  * 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;
 }

作者:opexs    项目:magento   
/**
  * @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);
 }

作者:aies    项目:magento   
/**
  * 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;
 }

作者:aies    项目:magento   
/**
  * @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);
 }

作者:shabbirvividad    项目:magento   
/**
  * 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);
 }

作者:mageplaz    项目:magento-2-blog-extensio   
/**
  * @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;
 }

作者:pradeep-wagent    项目:magento   
/**
  * 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);
             }
         }
     }
 }

作者:kidaa3    项目:magento2-platforms   
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());
 }

作者:aies    项目:magento   
/**
  * @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);
 }

作者:pradeep-wagent    项目:magento   
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());
 }

作者:opexs    项目:magento   
/**
  * @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);
 }

作者:mageplaz    项目:magento-2-blog-extensio   
/**
  * 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;
 }

作者:shabbirvividad    项目:magento   
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);
 }

作者:whoopl    项目:magento2-testin   
/**
  * 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;
 }

作者:Atli    项目:docker-magento   
/**
  * 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;
 }

作者:aies    项目:magento   
/**
  * 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);
 }

作者:shabbirvividad    项目:magento   
/**
  * 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);
 }

作者:kidaa3    项目:magento2-platforms   
/**
  * @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());
 }


问题


面经


文章

微信
公众号

扫码关注公众号