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