Skip to content

Commit efa362f

Browse files
committed
[DownloadableImportExport] Cover Helper Data by Unit Test
1 parent 1ad65a3 commit efa362f

File tree

1 file changed

+278
-0
lines changed
  • app/code/Magento/DownloadableImportExport/Test/Unit/Helper

1 file changed

+278
-0
lines changed
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
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\DownloadableImportExport\Test\Unit\Helper;
10+
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
12+
use Magento\DownloadableImportExport\Helper\Data as HelperData;
13+
use PHPUnit\Framework\TestCase;
14+
15+
class DataTest extends TestCase
16+
{
17+
/**
18+
* @var HelperData
19+
*/
20+
private $helper;
21+
22+
/**
23+
* Setup environment for test
24+
*/
25+
protected function setUp()
26+
{
27+
$objectManagerHelper = new ObjectManagerHelper($this);
28+
$this->helper = $objectManagerHelper->getObject(HelperData::class);
29+
}
30+
31+
/**
32+
* Test isRowDownloadableEmptyOptions with dataProvider
33+
*
34+
* @param array $rowData
35+
* @param bool $expected
36+
* @dataProvider isRowDownloadableEmptyOptionsDataProvider
37+
*/
38+
public function testIsRowDownloadableEmptyOptions($rowData, $expected)
39+
{
40+
$this->assertEquals($expected, $this->helper->isRowDownloadableEmptyOptions($rowData));
41+
}
42+
43+
/**
44+
* Data Provider to test isRowDownloadableEmptyOptions
45+
*
46+
* @return array
47+
*/
48+
public function isRowDownloadableEmptyOptionsDataProvider()
49+
{
50+
return [
51+
'Data set include downloadable link and sample' => [
52+
[
53+
'downloadable_links' => 'https://magento2.com/download_link',
54+
'downloadable_samples' => 'https://magento2.com/sample_link'
55+
],
56+
false
57+
],
58+
'Data set with empty' => [
59+
[
60+
'downloadable_links' => '',
61+
'downloadable_samples' => ''
62+
],
63+
true
64+
]
65+
];
66+
}
67+
68+
/**
69+
* Test isRowDownloadableNoValid with dataProvider
70+
*
71+
* @param array $rowData
72+
* @param bool $expected
73+
* @dataProvider isRowDownloadableNoValidDataProvider
74+
*/
75+
public function isRowDownloadableNoValid($rowData, $expected)
76+
{
77+
$this->assertEquals($expected, $this->helper->isRowDownloadableNoValid($rowData));
78+
}
79+
80+
/**
81+
* Data Provider to test isRowDownloadableEmptyOptions
82+
*
83+
* @return array
84+
*/
85+
public function isRowDownloadableNoValidDataProvider()
86+
{
87+
return [
88+
'Data set include downloadable link and sample' => [
89+
[
90+
'downloadable_links' => 'https://magento2.com/download_link',
91+
'downloadable_samples' => 'https://magento2.com/sample_link'
92+
],
93+
true
94+
],
95+
'Data set with empty' => [
96+
[
97+
'downloadable_links' => '',
98+
'downloadable_samples' => ''
99+
],
100+
false
101+
]
102+
];
103+
}
104+
105+
/**
106+
* Test fillExistOptions with dataProvider
107+
*
108+
* @param array $base
109+
* @param array $option
110+
* @param array $existingOptions
111+
* @param array $expected
112+
* @dataProvider fillExistOptionsDataProvider
113+
*/
114+
public function testFillExistOptions($base, $option, $existingOptions, $expected)
115+
{
116+
$this->assertEquals($expected, $this->helper->fillExistOptions($base, $option, $existingOptions));
117+
}
118+
119+
/**
120+
* Data Provider to test fillExistOptions
121+
*
122+
* @return array
123+
*/
124+
public function fillExistOptionsDataProvider()
125+
{
126+
return [
127+
'Data set 1' => [
128+
[],
129+
[
130+
'product_id' => 1,
131+
'sample_type' => 'sample_type1',
132+
'sample_url' => 'sample_url1',
133+
'sample_file' => 'sample_file1',
134+
'link_file' => 'link_file1',
135+
'link_type' => 'link_type1',
136+
'link_url' => 'link_url1'
137+
],
138+
[
139+
[
140+
'product_id' => 1,
141+
'sample_type' => 'sample_type1',
142+
'sample_url' => 'sample_url1',
143+
'sample_file' => 'sample_file1',
144+
'link_file' => 'link_file1',
145+
'link_type' => 'link_type1',
146+
'link_url' => 'link_url1'
147+
],
148+
[
149+
'product_id' => 2,
150+
'sample_type' => 'sample_type2',
151+
'sample_url' => 'sample_url2',
152+
'sample_file' => 'sample_file2',
153+
'link_file' => 'link_file2',
154+
'link_type' => 'link_type2',
155+
'link_url' => 'link_url2'
156+
]
157+
],
158+
[
159+
'product_id' => 1,
160+
'sample_type' => 'sample_type1',
161+
'sample_url' => 'sample_url1',
162+
'sample_file' => 'sample_file1',
163+
'link_file' => 'link_file1',
164+
'link_type' => 'link_type1',
165+
'link_url' => 'link_url1'
166+
]
167+
],
168+
'Data set 2' => [
169+
[],
170+
[
171+
'product_id' => 1,
172+
'sample_type' => 'sample_type1',
173+
'sample_url' => 'sample_url1',
174+
'sample_file' => 'sample_file1',
175+
'link_file' => 'link_file1',
176+
'link_type' => 'link_type1',
177+
'link_url' => 'link_url1'
178+
],
179+
[],
180+
[]
181+
]
182+
];
183+
}
184+
185+
/**
186+
* Test prepareDataForSave with dataProvider
187+
*
188+
* @param array $base
189+
* @param array $replacement
190+
* @param array $expected
191+
* @dataProvider prepareDataForSaveDataProvider
192+
*/
193+
public function testPrepareDataForSave($base, $replacement, $expected)
194+
{
195+
$this->assertEquals($expected, $this->helper->prepareDataForSave($base, $replacement));
196+
}
197+
198+
/**
199+
* Data Provider to test prepareDataForSave
200+
*
201+
* @return array
202+
*/
203+
public function prepareDataForSaveDataProvider()
204+
{
205+
return [
206+
'Data set 1' => [
207+
[],
208+
[],
209+
[]
210+
],
211+
212+
'Data set 2' => [
213+
[
214+
'product_id' => 1,
215+
'sample_type' => 'sample_type1',
216+
'sample_url' => 'sample_url1',
217+
'sample_file' => 'sample_file1',
218+
'link_file' => 'link_file1',
219+
'link_type' => 'link_type1',
220+
'link_url' => 'link_url1'
221+
],
222+
[
223+
[
224+
'product_id' => 2,
225+
'sample_type' => 'sample_type2',
226+
'sample_url' => 'sample_url2',
227+
'sample_file' => 'sample_file2',
228+
'link_file' => 'link_file2',
229+
'link_type' => 'link_type2',
230+
'link_url' => 'link_url2'
231+
]
232+
],
233+
[
234+
[
235+
'product_id' => 2,
236+
'sample_type' => 'sample_type2',
237+
'sample_url' => 'sample_url2',
238+
'sample_file' => 'sample_file2',
239+
'link_file' => 'link_file2',
240+
'link_type' => 'link_type2',
241+
'link_url' => 'link_url2'
242+
]
243+
]
244+
]
245+
];
246+
}
247+
248+
/**
249+
* Test getTypeByValue with dataProvider
250+
*
251+
* @param string $option
252+
* @param string $expected
253+
* @dataProvider getTypeByValueDataProvider
254+
*/
255+
public function testGetTypeByValue($option, $expected)
256+
{
257+
$this->assertEquals($expected, $this->helper->getTypeByValue($option));
258+
}
259+
260+
/**
261+
* Data Provider for getTypeByValue
262+
*
263+
* @return array
264+
*/
265+
public function getTypeByValueDataProvider()
266+
{
267+
return [
268+
'Case File Option Value' => [
269+
'file1',
270+
'file'
271+
],
272+
'Case url Option Value' => [
273+
'https://example.com',
274+
'url'
275+
]
276+
];
277+
}
278+
}

0 commit comments

Comments
 (0)