File tree Expand file tree Collapse file tree 2 files changed +47
-15
lines changed Expand file tree Collapse file tree 2 files changed +47
-15
lines changed Original file line number Diff line number Diff line change 11
11
use Magento \Framework \DataObject \IdentityInterface ;
12
12
use Magento \Framework \Exception \LocalizedException ;
13
13
use Magento \Framework \Model \AbstractModel ;
14
+ use Magento \Cms \Helper \Page as PageHelper ;
14
15
15
16
/**
16
17
* Cms Page Model
@@ -520,16 +521,16 @@ public function beforeSave()
520
521
{
521
522
$ originalIdentifier = $ this ->getOrigData ('identifier ' );
522
523
$ 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. ' ));
533
534
}
534
535
535
536
return parent ::beforeSave ();
Original file line number Diff line number Diff line change @@ -129,11 +129,42 @@ public function testBeforeSave404Identifier()
129
129
130
130
$ this ->scopeConfigMock ->expects ($ this ->once ())
131
131
->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
+ );
137
168
138
169
$ this ->model ->beforeSave ();
139
170
}
You can’t perform that action at this time.
0 commit comments