Skip to content

Commit 143b5db

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'tangoc/MAGETWO-43285' into new_pr_bugs
Conflicts: app/code/Magento/Cms/Model/Page/Source/Theme.php app/code/Magento/Cms/Test/Unit/Model/Page/Source/ThemeTest.php
2 parents 5587315 + b573e2b commit 143b5db

File tree

2 files changed

+112
-60
lines changed

2 files changed

+112
-60
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Page/InlineEdit.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
use Magento\Framework\Controller\Result\JsonFactory;
1111
use Magento\Cms\Api\Data\PageInterface;
1212

13+
/**
14+
* Cms page grid inline edit controller
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
1318
class InlineEdit extends \Magento\Backend\App\Action
1419
{
1520
/** @var PostDataProcessor */
@@ -63,7 +68,8 @@ public function execute()
6368
try {
6469
$pageData = $this->dataProcessor->filter($postItems[$pageId]);
6570
$this->validatePost($pageData, $page, $error, $messages);
66-
$page->setData(array_merge($page->getData(), $pageData));
71+
$extendedPageData = $page->getData();
72+
$this->setCmsPageData($page, $extendedPageData, $pageData);
6773
$this->pageRepository->save($page);
6874
} catch (\Magento\Framework\Exception\LocalizedException $e) {
6975
$messages[] = $this->getErrorWithPageId($page, $e->getMessage());
@@ -116,4 +122,18 @@ protected function getErrorWithPageId(PageInterface $page, $errorText)
116122
{
117123
return '[Page ID: ' . $page->getId() . '] ' . $errorText;
118124
}
125+
126+
/**
127+
* Set cms page data
128+
*
129+
* @param \Magento\Cms\Model\Page $page
130+
* @param array $extendedPageData
131+
* @param array $pageData
132+
* @return $this
133+
*/
134+
public function setCmsPageData(\Magento\Cms\Model\Page $page, array $extendedPageData, array $pageData)
135+
{
136+
$page->setData(array_merge($page->getData(), $extendedPageData, $pageData));
137+
return $this;
138+
}
119139
}

app/code/Magento/Cms/Test/Unit/Controller/Page/InlineEditTest.php renamed to app/code/Magento/Cms/Test/Unit/Controller/Adminhtml/Page/InlineEditTest.php

Lines changed: 91 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Cms\Test\Unit\Controller\Page;
6+
namespace Magento\Cms\Test\Unit\Controller\Adminhtml\Page;
77

88
use Magento\Cms\Controller\Adminhtml\Page\InlineEdit;
99

@@ -49,38 +49,11 @@ public function setUp()
4949
{
5050
$helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
5151

52-
$this->request = $this->getMockForAbstractClass(
53-
'Magento\Framework\App\RequestInterface',
54-
[],
55-
'',
56-
false
57-
);
58-
$this->messageManager = $this->getMockForAbstractClass(
59-
'Magento\Framework\Message\ManagerInterface',
60-
[],
61-
'',
62-
false
63-
);
64-
$this->messageCollection = $this->getMock(
65-
'Magento\Framework\Message\Collection',
66-
[],
67-
[],
68-
'',
69-
false
70-
);
71-
$this->message = $this->getMockForAbstractClass(
72-
'Magento\Framework\Message\MessageInterface',
73-
[],
74-
'',
75-
false
76-
);
77-
$this->cmsPage = $this->getMock(
78-
'Magento\Cms\Model\Page',
79-
[],
80-
[],
81-
'',
82-
false
83-
);
52+
$this->request = $this->getMockForAbstractClass('Magento\Framework\App\RequestInterface');
53+
$this->messageManager = $this->getMockForAbstractClass('Magento\Framework\Message\ManagerInterface');
54+
$this->messageCollection = $this->getMock('Magento\Framework\Message\Collection', [], [], '', false);
55+
$this->message = $this->getMockForAbstractClass('Magento\Framework\Message\MessageInterface');
56+
$this->cmsPage = $this->getMock('Magento\Cms\Model\Page', [], [], '', false);
8457
$this->context = $helper->getObject(
8558
'Magento\Backend\App\Action\Context',
8659
[
@@ -95,12 +68,7 @@ public function setUp()
9568
'',
9669
false
9770
);
98-
$this->pageRepository = $this->getMockForAbstractClass(
99-
'Magento\Cms\Api\PageRepositoryInterface',
100-
[],
101-
'',
102-
false
103-
);
71+
$this->pageRepository = $this->getMockForAbstractClass('Magento\Cms\Api\PageRepositoryInterface');
10472
$this->resultJson = $this->getMock('Magento\Framework\Controller\Result\Json', [], [], '', false);
10573
$this->jsonFactory = $this->getMock(
10674
'Magento\Framework\Controller\Result\JsonFactory',
@@ -125,15 +93,14 @@ public function prepareMocksForTestExecute()
12593
'identifier' => 'no-route'
12694
]
12795
];
128-
129-
$this->request->expects($this->at(1))
130-
->method('getParam')
131-
->with('isAjax')
132-
->willReturn(true);
133-
$this->request->expects($this->at(0))
96+
$this->request->expects($this->any())
13497
->method('getParam')
135-
->with('items', [])
136-
->willReturn($postData);
98+
->willReturnMap(
99+
[
100+
['isAjax', null, true],
101+
['items', [], $postData]
102+
]
103+
);
137104
$this->pageRepository->expects($this->once())
138105
->method('getById')
139106
->with(1)
@@ -160,7 +127,7 @@ public function prepareMocksForTestExecute()
160127
$this->cmsPage->expects($this->atLeastOnce())
161128
->method('getId')
162129
->willReturn('1');
163-
$this->cmsPage->expects($this->once())
130+
$this->cmsPage->expects($this->atLeastOnce())
164131
->method('getData')
165132
->willReturn([
166133
'layout' => '1column',
@@ -196,7 +163,7 @@ public function testExecuteWithLocalizedException()
196163
])
197164
->willReturnSelf();
198165

199-
$this->controller->execute();
166+
$this->assertSame($this->resultJson, $this->controller->execute());
200167
}
201168

202169
public function testExecuteWithRuntimeException()
@@ -217,7 +184,7 @@ public function testExecuteWithRuntimeException()
217184
])
218185
->willReturnSelf();
219186

220-
$this->controller->execute();
187+
$this->assertSame($this->resultJson, $this->controller->execute());
221188
}
222189

223190
public function testExecuteWithException()
@@ -238,22 +205,22 @@ public function testExecuteWithException()
238205
])
239206
->willReturnSelf();
240207

241-
$this->controller->execute();
208+
$this->assertSame($this->resultJson, $this->controller->execute());
242209
}
243210

244211
public function testExecuteWithoutData()
245212
{
246213
$this->jsonFactory->expects($this->once())
247214
->method('create')
248215
->willReturn($this->resultJson);
249-
$this->request->expects($this->at(0))
216+
$this->request->expects($this->any())
250217
->method('getParam')
251-
->with('items', [])
252-
->willReturn([]);
253-
$this->request->expects($this->at(1))
254-
->method('getParam')
255-
->with('isAjax', null)
256-
->willReturn(true);
218+
->willReturnMap(
219+
[
220+
['items', [], []],
221+
['isAjax', null, true]
222+
]
223+
);
257224
$this->resultJson->expects($this->once())
258225
->method('setData')
259226
->with([
@@ -264,6 +231,71 @@ public function testExecuteWithoutData()
264231
])
265232
->willReturnSelf();
266233

267-
$this->controller->execute();
234+
$this->assertSame($this->resultJson, $this->controller->execute());
235+
}
236+
237+
public function testSetCmsPageData()
238+
{
239+
$extendedPageData = [
240+
'page_id' => '2',
241+
'title' => 'Home Page',
242+
'page_layout' => '1column',
243+
'identifier' => 'home',
244+
'content_heading' => 'Home Page',
245+
'content' => 'CMS homepage content goes here.',
246+
'is_active' => '1',
247+
'sort_order' => '1',
248+
'custom_theme' => '3',
249+
'website_root' => '1',
250+
'under_version_control' => '0',
251+
'store_id' => ['0']
252+
];
253+
$pageData = [
254+
'page_id' => '2',
255+
'title' => 'Home Page',
256+
'page_layout' => '1column',
257+
'identifier' => 'home',
258+
'is_active' => '1',
259+
'custom_theme' => '3',
260+
'under_version_control' => '0',
261+
];
262+
$getData = [
263+
'page_id' => '2',
264+
'title' => 'Home Page',
265+
'page_layout' => '1column',
266+
'identifier' => 'home',
267+
'content_heading' => 'Home Page',
268+
'content' => 'CMS homepage content goes here.',
269+
'is_active' => '1',
270+
'sort_order' => '1',
271+
'custom_theme' => '3',
272+
'custom_root_template' => '1column',
273+
'published_revision_id' => '0',
274+
'website_root' => '1',
275+
'under_version_control' => '0',
276+
'store_id' => ['0']
277+
];
278+
$mergedData = [
279+
'page_id' => '2',
280+
'title' => 'Home Page',
281+
'page_layout' => '1column',
282+
'identifier' => 'home',
283+
'content_heading' => 'Home Page',
284+
'content' => 'CMS homepage content goes here.',
285+
'is_active' => '1',
286+
'sort_order' => '1',
287+
'custom_theme' => '3',
288+
'custom_root_template' => '1column',
289+
'published_revision_id' => '0',
290+
'website_root' => '1',
291+
'under_version_control' => '0',
292+
'store_id' => ['0']
293+
];
294+
$this->cmsPage->expects($this->once())->method('getData')->willReturn($getData);
295+
$this->cmsPage->expects($this->once())->method('setData')->with($mergedData)->willReturnSelf();
296+
$this->assertSame(
297+
$this->controller,
298+
$this->controller->setCmsPageData($this->cmsPage, $extendedPageData, $pageData)
299+
);
268300
}
269301
}

0 commit comments

Comments
 (0)