本文整理汇总了PHP中Magento\Backend\Model\Session类的典型用法代码示例。如果您正苦于以下问题:PHP Session类的具体用法?PHP Session怎么用?PHP Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* 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: execute
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: switchBackendInterfaceLocale
/**
* 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: testSwitchBackendInterfaceLocale
/**
* @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: bindLocale
/**
* 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: testToHtmlEmptyGlobalShareAndSessionData
/**
* @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: setLocale
/**
* 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);
}
示例8: execute
/**
* @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;
}
示例9: execute
/**
* 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);
}
}
}
}
示例10: testExecute
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());
}
示例11: testNewCustomer
/**
* @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);
}
示例12: testExecute
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());
}
示例13: testNewCustomer
/**
* @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);
}
示例14: execute
/**
* 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;
}
示例15: testExecute
/**
* @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());
}