Skip to content

Commit e88e150

Browse files
committed
Fix static, functional tests
1 parent 6aa28f3 commit e88e150

File tree

3 files changed

+154
-83
lines changed

3 files changed

+154
-83
lines changed

app/code/Magento/Cms/Test/Unit/Ui/Component/Listing/Column/PageActionsTest.php

Lines changed: 149 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -3,105 +3,112 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Cms\Test\Unit\Ui\Component\Listing\Column;
79

810
use Magento\Cms\Ui\Component\Listing\Column\PageActions;
11+
use Magento\Cms\ViewModel\Page\Grid\UrlBuilder;
912
use Magento\Framework\Escaper;
13+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
14+
use Magento\Framework\UrlInterface;
15+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
16+
use Magento\Framework\View\Element\UiComponent\Processor;
17+
use PHPUnit\Framework\TestCase;
18+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1019

1120
/**
1221
* Test for Magento\Cms\Ui\Component\Listing\Column\PageActions class.
1322
*/
14-
class PageActionsTest extends \PHPUnit\Framework\TestCase
23+
class PageActionsTest extends TestCase
1524
{
16-
public function testPrepareItemsByPageId()
25+
26+
/**
27+
* @var UrlInterface|MockObject
28+
*/
29+
private $urlBuilderMock;
30+
31+
/**
32+
* @var UrlBuilder|MockObject
33+
*/
34+
private $scopeUrlBuilderMock;
35+
36+
/**
37+
* @var ContextInterface|MockObject
38+
*/
39+
private $contextMock;
40+
41+
/**
42+
* @var Processor|MockObject
43+
*/
44+
private $processorMock;
45+
46+
/**
47+
* @var Escaper|MockObject
48+
*/
49+
private $escaperMock;
50+
51+
/**
52+
* @var PageActions
53+
*/
54+
private $model;
55+
56+
/**
57+
* @inheritDoc
58+
*/
59+
public function setUp()
1760
{
18-
$pageId = 1;
19-
// Create Mocks and SUT
20-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
21-
/** @var \PHPUnit_Framework_MockObject_MockObject $urlBuilderMock */
22-
$urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
23-
->disableOriginalConstructor()
24-
->getMock();
25-
$scopeUrlBuilderMock = $this->getMockBuilder(\Magento\Cms\ViewModel\Page\Grid\UrlBuilder::class)
26-
->disableOriginalConstructor()
27-
->getMock();
28-
$contextMock = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\ContextInterface::class)
61+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
62+
$this->scopeUrlBuilderMock = $this->createMock(UrlBuilder::class);
63+
$this->processorMock = $this->createMock(Processor::class);
64+
$this->contextMock = $this->getMockBuilder(ContextInterface::class)
2965
->getMockForAbstractClass();
30-
$processor = $this->getMockBuilder(\Magento\Framework\View\Element\UiComponent\Processor::class)
66+
$this->escaperMock = $this->getMockBuilder(Escaper::class)
3167
->disableOriginalConstructor()
68+
->setMethods(['escapeHtml'])
3269
->getMock();
33-
$contextMock->expects($this->never())->method('getProcessor')->willReturn($processor);
3470

35-
/** @var \Magento\Cms\Ui\Component\Listing\Column\PageActions $model */
36-
$model = $objectManager->getObject(
37-
\Magento\Cms\Ui\Component\Listing\Column\PageActions::class,
71+
$objectManager = new ObjectManager($this);
72+
73+
$this->model = $objectManager->getObject(
74+
PageActions::class,
3875
[
39-
'urlBuilder' => $urlBuilderMock,
40-
'context' => $contextMock,
41-
'scopeUrlBuilder' => $scopeUrlBuilderMock
76+
'urlBuilder' => $this->urlBuilderMock,
77+
'context' => $this->contextMock,
78+
'scopeUrlBuilder' => $this->scopeUrlBuilderMock
4279
]
4380
);
4481

45-
$escaper = $this->getMockBuilder(Escaper::class)
46-
->disableOriginalConstructor()
47-
->setMethods(['escapeHtml'])
48-
->getMock();
49-
$objectManager->setBackwardCompatibleProperty($model, 'escaper', $escaper);
50-
51-
// Define test input and expectations
52-
$title = 'page title';
53-
$identifier = 'page_identifier';
54-
55-
$items = [
56-
'data' => [
57-
'items' => [
58-
[
59-
'page_id' => $pageId,
60-
'title' => $title,
61-
'identifier' => $identifier
62-
]
63-
]
64-
]
65-
];
66-
$name = 'item_name';
67-
$expectedItems = [
68-
[
69-
'page_id' => $pageId,
70-
'title' => $title,
71-
'identifier' => $identifier,
72-
$name => [
73-
'edit' => [
74-
'href' => 'test/url/edit',
75-
'label' => __('Edit'),
76-
'__disableTmpl' => true,
77-
],
78-
'delete' => [
79-
'href' => 'test/url/delete',
80-
'label' => __('Delete'),
81-
'confirm' => [
82-
'title' => __('Delete %1', $title),
83-
'message' => __('Are you sure you want to delete a %1 record?', $title),
84-
'__disableTmpl' => true,
85-
],
86-
'post' => true,
87-
'__disableTmpl' => true,
88-
],
89-
'preview' => [
90-
'href' => 'test/url/view',
91-
'label' => __('View'),
92-
'__disableTmpl' => true,
93-
'target' => '_blank'
94-
]
95-
],
96-
],
97-
];
82+
$objectManager->setBackwardCompatibleProperty($this->model, 'escaper', $this->escaperMock);
83+
}
9884

99-
$escaper->expects(static::once())
85+
/**
86+
* Verify Prepare Items by page Id.
87+
*
88+
* @dataProvider configDataProvider
89+
* @param int $pageId
90+
* @param string $title
91+
* @param string $name
92+
* @param array $items
93+
* @param array $expectedItems
94+
* @return void
95+
*/
96+
public function testPrepareItemsByPageId(
97+
int $pageId,
98+
string $title,
99+
string $name,
100+
array $items,
101+
array $expectedItems
102+
):void {
103+
$this->contextMock->expects($this->never())
104+
->method('getProcessor')
105+
->willReturn($this->processorMock);
106+
$this->escaperMock->expects(static::once())
100107
->method('escapeHtml')
101108
->with($title)
102109
->willReturn($title);
103110
// Configure mocks and object data
104-
$urlBuilderMock->expects($this->any())
111+
$this->urlBuilderMock->expects($this->any())
105112
->method('getUrl')
106113
->willReturnMap(
107114
[
@@ -122,13 +129,76 @@ public function testPrepareItemsByPageId()
122129
]
123130
);
124131

125-
$scopeUrlBuilderMock->expects($this->any())
132+
$this->scopeUrlBuilderMock->expects($this->any())
126133
->method('getUrl')
127134
->willReturn('test/url/view');
128135

129-
$model->setName($name);
130-
$items = $model->prepareDataSource($items);
136+
$this->model->setName($name);
137+
$items = $this->model->prepareDataSource($items);
131138
// Run test
132139
$this->assertEquals($expectedItems, $items['data']['items']);
133140
}
141+
142+
/**
143+
* Data provider for testPrepareItemsByPageId
144+
*
145+
* @return array
146+
*/
147+
public function configDataProvider():array
148+
{
149+
$pageId = 1;
150+
$title = 'page title';
151+
$identifier = 'page_identifier';
152+
$name = 'item_name';
153+
154+
return [
155+
[
156+
'pageId' => $pageId,
157+
'title' => $title,
158+
'name' => $name,
159+
'items' => [
160+
'data' => [
161+
'items' => [
162+
[
163+
'page_id' => $pageId,
164+
'title' => $title,
165+
'identifier' => $identifier
166+
]
167+
]
168+
]
169+
],
170+
'expectedItems' => [
171+
[
172+
'page_id' => $pageId,
173+
'title' => $title,
174+
'identifier' => $identifier,
175+
$name => [
176+
'edit' => [
177+
'href' => 'test/url/edit',
178+
'label' => __('Edit'),
179+
'__disableTmpl' => true,
180+
],
181+
'delete' => [
182+
'href' => 'test/url/delete',
183+
'label' => __('Delete'),
184+
'confirm' => [
185+
'title' => __('Delete %1', $title),
186+
'message' => __('Are you sure you want to delete a %1 record?', $title),
187+
'__disableTmpl' => true,
188+
],
189+
'post' => true,
190+
'__disableTmpl' => true,
191+
],
192+
'preview' => [
193+
'href' => 'test/url/view',
194+
'label' => __('View'),
195+
'__disableTmpl' => true,
196+
'target' => '_blank'
197+
]
198+
],
199+
],
200+
]
201+
]
202+
];
203+
}
134204
}

app/code/Magento/Cms/Ui/Component/Listing/Column/PageActions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Magento\Ui\Component\Listing\Columns\Column;
1515

1616
/**
17-
* Class PageActions
17+
* Class prepare Page Actions
1818
*/
1919
class PageActions extends Column
2020
{

app/code/Magento/Widget/Test/Mftf/Test/ProductsListWidgetTest.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
*/
77
-->
88

9-
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10-
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
1110
<test name="ProductsListWidgetTest">
1211
<annotations>
1312
<features value="Widget"/>
@@ -61,8 +60,10 @@
6160
<click selector="{{CmsPagesPageActionsSection.select(_newDefaultCmsPage.title)}}" stepKey="clickSelect" />
6261
<waitForElementVisible selector="{{CmsPagesPageActionsSection.edit(_newDefaultCmsPage.title)}}" stepKey="waitForEditLink" />
6362
<click selector="{{CmsPagesPageActionsSection.preview(_newDefaultCmsPage.title)}}" stepKey="clickEdit" />
63+
<switchToNextTab stepKey="switchToNextTab"/>
6464
<waitForPageLoad stepKey="waitForCMSPage"/>
6565
<seeInTitle userInput="{{_newDefaultCmsPage.title}}" stepKey="seePageTitle"/>
6666
<see userInput="{{_newDefaultCmsPage.title}}" stepKey="seeProduct"/>
67+
<closeTab stepKey="closeCurrentTab"/>
6768
</test>
68-
</tests>
69+
</tests>

0 commit comments

Comments
 (0)