|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\ImportExport\Test\Unit\Helper; |
| 9 | + |
| 10 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 11 | +use Magento\Framework\App\Helper\Context; |
| 12 | +use Magento\Framework\File\Size as FileSize; |
| 13 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 14 | +use Magento\ImportExport\Helper\Data as HelperData; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * Test class to cover Data Helper |
| 19 | + * |
| 20 | + * Class \Magento\ImportExport\Test\Unit\Helper\DataTest |
| 21 | + */ |
| 22 | +class DataTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var ObjectManagerHelper |
| 26 | + */ |
| 27 | + private $objectManagerHelper; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var FileSize|PHPUnit_Framework_MockObject_MockObject |
| 31 | + */ |
| 32 | + private $fileSizeMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var Context|PHPUnit_Framework_MockObject_MockObject |
| 36 | + */ |
| 37 | + private $contextMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var ScopeConfigInterface|PHPUnit_Framework_MockObject_MockObject |
| 41 | + */ |
| 42 | + private $scopeConfigMock; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var HelperData|PHPUnit_Framework_MockObject_MockObject |
| 46 | + */ |
| 47 | + private $helperData; |
| 48 | + |
| 49 | + /** |
| 50 | + * Set up environment |
| 51 | + */ |
| 52 | + protected function setUp() |
| 53 | + { |
| 54 | + $this->contextMock = $this->createMock(Context::class); |
| 55 | + $this->fileSizeMock = $this->createMock(FileSize::class); |
| 56 | + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); |
| 57 | + $this->contextMock->expects($this->any())->method('getScopeConfig')->willReturn($this->scopeConfigMock); |
| 58 | + |
| 59 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 60 | + $this->helperData = $this->objectManagerHelper->getObject( |
| 61 | + HelperData::class, |
| 62 | + [ |
| 63 | + 'context' => $this->contextMock, |
| 64 | + 'fileSize' => $this->fileSizeMock |
| 65 | + ] |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Test getMaxUploadSizeMessage() with data provider below |
| 71 | + * |
| 72 | + * @param float $maxImageSize |
| 73 | + * @param string $expected |
| 74 | + * @return void |
| 75 | + * @dataProvider getMaxUploadSizeMessageDataProvider |
| 76 | + */ |
| 77 | + public function testGetMaxUploadSizeMessage($maxImageSize, $expected) |
| 78 | + { |
| 79 | + $this->fileSizeMock->expects($this->any())->method('getMaxFileSizeInMb')->willReturn($maxImageSize); |
| 80 | + $this->assertEquals($expected, $this->helperData->getMaxUploadSizeMessage()); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * DataProvider for testGetMaxUploadSizeMessage() function |
| 85 | + * |
| 86 | + * @return array |
| 87 | + */ |
| 88 | + public function getMaxUploadSizeMessageDataProvider() |
| 89 | + { |
| 90 | + return [ |
| 91 | + 'Test with max image size = 10Mb' => [ |
| 92 | + 'maxImageSize' => 10, |
| 93 | + 'expected' => 'Make sure your file isn\'t more than 10M.', |
| 94 | + ], |
| 95 | + 'Test with max image size = 0' => [ |
| 96 | + 'maxImageSize' => 0, |
| 97 | + 'expected' => 'We can\'t provide the upload settings right now.', |
| 98 | + ] |
| 99 | + ]; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Test getLocalValidPaths() |
| 104 | + * |
| 105 | + * @return void |
| 106 | + */ |
| 107 | + public function testGetLocalValidPaths() |
| 108 | + { |
| 109 | + $paths = [ |
| 110 | + 'available' => [ |
| 111 | + 'export_xml' => 'var/export/*/*.xml', |
| 112 | + 'export_csv' => 'var/export/*/*.csv', |
| 113 | + 'import_xml' => 'var/import/*/*.xml', |
| 114 | + 'import_csv' => 'var/import/*/*.csv', |
| 115 | + ] |
| 116 | + ]; |
| 117 | + $this->scopeConfigMock->expects($this->any())->method('getValue') |
| 118 | + ->with(HelperData::XML_PATH_EXPORT_LOCAL_VALID_PATH) |
| 119 | + ->willReturn($paths); |
| 120 | + |
| 121 | + $this->assertEquals($paths, $this->helperData->getLocalValidPaths()); |
| 122 | + } |
| 123 | + |
| 124 | + /** |
| 125 | + * Test getBunchSize() |
| 126 | + * |
| 127 | + * @return void |
| 128 | + */ |
| 129 | + public function testGetBunchSize() |
| 130 | + { |
| 131 | + $bunchSize = '100'; |
| 132 | + |
| 133 | + $this->scopeConfigMock->expects($this->any())->method('getValue') |
| 134 | + ->with(HelperData::XML_PATH_BUNCH_SIZE) |
| 135 | + ->willReturn($bunchSize); |
| 136 | + |
| 137 | + $this->assertEquals(100, $this->helperData->getBunchSize()); |
| 138 | + } |
| 139 | +} |
0 commit comments