Skip to content

Commit dd7479d

Browse files
committed
[Search] Cover SynonymActions Column by Unit Test
1 parent c7a2450 commit dd7479d

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
* @var SynonymActions
21+
*/
22+
private $synonymActions;
23+
24+
/**
25+
* @var UrlInterface|MockObject
26+
*/
27+
private $urlBuilderMock;
28+
29+
/**
30+
* Setup environment to test
31+
*/
32+
protected function setup()
33+
{
34+
$this->urlBuilderMock = $this->createMock(UrlInterface::class);
35+
36+
$objectManager = new ObjectManager($this);
37+
38+
$this->synonymActions = $objectManager->getObject(
39+
SynonymActions::class,
40+
[
41+
'urlBuilder' => $this->urlBuilderMock,
42+
'data' => [
43+
'name' => 'actions'
44+
]
45+
]
46+
);
47+
}
48+
49+
/**
50+
* Test prepareDataSource() with data source has no item
51+
*/
52+
public function testPrepareDataSourceWithNoItem()
53+
{
54+
$dataSource = [
55+
'data' => []
56+
];
57+
$expected = [
58+
'data' => []
59+
];
60+
/**
61+
* Assert Result
62+
*/
63+
$this->assertEquals($expected, $this->synonymActions->prepareDataSource($dataSource));
64+
}
65+
66+
/**
67+
* Test prepareDataSource() with data source has items
68+
*/
69+
public function testPrepareDataSourceWithItems()
70+
{
71+
$dataSource = [
72+
'data' => [
73+
'items' => [
74+
[
75+
'group_id' => 1
76+
]
77+
]
78+
]
79+
];
80+
$expected = [
81+
'data' => [
82+
'items' => [
83+
[
84+
'group_id' => 1,
85+
'actions' => [
86+
'delete' => [
87+
'href' => 'http://localhost/magento2/admin/search/synonyms/delete/group_id/1',
88+
'label' => (string)__('Delete'),
89+
'confirm' => [
90+
'title' => (string)__('Delete'),
91+
'message' => (string)__(
92+
'Are you sure you want to delete synonym group with id: %1?',
93+
1
94+
)
95+
],
96+
'__disableTmpl' => true
97+
],
98+
'edit' => [
99+
'href' => 'http://localhost/magento2/admin/search/synonyms/edit/group_id/1',
100+
'label' => (string)__('View/Edit'),
101+
'__disableTmpl' => true
102+
]
103+
]
104+
]
105+
]
106+
]
107+
];
108+
109+
$this->urlBuilderMock->expects($this->at(0))->method('getUrl')
110+
->with(SynonymActions::SYNONYM_URL_PATH_DELETE, ['group_id' => 1])
111+
->willReturn('http://localhost/magento2/admin/search/synonyms/delete/group_id/1');
112+
113+
$this->urlBuilderMock->expects($this->at(1))->method('getUrl')
114+
->with(SynonymActions::SYNONYM_URL_PATH_EDIT, ['group_id' => 1])
115+
->willReturn('http://localhost/magento2/admin/search/synonyms/edit/group_id/1');
116+
117+
/**
118+
* Assert Result
119+
*/
120+
$this->assertEquals($expected, $this->synonymActions->prepareDataSource($dataSource));
121+
}
122+
}

0 commit comments

Comments
 (0)