Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ImportExport] Cover Helper Data by Unit Test #25702

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions app/code/Magento/ImportExport/Test/Unit/Helper/DataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ImportExport\Test\Unit\Helper;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\File\Size as FileSize;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\ImportExport\Helper\Data as HelperData;
use PHPUnit\Framework\TestCase;

/**
* Test class to cover Data Helper
*
* Class \Magento\ImportExport\Test\Unit\Helper\DataTest
*/
class DataTest extends TestCase
{
/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;

/**
* @var FileSize|PHPUnit_Framework_MockObject_MockObject
*/
private $fileSizeMock;

/**
* @var Context|PHPUnit_Framework_MockObject_MockObject
*/
private $contextMock;

/**
* @var ScopeConfigInterface|PHPUnit_Framework_MockObject_MockObject
*/
private $scopeConfigMock;

/**
* @var HelperData|PHPUnit_Framework_MockObject_MockObject
*/
private $helperData;

/**
* Set up environment
*/
protected function setUp()
{
$this->contextMock = $this->createMock(Context::class);
$this->fileSizeMock = $this->createMock(FileSize::class);
$this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class);
$this->contextMock->expects($this->any())->method('getScopeConfig')->willReturn($this->scopeConfigMock);

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->helperData = $this->objectManagerHelper->getObject(
HelperData::class,
[
'context' => $this->contextMock,
'fileSize' => $this->fileSizeMock
]
);
}

/**
* Test getMaxUploadSizeMessage() with data provider below
*
* @param float $maxImageSize
* @param string $expected
* @return void
* @dataProvider getMaxUploadSizeMessageDataProvider
*/
public function testGetMaxUploadSizeMessage($maxImageSize, $expected)
{
$this->fileSizeMock->expects($this->any())->method('getMaxFileSizeInMb')->willReturn($maxImageSize);
$this->assertEquals($expected, $this->helperData->getMaxUploadSizeMessage());
}

/**
* DataProvider for testGetMaxUploadSizeMessage() function
*
* @return array
*/
public function getMaxUploadSizeMessageDataProvider()
{
return [
'Test with max image size = 10Mb' => [
'maxImageSize' => 10,
'expected' => 'Make sure your file isn\'t more than 10M.',
],
'Test with max image size = 0' => [
'maxImageSize' => 0,
'expected' => 'We can\'t provide the upload settings right now.',
]
];
}

/**
* Test getLocalValidPaths()
*
* @return void
*/
public function testGetLocalValidPaths()
{
$paths = [
'available' => [
'export_xml' => 'var/export/*/*.xml',
'export_csv' => 'var/export/*/*.csv',
'import_xml' => 'var/import/*/*.xml',
'import_csv' => 'var/import/*/*.csv',
]
];
$this->scopeConfigMock->expects($this->any())->method('getValue')
->with(HelperData::XML_PATH_EXPORT_LOCAL_VALID_PATH)
->willReturn($paths);

$this->assertEquals($paths, $this->helperData->getLocalValidPaths());
}

/**
* Test getBunchSize()
*
* @return void
*/
public function testGetBunchSize()
{
$bunchSize = '100';

$this->scopeConfigMock->expects($this->any())->method('getValue')
->with(HelperData::XML_PATH_BUNCH_SIZE)
->willReturn($bunchSize);

$this->assertEquals(100, $this->helperData->getBunchSize());
}
}