Skip to content

Commit c0854f5

Browse files
ENGCOM-6498: [Search] Cover SynonymActions Column by Unit Test #26076
2 parents 9400c1e + 7059ab2 commit c0854f5

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Search\Test\Unit\Ui\Component\Listing\Column;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\Framework\UrlInterface;
13+
use Magento\Search\Ui\Component\Listing\Column\SynonymActions;
14+
use PHPUnit\Framework\MockObject\MockObject;
15+
use PHPUnit\Framework\TestCase;
16+
17+
class SynonymActionsTest extends TestCase
18+
{
19+
/**
20+
* Stub synonym group id
21+
*/
22+
private const STUB_SYNONYM_GROUP_ID = 1;
23+
24+
/**
25+
* Synonym group delete url
26+
*/
27+
private const SYNONYM_GROUP_DELETE_URL = 'http://localhost/magento2/admin/search/synonyms/delete/group_id/%d';
28+
29+
/**
30+
* Synonym group edit url
31+
*/
32+
private const SYNONYM_GROUP_EDIT_URL = 'http://localhost/magento2/admin/search/synonyms/edit/group_id/%d';
33+
34+
/**
35+
* @var SynonymActions
36+
*/
37+
private $synonymActions;
38+
39+
/**
40+
* @var UrlInterface|MockObject
41+
*/
42+
private $urlBuilderMock;
43+
44+
/**
45+
* Setup environment to test
46+
*/
47+
protected function setup()
48+
{
49+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
50+
51+
$objectManager = new ObjectManager($this);
52+
53+
$this->synonymActions = $objectManager->getObject(
54+
SynonymActions::class,
55+
[
56+
'urlBuilder' => $this->urlBuilderMock,
57+
'data' => [
58+
'name' => 'actions'
59+
]
60+
]
61+
);
62+
}
63+
64+
/**
65+
* Test prepareDataSource() with data source has no item
66+
*/
67+
public function testPrepareDataSourceWithNoItem()
68+
{
69+
$dataSource = [
70+
'data' => []
71+
];
72+
$expected = [
73+
'data' => []
74+
];
75+
/**
76+
* Assert Result
77+
*/
78+
$this->assertEquals($expected, $this->synonymActions->prepareDataSource($dataSource));
79+
}
80+
81+
/**
82+
* Test prepareDataSource() with data source has items
83+
*/
84+
public function testPrepareDataSourceWithItems()
85+
{
86+
$dataSource = [
87+
'data' => [
88+
'items' => [
89+
[
90+
'group_id' => self::STUB_SYNONYM_GROUP_ID
91+
]
92+
]
93+
]
94+
];
95+
96+
$expected = [
97+
'data' => [
98+
'items' => [
99+
[
100+
'group_id' => self::STUB_SYNONYM_GROUP_ID,
101+
'actions' => [
102+
'delete' => [
103+
'href' => sprintf(
104+
self::SYNONYM_GROUP_DELETE_URL,
105+
self::STUB_SYNONYM_GROUP_ID
106+
),
107+
'label' => (string)__('Delete'),
108+
'confirm' => [
109+
'title' => (string)__('Delete'),
110+
'message' => (string)__(
111+
'Are you sure you want to delete synonym group with id: %1?',
112+
self::STUB_SYNONYM_GROUP_ID
113+
)
114+
],
115+
'__disableTmpl' => true
116+
],
117+
'edit' => [
118+
'href' => sprintf(
119+
self::SYNONYM_GROUP_EDIT_URL,
120+
self::STUB_SYNONYM_GROUP_ID
121+
),
122+
'label' => (string)__('View/Edit'),
123+
'__disableTmpl' => true
124+
]
125+
]
126+
]
127+
]
128+
]
129+
];
130+
131+
$this->urlBuilderMock->method('getUrl')->will(
132+
$this->returnValueMap([
133+
[
134+
SynonymActions::SYNONYM_URL_PATH_DELETE, ['group_id' => self::STUB_SYNONYM_GROUP_ID],
135+
sprintf(self::SYNONYM_GROUP_DELETE_URL, self::STUB_SYNONYM_GROUP_ID)
136+
],
137+
[
138+
SynonymActions::SYNONYM_URL_PATH_EDIT, ['group_id' => self::STUB_SYNONYM_GROUP_ID],
139+
sprintf(self::SYNONYM_GROUP_EDIT_URL, self::STUB_SYNONYM_GROUP_ID)
140+
]
141+
])
142+
);
143+
144+
/**
145+
* Assert Result
146+
*/
147+
$this->assertEquals($expected, $this->synonymActions->prepareDataSource($dataSource));
148+
}
149+
}

0 commit comments

Comments
 (0)