-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #937 from magento-epam/PR-4
[Epam] Extend functional test sprint 4 - MTO-138: [Test] Export Advanced Pricing - MTO-127: [Test] Import Advanced Pricing
- Loading branch information
Showing
40 changed files
with
1,769 additions
and
94 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
...s/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\AdvancedPricingImportExport\Test\Constraint; | ||
|
||
use Magento\Mtf\Constraint\AbstractConstraint; | ||
use Magento\Mtf\Fixture\InjectableFixture; | ||
use Magento\Mtf\Util\Command\File\ExportInterface; | ||
|
||
/** | ||
* Assert that exported file with advanced pricing options contains product data. | ||
*/ | ||
class AssertExportAdvancedPricing extends AbstractConstraint | ||
{ | ||
/** | ||
* Export data. | ||
* | ||
* @var array | ||
*/ | ||
private $exportData; | ||
|
||
/** | ||
* Assert that exported file with advanced pricing options contains product data. | ||
* | ||
* @param ExportInterface $export | ||
* @param array $products | ||
* @param array $exportedFields | ||
* @return void | ||
*/ | ||
public function processAssert( | ||
ExportInterface $export, | ||
array $products, | ||
array $exportedFields | ||
) { | ||
$this->exportData = $export->getLatest(); | ||
foreach ($products as $product) { | ||
$regexps = $this->prepareRegexpsForCheck($exportedFields, $product); | ||
\PHPUnit_Framework_Assert::assertTrue( | ||
$this->isProductDataExists($regexps), | ||
'A product with name ' . $product->getName() . ' was not found in exported file.' | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Returns a string representation of the object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'A product(s) with correct data was found in exported file.'; | ||
} | ||
|
||
/** | ||
* Prepare regular expressions for product data in exported file. | ||
* | ||
* @param array $fields | ||
* @param InjectableFixture $product | ||
* @return array | ||
*/ | ||
private function prepareRegexpsForCheck( | ||
array $fields, | ||
InjectableFixture $product | ||
) { | ||
$regexpsForCheck = []; | ||
$tierPrices = count($product->getData()['tier_price']); | ||
for ($i = 0; $i < $tierPrices; $i++) { | ||
$regexp = '/'; | ||
foreach ($fields as $field) { | ||
if (strpos($field, 'tier_price') !== false) { | ||
$replace = ($field == 'tier_price' || $field == 'tier_price_qty') ? 'tier_' : 'tier_price_'; | ||
$regexp .= preg_replace( | ||
'/[\[\]]/', | ||
'.*', | ||
'.*(' . $product->getData()['tier_price'][$i][str_replace($replace, '', $field)] . ')' | ||
); | ||
} else { | ||
$regexp .= '.*(' . $product->getData($field) . ').*'; | ||
} | ||
} | ||
$regexp .= '/U'; | ||
|
||
$regexpsForCheck[] = $regexp; | ||
} | ||
|
||
return $regexpsForCheck; | ||
} | ||
|
||
/** | ||
* Check product data existing in exported file. | ||
* | ||
* @param array $data | ||
* @return bool | ||
*/ | ||
private function isProductDataExists(array $data) | ||
{ | ||
foreach ($data as $regexp) { | ||
preg_match($regexp, $this->exportData->getContent(), $matches); | ||
if (empty($matches)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
...s/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\AdvancedPricingImportExport\Test\Constraint; | ||
|
||
use Magento\Mtf\Constraint\AbstractConstraint; | ||
use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit; | ||
use Magento\ImportExport\Test\Fixture\ImportData; | ||
|
||
/** | ||
* Check imported advanced prices are correct. | ||
*/ | ||
class AssertImportAdvancedPricing extends AbstractConstraint | ||
{ | ||
/** | ||
* Array keys mapping for csv file. | ||
* | ||
* @var array | ||
*/ | ||
private $mappingData = [ | ||
'sku' => 'sku', | ||
'tier_price' => 'price', | ||
'tier_price_qty' => 'price_qty', | ||
'tier_price_website' => 'website', | ||
'tier_price_customer_group' => 'customer_group', | ||
'tier_price_value_type' => 'value_type' | ||
]; | ||
|
||
/** | ||
* Edit page on backend. | ||
* | ||
* @var CatalogProductEdit | ||
*/ | ||
private $catalogProductEdit; | ||
|
||
/** | ||
* Import fixture. | ||
* | ||
* @var ImportData | ||
*/ | ||
private $import; | ||
|
||
/** | ||
* Assert imported advanced prices are correct. | ||
* | ||
* @param CatalogProductEdit $catalogProductEdit | ||
* @param ImportData $import | ||
* @return void | ||
*/ | ||
public function processAssert( | ||
CatalogProductEdit $catalogProductEdit, | ||
ImportData $import | ||
) { | ||
$this->catalogProductEdit = $catalogProductEdit; | ||
$this->import = $import; | ||
|
||
$resultArrays = $this->getPreparePrices(); | ||
|
||
\PHPUnit_Framework_Assert::assertEquals( | ||
$resultArrays['pageData'], | ||
$resultArrays['csvData'], | ||
'Tier prices from page and csv are not match.' | ||
); | ||
} | ||
|
||
/** | ||
* Prepare arrays for compare. | ||
* | ||
* @return array | ||
*/ | ||
private function getPreparePrices() | ||
{ | ||
$products = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); | ||
|
||
// Prepare tier prices data from page form. | ||
$resultProductArray = []; | ||
foreach ($products as $product) { | ||
$this->catalogProductEdit->open(['id' => $product->getId()]); | ||
$advancedPricing = $this->catalogProductEdit->getProductForm()->openSection('advanced-pricing') | ||
->getSection('advanced-pricing'); | ||
$tierPrices = $advancedPricing->getTierPriceForm()->getFieldsData(); | ||
$productSku = $product->getSku(); | ||
foreach ($tierPrices as $tierPrice) { | ||
$resultProductArray[$productSku][] = $tierPrice; | ||
} | ||
} | ||
|
||
// Prepare tier prices data from csv file. | ||
$resultCsvArray = []; | ||
if ($this->import->getBehavior() !== 'Delete') { | ||
$resultCsvArray = $this->getResultCsv(); | ||
} | ||
|
||
return ['pageData' => $resultProductArray, 'csvData' => $resultCsvArray]; | ||
} | ||
|
||
/** | ||
* Prepare array from csv file. | ||
* | ||
* @return array | ||
*/ | ||
private function getResultCsv() | ||
{ | ||
$csvData = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); | ||
|
||
$csvKeys = []; | ||
foreach (array_shift($csvData) as $csvKey) { | ||
$csvKeys[] = isset($this->mappingData[$csvKey]) ? $this->mappingData[$csvKey] : $csvKey; | ||
} | ||
|
||
$resultCsvData = []; | ||
foreach ($csvData as $csvRowData) { | ||
$csvRowData = array_combine($csvKeys, $csvRowData); | ||
$sku = $csvRowData['sku']; | ||
unset($csvRowData['sku']); | ||
$resultCsvData[$sku][] = $csvRowData; | ||
} | ||
return $resultCsvData; | ||
} | ||
|
||
/** | ||
* Return string representation of object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'Imported advanced prices are correct.'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...s/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Repository/ExportData.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" ?> | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/Magento/Mtf/Repository/etc/repository.xsd"> | ||
<repository class="Magento\ImportExport\Test\Repository\ExportData"> | ||
<dataset name="csv_with_advanced_pricing"> | ||
<field name="entity" xsi:type="string">Advanced Pricing</field> | ||
<field name="file_format" xsi:type="string">CSV</field> | ||
</dataset> | ||
</repository> | ||
</config> |
Oops, something went wrong.