Skip to content

Commit 1869f2b

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-47940-bunch-of-publick-prs' into PR_Branch
2 parents af8e481 + 67eedfc commit 1869f2b

File tree

6 files changed

+69
-16
lines changed

6 files changed

+69
-16
lines changed

app/code/Magento/Backend/Model/Locale/Manager.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,30 @@ class Manager
2626
* @var \Magento\Framework\TranslateInterface
2727
*/
2828
protected $_translator;
29+
30+
/**
31+
* @var \Magento\Backend\App\ConfigInterface
32+
*/
33+
protected $_backendConfig;
2934

3035
/**
3136
* Constructor
3237
*
3338
* @param \Magento\Backend\Model\Session $session
3439
* @param \Magento\Backend\Model\Auth\Session $authSession
3540
* @param \Magento\Framework\TranslateInterface $translator
41+
* @param \Magento\Backend\App\ConfigInterface $backendConfig
3642
*/
3743
public function __construct(
3844
\Magento\Backend\Model\Session $session,
3945
\Magento\Backend\Model\Auth\Session $authSession,
40-
\Magento\Framework\TranslateInterface $translator
46+
\Magento\Framework\TranslateInterface $translator,
47+
\Magento\Backend\App\ConfigInterface $backendConfig
4148
) {
4249
$this->_session = $session;
4350
$this->_authSession = $authSession;
4451
$this->_translator = $translator;
52+
$this->_backendConfig = $backendConfig;
4553
}
4654

4755
/**
@@ -53,28 +61,40 @@ public function __construct(
5361
public function switchBackendInterfaceLocale($localeCode)
5462
{
5563
$this->_session->setSessionLocale(null);
56-
64+
5765
$this->_authSession->getUser()->setInterfaceLocale($localeCode);
58-
66+
5967
$this->_translator->setLocale($localeCode)->loadData(null, true);
60-
68+
6169
return $this;
6270
}
6371

72+
/**
73+
* Get general interface locale
74+
*
75+
* @return string
76+
*/
77+
public function getGeneralLocale()
78+
{
79+
return $this->_backendConfig->getValue('general/locale/code');
80+
}
81+
6482
/**
6583
* Get user interface locale stored in session data
6684
*
6785
* @return string
6886
*/
6987
public function getUserInterfaceLocale()
7088
{
71-
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
72-
7389
$userData = $this->_authSession->getUser();
90+
$interfaceLocale = \Magento\Framework\Locale\Resolver::DEFAULT_LOCALE;
91+
7492
if ($userData && $userData->getInterfaceLocale()) {
7593
$interfaceLocale = $userData->getInterfaceLocale();
94+
} elseif ($this->getGeneralLocale()) {
95+
$interfaceLocale = $this->getGeneralLocale();
7696
}
77-
97+
7898
return $interfaceLocale;
7999
}
80100
}

app/code/Magento/Backend/Test/Unit/Model/Locale/ManagerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
1515
protected $_model;
1616

1717
/**
18-
* @var \Magento\Framework\TranslateInterface
18+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\TranslateInterface
1919
*/
2020
protected $_translator;
2121

@@ -25,9 +25,14 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
2525
protected $_session;
2626

2727
/**
28-
* @var \Magento\Backend\Model\Auth\Session
28+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\Model\Auth\Session
2929
*/
3030
protected $_authSession;
31+
32+
/**
33+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Backend\App\ConfigInterface
34+
*/
35+
protected $_backendConfig;
3136

3237
protected function setUp()
3338
{
@@ -40,7 +45,9 @@ protected function setUp()
4045
'',
4146
false
4247
);
43-
48+
49+
$this->_backendConfig = $this->getMockForAbstractClass('Magento\Backend\App\ConfigInterface', [], '', false);
50+
4451
$userMock = new \Magento\Framework\DataObject();
4552

4653
$this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
@@ -54,7 +61,8 @@ protected function setUp()
5461
$this->_model = new \Magento\Backend\Model\Locale\Manager(
5562
$this->_session,
5663
$this->_authSession,
57-
$this->_translator
64+
$this->_translator,
65+
$this->_backendConfig
5866
);
5967
}
6068

@@ -102,4 +110,17 @@ public function testGetUserInterfaceLocale()
102110

103111
$this->assertEquals($locale, 'de_DE');
104112
}
113+
114+
/**
115+
* @covers \Magento\Backend\Model\Locale\Manager::getUserInterfaceLocale
116+
*/
117+
public function testGetUserInterfaceGeneralLocale()
118+
{
119+
$this->_backendConfig->expects($this->any())
120+
->method('getValue')
121+
->with('general/locale/code')
122+
->willReturn('test_locale');
123+
$locale = $this->_model->getUserInterfaceLocale();
124+
$this->assertEquals($locale, 'test_locale');
125+
}
105126
}

app/code/Magento/Cms/etc/webapi.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<route url="/V1/cmsPage/:pageId" method="GET">
1212
<service class="Magento\Cms\Api\PageRepositoryInterface" method="getById"/>
1313
<resources>
14-
<resource ref="Magento_Cms::page"/>
14+
<resource ref="anonymous"/>
1515
</resources>
1616
</route>
1717
<route url="/V1/cmsPage/search" method="GET">
@@ -42,7 +42,7 @@
4242
<route url="/V1/cmsBlock/:blockId" method="GET">
4343
<service class="Magento\Cms\Api\BlockRepositoryInterface" method="getById"/>
4444
<resources>
45-
<resource ref="Magento_Cms::block"/>
45+
<resource ref="anonymous"/>
4646
</resources>
4747
</route>
4848
<route url="/V1/cmsBlock/search" method="GET">

lib/internal/Magento/Framework/App/Action/AbstractAction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ abstract class AbstractAction implements \Magento\Framework\App\ActionInterface
3333
protected $resultFactory;
3434

3535
/**
36-
* @param \Magento\Framework\App\Action\Context $context
36+
* @param Context $context
3737
*/
3838
public function __construct(
39-
\Magento\Framework\App\Action\Context $context
39+
Context $context
4040
) {
4141
$this->_request = $context->getRequest();
4242
$this->_response = $context->getResponse();

lib/internal/Magento/Framework/Session/SaveHandler/Native.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@
1010
*/
1111
class Native extends \SessionHandler
1212
{
13+
/**
14+
* Workaround for php7 session_regenerate_id error
15+
* @see https://bugs.php.net/bug.php?id=71187
16+
*
17+
* @param string $sessionId
18+
* @return string
19+
*/
20+
public function read($sessionId)
21+
{
22+
return (string)parent::read($sessionId);
23+
}
1324
}

lib/internal/Magento/Framework/Url.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ public function addQueryParams(array $data)
763763
*/
764764
public function setQueryParam($key, $data)
765765
{
766-
return $this->_queryParamsResolver->setQueryParam($key, $data);
766+
$this->_queryParamsResolver->setQueryParam($key, $data);
767+
return $this;
767768
}
768769

769770
/**

0 commit comments

Comments
 (0)