Skip to content

Commit 36ff0dc

Browse files
MAGETWO-52215: Cms pages isn't synchronized with core_config_data
1 parent ea39011 commit 36ff0dc

File tree

2 files changed

+47
-15
lines changed

2 files changed

+47
-15
lines changed

app/code/Magento/Cms/Model/Page.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\DataObject\IdentityInterface;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\Model\AbstractModel;
14+
use Magento\Cms\Helper\Page as PageHelper;
1415

1516
/**
1617
* Cms Page Model
@@ -520,16 +521,16 @@ public function beforeSave()
520521
{
521522
$originalIdentifier = $this->getOrigData('identifier');
522523
$currentIdentifier = $this->getIdentifier();
523-
$scopeConfigIdentifier = $this->getScopeConfig()->getValue(
524-
\Magento\Cms\Helper\Page::XML_PATH_NO_ROUTE_PAGE
525-
);
526-
527-
if (
528-
$this->getId()
529-
&& $originalIdentifier !== $currentIdentifier
530-
&& $originalIdentifier === $scopeConfigIdentifier
531-
) {
532-
throw new LocalizedException(__('This identifier is reserved for 404 error page in configuration.'));
524+
525+
if (!$this->getId() || $originalIdentifier === $currentIdentifier) {
526+
return parent::beforeSave();
527+
}
528+
529+
switch ($originalIdentifier) {
530+
case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_NO_ROUTE_PAGE):
531+
throw new LocalizedException(__('This identifier is reserved for 404 error page in configuration.'));
532+
case $this->getScopeConfig()->getValue(PageHelper::XML_PATH_HOME_PAGE):
533+
throw new LocalizedException(__('This identifier is reserved for home page in configuration.'));
533534
}
534535

535536
return parent::beforeSave();

app/code/Magento/Cms/Test/Unit/Model/PageTest.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,42 @@ public function testBeforeSave404Identifier()
129129

130130
$this->scopeConfigMock->expects($this->once())
131131
->method('getValue')
132-
->with(
133-
\Magento\Cms\Helper\Page::XML_PATH_NO_ROUTE_PAGE,
134-
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
135-
null
136-
)->willReturn('no-route');
132+
->willReturnMap(
133+
[
134+
[
135+
\Magento\Cms\Helper\Page::XML_PATH_NO_ROUTE_PAGE,
136+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
137+
null,
138+
'no-route'
139+
]
140+
]
141+
);
142+
143+
$this->model->beforeSave();
144+
}
145+
146+
/**
147+
* @expectedException \Magento\Framework\Exception\LocalizedException
148+
* @expectedExceptionMessage This identifier is reserved for home page in configuration.
149+
*/
150+
public function testBeforeSaveHomeIdentifier()
151+
{
152+
$this->model->setId(1);
153+
$this->model->setOrigData('identifier', 'home');
154+
$this->model->setIdentifier('home2');
155+
156+
$this->scopeConfigMock->expects($this->atLeastOnce())
157+
->method('getValue')
158+
->willReturnMap(
159+
[
160+
[
161+
\Magento\Cms\Helper\Page::XML_PATH_HOME_PAGE,
162+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
163+
null,
164+
'home'
165+
]
166+
]
167+
);
137168

138169
$this->model->beforeSave();
139170
}

0 commit comments

Comments
 (0)