Пример #1
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);
 }
Пример #2
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = array('password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**');
     $testedMessage = 'The account has been saved.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Locale\\Validator'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
Пример #3
0
 public function testSaveAction()
 {
     $userId = 1;
     $requestParams = ['password' => 'password', 'password_confirmation' => true, 'interface_locale' => 'US', 'username' => 'Foo', 'firstname' => 'Bar', 'lastname' => 'Dummy', 'email' => '*****@*****.**', \Magento\Backend\Block\System\Account\Edit\Form::IDENTITY_VERIFICATION_PASSWORD_FIELD => 'current_password'];
     $testedMessage = 'You saved the account.';
     $this->_authSessionMock->expects($this->any())->method('getUser')->will($this->returnValue($this->_userMock));
     $this->_userMock->expects($this->any())->method('load')->will($this->returnSelf());
     $this->_validatorMock->expects($this->once())->method('isValid')->with($this->equalTo($requestParams['interface_locale']))->will($this->returnValue(true));
     $this->_managerMock->expects($this->any())->method('switchBackendInterfaceLocale');
     $this->_objectManagerMock->expects($this->at(0))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Auth\\Session'))->will($this->returnValue($this->_authSessionMock));
     $this->_objectManagerMock->expects($this->at(1))->method('create')->with($this->equalTo('Magento\\User\\Model\\User'))->will($this->returnValue($this->_userMock));
     $this->_objectManagerMock->expects($this->at(2))->method('get')->with($this->equalTo('Magento\\Framework\\Validator\\Locale'))->will($this->returnValue($this->_validatorMock));
     $this->_objectManagerMock->expects($this->at(3))->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Locale\\Manager'))->will($this->returnValue($this->_managerMock));
     $this->_userMock->setUserId($userId);
     $this->_userMock->expects($this->once())->method('save');
     $this->_userMock->expects($this->once())->method('verifyIdentity')->will($this->returnValue(true));
     $this->_userMock->expects($this->once())->method('sendPasswordResetNotificationEmail');
     $this->_requestMock->setParams($requestParams);
     $this->_messagesMock->expects($this->once())->method('addSuccess')->with($this->equalTo($testedMessage));
     $this->_controller->execute();
 }
Пример #4
0
 /**
  * @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
  */
 public function testGetUserInterfaceLocale()
 {
     $this->_model->switchBackendInterfaceLocale('de_DE');
     $locale = $this->_model->getUserInterfaceLocale();
     $this->assertEquals($locale, 'de_DE');
 }
Пример #5
0
 /**
  * @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
  */
 public function testGetUserInterfaceGeneralLocale()
 {
     $this->_backendConfig->expects($this->any())->method('getValue')->with('general/locale/code')->willReturn('test_locale');
     $locale = $this->_model->getUserInterfaceLocale();
     $this->assertEquals($locale, 'test_locale');
 }