Skip to content

Commit 3296659

Browse files
committed
MAGETWO-58383: [Backport] - [GitHub] Saving CMS page does not create URL rewrite in Magento 2.1.0 with single-store mode #5923 - for 2.1
1 parent 1ac2cb9 commit 3296659

File tree

2 files changed

+81
-79
lines changed

2 files changed

+81
-79
lines changed

app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Page/SaveTest.php

Lines changed: 69 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ protected function setUp()
8181
->willReturn($this->resultRedirect);
8282
$this->dataProcessorMock = $this->getMockBuilder(
8383
\Magento\Cms\Controller\Adminhtml\Page\PostDataProcessor::class
84-
)->setMethods(['filter'])->disableOriginalConstructor()->getMock();
84+
)->disableOriginalConstructor()
85+
->setMethods(['filter'])
86+
->getMock();
8587
$this->dataPersistorMock = $this->getMockBuilder(\Magento\Framework\App\Request\DataPersistorInterface::class)
8688
->getMock();
8789
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
@@ -132,34 +134,19 @@ public function testSaveAction()
132134
'content' => '"><script>alert("cookie: "+document.cookie)</script>'
133135
];
134136

137+
$params = [
138+
['page_id', null, $this->pageId],
139+
['back', null, false],
140+
];
141+
135142
$this->dataProcessorMock->expects($this->any())
136143
->method('filter')
137144
->with($postData)
138145
->willReturn($filteredPostData);
139146

140-
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn($postData);
141-
$this->requestMock->expects($this->atLeastOnce())
142-
->method('getParam')
143-
->willReturnMap(
144-
[
145-
['page_id', null, $this->pageId],
146-
['back', null, false],
147-
]
148-
);
149-
$page = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
150-
->disableOriginalConstructor()
151-
->getMock();
152-
$this->pageFactory->expects($this->atLeastOnce())
153-
->method('create')
154-
->willReturn($page);
155-
156-
$page->expects($this->any())
157-
->method('load')
158-
->willReturnSelf();
159-
$page->expects($this->any())
160-
->method('getId')
161-
->willReturn(true);
162-
$page->expects($this->once())->method('setData');
147+
$this->processRequest($postData, $params);
148+
/** @var \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject $cmsPage */
149+
$page = $this->getPageMock();
163150
$this->pageRepository->expects($this->once())->method('save')->with($page);
164151

165152
$this->dataPersistorMock->expects($this->any())
@@ -184,39 +171,25 @@ public function testSaveActionWithoutData()
184171

185172
public function testSaveAndContinue()
186173
{
187-
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['page_id' => $this->pageId]);
188-
$this->requestMock->expects($this->atLeastOnce())
189-
->method('getParam')
190-
->willReturnMap(
191-
[
192-
['page_id', null, $this->pageId],
193-
['back', null, true],
194-
]
195-
);
174+
$postData = ['page_id' => $this->pageId];
175+
$params = [
176+
['page_id', null, $this->pageId],
177+
['back', null, true],
178+
];
179+
180+
$this->processRequest($postData, $params);
196181

197182
$this->dataProcessorMock->expects($this->any())
198183
->method('filter')
199184
->willReturnArgument(0);
200-
$page = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
201-
->disableOriginalConstructor()
202-
->getMock();
203-
$this->pageFactory->expects($this->atLeastOnce())
204-
->method('create')
205-
->willReturn($page);
185+
/** @var \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject $cmsPage */
186+
$page = $this->getPageMock();
206187

207-
$page->expects($this->any())
208-
->method('load')
209-
->willReturnSelf();
210-
$page->expects($this->any())
211-
->method('getId')
212-
->willReturn(true);
213-
$page->expects($this->once())->method('setData');
214188
$this->pageRepository->expects($this->once())->method('save')->with($page);
215189

216190
$this->messageManagerMock->expects($this->once())
217191
->method('addSuccess')
218192
->with(__('You saved the page.'));
219-
220193
$this->dataPersistorMock->expects($this->any())
221194
->method('clear')
222195
->with('cms_page');
@@ -231,33 +204,19 @@ public function testSaveAndContinue()
231204

232205
public function testSaveActionThrowsException()
233206
{
234-
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn(['page_id' => $this->pageId]);
235-
$this->requestMock->expects($this->atLeastOnce())
236-
->method('getParam')
237-
->willReturnMap(
238-
[
239-
['page_id', null, $this->pageId],
240-
['back', null, true],
241-
]
242-
);
207+
$postData = ['page_id' => $this->pageId];
208+
$params = [
209+
['page_id', null, $this->pageId],
210+
['back', null, true],
211+
];
212+
213+
$this->processRequest($postData, $params);
243214

244215
$this->dataProcessorMock->expects($this->any())
245216
->method('filter')
246217
->willReturnArgument(0);
247-
$page = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
248-
->disableOriginalConstructor()
249-
->getMock();
250-
$this->pageFactory->expects($this->atLeastOnce())
251-
->method('create')
252-
->willReturn($page);
253-
254-
$page->expects($this->any())
255-
->method('load')
256-
->willReturnSelf();
257-
$page->expects($this->any())
258-
->method('getId')
259-
->willReturn(true);
260-
$page->expects($this->once())->method('setData');
218+
/** @var \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject $cmsPage */
219+
$page = $this->getPageMock();
261220
$this->pageRepository->expects($this->once())
262221
->method('save')
263222
->with($page)
@@ -279,4 +238,44 @@ public function testSaveActionThrowsException()
279238

280239
$this->assertSame($this->resultRedirect, $this->saveController->execute());
281240
}
241+
242+
/**
243+
* Create Cms Page Mock.
244+
*
245+
* @return \Magento\Cms\Model\Page|\PHPUnit_Framework_MockObject_MockObject
246+
*/
247+
private function getPageMock()
248+
{
249+
$page = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
250+
->disableOriginalConstructor()
251+
->getMock();
252+
$this->pageFactory->expects($this->atLeastOnce())
253+
->method('create')
254+
->willReturn($page);
255+
256+
$page->expects($this->any())
257+
->method('load')
258+
->willReturnSelf();
259+
$page->expects($this->any())
260+
->method('getId')
261+
->willReturn(true);
262+
$page->expects($this->once())->method('setData');
263+
264+
return $page;
265+
}
266+
267+
/**
268+
* Process save page action request.
269+
*
270+
* @param array $postData
271+
* @param array $params
272+
* @return void
273+
*/
274+
private function processRequest($postData, $params)
275+
{
276+
$this->requestMock->expects($this->any())->method('getPostValue')->willReturn($postData);
277+
$this->requestMock->expects($this->atLeastOnce())
278+
->method('getParam')
279+
->willReturnMap($params);
280+
}
282281
}

app/code/Magento/CmsUrlRewrite/Test/Unit/Model/CmsPageUrlRewriteGeneratorTest.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function testGenerateForAllStores()
6868
$cmsPage = $this->getMockBuilder(\Magento\Cms\Model\Page::class)
6969
->disableOriginalConstructor()
7070
->getMock();
71-
7271
$cmsPage->expects($this->any())->method('getStores')->willReturn($initializesStores);
7372
$store = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
7473
->setMethods(['getStoreId'])
@@ -80,7 +79,9 @@ public function testGenerateForAllStores()
8079
$this->urlRewriteFactory->expects($this->any())->method('create')->willReturn($urlRewrite);
8180
$cmsPage->expects($this->any())->method('getId')->willReturn($cmsPageId);
8281
$cmsPage->expects($this->any())->method('getIdentifier')->willReturn('request_path');
83-
$this->urlPathGenerator->expects($this->any())->method('getCanonicalUrlPath')->with($cmsPage)
82+
$this->urlPathGenerator->expects($this->any())
83+
->method('getCanonicalUrlPath')
84+
->with($cmsPage)
8485
->willReturn('cms/page/view/page_id/' . $cmsPageId);
8586

8687
$urls = $this->urlRewriteGenerator->generate($cmsPage);
@@ -104,12 +105,14 @@ public function testGenerateForSpecificStores()
104105
$secondStore = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)
105106
->setMethods(['getStoreId'])
106107
->getMockForAbstractClass();
107-
$this->storeManager->expects($this->any())->method('getStores')->willReturn(
108-
[
109-
1 => $firstStore,
110-
2 => $secondStore
111-
]
112-
);
108+
$this->storeManager->expects($this->any())
109+
->method('getStores')
110+
->willReturn(
111+
[
112+
1 => $firstStore,
113+
2 => $secondStore,
114+
]
115+
);
113116
$firstStore->expects($this->any())->method('getStoreId')->willReturn($initializesStores[0]);
114117
$secondStore->expects($this->any())->method('getStoreId')->willReturn($initializesStores[1]);
115118

@@ -128,7 +131,7 @@ public function testGenerateForSpecificStores()
128131
$this->assertEquals(
129132
[
130133
$initializesStores[0],
131-
$initializesStores[1]
134+
$initializesStores[1],
132135
],
133136
[
134137
$urls[0]->getStoreId(),

0 commit comments

Comments
 (0)