ltsecurityinc安防产品在线商城代码
This commit is contained in:
+81
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Block\Adminhtml\Export\Edit;
|
||||
|
||||
/**
|
||||
* Test class for block \Magento\ImportExport\Block\Adminhtml\Export\Edit\Form
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Testing model
|
||||
*
|
||||
* @var \Magento\ImportExport\Block\Adminhtml\Export\Edit\Form
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* Expected form fieldsets and fields
|
||||
* array (
|
||||
* <fieldset_id> => array(
|
||||
* <element_id> => <element_name>,
|
||||
* ...
|
||||
* ),
|
||||
* ...
|
||||
* )
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_expectedFields = ['base_fieldset' => [
|
||||
'entity' => 'entity',
|
||||
'file_format' => 'file_format',
|
||||
'fields_enclosure' => 'fields_enclosure'
|
||||
]];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\ImportExport\Block\Adminhtml\Export\Edit\Form::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test preparing of form
|
||||
*
|
||||
* @covers \Magento\ImportExport\Block\Adminhtml\Export\Edit\Form::_prepareForm
|
||||
*/
|
||||
public function testPrepareForm()
|
||||
{
|
||||
// invoking _prepareForm
|
||||
$this->_model->toHtml();
|
||||
|
||||
// get fieldset list
|
||||
$actualFieldsets = [];
|
||||
$formElements = $this->_model->getForm()->getElements();
|
||||
foreach ($formElements as $formElement) {
|
||||
if ($formElement instanceof \Magento\Framework\Data\Form\Element\Fieldset) {
|
||||
$actualFieldsets[] = $formElement;
|
||||
}
|
||||
}
|
||||
|
||||
// assert fieldsets and fields
|
||||
$this->assertSameSize($this->_expectedFields, $actualFieldsets);
|
||||
/** @var $actualFieldset \Magento\Framework\Data\Form\Element\Fieldset */
|
||||
foreach ($actualFieldsets as $actualFieldset) {
|
||||
$this->assertArrayHasKey($actualFieldset->getId(), $this->_expectedFields);
|
||||
$expectedFields = $this->_expectedFields[$actualFieldset->getId()];
|
||||
/** @var $actualField \Magento\Framework\Data\Form\Element\AbstractElement */
|
||||
foreach ($actualFieldset->getElements() as $actualField) {
|
||||
$this->assertArrayHasKey($actualField->getId(), $expectedFields);
|
||||
$this->assertEquals($expectedFields[$actualField->getId()], $actualField->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\ImportExport\Block\Adminhtml\Export\Filter
|
||||
*/
|
||||
namespace Magento\ImportExport\Block\Adminhtml\Export;
|
||||
|
||||
class FilterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
*/
|
||||
public function testGetDateFromToHtmlWithValue()
|
||||
{
|
||||
\Magento\TestFramework\Helper\Bootstrap::getInstance()
|
||||
->loadArea(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE);
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Framework\View\DesignInterface::class)
|
||||
->setDefaultDesignTheme();
|
||||
$block = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\ImportExport\Block\Adminhtml\Export\Filter::class);
|
||||
$method = new \ReflectionMethod(
|
||||
\Magento\ImportExport\Block\Adminhtml\Export\Filter::class,
|
||||
'_getDateFromToHtmlWithValue'
|
||||
);
|
||||
$method->setAccessible(true);
|
||||
|
||||
$arguments = [
|
||||
'data' => [
|
||||
'attribute_code' => 'date',
|
||||
'backend_type' => 'datetime',
|
||||
'frontend_input' => 'date',
|
||||
'frontend_label' => 'Date',
|
||||
],
|
||||
];
|
||||
$attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Eav\Model\Entity\Attribute::class,
|
||||
$arguments
|
||||
);
|
||||
$html = $method->invoke($block, $attribute, null);
|
||||
$this->assertNotEmpty($html);
|
||||
|
||||
$dateFormat = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class
|
||||
)->getDateFormat(
|
||||
\IntlDateFormatter::SHORT
|
||||
);
|
||||
$pieces = array_filter(explode('<strong>', $html));
|
||||
foreach ($pieces as $piece) {
|
||||
$this->assertStringContainsString('dateFormat: "' . $dateFormat . '",', $piece);
|
||||
}
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\ImportExport\Block\Adminhtml\Import\Edit\Before
|
||||
*/
|
||||
namespace Magento\ImportExport\Block\Adminhtml\Import\Edit;
|
||||
|
||||
class BeforeTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test model
|
||||
*
|
||||
* @var \Magento\ImportExport\Block\Adminhtml\Import\Edit\Before
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* Source entity behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_sourceEntities = [
|
||||
'entity_1' => ['code' => 'behavior_1', 'token' => 'Some_Random_First_Class'],
|
||||
'entity_2' => ['code' => 'behavior_2', 'token' => 'Some_Random_Second_Class'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected entity behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_expectedEntities = ['entity_1' => 'behavior_1', 'entity_2' => 'behavior_2'];
|
||||
|
||||
/**
|
||||
* Source unique behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_sourceBehaviors = [
|
||||
'behavior_1' => 'Some_Random_First_Class',
|
||||
'behavior_2' => 'Some_Random_Second_Class',
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected unique behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_expectedBehaviors = ['behavior_1', 'behavior_2'];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$importModel = $this->createPartialMock(
|
||||
\Magento\ImportExport\Model\Import::class,
|
||||
['getEntityBehaviors', 'getUniqueEntityBehaviors']
|
||||
);
|
||||
$importModel->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getEntityBehaviors'
|
||||
)->willReturn(
|
||||
$this->_sourceEntities
|
||||
);
|
||||
$importModel->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getUniqueEntityBehaviors'
|
||||
)->willReturn(
|
||||
$this->_sourceBehaviors
|
||||
);
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_model = $objectManager->create(
|
||||
\Magento\ImportExport\Block\Adminhtml\Import\Edit\Before::class,
|
||||
[
|
||||
'importModel' => $importModel,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getEntityBehaviors method
|
||||
*
|
||||
* @covers \Magento\ImportExport\Block\Adminhtml\Import\Edit\Before::getEntityBehaviors
|
||||
*/
|
||||
public function testGetEntityBehaviors()
|
||||
{
|
||||
$actualEntities = $this->_model->getEntityBehaviors();
|
||||
$expectedEntities = json_encode($this->_expectedEntities);
|
||||
$this->assertEquals($expectedEntities, $actualEntities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for getUniqueBehaviors method
|
||||
*
|
||||
* @covers \Magento\ImportExport\Block\Adminhtml\Import\Edit\Before::getUniqueBehaviors
|
||||
*/
|
||||
public function testGetUniqueBehaviors()
|
||||
{
|
||||
$actualBehaviors = $this->_model->getUniqueBehaviors();
|
||||
$expectedBehaviors = json_encode($this->_expectedBehaviors);
|
||||
$this->assertEquals($expectedBehaviors, $actualBehaviors);
|
||||
}
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Block\Adminhtml\Import\Edit;
|
||||
|
||||
/**
|
||||
* Tests for block \Magento\ImportExport\Block\Adminhtml\Import\Edit\FormTest
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class FormTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* List of expected fieldsets in import edit form
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_expectedFieldsets = ['base_fieldset', 'upload_file_fieldset'];
|
||||
|
||||
/**
|
||||
* Add behaviour fieldsets to expected fieldsets
|
||||
*
|
||||
* @static
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$importModel = $objectManager->create(\Magento\ImportExport\Model\Import::class);
|
||||
$uniqueBehaviors = $importModel->getUniqueEntityBehaviors();
|
||||
foreach (array_keys($uniqueBehaviors) as $behavior) {
|
||||
$this->_expectedFieldsets[] = $behavior . '_fieldset';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test content of form after _prepareForm
|
||||
*/
|
||||
public function testPrepareForm()
|
||||
{
|
||||
$formBlock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\LayoutInterface::class
|
||||
)->createBlock(
|
||||
\Magento\ImportExport\Block\Adminhtml\Import\Edit\Form::class
|
||||
);
|
||||
$prepareForm = new \ReflectionMethod(
|
||||
\Magento\ImportExport\Block\Adminhtml\Import\Edit\Form::class,
|
||||
'_prepareForm'
|
||||
);
|
||||
$prepareForm->setAccessible(true);
|
||||
$prepareForm->invoke($formBlock);
|
||||
|
||||
// check form
|
||||
$form = $formBlock->getForm();
|
||||
$this->assertInstanceOf(\Magento\Framework\Data\Form::class, $form, 'Incorrect import form class.');
|
||||
$this->assertTrue($form->getUseContainer(), 'Form should use container.');
|
||||
|
||||
// check form fieldsets
|
||||
$formFieldsets = [];
|
||||
$formElements = $form->getElements();
|
||||
foreach ($formElements as $element) {
|
||||
/** @var $element \Magento\Framework\Data\Form\Element\AbstractElement */
|
||||
if (in_array($element->getId(), $this->_expectedFieldsets)) {
|
||||
$formFieldsets[] = $element;
|
||||
}
|
||||
}
|
||||
$this->assertSameSize($this->_expectedFieldsets, $formFieldsets);
|
||||
foreach ($formFieldsets as $fieldset) {
|
||||
$this->assertInstanceOf(
|
||||
\Magento\Framework\Data\Form\Element\Fieldset::class,
|
||||
$fieldset,
|
||||
'Incorrect fieldset class.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Controller\Adminhtml\Export;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
|
||||
use Magento\Framework\MessageQueue\DefaultValueProvider;
|
||||
use Magento\Framework\MessageQueue\Envelope;
|
||||
use Magento\Framework\MessageQueue\QueueRepository;
|
||||
use Magento\Framework\Serialize\SerializerInterface;
|
||||
use Magento\TestFramework\MessageQueue\ClearQueueProcessor;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Test for export controller
|
||||
*
|
||||
* @see \Magento\ImportExport\Controller\Adminhtml\Export\Export
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
* @magentoDbIsolation enabled
|
||||
*/
|
||||
class ExportTest extends AbstractBackendController
|
||||
{
|
||||
private const TOPIC_NAME = 'import_export.export';
|
||||
|
||||
/** @var SerializerInterface */
|
||||
private $json;
|
||||
|
||||
/** @var ClearQueueProcessor */
|
||||
private $clearQueueProcessor;
|
||||
|
||||
/**
|
||||
* @var QueueRepository
|
||||
*/
|
||||
private $queueRepository;
|
||||
|
||||
/**
|
||||
* @var DefaultValueProvider
|
||||
*/
|
||||
private $defaultValueProvider;
|
||||
|
||||
/** @var LocaleResolver */
|
||||
private $localeResolver;
|
||||
|
||||
/**
|
||||
* @inheridoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->json = $this->_objectManager->get(SerializerInterface::class);
|
||||
$this->clearQueueProcessor = $this->_objectManager->get(ClearQueueProcessor::class);
|
||||
$this->clearQueueProcessor->execute('exportProcessor');
|
||||
$this->queueRepository = $this->_objectManager->get(QueueRepository::class);
|
||||
$this->defaultValueProvider = $this->_objectManager->get(DefaultValueProvider::class);
|
||||
$this->localeResolver = $this->_objectManager->get(LocaleResolver::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->clearQueueProcessor->execute('exportProcessor');
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store admin/security/use_form_key 1
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testExecute(): void
|
||||
{
|
||||
$expectedSessionMessage = (string)__('Message is added to queue, wait to get your file soon.'
|
||||
. ' Make sure your cron job is running to export the file');
|
||||
$locale = $this->localeResolver->getLocale();
|
||||
$fileFormat = 'csv';
|
||||
$filter = ['price' => [0, 1000]];
|
||||
$this->getRequest()->setMethod(Http::METHOD_POST)
|
||||
->setPostValue(['export_filter' => [$filter]])
|
||||
->setParams(
|
||||
[
|
||||
'entity' => ProductAttributeInterface::ENTITY_TYPE_CODE,
|
||||
'file_format' => $fileFormat,
|
||||
]
|
||||
);
|
||||
$this->dispatch('backend/admin/export/export');
|
||||
$this->assertSessionMessages($this->containsEqual($expectedSessionMessage));
|
||||
$this->assertRedirect($this->stringContains('/export/index/key/'));
|
||||
$queue = $this->queueRepository->get($this->defaultValueProvider->getConnection(), 'export');
|
||||
/** @var Envelope $message */
|
||||
$message = $queue->dequeue();
|
||||
$this->assertEquals(self::TOPIC_NAME, $message->getProperties()['topic_name']);
|
||||
$body = $this->json->unserialize($message->getBody());
|
||||
$this->assertStringContainsString(ProductAttributeInterface::ENTITY_TYPE_CODE, $body['file_name']);
|
||||
$this->assertEquals($fileFormat, $body['file_format']);
|
||||
$actualFilter = $this->json->unserialize($body['export_filter']);
|
||||
$this->assertCount(1, $actualFilter);
|
||||
$this->assertEquals($filter, reset($actualFilter));
|
||||
$this->assertNotEmpty($body['locale']);
|
||||
$this->assertEquals($locale, $body['locale']);
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Delete class.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class DeleteTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var WriteInterface
|
||||
*/
|
||||
protected $varDirectory;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fileName = 'catalog_product.csv';
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $fileSystem;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sourceFilePath;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->fileSystem = $this->_objectManager->get(Filesystem::class);
|
||||
$this->sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
|
||||
//Refers to tests 'var' directory
|
||||
$this->varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that file can be removed under var/export directory.
|
||||
*
|
||||
* @param string $file
|
||||
* @dataProvider testExecuteProvider
|
||||
* @return void
|
||||
* @magentoConfigFixture default_store admin/security/use_form_key 1
|
||||
*/
|
||||
public function testExecute($file): void
|
||||
{
|
||||
$fullPath = 'export/' . $file;
|
||||
$this->copyFile($fullPath);
|
||||
$request = $this->getRequest();
|
||||
$request->setParam('filename', $file);
|
||||
$request->setMethod(Http::METHOD_POST);
|
||||
|
||||
if ($this->varDirectory->isExist($fullPath)) {
|
||||
$this->dispatch('backend/admin/export_file/delete');
|
||||
} else {
|
||||
throw new \AssertionError('Export product file supposed to exist');
|
||||
}
|
||||
|
||||
$this->assertFalse($this->varDirectory->isExist($fullPath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy csv file from sourceFilePath to destinationFilePath
|
||||
*
|
||||
* @param $destinationFilePath
|
||||
* @return void
|
||||
* @throws \Magento\Framework\Exception\FileSystemException
|
||||
*/
|
||||
protected function copyFile($destinationFilePath): void
|
||||
{
|
||||
$driver = $this->varDirectory->getDriver();
|
||||
$absolutePath = $this->varDirectory->getAbsolutePath($destinationFilePath);
|
||||
|
||||
$driver->createDirectory(dirname($absolutePath));
|
||||
$driver->filePutContents($absolutePath, file_get_contents($this->sourceFilePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Csv file path for copying from sourceFilePath and for future deleting
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function testExecuteProvider(): array
|
||||
{
|
||||
return [
|
||||
['catalog_product.csv'],
|
||||
['test/catalog_product.csv']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
|
||||
/** @var WriteInterface $directory */
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
if ($directory->isExist('export')) {
|
||||
$directory->delete('export');
|
||||
}
|
||||
}
|
||||
}
|
||||
+169
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Controller\Adminhtml\Export\File;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\App\Request\Http;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
use Magento\Backend\Model\UrlInterface as BackendUrl;
|
||||
use Magento\Backend\Model\Auth;
|
||||
|
||||
/**
|
||||
* Test for \Magento\ImportExport\Controller\Adminhtml\Export\File\Download class.
|
||||
*/
|
||||
class DownloadTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $fileName = 'catalog_product.csv';
|
||||
|
||||
/**
|
||||
* @var Auth
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* @var BackendUrl
|
||||
*/
|
||||
private $backendUrl;
|
||||
|
||||
/**
|
||||
* @var WriteInterface
|
||||
*/
|
||||
private $varDirectory;
|
||||
|
||||
/**
|
||||
* @var Filesystem
|
||||
*/
|
||||
private $fileSystem;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $sourceFilePath;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->fileSystem = $this->_objectManager->get(Filesystem::class);
|
||||
$auth = $this->_objectManager->get(Auth::class);
|
||||
$auth->getAuthStorage()->setIsFirstPageAfterLogin(false);
|
||||
$this->backendUrl = $this->_objectManager->get(BackendUrl::class);
|
||||
$this->backendUrl->turnOnSecretKey();
|
||||
$this->sourceFilePath = __DIR__ . '/../../Import/_files' . DIRECTORY_SEPARATOR . $this->fileName;
|
||||
//Refers to tests 'var' directory
|
||||
$this->varDirectory = $this->fileSystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that file can be downloaded.
|
||||
*
|
||||
* @param string $file
|
||||
* @dataProvider testExecuteProvider
|
||||
* @return void
|
||||
* @magentoConfigFixture default_store admin/security/use_form_key 1
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
public function testExecute($file): void
|
||||
{
|
||||
$this->copyFile('export/' . $file);
|
||||
$fileSize = $this->varDirectory->stat('export/' . $file)['size'];
|
||||
$request = $this->getRequest();
|
||||
list($routeName, $controllerName, $actionName) = explode('/', Download::URL);
|
||||
$request->setMethod(Http::METHOD_GET)
|
||||
->setRouteName($routeName)
|
||||
->setControllerName($controllerName)
|
||||
->setActionName($actionName);
|
||||
$request->setParam('filename', $this->fileName);
|
||||
$request->setParam(BackendUrl::SECRET_KEY_PARAM_NAME, $this->backendUrl->getSecretKey());
|
||||
|
||||
ob_start();
|
||||
$this->dispatch('backend/admin/export_file/download');
|
||||
ob_end_clean();
|
||||
|
||||
$contentType = $this->getResponse()->getHeader('content-type');
|
||||
$contentLength = $this->getResponse()->getHeader('content-length');
|
||||
$contentDisposition = $this->getResponse()->getHeader('content-disposition');
|
||||
|
||||
$this->assertEquals(200, $this->getResponse()->getStatusCode(), 'Incorrect response status code');
|
||||
$this->assertEquals(
|
||||
'application/octet-stream',
|
||||
$contentType->getFieldValue(),
|
||||
'Incorrect response header "content-type"'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'attachment; filename="export/' . $this->fileName . '"',
|
||||
$contentDisposition->getFieldValue(),
|
||||
'Incorrect response header "content-disposition"'
|
||||
);
|
||||
$this->assertEquals(
|
||||
$fileSize,
|
||||
$contentLength->getFieldValue(),
|
||||
'Incorrect response header "content-length"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy csv file from sourceFilePath to destinationFilePath
|
||||
*
|
||||
* @param $destinationFilePath
|
||||
* @return void
|
||||
*/
|
||||
private function copyFile($destinationFilePath): void
|
||||
{
|
||||
$driver = $this->varDirectory->getDriver();
|
||||
$absolutePath = $this->varDirectory->getAbsolutePath($destinationFilePath);
|
||||
|
||||
$driver->createDirectory(dirname($absolutePath));
|
||||
$driver->filePutContents($absolutePath, file_get_contents($this->sourceFilePath));
|
||||
}
|
||||
|
||||
/**
|
||||
* Csv file path for copying from sourceFilePath and for future deleting
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function testExecuteProvider(): array
|
||||
{
|
||||
return [
|
||||
['catalog_product.csv'],
|
||||
['test/catalog_product.csv']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$this->auth = null;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
|
||||
/** @var WriteInterface $directory */
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
|
||||
if ($directory->isExist('export')) {
|
||||
$directory->delete('export');
|
||||
}
|
||||
}
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Controller\Adminhtml;
|
||||
|
||||
use Magento\TestFramework\Helper\Xpath;
|
||||
use Magento\TestFramework\TestCase\AbstractBackendController;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ExportTest extends AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* Set value of $_SERVER['HTTP_X_REQUESTED_WITH'] parameter here
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_httpXRequestedWith;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
|
||||
$this->_httpXRequestedWith = $_SERVER['HTTP_X_REQUESTED_WITH'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->_httpXRequestedWith !== null) {
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = $this->_httpXRequestedWith;
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getFilter action
|
||||
*
|
||||
* @dataProvider getEntityTypesDataProvider
|
||||
*
|
||||
* @param string $entityType
|
||||
* @param string|null $customerEntityType
|
||||
* @param array $expectedAttributes
|
||||
*/
|
||||
public function testGetFilterAction(
|
||||
string $entityType,
|
||||
string $customerEntityType = null,
|
||||
array $expectedAttributes = []
|
||||
) {
|
||||
$this->getRequest()->setParam('isAjax', true);
|
||||
|
||||
// Provide X_REQUESTED_WITH header in response to mark next action as ajax
|
||||
$this->getRequest()->getHeaders()
|
||||
->addHeaderLine('X_REQUESTED_WITH', 'XMLHttpRequest');
|
||||
|
||||
$url = 'backend/admin/export/getFilter/entity/' . $entityType;
|
||||
if ($customerEntityType) {
|
||||
$url .= '/customer_entity/' . $customerEntityType;
|
||||
}
|
||||
$this->dispatch($url);
|
||||
|
||||
$body = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString('<div id="export_filter_grid"', $body);
|
||||
foreach ($expectedAttributes as $attribute) {
|
||||
$this->assertStringContainsString("name=\"export_filter[{$attribute}]\"", $body);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get possible entity types
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEntityTypesDataProvider()
|
||||
{
|
||||
return [
|
||||
'products' => [
|
||||
'entityType' => 'catalog_product',
|
||||
'customerEntityType' => null,
|
||||
'expectedAttributes' => ['category_ids']
|
||||
],
|
||||
'customers' => [
|
||||
'entityType' => 'customer'
|
||||
],
|
||||
// customer entities
|
||||
'customers_customer_entities' => [
|
||||
'entityType' => 'customer',
|
||||
'customerEntityType' => 'customer'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test index action
|
||||
*/
|
||||
public function testIndexAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/export/index');
|
||||
|
||||
$body = $this->getResponse()->getBody();
|
||||
|
||||
$this->assertEquals(
|
||||
1,
|
||||
Xpath::getElementsCountForXpath(
|
||||
'//fieldset[@id="base_fieldset"]',
|
||||
$body
|
||||
)
|
||||
);
|
||||
$this->assertEquals(
|
||||
3,
|
||||
Xpath::getElementsCountForXpath(
|
||||
'//fieldset[@id="base_fieldset"]/div[contains(@class,"field")]',
|
||||
$body
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Controller\Adminhtml\Import;
|
||||
|
||||
use Magento\Framework\HTTP\Adapter\FileTransferFactory;
|
||||
|
||||
class HttpFactoryMock extends FileTransferFactory
|
||||
{
|
||||
public function create(array $options = [])
|
||||
{
|
||||
return new \Magento\Framework\Validator\NotEmpty($options);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\ImportExport\Controller\Adminhtml\Import;
|
||||
|
||||
use Magento\Framework\Filesystem\DirectoryList;
|
||||
use Magento\Framework\HTTP\Adapter\FileTransferFactory;
|
||||
use Magento\ImportExport\Model\Import;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ValidateImportTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @dataProvider validationDataProvider
|
||||
* @param string $fileName
|
||||
* @param string $mimeType
|
||||
* @param string $message
|
||||
* @param string $delimiter
|
||||
* @throws \Magento\Framework\Exception\FileSystemException
|
||||
* @backupGlobals enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function testValidationReturn(string $fileName, string $mimeType, string $message, string $delimiter): void
|
||||
{
|
||||
$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
|
||||
|
||||
$this->getRequest()->setParam('isAjax', true);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
|
||||
/** @var $formKey \Magento\Framework\Data\Form\FormKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$this->getRequest()->setPostValue('form_key', $formKey->getFormKey());
|
||||
$this->getRequest()->setPostValue('entity', 'catalog_product');
|
||||
$this->getRequest()->setPostValue('behavior', 'append');
|
||||
$this->getRequest()->setPostValue(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
|
||||
$this->getRequest()->setPostValue(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);
|
||||
$this->getRequest()->setPostValue('_import_field_separator', $delimiter);
|
||||
|
||||
/** @var \Magento\TestFramework\App\Filesystem $filesystem */
|
||||
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
$tmpDir = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
|
||||
$subDir = str_replace('\\', '_', __CLASS__);
|
||||
$tmpDir->create($subDir);
|
||||
$target = $tmpDir->getAbsolutePath("{$subDir}/{$fileName}");
|
||||
copy(__DIR__ . "/_files/{$fileName}", $target);
|
||||
|
||||
$_FILES = [
|
||||
'import_file' => [
|
||||
'name' => $fileName,
|
||||
'type' => $mimeType,
|
||||
'tmp_name' => $target,
|
||||
'error' => 0,
|
||||
'size' => filesize($target)
|
||||
]
|
||||
];
|
||||
|
||||
$this->_objectManager->configure(
|
||||
[
|
||||
'preferences' => [FileTransferFactory::class => HttpFactoryMock::class]
|
||||
]
|
||||
);
|
||||
|
||||
$this->dispatch('backend/admin/import/validate');
|
||||
|
||||
$this->assertStringContainsString($message, $this->getResponse()->getBody());
|
||||
$this->assertStringNotContainsString('The file was not uploaded.', $this->getResponse()->getBody());
|
||||
$this->assertDoesNotMatchRegularExpression(
|
||||
'/clear[^\[]*\[[^\]]*(import_file|import_image_archive)[^\]]*\]/m',
|
||||
$this->getResponse()->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validationDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'file_name' => 'catalog_product.csv',
|
||||
'mime-type' => 'text/csv',
|
||||
'message' => 'File is valid',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
[
|
||||
'file_name' => 'test.txt',
|
||||
'mime-type' => 'text/csv',
|
||||
'message' => 'The file cannot be uploaded.',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
[
|
||||
'file_name' => 'incorrect_catalog_product_comma.csv',
|
||||
'mime-type' => 'text/csv',
|
||||
'message' => 'Download full report',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
[
|
||||
'file_name' => 'incorrect_catalog_product_semicolon.csv',
|
||||
'mime-type' => 'text/csv',
|
||||
'message' => 'Download full report',
|
||||
'delimiter' => ';',
|
||||
],
|
||||
[
|
||||
'file_name' => 'invalid_catalog_products.zip',
|
||||
'mime-type' => 'application/zip',
|
||||
'message' => 'Data validation failed.',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
[
|
||||
'file_name' => 'catalog_product.zip',
|
||||
'mime-type' => 'application/zip',
|
||||
'message' => 'File is valid',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
sku,_store,_attribute_set,product_type,categories,_product_websites,color,cost,country_of_manufacture,created_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,description,gallery,gift_message_available,gift_wrapping_available,gift_wrapping_price,has_options,image,image_label,is_returnable,manufacturer,meta_description,meta_keyword,meta_title,minimal_price,msrp,msrp_display_actual_price_type,name,news_from_date,news_to_date,options_container,page_layout,price,quantity_and_stock_status,related_tgtr_position_behavior,related_tgtr_position_limit,required_options,short_description,small_image,small_image_label,special_from_date,special_price,special_to_date,status,tax_class_id,thumbnail,thumbnail_label,updated_at,upsell_tgtr_position_behavior,upsell_tgtr_position_limit,url_key,url_path,visibility,weight,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,_related_sku,_related_position,_crosssell_sku,_crosssell_position,_upsell_sku,_upsell_position,_tier_price_website,_tier_price_customer_group,_tier_price_qty,_tier_price_price,_media_attribute_id,_media_image,_media_label,_media_position,_media_is_disabled,_associated_sku,_associated_default_qty,_associated_position
|
||||
"simple product 1",,Default,simple,,base,,,,"2014-12-25 19:52:47",,,,,,,,,,0,,,"No",,"simple product 1 ","simple product 1","simple product 1",,,,"simple product 1",,,"Block after Info Column",,100.0000,"In Stock",,,0,,,,,,,1,2,,,"2014-12-25 19:52:47",,,simple-product-1,,"catalog, search",,123.0000,0.0000,1,0,0,1,1.0000,1,0.0000,1,1,,1,1,0,1,0.0000,1,0,0,1,,,,,,,,,,,,,,,,,,
|
||||
"simple product 2",,Default,simple,,base,,,,"2014-12-25 19:53:14",,,,,,,,,,0,,,"No",,"simple product 2 ","simple product 2","simple product 2",,,,"simple product 2",,,"Block after Info Column",,200.0000,"In Stock",,,0,,,,,,,1,2,,,"2014-12-25 19:53:14",,,simple-product-2,,"catalog, search",,234.0000,0.0000,1,0,0,1,1.0000,1,0.0000,1,1,,1,1,0,1,0.0000,1,0,0,1,,,,,,,,,,,,,,,,,,
|
||||
|
BIN
Binary file not shown.
+2
@@ -0,0 +1,2 @@
|
||||
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,configurable_variations,configurable_variation_labels,associated_skus
|
||||
Simple,,Default,simple,"Default Category/New",base,Simple,,,,1,"Taxable Goods","Catalo g, Search",100.0000,,,,simple,Simple,Simple,"Simple ",,,,,,,,,"10/25/17, 8:21 AM","10/25/17, 8:21 AM",,,"Block after Info Column",,,,"Use config",,,,,,,,,,100.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,,
|
||||
|
+2
@@ -0,0 +1,2 @@
|
||||
sku;store_view_code;attribute_set_code;product_type;categories;product_websites;name;description;short_description;weight;product_online;tax_class_name;visibility;price;special_price;special_price_from_date;special_price_to_date;url_key;meta_title;meta_keywords;meta_description;base_image;base_image_label;small_image;small_image_label;thumbnail_image;thumbnail_image_label;swatch_image;swatch_image_label;created_at;updated_at;new_from_date;new_to_date;display_product_options_in;map_price;msrp_price;map_enabled;gift_message_available;custom_design;custom_design_from;custom_design_to;custom_layout_update;page_layout;product_options_container;msrp_display_actual_price_type;country_of_manufacture;additional_attributes;qty;out_of_stock_qty;use_config_min_qty;is_qty_decimal;allow_backorders;use_config_backorders;min_cart_qty;use_config_min_sale_qty;max_cart_qty;use_config_max_sale_qty;is_in_stock;notify_on_stock_below;use_config_notify_stock_qty;manage_stock;use_config_manage_stock;use_config_qty_increments;qty_increments;use_config_enable_qty_inc;enable_qty_increments;is_decimal_divided;website_id;related_skus;related_position;crosssell_skus;crosssell_position;upsell_skus;upsell_position;additional_images;additional_image_labels;hide_from_product_page;custom_options;bundle_price_type;bundle_sku_type;bundle_price_view;bundle_weight_type;bundle_values;bundle_shipment_type;configurable_variations;configurable_variation_labels;associated_skus
|
||||
Simple;;Default;simple;"Default Category/New";base;Simple;;;;1;"Taxable Goods";"Catalo g, Search";100.0000;;;;simple;Simple;Simple;"Simple ";;;;;;;;;"10/25/17, 8,21 AM";"10/25/17, 8,21 AM";;;"Block after Info Column";;;;"Use config";;;;;;;;;;100.0000;0.0000;1;0;0;1;1.0000;1;10000.0000;1;1;1.0000;1;1;1;1;1.0000;1;0;0;0;;;;;;;;;;;;;;;;;;;
|
||||
|
+3
@@ -0,0 +1,3 @@
|
||||
sku,_store,_attribute_set,product_type,categories,_product_websites,color,cost,country_of_manufacture,created_at,custom_design,custom_design_from,custom_design_to,custom_layout_update,description,gallery,gift_message_available,gift_wrapping_available,gift_wrapping_price,has_options,image,image_label,is_returnable,manufacturer,meta_description,meta_keyword,meta_title,minimal_price,msrp,msrp_display_actual_price_type,name,news_from_date,news_to_date,options_container,page_layout,price,quantity_and_stock_status,related_tgtr_position_behavior,related_tgtr_position_limit,required_options,short_description,small_image,small_image_label,special_from_date,special_price,special_to_date,status,tax_class_id,thumbnail,thumbnail_label,updated_at,upsell_tgtr_position_behavior,upsell_tgtr_position_limit,url_key,url_path,visibility,weight,qty,min_qty,use_config_min_qty,is_qty_decimal,backorders,use_config_backorders,min_sale_qty,use_config_min_sale_qty,max_sale_qty,use_config_max_sale_qty,is_in_stock,notify_stock_qty,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,_related_sku,_related_position,_crosssell_sku,_crosssell_position,_upsell_sku,_upsell_position,_tier_price_website,_tier_price_customer_group,_tier_price_qty,_tier_price_price,_media_attribute_id,_media_image,_media_label,_media_position,_media_is_disabled,_associated_sku,_associated_default_qty,_associated_position
|
||||
"",,Default,simple,,base,,,,"2014-12-25 19:52:47",,,,,,,,,,0,,,"No",,"simple product 1 ","simple product 1","simple product 1",,,,"simple product 1",,,"Block after Info Column",,100.0000,"In Stock",,,0,,,,,,,1,2,,,"2014-12-25 19:52:47",,,simple-product-1,,"catalog, search",,123.0000,0.0000,1,0,0,1,1.0000,1,0.0000,1,1,,1,1,0,1,0.0000,1,0,0,1,,,,,,,,,,,,,,,,,,
|
||||
"",,Default,simple,,base,,,,"2014-12-25 19:53:14",,,,,,,,,,0,,,"No",,"simple product 2 ","simple product 2","simple product 2",,,,"simple product 2",,,"Block after Info Column",,200.0000,"In Stock",,,0,,,,,,,1,2,,,"2014-12-25 19:53:14",,,simple-product-2,,"catalog, search",,234.0000,0.0000,1,0,0,1,1.0000,1,0.0000,1,1,,1,1,0,1,0.0000,1,0,0,1,,,,,,,,,,,,,,,,,,
|
||||
|
BIN
Binary file not shown.
+1
@@ -0,0 +1 @@
|
||||
Import test file
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Controller\Adminhtml;
|
||||
|
||||
use Magento\Framework\Filesystem\DirectoryList;
|
||||
use Magento\Framework\HTTP\Adapter\FileTransferFactory;
|
||||
use Magento\ImportExport\Model\Import;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
||||
use Magento\ImportExport\Controller\Adminhtml\Import\HttpFactoryMock;
|
||||
|
||||
/**
|
||||
* Test for \Magento\ImportExport\Controller\Adminhtml\ImportResult class.
|
||||
*
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ImportResultTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $mimeType
|
||||
* @param string $delimiter
|
||||
* @backupGlobals enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @dataProvider validationDataProvider
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function testAddErrorMessages(string $fileName, string $mimeType, string $delimiter): void
|
||||
{
|
||||
$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
|
||||
|
||||
$this->getRequest()->setParam('isAjax', true);
|
||||
$this->getRequest()->setMethod('POST');
|
||||
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest';
|
||||
|
||||
/** @var $formKey \Magento\Framework\Data\Form\FormKey */
|
||||
$formKey = $this->_objectManager->get(\Magento\Framework\Data\Form\FormKey::class);
|
||||
$this->getRequest()->setPostValue('form_key', $formKey->getFormKey());
|
||||
$this->getRequest()->setPostValue('entity', 'catalog_product');
|
||||
$this->getRequest()->setPostValue('behavior', 'append');
|
||||
$this->getRequest()->setPostValue(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
|
||||
$this->getRequest()->setPostValue(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);
|
||||
$this->getRequest()->setPostValue('_import_field_separator', $delimiter);
|
||||
|
||||
/** @var \Magento\TestFramework\App\Filesystem $filesystem */
|
||||
$filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class);
|
||||
$tmpDir = $filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
|
||||
$subDir = str_replace('\\', '_', __CLASS__);
|
||||
$tmpDir->create($subDir);
|
||||
$target = $tmpDir->getAbsolutePath("{$subDir}" . DIRECTORY_SEPARATOR . "{$fileName}");
|
||||
copy(__DIR__ . DIRECTORY_SEPARATOR . 'Import' . DIRECTORY_SEPARATOR . '_files'
|
||||
. DIRECTORY_SEPARATOR . "{$fileName}", $target);
|
||||
|
||||
$_FILES = [
|
||||
'import_file' => [
|
||||
'name' => $fileName,
|
||||
'type' => $mimeType,
|
||||
'tmp_name' => $target,
|
||||
'error' => 0,
|
||||
'size' => filesize($target)
|
||||
]
|
||||
];
|
||||
|
||||
$this->_objectManager->configure(
|
||||
[
|
||||
'preferences' => [FileTransferFactory::class => HttpFactoryMock::class]
|
||||
]
|
||||
);
|
||||
|
||||
$this->dispatch('backend/admin/import/validate');
|
||||
$this->assertStringNotContainsString('<br>', $this->getResponse()->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validationDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'file_name' => 'invalid_catalog_products.csv',
|
||||
'mime-type' => 'text/csv',
|
||||
'delimiter' => ',',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Controller\Adminhtml;
|
||||
|
||||
use Magento\Framework\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class ImportTest extends \Magento\TestFramework\TestCase\AbstractBackendController
|
||||
{
|
||||
public function testGetFilterAction()
|
||||
{
|
||||
$this->dispatch('backend/admin/import/index');
|
||||
$body = $this->getResponse()->getBody();
|
||||
$this->assertStringContainsString(
|
||||
(string)\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\ImportExport\Helper\Data::class
|
||||
)->getMaxUploadSizeMessage(),
|
||||
$body
|
||||
);
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
"sku","store_view_code","attribute_set_code","product_type","categories","name","price"
|
||||
"simple1",,"Default","simple","Default Category/Category 1","simple1","10.0000"
|
||||
"simple2",,"Default","simple","Default Category/Category 1","simple2","10.0000"
|
||||
"simple3",,"Default","simple","Default Category/Category 2","simple3","10.0000"
|
||||
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace Magento\ImportExport\Model\Export\Adapter;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\ImportExport\Model\Import;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for Export adapter csv
|
||||
*/
|
||||
class CsvTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var string Destination file name
|
||||
*/
|
||||
private $destination = 'destinationFile';
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test to destruct export adapter
|
||||
*
|
||||
* @dataProvider destructDataProvider
|
||||
*
|
||||
* @param string $destination
|
||||
* @param bool $shouldBeDeleted
|
||||
* @return void
|
||||
*/
|
||||
public function testDestruct(string $destination, bool $shouldBeDeleted): void
|
||||
{
|
||||
$csv = $this->objectManager->create(Csv::class, [
|
||||
'destination' => $destination,
|
||||
'destinationDirectoryCode' => DirectoryList::VAR_DIR
|
||||
]);
|
||||
/** @var Filesystem $fileSystem */
|
||||
$fileSystem = $this->objectManager->get(Filesystem::class);
|
||||
$directoryHandle = $fileSystem->getDirectoryRead(DirectoryList::VAR_DIR);
|
||||
/** Assert that the destination file is present after construct */
|
||||
$this->assertFileExists(
|
||||
$directoryHandle->getAbsolutePath($destination),
|
||||
'The destination file was\'t created after construct'
|
||||
);
|
||||
unset($csv);
|
||||
|
||||
if ($shouldBeDeleted) {
|
||||
$this->assertFileDoesNotExist($directoryHandle->getAbsolutePath($destination));
|
||||
} else {
|
||||
$this->assertFileExists($directoryHandle->getAbsolutePath($destination));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DataProvider for testDestruct
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function destructDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'temporary file' => [$this->destination, true],
|
||||
'import history file' => [Import::IMPORT_HISTORY_DIR . $this->destination, false],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Model\Export;
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\Framework\Filesystem\Directory\WriteInterface;
|
||||
use Magento\Framework\MessageQueue\ConsumerFactory;
|
||||
use Magento\Framework\MessageQueue\DefaultValueProvider;
|
||||
use Magento\Framework\MessageQueue\MessageEncoder;
|
||||
use Magento\Framework\MessageQueue\PublisherInterface;
|
||||
use Magento\Framework\MessageQueue\QueueRepository;
|
||||
use Magento\Framework\ObjectManagerInterface;
|
||||
use Magento\ImportExport\Model\Export\Entity\ExportInfoFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\MessageQueue\ClearQueueProcessor;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test for export consumer
|
||||
*
|
||||
* @see \Magento\ImportExport\Model\Export\Consumer
|
||||
*
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class ConsumerTest extends TestCase
|
||||
{
|
||||
/** @var ObjectManagerInterface */
|
||||
private $objectManager;
|
||||
|
||||
/** @var MessageEncoder */
|
||||
private $messageEncoder;
|
||||
|
||||
/** @var Consumer */
|
||||
private $consumer;
|
||||
|
||||
/** @var WriteInterface */
|
||||
private $directory;
|
||||
|
||||
/** @var string */
|
||||
private $filePath;
|
||||
|
||||
/**
|
||||
* @var QueueRepository
|
||||
*/
|
||||
private $queueRepository;
|
||||
|
||||
/**
|
||||
* @var DefaultValueProvider
|
||||
*/
|
||||
private $defaultValueProvider;
|
||||
|
||||
/** @var ConsumerFactory */
|
||||
private $consumerFactory;
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
$this->messageEncoder = $this->objectManager->get(MessageEncoder::class);
|
||||
$this->consumer = $this->objectManager->get(Consumer::class);
|
||||
$filesystem = $this->objectManager->get(Filesystem::class);
|
||||
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
$this->queueRepository = $this->objectManager->get(QueueRepository::class);
|
||||
$this->defaultValueProvider = $this->objectManager->get(DefaultValueProvider::class);
|
||||
$this->consumerFactory = $this->objectManager->get(ConsumerFactory::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
if ($this->filePath && $this->directory->isExist($this->filePath)) {
|
||||
$this->directory->delete($this->filePath);
|
||||
}
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture default_store admin/security/use_form_key 1
|
||||
*
|
||||
* @magentoDataFixture Magento/Catalog/_files/second_product_simple.php
|
||||
* @magentoDataFixture Magento/Catalog/_files/product_virtual.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testProcess(): void
|
||||
{
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
$objectManager->get(ClearQueueProcessor::class)->execute('exportProcessor');
|
||||
/** @var ExportInfoFactory $exportInfoFactory */
|
||||
$exportInfoFactory = $objectManager->get(ExportInfoFactory::class);
|
||||
/** @var PublisherInterface $messagePublisher */
|
||||
$messagePublisher = $objectManager->get(PublisherInterface::class);
|
||||
$dataObject = $exportInfoFactory->create(
|
||||
'csv',
|
||||
ProductAttributeInterface::ENTITY_TYPE_CODE,
|
||||
[ProductInterface::SKU => 'simple2'],
|
||||
[]
|
||||
);
|
||||
$messagePublisher->publish('import_export.export', $dataObject);
|
||||
$consumer = $this->consumerFactory->get('exportProcessor');
|
||||
$consumer->process(1);
|
||||
$this->filePath = 'export/' . $dataObject->getFileName();
|
||||
$this->assertTrue($this->directory->isExist($this->filePath));
|
||||
$data = $this->getCsvData($this->directory->getAbsolutePath($this->filePath));
|
||||
$this->assertCount(2, $data);
|
||||
$skuPosition = $this->getSkuPosition($data);
|
||||
$this->assertNotNull($skuPosition);
|
||||
$this->assertEquals('simple2', $data[1][$skuPosition]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sku position from array.
|
||||
*
|
||||
* @param array $csvFileData
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
private function getSkuPosition(array $csvFileData): ?int
|
||||
{
|
||||
foreach ($csvFileData as $data) {
|
||||
$skuPosition = array_search(ProductInterface::SKU, $data);
|
||||
|
||||
if ($skuPosition !== false) {
|
||||
return $skuPosition;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse csv file and return csv data as array
|
||||
*
|
||||
* @param string $filePath
|
||||
* @return array
|
||||
* @throws \Magento\Framework\Exception\FileSystemException
|
||||
*/
|
||||
private function getCsvData(string $filePath): array
|
||||
{
|
||||
$driver = $this->directory->getDriver();
|
||||
$fileResource = $driver->fileOpen($filePath, 'r');
|
||||
|
||||
$data = [];
|
||||
while ($rowData = $driver->fileGetCsv($fileResource, 100000)) {
|
||||
$data[] = $rowData;
|
||||
}
|
||||
$driver->fileClose($fileResource);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for eav abstract export model
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\Export\Entity;
|
||||
|
||||
class AbstractEavTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Skipped attribute codes
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $_skippedAttributes = ['confirmation', 'lastname'];
|
||||
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\Export\Entity\AbstractEav
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* Entity code
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_entityCode = 'customer';
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
/** @var \Magento\TestFramework\ObjectManager $objectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$customerAttributes = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Attribute\Collection::class
|
||||
);
|
||||
|
||||
$this->_model = $this->getMockBuilder(\Magento\ImportExport\Model\Export\Entity\AbstractEav::class)
|
||||
->setMethods(['getEntityTypeCode', 'getAttributeCollection'])
|
||||
->disableOriginalConstructor()
|
||||
->getMockForAbstractClass();
|
||||
|
||||
$this->_model->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getEntityTypeCode'
|
||||
)->willReturn(
|
||||
$this->_entityCode
|
||||
);
|
||||
$this->_model->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'getAttributeCollection'
|
||||
)->willReturn(
|
||||
$customerAttributes
|
||||
);
|
||||
$this->_model->__construct(
|
||||
$objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class),
|
||||
$objectManager->get(\Magento\Store\Model\StoreManager::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\Export\Factory::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class),
|
||||
$objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class),
|
||||
$objectManager->get(\Magento\Eav\Model\Config::class)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method getEntityTypeId()
|
||||
*/
|
||||
public function testGetEntityTypeId()
|
||||
{
|
||||
$entityCode = 'customer';
|
||||
$entityId = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Eav\Model\Config::class
|
||||
)->getEntityType(
|
||||
$entityCode
|
||||
)->getEntityTypeId();
|
||||
|
||||
$this->assertEquals($entityId, $this->_model->getEntityTypeId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method _getExportAttrCodes()
|
||||
*
|
||||
* @covers \Magento\ImportExport\Model\Export\Entity\AbstractEav::_getExportAttributeCodes
|
||||
*/
|
||||
public function testGetExportAttrCodes()
|
||||
{
|
||||
$this->_model->setParameters($this->_getSkippedAttributes());
|
||||
$method = new \ReflectionMethod($this->_model, '_getExportAttributeCodes');
|
||||
$method->setAccessible(true);
|
||||
$attributes = $method->invoke($this->_model);
|
||||
foreach (self::$_skippedAttributes as $code) {
|
||||
$this->assertNotContains($code, $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method getAttributeOptions()
|
||||
*/
|
||||
public function testGetAttributeOptions()
|
||||
{
|
||||
/** @var $attributeCollection \Magento\Customer\Model\ResourceModel\Attribute\Collection */
|
||||
$attributeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Attribute\Collection::class
|
||||
);
|
||||
$attributeCollection->addFieldToFilter('attribute_code', 'gender');
|
||||
/** @var $attribute \Magento\Customer\Model\Attribute */
|
||||
$attribute = $attributeCollection->getFirstItem();
|
||||
|
||||
$expectedOptions = [];
|
||||
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
|
||||
$expectedOptions[$option['value']] = $option['label'];
|
||||
}
|
||||
|
||||
$actualOptions = $this->_model->getAttributeOptions($attribute);
|
||||
$this->assertEquals($expectedOptions, $actualOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of skipped attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function _getSkippedAttributes()
|
||||
{
|
||||
/** @var $attributeCollection \Magento\Customer\Model\ResourceModel\Attribute\Collection */
|
||||
$attributeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Attribute\Collection::class
|
||||
);
|
||||
$attributeCollection->addFieldToFilter('attribute_code', ['in' => self::$_skippedAttributes]);
|
||||
$skippedAttributes = [];
|
||||
/** @var $attribute \Magento\Customer\Model\Attribute */
|
||||
foreach ($attributeCollection as $attribute) {
|
||||
$skippedAttributes[$attribute->getAttributeCode()] = $attribute->getId();
|
||||
}
|
||||
|
||||
return [\Magento\ImportExport\Model\Export::FILTER_ELEMENT_SKIP => $skippedAttributes];
|
||||
}
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test for abstract export model
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\Export;
|
||||
|
||||
class EntityAbstractTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\Export\AbstractEntity
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
/** @var \Magento\TestFramework\ObjectManager $objectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$this->_model = $this->getMockForAbstractClass(
|
||||
\Magento\ImportExport\Model\Export\AbstractEntity::class,
|
||||
[
|
||||
$objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class),
|
||||
$objectManager->get(\Magento\Store\Model\StoreManager::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\Export\Factory::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory::class)
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check methods which provide ability to manage errors
|
||||
*/
|
||||
public function testAddRowError()
|
||||
{
|
||||
$errorCode = 'test_error';
|
||||
$errorNum = 1;
|
||||
$errorMessage = 'Test error!';
|
||||
$this->_model->addMessageTemplate($errorCode, $errorMessage);
|
||||
$this->_model->addRowError($errorCode, $errorNum);
|
||||
|
||||
$this->assertEquals(1, $this->_model->getErrorsCount());
|
||||
$this->assertEquals(1, $this->_model->getInvalidRowsCount());
|
||||
$this->assertArrayHasKey($errorMessage, $this->_model->getErrorMessages());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check methods which provide ability to manage writer object
|
||||
*/
|
||||
public function testGetWriter()
|
||||
{
|
||||
$this->_model->setWriter(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\ImportExport\Model\Export\Adapter\Csv::class
|
||||
)
|
||||
);
|
||||
$this->assertInstanceOf(\Magento\ImportExport\Model\Export\Adapter\Csv::class, $this->_model->getWriter());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that method throw exception when writer was not defined
|
||||
*
|
||||
*/
|
||||
public function testGetWriterThrowsException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
$this->_model->getWriter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method filterAttributeCollection
|
||||
*/
|
||||
public function testFilterAttributeCollection()
|
||||
{
|
||||
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Attribute\Collection::class
|
||||
);
|
||||
$collection = $this->_model->filterAttributeCollection($collection);
|
||||
/**
|
||||
* Check that disabled attributes is not existed in attribute collection
|
||||
*/
|
||||
$existedAttributes = [];
|
||||
/** @var $attribute \Magento\Customer\Model\Attribute */
|
||||
foreach ($collection as $attribute) {
|
||||
$existedAttributes[] = $attribute->getAttributeCode();
|
||||
}
|
||||
$disabledAttributes = $this->_model->getDisabledAttributes();
|
||||
foreach ($disabledAttributes as $attributeCode) {
|
||||
$this->assertNotContains(
|
||||
$attributeCode,
|
||||
$existedAttributes,
|
||||
'Disabled attribute "' . $attributeCode . '" existed in collection'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Model;
|
||||
|
||||
use ReflectionClass;
|
||||
|
||||
class ExportTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Model object which used for tests
|
||||
*
|
||||
* @var \Magento\ImportExport\Model\Export
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\ImportExport\Model\Export::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method '_getEntityAdapter' in case when entity is valid
|
||||
*
|
||||
* @param string $entity
|
||||
* @param string $expectedEntityType
|
||||
* @dataProvider getEntityDataProvider
|
||||
* @covers \Magento\ImportExport\Model\Export::_getEntityAdapter
|
||||
*/
|
||||
public function testGetEntityAdapterWithValidEntity($entity, $expectedEntityType)
|
||||
{
|
||||
$this->_model->setData(['entity' => $entity]);
|
||||
$this->_model->getEntityAttributeCollection();
|
||||
$this->assertClassHasAttribute('_entityAdapter', get_class($this->_model));
|
||||
$object = new ReflectionClass(get_class($this->_model));
|
||||
$attribute = $object->getProperty('_entityAdapter');
|
||||
$attribute->setAccessible(true);
|
||||
$propertyObject = $attribute->getValue($this->_model);
|
||||
$attribute->setAccessible(false);
|
||||
$this->assertInstanceOf($expectedEntityType, $propertyObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getEntityDataProvider()
|
||||
{
|
||||
return [
|
||||
'product' => [
|
||||
'$entity' => 'catalog_product',
|
||||
'$expectedEntityType' => \Magento\CatalogImportExport\Model\Export\Product::class,
|
||||
],
|
||||
'customer main data' => [
|
||||
'$entity' => 'customer',
|
||||
'$expectedEntityType' => \Magento\CustomerImportExport\Model\Export\Customer::class,
|
||||
],
|
||||
'customer address' => [
|
||||
'$entity' => 'customer_address',
|
||||
'$expectedEntityType' => \Magento\CustomerImportExport\Model\Export\Address::class,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method '_getEntityAdapter' in case when entity is invalid
|
||||
*
|
||||
* @covers \Magento\ImportExport\Model\Export::_getEntityAdapter
|
||||
*/
|
||||
public function testGetEntityAdapterWithInvalidEntity()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
$this->_model->setData(['entity' => 'test']);
|
||||
$this->_model->getEntityAttributeCollection();
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\ImportExport\Model\Import\Entity\AbstractEav
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\Import\Entity;
|
||||
|
||||
class EavAbstractTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Model object which used for tests
|
||||
*
|
||||
* @var \Magento\ImportExport\Model\Import\Entity\AbstractEav|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* Create all necessary data for tests
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->_model = $this->getMockForAbstractClass(
|
||||
\Magento\ImportExport\Model\Import\Entity\AbstractEav::class,
|
||||
[],
|
||||
'',
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for method getAttributeOptions()
|
||||
*/
|
||||
public function testGetAttributeOptions()
|
||||
{
|
||||
$indexAttributeCode = 'gender';
|
||||
|
||||
/** @var $attributeCollection \Magento\Customer\Model\ResourceModel\Attribute\Collection */
|
||||
$attributeCollection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Attribute\Collection::class
|
||||
);
|
||||
$attributeCollection->addFieldToFilter(
|
||||
'attribute_code',
|
||||
['in' => [$indexAttributeCode, 'group_id']]
|
||||
);
|
||||
/** @var $attribute \Magento\Customer\Model\Attribute */
|
||||
foreach ($attributeCollection as $attribute) {
|
||||
$index = $attribute->getAttributeCode() == $indexAttributeCode ? 'value' : 'label';
|
||||
$expectedOptions = [];
|
||||
foreach ($attribute->getSource()->getAllOptions(false) as $option) {
|
||||
if (is_array($option['value'])) {
|
||||
foreach ($option['value'] as $value) {
|
||||
$expectedOptions[strtolower($value[$index])] = $value['value'];
|
||||
}
|
||||
} else {
|
||||
$expectedOptions[strtolower($option[$index])] = $option['value'];
|
||||
}
|
||||
}
|
||||
$actualOptions = $this->_model->getAttributeOptions($attribute, [$indexAttributeCode]);
|
||||
asort($expectedOptions);
|
||||
asort($actualOptions);
|
||||
$this->assertEquals($expectedOptions, $actualOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Model\Import\Entity;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\ImportExport\Model\Import\Source\Csv;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
||||
|
||||
/**
|
||||
* Test class for \Magento\ImportExport\Model\Import\AbstractEntity
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class EntityAbstractTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test for method _saveValidatedBunches()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSaveValidatedBunches() : void
|
||||
{
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$filesystem = $objectManager->create(\Magento\Framework\Filesystem::class);
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
|
||||
$source = new Csv(__DIR__ . '/_files/advanced_price_for_validation_test.csv', $directory);
|
||||
$source->rewind();
|
||||
|
||||
$eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
|
||||
$entityTypeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
|
||||
$eavConfig->expects($this->any())->method('getEntityType')->willReturn($entityTypeMock);
|
||||
|
||||
/** @var $model AbstractEntity|\PHPUnit\Framework\MockObject\MockObject */
|
||||
$model = $this->getMockForAbstractClass(
|
||||
AbstractEntity::class,
|
||||
[
|
||||
$objectManager->get(\Magento\Framework\Json\Helper\Data::class),
|
||||
$objectManager->get(\Magento\ImportExport\Helper\Data::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ResourceModel\Import\Data::class),
|
||||
$eavConfig,
|
||||
$objectManager->get(\Magento\Framework\App\ResourceConnection::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ResourceModel\Helper::class),
|
||||
$objectManager->get(\Magento\Framework\Stdlib\StringUtils::class),
|
||||
$objectManager->get(ProcessingErrorAggregatorInterface::class),
|
||||
],
|
||||
'',
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
['validateRow', 'getEntityTypeCode']
|
||||
);
|
||||
$model->expects($this->any())->method('validateRow')->willReturn(true);
|
||||
$model->expects($this->any())->method('getEntityTypeCode')->willReturn('catalog_product');
|
||||
|
||||
$model->setSource($source);
|
||||
|
||||
$method = new \ReflectionMethod($model, '_saveValidatedBunches');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($model);
|
||||
|
||||
$this->assertEquals(1, $model->getProcessedEntitiesCount());
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
sku,tier_price_website,tier_price_customer_group,tier_price_qty,tier_price,tier_price_value_type
|
||||
SimpleProduct,All Websites [USD],ALL GROUPS,100,50,Fixed
|
||||
SimpleProduct,All Websites [USD],ALL GROUPS,33,55,Fixed
|
||||
|
+3
@@ -0,0 +1,3 @@
|
||||
email,_website,_store,attr_pylwhnacmivoekxo,attr_qpygb,confirmation,created_at,created_in,default_billing,default_shipping,disable_auto_group_change,dob,firstname,gender,group_id,irinkin,iriyes,lastname,middlename,password_hash,prefix,rp_token,rp_token_created_at,store_id,suffix,taxvat,textiri,website_id,zagogulina,password
|
||||
qwerty@example.ru,base,admin,,,,"2012-06-15 07:58:23",,11,,0,,qwerty,,1,,,qwerty,,,,,,0,,,,1,,
|
||||
ziza@example.com,base,admin,,,,"2012-06-14 07:43:00",Admin,12,,0,,Irina1,,1,111,,Glazunova1,,e02484cbed89b7eeb5fb6abb437424c70e805b4d4e6ef91ae1bf07d79bc7938b:xi,,,,0,,,,1,No,
|
||||
|
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for \Magento\ImportExport\Model\Import\AbstractEntity
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\Import;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class EntityAbstractTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Test for method _saveValidatedBunches()
|
||||
*/
|
||||
public function testSaveValidatedBunches()
|
||||
{
|
||||
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
|
||||
->create(\Magento\Framework\Filesystem::class);
|
||||
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
|
||||
$source = new \Magento\ImportExport\Model\Import\Source\Csv(
|
||||
__DIR__ . '/Entity/_files/customers_for_validation_test.csv',
|
||||
$directory
|
||||
);
|
||||
$source->rewind();
|
||||
$expected = $source->current();
|
||||
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
/** @var $model \Magento\ImportExport\Model\Import\AbstractEntity|\PHPUnit\Framework\MockObject\MockObject */
|
||||
$model = $this->getMockForAbstractClass(
|
||||
\Magento\ImportExport\Model\Import\AbstractEntity::class,
|
||||
[
|
||||
$objectManager->get(\Magento\Framework\Stdlib\StringUtils::class),
|
||||
$objectManager->get(\Magento\Framework\App\Config\ScopeConfigInterface::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ImportFactory::class),
|
||||
$objectManager->get(\Magento\ImportExport\Model\ResourceModel\Helper::class),
|
||||
$objectManager->get(\Magento\Framework\App\ResourceConnection::class),
|
||||
$objectManager->get(
|
||||
\Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface::class
|
||||
)
|
||||
],
|
||||
'',
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
['getMasterAttributeCode', 'validateRow', 'getEntityTypeCode']
|
||||
);
|
||||
$model->expects($this->any())->method('getMasterAttributeCode')->willReturn("email");
|
||||
$model->expects($this->any())->method('validateRow')->willReturn(true);
|
||||
$model->expects($this->any())->method('getEntityTypeCode')->willReturn('customer');
|
||||
|
||||
$model->setSource($source);
|
||||
|
||||
$method = new \ReflectionMethod($model, '_saveValidatedBunches');
|
||||
$method->setAccessible(true);
|
||||
$method->invoke($model);
|
||||
|
||||
/** @var $dataSourceModel \Magento\ImportExport\Model\ResourceModel\Import\Data */
|
||||
$dataSourceModel = $objectManager->get(\Magento\ImportExport\Model\ResourceModel\Import\Data::class);
|
||||
$this->assertCount(1, $dataSourceModel->getIterator());
|
||||
|
||||
$bunch = $dataSourceModel->getNextBunch();
|
||||
$this->assertEquals($expected, $bunch[0]);
|
||||
|
||||
//Delete created bunch from DB
|
||||
$dataSourceModel->cleanBunches();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Model;
|
||||
|
||||
use Magento\Framework\Phrase;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
||||
use Magento\ImportExport\Model\Import\ImageDirectoryBaseProvider;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoDataFixture Magento/ImportExport/_files/import_data.php
|
||||
*/
|
||||
class ImportTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Model object which is used for tests
|
||||
*
|
||||
* @var Import
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var Import\Config
|
||||
*/
|
||||
protected $_importConfig;
|
||||
|
||||
/**
|
||||
* Expected entity behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_entityBehaviors = [
|
||||
'catalog_product' => [
|
||||
'token' => \Magento\ImportExport\Model\Source\Import\Behavior\Basic::class,
|
||||
'code' => 'basic_behavior',
|
||||
'notes' => [],
|
||||
],
|
||||
'customer_composite' => [
|
||||
'token' => \Magento\ImportExport\Model\Source\Import\Behavior\Basic::class,
|
||||
'code' => 'basic_behavior',
|
||||
'notes' => [],
|
||||
],
|
||||
'customer' => [
|
||||
'token' => \Magento\ImportExport\Model\Source\Import\Behavior\Custom::class,
|
||||
'code' => 'custom_behavior',
|
||||
'notes' => [],
|
||||
],
|
||||
'customer_address' => [
|
||||
'token' => \Magento\ImportExport\Model\Source\Import\Behavior\Custom::class,
|
||||
'code' => 'custom_behavior',
|
||||
'notes' => [],
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Expected unique behaviors
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_uniqueBehaviors = [
|
||||
'basic_behavior' => \Magento\ImportExport\Model\Source\Import\Behavior\Basic::class,
|
||||
'custom_behavior' => \Magento\ImportExport\Model\Source\Import\Behavior\Custom::class,
|
||||
];
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_importConfig = Bootstrap::getObjectManager()->create(
|
||||
Import\Config::class
|
||||
);
|
||||
/** @var ImageDirectoryBaseProvider $provider */
|
||||
$provider = Bootstrap::getObjectManager()->get(ImageDirectoryBaseProvider::class);
|
||||
$this->_model = Bootstrap::getObjectManager()->create(
|
||||
Import::class,
|
||||
[
|
||||
'importConfig' => $this->_importConfig
|
||||
]
|
||||
);
|
||||
$this->_model->setData('images_base_directory', $provider->getDirectory());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test validation of images directory against provided base directory.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testImagesDirBase(): void
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Images file directory is outside required directory');
|
||||
|
||||
$this->_model->setData(
|
||||
Import::FIELD_NAME_VALIDATION_STRATEGY,
|
||||
ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS
|
||||
);
|
||||
$this->_model->setEntity('catalog_product');
|
||||
$this->_model->setData(Import::FIELD_NAME_IMG_FILE_DIR, '../_files');
|
||||
$this->_model->importSource();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \Magento\ImportExport\Model\Import::_getEntityAdapter
|
||||
*/
|
||||
public function testImportSource()
|
||||
{
|
||||
/** @var $customersCollection \Magento\Customer\Model\ResourceModel\Customer\Collection */
|
||||
$customersCollection = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Customer\Model\ResourceModel\Customer\Collection::class
|
||||
);
|
||||
|
||||
$existCustomersCount = count($customersCollection->load());
|
||||
|
||||
$customersCollection->resetData();
|
||||
$customersCollection->clear();
|
||||
$this->_model->setEntity('customer');
|
||||
$this->_model->setData(
|
||||
Import::FIELD_NAME_VALIDATION_STRATEGY,
|
||||
ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS
|
||||
);
|
||||
$this->_model->importSource();
|
||||
|
||||
$customers = $customersCollection->getItems();
|
||||
|
||||
$addedCustomers = count($customers) - $existCustomersCount;
|
||||
|
||||
$this->assertGreaterThan($existCustomersCount, $addedCustomers);
|
||||
}
|
||||
|
||||
public function testValidateSource()
|
||||
{
|
||||
$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
|
||||
|
||||
$this->_model->setEntity('catalog_product');
|
||||
$this->_model->setData(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
|
||||
$this->_model->setData(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);
|
||||
|
||||
/** @var \Magento\ImportExport\Model\Import\AbstractSource|\PHPUnit\Framework\MockObject\MockObject $source */
|
||||
$source = $this->getMockForAbstractClass(
|
||||
\Magento\ImportExport\Model\Import\AbstractSource::class,
|
||||
[['sku', 'name']]
|
||||
);
|
||||
$source->expects($this->any())->method('_getNextRow')->willReturn(false);
|
||||
$this->assertTrue($this->_model->validateSource($source));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testValidateSourceException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Entity is unknown');
|
||||
|
||||
$source = $this->getMockForAbstractClass(
|
||||
\Magento\ImportExport\Model\Import\AbstractSource::class,
|
||||
[],
|
||||
'',
|
||||
false
|
||||
);
|
||||
$this->_model->validateSource($source);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetUnknownEntity()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Entity is unknown');
|
||||
|
||||
$entityName = 'entity_name';
|
||||
$this->_model->setEntity($entityName);
|
||||
$this->assertSame($entityName, $this->_model->getEntity());
|
||||
}
|
||||
|
||||
public function testGetEntity()
|
||||
{
|
||||
$entityName = 'catalog_product';
|
||||
$this->_model->setEntity($entityName);
|
||||
$this->assertSame($entityName, $this->_model->getEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public function testGetEntityEntityIsNotSet()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('Entity is unknown');
|
||||
|
||||
$this->_model->getEntity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getEntityBehaviors with all required data
|
||||
* Can't check array on equality because this test should be useful for CE
|
||||
*
|
||||
* @covers \Magento\ImportExport\Model\Import::getEntityBehaviors
|
||||
*/
|
||||
public function testGetEntityBehaviors()
|
||||
{
|
||||
$this->prepareProductNotes();
|
||||
|
||||
$importModel = $this->_model;
|
||||
$actualBehaviors = $importModel->getEntityBehaviors();
|
||||
|
||||
foreach ($this->_entityBehaviors as $entityKey => $behaviorData) {
|
||||
$this->assertArrayHasKey($entityKey, $actualBehaviors);
|
||||
$this->assertEquals($behaviorData, $actualBehaviors[$entityKey]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getEntityBehaviors with not existing behavior class
|
||||
*
|
||||
*/
|
||||
public function testGetEntityBehaviorsWithUnknownBehavior()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
$this->expectExceptionMessage('The behavior token for customer is invalid.');
|
||||
|
||||
$this->_importConfig->merge(
|
||||
['entities' => ['customer' => ['behaviorModel' => 'Unknown_Behavior_Class']]]
|
||||
);
|
||||
$importModel = $this->_model;
|
||||
$actualBehaviors = $importModel->getEntityBehaviors();
|
||||
$this->assertArrayNotHasKey('customer', $actualBehaviors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getUniqueEntityBehaviors with all required data
|
||||
* Can't check array on equality because this test should be useful for CE
|
||||
*
|
||||
* @covers \Magento\ImportExport\Model\Import::getUniqueEntityBehaviors
|
||||
*/
|
||||
public function testGetUniqueEntityBehaviors()
|
||||
{
|
||||
$importModel = $this->_model;
|
||||
$actualBehaviors = $importModel->getUniqueEntityBehaviors();
|
||||
|
||||
foreach ($this->_uniqueBehaviors as $behaviorCode => $behaviorClass) {
|
||||
$this->assertArrayHasKey($behaviorCode, $actualBehaviors);
|
||||
$this->assertEquals($behaviorClass, $actualBehaviors[$behaviorCode]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Catalog Product Notes to expected results.
|
||||
*
|
||||
* @return void
|
||||
* @ SuppressWarnings(PHPMD.)
|
||||
*/
|
||||
private function prepareProductNotes(): void
|
||||
{
|
||||
$this->_entityBehaviors['catalog_product']['notes'] =
|
||||
[
|
||||
Import::BEHAVIOR_APPEND => new Phrase('New product data is added to the existing product data for'
|
||||
. ' the existing entries in the database. All fields except sku can be updated.'),
|
||||
Import::BEHAVIOR_REPLACE => new Phrase('The existing product data is replaced with new data.'
|
||||
. ' <b>Exercise caution when replacing data because the existing product data will be completely'
|
||||
. ' cleared and all references in the system will be lost.</b>'),
|
||||
Import::BEHAVIOR_DELETE => new Phrase('Any entities in the import data that already exist in the'
|
||||
. ' database are deleted from the database.'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\ImportExport\Model\Report;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\ImportExport\Model\Import;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
|
||||
use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingErrorAggregatorInterface;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDbIsolation enabled
|
||||
* @magentoAppArea adminhtml
|
||||
*/
|
||||
class CsvTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Filesystem\Directory\WriteInterface
|
||||
*/
|
||||
private $directory;
|
||||
|
||||
/**
|
||||
* @var Csv
|
||||
*/
|
||||
private $csvReport;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $importFilePath;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $reportPath;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$filesystem = Bootstrap::getObjectManager()->create(Filesystem::class);
|
||||
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
|
||||
|
||||
$this->csvReport = Bootstrap::getObjectManager()->create(Csv::class);
|
||||
}
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach ([$this->importFilePath, $this->reportPath] as $path) {
|
||||
if ($path && $this->directory->isExist($path)) {
|
||||
$this->directory->delete($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateReport()
|
||||
{
|
||||
$importData = <<<fileContent
|
||||
sku,store_view_code,name,price,product_type,attribute_set_code,weight
|
||||
simple1,,"simple 1",10,simple,Default,-5
|
||||
fileContent;
|
||||
$this->importFilePath = 'test_import.csv';
|
||||
$this->directory->writeFile($this->importFilePath, $importData);
|
||||
|
||||
$errorAggregator = Bootstrap::getObjectManager()->create(ProcessingErrorAggregatorInterface::class);
|
||||
$error = 'Value for \'weight\' attribute contains incorrect value';
|
||||
$errorAggregator->addError($error, ProcessingError::ERROR_LEVEL_CRITICAL, 1, 'weight', $error);
|
||||
|
||||
$outputFileName = $this->csvReport->createReport(
|
||||
$this->directory->getAbsolutePath($this->importFilePath),
|
||||
$errorAggregator
|
||||
);
|
||||
|
||||
$this->reportPath = Import::IMPORT_HISTORY_DIR . $outputFileName;
|
||||
$this->assertTrue($this->directory->isExist($this->reportPath), 'Report was not generated');
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\ResourceModel\Import;
|
||||
|
||||
/**
|
||||
* Test Import Data resource model
|
||||
*
|
||||
* @magentoDataFixture Magento/ImportExport/_files/import_data.php
|
||||
*/
|
||||
class DataTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\ResourceModel\Import\Data
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\ImportExport\Model\ResourceModel\Import\Data::class
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getUniqueColumnData() in case when in data stored in requested column is unique
|
||||
*/
|
||||
public function testGetUniqueColumnData()
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$expectedBunches = $objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->registry(
|
||||
'_fixture/Magento_ImportExport_Import_Data'
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedBunches[0]['entity'], $this->_model->getUniqueColumnData('entity'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getUniqueColumnData() in case when in data stored in requested column is NOT unique
|
||||
*
|
||||
*/
|
||||
public function testGetUniqueColumnDataException()
|
||||
{
|
||||
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
|
||||
|
||||
$this->_model->getUniqueColumnData('data');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful getBehavior()
|
||||
*/
|
||||
public function testGetBehavior()
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$expectedBunches = $objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->registry(
|
||||
'_fixture/Magento_ImportExport_Import_Data'
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedBunches[0]['behavior'], $this->_model->getBehavior());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test successful getEntityTypeCode()
|
||||
*/
|
||||
public function testGetEntityTypeCode()
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$expectedBunches = $objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->registry(
|
||||
'_fixture/Magento_ImportExport_Import_Data'
|
||||
);
|
||||
|
||||
$this->assertEquals($expectedBunches[0]['entity'], $this->_model->getEntityTypeCode());
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Test class for entity source model \Magento\ImportExport\Model\Source\Import\Entity
|
||||
*/
|
||||
namespace Magento\ImportExport\Model\Source\Import;
|
||||
|
||||
class EntityTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var \Magento\ImportExport\Model\Source\Import\Entity
|
||||
*/
|
||||
protected $_model;
|
||||
|
||||
/**
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_importConfigMock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->_importConfigMock = $this->createMock(\Magento\ImportExport\Model\Import\ConfigInterface::class);
|
||||
$this->_model = new \Magento\ImportExport\Model\Source\Import\Entity($this->_importConfigMock);
|
||||
}
|
||||
|
||||
public function testToOptionArray()
|
||||
{
|
||||
$entities = [
|
||||
'entity_name_1' => ['name' => 'entity_name_1', 'label' => 'entity_label_1'],
|
||||
'entity_name_2' => ['name' => 'entity_name_2', 'label' => 'entity_label_2'],
|
||||
];
|
||||
$expectedResult = [
|
||||
['label' => __('-- Please Select --'), 'value' => ''],
|
||||
['label' => __('entity_label_1'), 'value' => 'entity_name_1'],
|
||||
['label' => __('entity_label_2'), 'value' => 'entity_name_2'],
|
||||
];
|
||||
$this->_importConfigMock->expects($this->any())->method('getEntities')->willReturn($entities);
|
||||
$this->assertEquals($expectedResult, $this->_model->toOptionArray());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
||||
use Magento\Catalog\Api\Data\ProductInterface;
|
||||
use Magento\Framework\MessageQueue\PublisherInterface;
|
||||
use Magento\ImportExport\Model\Export\Entity\ExportInfoFactory;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple.php');
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ExportInfoFactory $exportInfoFactory */
|
||||
$exportInfoFactory = $objectManager->get(ExportInfoFactory::class);
|
||||
/** @var PublisherInterface $messagePublisher */
|
||||
$messagePublisher = $objectManager->get(PublisherInterface::class);
|
||||
$dataObject = $exportInfoFactory->create(
|
||||
'csv',
|
||||
ProductAttributeInterface::ENTITY_TYPE_CODE,
|
||||
[ProductInterface::SKU => 'simple2']
|
||||
);
|
||||
$messagePublisher->publish('import_export.export', $dataObject);
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Magento\TestFramework\MessageQueue\ClearQueueProcessor;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
|
||||
|
||||
$objectManager = Bootstrap::getObjectManager();
|
||||
/** @var ClearQueueProcessor $clearQueueProcessor */
|
||||
$clearQueueProcessor = $objectManager->get(ClearQueueProcessor::class);
|
||||
$clearQueueProcessor->execute('exportProcessor');
|
||||
|
||||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/second_product_simple_rollback.php');
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$bunches = [
|
||||
0 => [
|
||||
'entity' => 'customer',
|
||||
'behavior' => 'v2_update',
|
||||
'data' => [
|
||||
0 => [
|
||||
'email' => 'AnthonyANealy@magento.com',
|
||||
'_website' => 'base',
|
||||
'_store' => 'admin',
|
||||
'confirmation' => null,
|
||||
'created_at' => '05-06-12 15:53',
|
||||
'created_in' => 'Admin',
|
||||
'default_billing' => '1',
|
||||
'default_shipping' => '1',
|
||||
'disable_auto_group_change' => '0',
|
||||
'dob' => '13-06-1984',
|
||||
'firstname' => 'Anthony',
|
||||
'gender' => 'Male',
|
||||
'group_id' => '1',
|
||||
'lastname' => 'Nealy',
|
||||
'middlename' => 'A.',
|
||||
'password_hash' => '6a9c9bfb2ba88a6ad2a64e7402df44a763e0c48cd21d7af9e7e796cd4677ee28:RF',
|
||||
'prefix' => null,
|
||||
'reward_update_notification' => '1',
|
||||
'reward_warning_notification' => '1',
|
||||
'rp_token' => null,
|
||||
'rp_token_created_at' => null,
|
||||
'store_id' => '0',
|
||||
'suffix' => null,
|
||||
'taxvat' => null,
|
||||
'website_id' => '1',
|
||||
'password' => null,
|
||||
],
|
||||
1 => [
|
||||
'email' => 'LoriBBanks@magento.com',
|
||||
'_website' => 'admin',
|
||||
'_store' => 'admin',
|
||||
'confirmation' => null,
|
||||
'created_at' => '05-06-12 15:59',
|
||||
'created_in' => 'Admin',
|
||||
'default_billing' => '3',
|
||||
'default_shipping' => '3',
|
||||
'disable_auto_group_change' => '0',
|
||||
'dob' => '13-06-1984',
|
||||
'firstname' => 'Lori',
|
||||
'gender' => 'Female',
|
||||
'group_id' => '1',
|
||||
'lastname' => 'Banks',
|
||||
'middlename' => 'R.',
|
||||
'password_hash' => '7ad6dbdc83d3e9f598825dc58b84678c7351e4281f6bc2b277a32dcd88b9756b:pz',
|
||||
'prefix' => null,
|
||||
'reward_update_notification' => '1',
|
||||
'reward_warning_notification' => '1',
|
||||
'rp_token' => null,
|
||||
'rp_token_created_at' => null,
|
||||
'store_id' => '0',
|
||||
'suffix' => null,
|
||||
'taxvat' => null,
|
||||
'website_id' => '0',
|
||||
'password' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
1 => [
|
||||
'entity' => 'customer',
|
||||
'behavior' => 'v2_update',
|
||||
'data' => [
|
||||
0 => [
|
||||
'email' => 'BetsyHParker@magento.com',
|
||||
'_website' => 'base',
|
||||
'_store' => 'admin',
|
||||
'confirmation' => null,
|
||||
'created_at' => '05-06-12 16:13',
|
||||
'created_in' => 'Admin',
|
||||
'default_billing' => '4',
|
||||
'default_shipping' => '4',
|
||||
'disable_auto_group_change' => '0',
|
||||
'dob' => null,
|
||||
'firstname' => 'Betsy',
|
||||
'gender' => 'Female',
|
||||
'group_id' => '1',
|
||||
'lastname' => 'Parker',
|
||||
'middlename' => 'H.',
|
||||
'password_hash' => '145d12bfff8a6a279eb61e277e3d727c0ba95acc1131237f1594ddbb7687a564:l1',
|
||||
'prefix' => null,
|
||||
'reward_update_notification' => '1',
|
||||
'reward_warning_notification' => '1',
|
||||
'rp_token' => null,
|
||||
'rp_token_created_at' => null,
|
||||
'store_id' => '0',
|
||||
'suffix' => null,
|
||||
'taxvat' => null,
|
||||
'website_id' => '2',
|
||||
'password' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$importDataResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\ImportExport\Model\ResourceModel\Import\Data::class
|
||||
);
|
||||
|
||||
foreach ($bunches as $bunch) {
|
||||
$importDataResource->saveBunch($bunch['entity'], $bunch['behavior'], $bunch['data']);
|
||||
}
|
||||
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$objectManager->get(\Magento\Framework\Registry::class)->unregister('_fixture/Magento_ImportExport_Import_Data');
|
||||
$objectManager->get(
|
||||
\Magento\Framework\Registry::class
|
||||
)->register('_fixture/Magento_ImportExport_Import_Data', $bunches);
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
|
||||
$product->setTypeId(
|
||||
\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
|
||||
)->setId(
|
||||
1
|
||||
)->setAttributeSetId(
|
||||
4
|
||||
)->setName(
|
||||
'New Product'
|
||||
)->setSku(
|
||||
'simple'
|
||||
)->setPrice(
|
||||
10
|
||||
)->setVisibility(
|
||||
\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH
|
||||
)->setStatus(
|
||||
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
|
||||
)->setWebsiteIds(
|
||||
[1]
|
||||
)->setCategoryIds(
|
||||
[]
|
||||
)->setStockData(
|
||||
['qty' => 100, 'is_in_stock' => 1, 'manage_stock' => 1]
|
||||
)->save();
|
||||
Reference in New Issue
Block a user