From 84b2cda47db615d9178782efd5576a29c441d749 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Sun, 5 Mar 2017 12:10:45 +0300 Subject: [PATCH 01/29] MTO-127: [Test] Import Advanced Pricing - Functional test implemented --- .../AssertImportAdvancedPricing.php | 144 ++++++++++++++++++ .../AssertImportAdvancedPricingCheckData.php | 46 ++++++ .../Constraint/AssertImportSuccessMessage.php | 50 ++++++ .../Test/TestCase/ImportDataTest.xml | 111 ++++++++++++++ .../template/pricing/advanced_incorrect.php | 18 ++- .../pricing/advanced_price_variation_1.php | 29 ++++ .../pricing/advanced_price_variation_2.php | 20 +++ .../pricing/advanced_price_variation_3.php | 20 +++ .../pricing/advanced_price_variation_4.php | 29 ++++ .../Section/AdvancedPricing/OptionTier.php | 39 +++++ .../Test/Repository/CatalogProductSimple.xml | 26 ++++ .../Mtf/Util/Import/File/CsvTemplate.php | 52 ++++--- .../Block/Adminhtml/Import/Frame/Result.php | 66 ++++++++ .../ImportExport/Test/Fixture/Import/File.php | 92 +++++++++-- .../Test/TestCase/ImportDataTest.php | 34 +++++ .../Test/TestStep/CreateCustomStoreStep.php | 142 +++++++++++++++++ .../Test/TestStep/FillImportFormStep.php | 31 +++- .../ImportExport/Test/etc/testcase.xml | 5 + 18 files changed, 913 insertions(+), 41 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php new file mode 100644 index 0000000000000..030ce8c12bd43 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -0,0 +1,144 @@ + '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' + ]; + + /** + * Csv keys. + * + * @param array $csvKeys + */ + private $csvKeys; + + /** + * Edit page on backend + * + * @var CatalogProductEdit + */ + private $catalogProductEdit; + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Assert imported advanced prices are correct. + * + * @param CatalogProductEdit $catalogProductEdit + * @param FixtureFactory $fixtureFactory + * @param string $behavior + * @param array $products + * @param array $csv + * @return void + */ + public function processAssert( + CatalogProductEdit $catalogProductEdit, + FixtureFactory $fixtureFactory, + $behavior, + array $products, + array $csv + ) { + $this->catalogProductEdit = $catalogProductEdit; + $this->fixtureFactory = $fixtureFactory; + $this->prepareCsv($csv); + + $resultArrays = $this->preparePrices($behavior, $products, array_reverse($csv)); + + \PHPUnit_Framework_Assert::assertEquals( + $resultArrays['pageData'], + $resultArrays['csvData'] + ); + } + + /** + * Prepare arrays for compare. + * + * @param string $behavior + * @param array $products + * @param array $csv + * @return array + */ + public function preparePrices($behavior, array $products, array $csv) + { + $resultProductArray = []; + for ($i = 0; $i < count($products); $i++) { + $this->catalogProductEdit->open(['id' => $products[$i]->getId()]); + $advancedPricing = $this->catalogProductEdit->getProductForm()->openSection('advanced-pricing') + ->getSection('advanced-pricing'); + $tierPrices = $advancedPricing->getTierPriceForm()->getFieldsData(); + foreach ($tierPrices as $tierPrice) { + asort($tierPrice); + $resultProductArray[$products[$i]->getSku()][] = $tierPrice; + } + } + + $resultCsvArray = []; + if ($behavior === 'Delete') { + $csv = []; + } + foreach ($csv as $tierPrice) { + $tierPrice = array_combine($this->csvKeys, $tierPrice); + asort($tierPrice); + $sku = $tierPrice['sku']; + unset($tierPrice['sku']); + $resultCsvArray[$sku][] = $tierPrice; + } + + return ['pageData' => $resultProductArray, 'csvData' => $resultCsvArray]; + } + + /** + * Prepare assert data. + * + * @param array $csv + * @return array + */ + private function prepareCsv(array &$csv) + { + $this->csvKeys = array_map( + function ($value) { + return strtr($value, $this->mapping); + }, + array_shift($csv) + ) ; + } + + /** + * Return string representation of object. + * + * @return string + */ + public function toString() + { + return 'Imported advanced prices are correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php new file mode 100644 index 0000000000000..4c24a31757fac --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php @@ -0,0 +1,46 @@ +getImportResult()->getNoticeMessage(); + \PHPUnit_Framework_Assert::assertNotFalse($message, 'Validation result block is absent.'); + \PHPUnit_Framework_Assert::assertEquals( + $expectedMessage, + $message, + 'Wrong validation result is displayed.' + . "\nExpected: " . $expectedMessage + . "\nActual: " . $message + ); + } + + /** + * Return string representation of object. + * + * @return string + */ + public function toString() + { + return 'Displayed validation result is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php new file mode 100644 index 0000000000000..7fb7b7814c3e7 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php @@ -0,0 +1,50 @@ +getImportResult()->clickImportButton(); + $validationMessage = $adminImportIndex->getImportResult()->getImportResultMessage(); + \PHPUnit_Framework_Assert::assertEquals( + self::SUCCESS_MESSAGE, + $validationMessage, + 'Wrong validation result is displayed.' + . "\nExpected: " . self::SUCCESS_MESSAGE + . "\nActual: " . $validationMessage + ); + } + + /** + * Return string representation of object. + * + * @return string + */ + public function toString() + { + return 'Displayed import result is correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml new file mode 100644 index 0000000000000..831c8dd48bac2 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -0,0 +1,111 @@ + + + + + + Checked rows: 2, checked entities: 0, invalid rows: 0, total errors: 0 + false + + Advanced Pricing + Add/Update + Stop on Error + 10 + , + , + + + catalogProductSimple::default + + + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1 + 2 + + + + + + + + + Checked rows: 1, checked entities: 0, invalid rows: 0, total errors: 0 + false + + Advanced Pricing + Replace + Stop on Error + 10 + , + , + + + catalogProductSimple::simple_with_tier_price_and_qty_10 + + + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2 + 1 + + + + + + + + + Checked rows: 1, checked entities: 0, invalid rows: 0, total errors: 0 + false + + Advanced Pricing + Delete + Stop on Error + 10 + , + , + + + catalogProductSimple::simple_with_one_tier_price + + + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3 + 1 + + + + + + + + + Checked rows: 2, checked entities: 0, invalid rows: 0, total errors: 0 + true + + Advanced Pricing + Replace + Stop on Error + 10 + , + , + + + catalogProductSimple::default_in_custom_website + + + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 + 2 + + + + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php index 9a7a19fd11a84..4ed027cd56339 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php @@ -5,10 +5,16 @@ */ return [ - 'sku' => '%sku%', - 'tier_price_website' => 'All Websites [USD]', - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '3', - 'tier_price' => 'text', - 'tier_price_value_type' => 'Fixed', + 'product_0' => + [ + 'tier_price_0' => + [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '3', + 'tier_price' => 'text', + 'tier_price_value_type' => 'Fixed', + ], + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php new file mode 100644 index 0000000000000..d08434673ac3b --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php @@ -0,0 +1,29 @@ + + [ + 'tier_price_0' => + [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'General', + 'tier_price_qty' => '10', + 'tier_price' => '8.00', + 'tier_price_value_type' => 'Fixed', + ], + 'tier_price_1' => + [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => "NOT LOGGED IN", + 'tier_price_qty' => '10', + 'tier_price' => '9.00', + 'tier_price_value_type' => 'Fixed', + ] + ], +]; \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php new file mode 100644 index 0000000000000..5c617abf15857 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php @@ -0,0 +1,20 @@ + + [ + 'tier_price_0' => + [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '10', + 'tier_price' => '8.00', + 'tier_price_value_type' => 'Fixed', + ], + ], +]; \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php new file mode 100644 index 0000000000000..ea362c86f710c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php @@ -0,0 +1,20 @@ + + [ + 'tier_price_0' => + [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', + ], + ], +]; \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php new file mode 100644 index 0000000000000..89b8acbb1e12f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php @@ -0,0 +1,29 @@ + + [ + 'tier_price_0' => + [ + 'sku' => '%sku%', + 'tier_price_website' => '%code%', + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', + ], + 'tier_price_1' => + [ + 'sku' => '%sku%', + 'tier_price_website' => 'base', + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', + ], + ], +]; \ No newline at end of file diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php index c18e7f0790522..c0d093316d7c1 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php @@ -29,6 +29,20 @@ class OptionTier extends AbstractOptions */ protected $customerGroup = '//*[contains(@name, "[cust_group]")]'; + /** + * Locator for Customer Group Price Rows element. + * + * @var string + */ + private $tierPriceRows = ".//*[@data-index='tier_price']/tbody/tr"; + + /** + * Locator for value type of tier price element. + * + * @var string + */ + private $valueTypePrice = "[name$='[value_type]']"; + /** * Fill product form 'Tier price'. * @@ -66,6 +80,31 @@ public function getDataOptions(array $fields = null, SimpleElement $element = nu return $data; } + /** + * Get data of the container. + * + * @param array|null $fields + * @param SimpleElement|null $element + * @return array + */ + public function getFieldsData($fields = null, SimpleElement $element = null) + { + $fieldsData = []; + $rows = $this->_rootElement->getElements($this->tierPriceRows, Locator::SELECTOR_XPATH); + + if (null !== $rows) { + foreach ($rows as $row) { + $data = $this->dataMapping($fields); + if ($row->find($this->valueTypePrice)->getValue() == "fixed") { + unset($data['percentage_value']); + } + $fieldsData[] = $this->_getData($data, $row); + } + } + + return $fieldsData; + } + /** * Check whether Customer Group is visible. * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml index d114ff1d9f07d..0e07e4c506547 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml @@ -1230,6 +1230,32 @@ + + + default + + Simple Product %isolation% + sku_simple_product_%isolation% + + 300 + + This item has weight + 1 + + 25 + In Stock + + simple-product-%isolation% + + custom_with_fixed_discount + + + + default + + + + simple_product_with_category_%isolation% Simple product with category %isolation% diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php index 6c080d4095b86..465c5c8524577 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php @@ -19,6 +19,13 @@ class CsvTemplate implements TemplateInterface */ private $config; + /** + * Csv data. + * + * @var string + */ + private $csv; + /** * @param array $config */ @@ -45,7 +52,6 @@ public function render() } $data = include $filename; - $count = abs($this->config['count']); $placeholders = []; if (!empty($this->config['placeholders'])) { @@ -53,27 +59,29 @@ public function render() } $fh = fopen('php://temp', 'rw'); - fputcsv($fh, array_keys($data)); - - for ($i = 0; $i < $count; ++$i) { - $row = array_map( - function ($value) use ($placeholders, $i) { - if (is_string($value) && isset($placeholders[$i])) { - return strtr($value, $placeholders[$i]); - } - - return $value; - }, - $data - ); - fputcsv($fh, $row); + fputcsv($fh, array_keys($data['product_0']['tier_price_0'])); + + foreach ($placeholders as $productKey => $tierPrices) { + foreach ($tierPrices as $tierPriceKey => $tierPriceValue) { + $row = array_map( + function ($value) use ($placeholders, $productKey, $tierPriceKey, $tierPriceValue) { + if (is_string($value) && isset($placeholders[$productKey][$tierPriceKey])) { + return strtr($value, $tierPriceValue); + } + return $value; + }, + $data[$productKey][$tierPriceKey] + ); + fputcsv($fh, $row); + + } } rewind($fh); - $csv = stream_get_contents($fh); + $this->csv = stream_get_contents($fh); fclose($fh); - return $csv; + return $this->csv; } /** @@ -87,4 +95,14 @@ public function getName() basename($this->config['filename']) ); } + + /** + * Return csv data. + * + * @return string + */ + public function getCsv() + { + return $this->csv; + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php index 13540187449c3..339b389eb957d 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php @@ -12,6 +12,34 @@ */ class Result extends Block { + /** + * CSS selector for import button. + * + * @var string + */ + private $importButton = 'div > .success > div > button'; + + /** + * CSS selector for notice message block. + * + * @var string + */ + private $noticeMessage = '.message-notice'; + + /** + * CSS selector for import message. + * + * @var string + */ + private $importResultMessage = '.messages'; + + /** + * Magento loader. + * + * @var string + */ + private $loader = '[data-role="loader"]'; + /** * CSS selector for error message block. * @@ -42,6 +70,44 @@ public function getErrorMessage() return (string) $this->_rootElement->find($this->errorMessage)->getText(); } + /** + * Get notice message text. + * + * @return string|bool + */ + public function getNoticeMessage() + { + $element = $this->_rootElement->find($this->noticeMessage); + + if (!$element->isVisible()) { + return false; + } + + return (string) $this->_rootElement->find($this->noticeMessage)->getText(); + } + + /** + * Click import button. + * + * @return void + */ + public function clickImportButton() + { + $this->_rootElement->find($this->importButton)->click(); + } + + /** + * Get import result message. + * + * @return string + */ + public function getImportResultMessage() + { + $this->waitForElementNotVisible($this->loader); + + return (string) $this->_rootElement->find($this->importResultMessage)->getText(); + } + /** * Get errors messages list. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 7e09d568f8e45..0652749ab84f9 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -24,6 +24,13 @@ class File extends DataSource */ private $value; + /** + * Template of csv file. + * + * @var array + */ + private $csvTemplate; + /** * Generator for the uploaded file. * @@ -52,6 +59,13 @@ class File extends DataSource */ private $objectManager; + /** + * Csv as array. + * + * @var array + */ + private $csv; + /** * @param ObjectManager $objectManager * @param FixtureFactory $fixtureFactory @@ -82,6 +96,13 @@ public function getData($key = null) return parent::getData($key); } + $filename = MTF_TESTS_PATH . $this->value['template']['filename'] . '.php'; + if (!file_exists($filename)) { + throw new \Exception("CSV file '{$filename}'' not found on the server."); + } + + $this->csvTemplate = include $filename; + $placeholders = []; if (!isset($this->products) && isset($this->value['products']) @@ -89,25 +110,23 @@ public function getData($key = null) ) { $this->products = $this->createProducts(); - foreach ($this->products as $product) { - $placeholders[] = ['%sku%' => $product->getData('sku')]; - } + $placeholders = $this->getPlaceHolders(); } if (isset($this->value['template']) && is_array($this->value['template'])) { - $this->data = $this->generator->generate( - $this->objectManager->create( - CsvTemplate::class, - [ - 'config' => array_merge( - $this->value['template'], - [ - 'placeholders' => $placeholders - ] - ) - ] - ) + $csvTemplate = $this->objectManager->create( + CsvTemplate::class, + [ + 'config' => array_merge( + $this->value['template'], + [ + 'placeholders' => $placeholders + ] + ) + ] ); + $this->data = $this->generator->generate($csvTemplate); + $this->csv = $csvTemplate->getCsv(); return parent::getData($key); } @@ -152,4 +171,47 @@ private function createProducts() return $products; } + + /** + * Create placeholders for products. + * + * @return array + */ + private function getPlaceHolders() + { + $key = 0; + foreach ($this->products as $product) { + $productData = $product->getData(); + $productData['code'] = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]->getCode(); + foreach ($this->csvTemplate['product_' . $key] as $tierKey => $tier) { + $values = implode('', array_values($tier)); + preg_match_all('/\%(.*)\%/U', $values, $indexes); + + foreach ($indexes[1] as $index) { + if (isset($productData[$index])) { + $placeholders['product_' . $key][$tierKey]["%{$index}%"] = $productData[$index]; + } + } + + } + $key++; + } + + return $placeholders; + } + + /** + * Return csv as array. + * + * @return array + */ + public function getCsv() + { + return array_map( + function ($value) { + return explode(',', str_replace('"', '', $value)); + }, + str_getcsv($this->csv, "\n") + ); + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php new file mode 100644 index 0000000000000..707e6b3968a8e --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php @@ -0,0 +1,34 @@ +executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php new file mode 100644 index 0000000000000..9dc67f9326a6f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php @@ -0,0 +1,142 @@ +stepFactory = $stepFactory; + $this->fixtureFactory = $fixtureFactory; + $this->products = $products; + $this->currency = $currency; + $this->csv = $csv; + } + + /** + * Fill import form. + * + * @return array + */ + public function run() + { + $this->stepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => 'price_scope_website'] + )->run(); + + foreach ($this->products as $product) { + $websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites(); + + $configFixture = $this->fixtureFactory->createByCode( + 'configData', + [ + 'data' => [ + 'currency/options/allow' => [ + 'value' => [$this->currency] + ], + 'currency/options/base' => [ + 'value' => $this->currency + ], + 'currency/options/default' => [ + 'value' => $this->currency + ], + 'scope' => [ + 'fixture' => $websites[0], + 'scope_type' => 'website', + 'website_id' => $websites[0]->getWebsiteId(), + 'set_level' => 'website', + ] + ] + ] + ); + $configFixture->persist(); + } + + return $this->getCsv(); + } + + /** + * Return refactored csv data with custom store. + * + * @return array + */ + public function getCsv() + { + $mapping['base'] = 'Main Website[USD]'; + + foreach ($this->products as $product) { + $website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; + $mapping[$website->getCode()] = $website->getName() . "[{$this->currency}]"; + } + + $csv = []; + foreach ($this->csv as $row) { + $row = array_map( + function ($value) use ($mapping) { + return strtr($value, $mapping); + }, + $row + ); + $csv[] = $row; + } + return $csv; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 0b9475c071a6d..43248860e0520 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -9,6 +9,7 @@ use Magento\ImportExport\Test\Fixture\ImportData; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\TestStep\TestStepInterface; +use Magento\Mtf\TestStep\TestStepFactory; /** * Fill import form. @@ -29,14 +30,36 @@ class FillImportFormStep implements TestStepInterface */ private $import; + /** + * Csv as array. + * + * @var array + */ + private $csv; + /** * @param AdminImportIndex $adminImportIndex * @param ImportData $import + * @param TestStepFactory $stepFactory + * @param bool $createStore */ - public function __construct(AdminImportIndex $adminImportIndex, ImportData $import) - { + public function __construct( + AdminImportIndex $adminImportIndex, + ImportData $import, + TestStepFactory $stepFactory, + $createStore + ) { + $file = $import->getDataFieldConfig('import_file')['source']; $this->adminImportIndex = $adminImportIndex; $this->import = $import; + $this->csv = $file->getCsv(); + + if ($createStore === true) { + $this->csv = $stepFactory->create( + CreateCustomStoreStep::class, + ['products' => $file->getProducts(), 'csv' => $this->csv] + )->run(); + } } /** @@ -52,7 +75,9 @@ public function run() $file = $this->import->getDataFieldConfig('import_file')['source']; return [ - 'products' => $file->getProducts() + 'products' => $file->getProducts(), + 'csv' => $this->csv, + 'behavior' => $this->import->getBehavior() ]; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml index 8c9ff10484fa6..bc4cc58622f80 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml @@ -12,4 +12,9 @@ + + + + + From 485844d5394fdb501a3ce079a55fb276133dc320 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Mon, 6 Mar 2017 22:47:33 +0300 Subject: [PATCH 02/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../AssertImportAdvancedPricing.php | 90 ++++++++++--------- .../ImportExport/Test/Fixture/Import/File.php | 20 +++-- .../Test/TestStep/CreateCustomStoreStep.php | 48 ++++------ .../Test/TestStep/FillImportFormStep.php | 9 +- 4 files changed, 82 insertions(+), 85 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index 030ce8c12bd43..befb14a67cab6 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -8,6 +8,7 @@ use Magento\Mtf\Constraint\AbstractConstraint; use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit; +use Magento\ImportExport\Test\Fixture\ImportData; use Magento\Mtf\Fixture\FixtureFactory; /** @@ -20,7 +21,7 @@ class AssertImportAdvancedPricing extends AbstractConstraint * * @param array */ - private $mapping = [ + private $mappingData = [ 'sku' => 'sku', 'tier_price' => 'price', 'tier_price_qty' => 'price_qty', @@ -29,13 +30,6 @@ class AssertImportAdvancedPricing extends AbstractConstraint 'tier_price_value_type' => 'value_type' ]; - /** - * Csv keys. - * - * @param array $csvKeys - */ - private $csvKeys; - /** * Edit page on backend * @@ -50,67 +44,69 @@ class AssertImportAdvancedPricing extends AbstractConstraint */ private $fixtureFactory; + /** + * Import fixture. + * + * @var ImportData + */ + private $import; + /** * Assert imported advanced prices are correct. * * @param CatalogProductEdit $catalogProductEdit * @param FixtureFactory $fixtureFactory - * @param string $behavior - * @param array $products - * @param array $csv + * @param ImportData $import * @return void */ public function processAssert( CatalogProductEdit $catalogProductEdit, FixtureFactory $fixtureFactory, - $behavior, - array $products, - array $csv + ImportData $import ) { $this->catalogProductEdit = $catalogProductEdit; $this->fixtureFactory = $fixtureFactory; - $this->prepareCsv($csv); + $this->import = $import; - $resultArrays = $this->preparePrices($behavior, $products, array_reverse($csv)); + $resultArrays = $this->preparePrices(); \PHPUnit_Framework_Assert::assertEquals( $resultArrays['pageData'], - $resultArrays['csvData'] + $resultArrays['csvData'], + 'Wrong validation result is displayed.' + . "\nExpected: " . print_r($resultArrays['csvData']) + . "\nActual: " . print_r($resultArrays['pageData']) ); } /** * Prepare arrays for compare. * - * @param string $behavior - * @param array $products - * @param array $csv * @return array */ - public function preparePrices($behavior, array $products, array $csv) + public function preparePrices() { + $products = $this->import->getDataFieldConfig('import_file')['source']->getProducts(); + + // Prepare tier prices data from backend. $resultProductArray = []; - for ($i = 0; $i < count($products); $i++) { - $this->catalogProductEdit->open(['id' => $products[$i]->getId()]); + 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) { - asort($tierPrice); - $resultProductArray[$products[$i]->getSku()][] = $tierPrice; + $resultProductArray[$productSku][] = $tierPrice; } + $resultProductArray[$productSku] = array_reverse($resultProductArray[$productSku]); } + // Prepare tier prices data from csv file. $resultCsvArray = []; - if ($behavior === 'Delete') { - $csv = []; - } - foreach ($csv as $tierPrice) { - $tierPrice = array_combine($this->csvKeys, $tierPrice); - asort($tierPrice); - $sku = $tierPrice['sku']; - unset($tierPrice['sku']); - $resultCsvArray[$sku][] = $tierPrice; + if ($this->import->getBehavior() !== 'Delete') { + $resultCsvArray = $this->getResultCsv(); } return ['pageData' => $resultProductArray, 'csvData' => $resultCsvArray]; @@ -119,17 +115,31 @@ public function preparePrices($behavior, array $products, array $csv) /** * Prepare assert data. * - * @param array $csv * @return array */ - private function prepareCsv(array &$csv) + private function getResultCsv() { - $this->csvKeys = array_map( + $rowStreamContent = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); + $csvData = array_map( function ($value) { - return strtr($value, $this->mapping); + return explode(',', str_replace('"', '', $value)); }, - array_shift($csv) - ) ; + str_getcsv($rowStreamContent, "\n") + ); + + $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; } /** diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 0652749ab84f9..67d23f3daf684 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -203,15 +203,21 @@ private function getPlaceHolders() /** * Return csv as array. * - * @return array + * @return string */ public function getCsv() { - return array_map( - function ($value) { - return explode(',', str_replace('"', '', $value)); - }, - str_getcsv($this->csv, "\n") - ); + return $this->csv; + } + + /** + * Return csv as array. + * + * @param $csv + * @return void + */ + public function setCsv($csv) + { + $this->csv = $csv; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php index 9dc67f9326a6f..dc4ab25ac3922 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php @@ -5,6 +5,7 @@ */ namespace Magento\ImportExport\Test\TestStep; +use Magento\ImportExport\Test\Fixture\ImportData; use Magento\Mtf\TestStep\TestStepInterface; use Magento\Mtf\TestStep\TestStepFactory; use Magento\Mtf\Fixture\FixtureFactory; @@ -28,13 +29,6 @@ class CreateCustomStoreStep implements TestStepInterface */ private $fixtureFactory; - /** - * Products. - * - * @var array - */ - private $products; - /** * Currency. * @@ -43,31 +37,28 @@ class CreateCustomStoreStep implements TestStepInterface private $currency; /** - * Csv data. + * Import fixture. * - * @var array + * @var ImportData */ - private $csv; + private $import; /** * @param TestStepFactory $stepFactory * @param FixtureFactory $fixtureFactory - * @param array $products - * @param array $csv + * @param ImportData $import * @param string $currency */ public function __construct( TestStepFactory $stepFactory, FixtureFactory $fixtureFactory, - array $products, - array $csv, + ImportData $import, $currency = 'EUR' ) { $this->stepFactory = $stepFactory; $this->fixtureFactory = $fixtureFactory; - $this->products = $products; + $this->import = $import; $this->currency = $currency; - $this->csv = $csv; } /** @@ -82,7 +73,8 @@ public function run() ['configData' => 'price_scope_website'] )->run(); - foreach ($this->products as $product) { + $products = $this->import->getDataFieldConfig('import_file')['source']->getProducts(); + foreach ($products as $product) { $websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites(); $configFixture = $this->fixtureFactory->createByCode( @@ -109,34 +101,26 @@ public function run() ); $configFixture->persist(); } - - return $this->getCsv(); + $this->getCsv($products); } /** * Return refactored csv data with custom store. * + * @param array $products * @return array */ - public function getCsv() + public function getCsv(array $products) { + $mapping['base'] = 'Main Website[USD]'; - foreach ($this->products as $product) { + foreach ($products as $product) { $website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; $mapping[$website->getCode()] = $website->getName() . "[{$this->currency}]"; } - $csv = []; - foreach ($this->csv as $row) { - $row = array_map( - function ($value) use ($mapping) { - return strtr($value, $mapping); - }, - $row - ); - $csv[] = $row; - } - return $csv; + $csv = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); + $this->import->getDataFieldConfig('import_file')['source']->setCsv(strtr($csv, $mapping)); } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 43248860e0520..7f524bcb9ec10 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -49,15 +49,13 @@ public function __construct( TestStepFactory $stepFactory, $createStore ) { - $file = $import->getDataFieldConfig('import_file')['source']; $this->adminImportIndex = $adminImportIndex; $this->import = $import; - $this->csv = $file->getCsv(); if ($createStore === true) { - $this->csv = $stepFactory->create( + $stepFactory->create( CreateCustomStoreStep::class, - ['products' => $file->getProducts(), 'csv' => $this->csv] + ['import' => $this->import] )->run(); } } @@ -76,8 +74,7 @@ public function run() return [ 'products' => $file->getProducts(), - 'csv' => $this->csv, - 'behavior' => $this->import->getBehavior() + 'import' => $this->import ]; } } From e59bba8c718a1ab946276d171745877dc1e8ed94 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Wed, 8 Mar 2017 00:25:14 +0300 Subject: [PATCH 03/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../AssertImportAdvancedPricing.php | 11 +-- .../AssertImportAdvancedPricingCheckData.php | 26 ++++-- ...AssertImportCheckDataErrorMessagesList.php | 2 +- .../Constraint/AssertImportSuccessMessage.php | 3 +- .../Test/TestCase/ImportDataTest.xml | 38 +++----- .../template/pricing/advanced_incorrect.php | 4 +- .../pricing/advanced_price_variation_1.php | 6 +- .../pricing/advanced_price_variation_2.php | 4 +- .../pricing/advanced_price_variation_3.php | 4 +- .../pricing/advanced_price_variation_4.php | 6 +- .../Section/AdvancedPricing/OptionTier.php | 13 +-- .../Test/Repository/CatalogProductSimple.xml | 2 +- .../Mtf/Util/Import/File/CsvTemplate.php | 62 +++++++------ .../Block/Adminhtml/Import/Frame/Result.php | 72 ---------------- .../Test/Block/Adminhtml/Import/Messages.php | 86 +++++++++++++++++++ .../AssertImportCheckDataErrorMessage.php | 2 +- .../ImportExport/Test/Fixture/Import/File.php | 52 ++++++----- .../Test/Page/Adminhtml/AdminImportIndex.xml | 1 + .../Test/TestCase/ImportDataTest.php | 1 + .../Test/TestStep/ClickCheckDataStep.php | 24 +++++- .../Test/TestStep/ClickImportDataStep.php | 40 +++++++++ .../Test/TestStep/CreateCustomStoreStep.php | 20 +++-- .../Test/TestStep/FillImportFormStep.php | 9 +- .../ImportExport/Test/etc/testcase.xml | 3 +- 24 files changed, 289 insertions(+), 202 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index befb14a67cab6..0e46a9bcb7b7b 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -73,9 +73,7 @@ public function processAssert( \PHPUnit_Framework_Assert::assertEquals( $resultArrays['pageData'], $resultArrays['csvData'], - 'Wrong validation result is displayed.' - . "\nExpected: " . print_r($resultArrays['csvData']) - . "\nActual: " . print_r($resultArrays['pageData']) + 'Tier prices from page and csv are not match.' ); } @@ -86,7 +84,7 @@ public function processAssert( */ public function preparePrices() { - $products = $this->import->getDataFieldConfig('import_file')['source']->getProducts(); + $products = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); // Prepare tier prices data from backend. $resultProductArray = []; @@ -97,10 +95,13 @@ public function preparePrices() $tierPrices = $advancedPricing->getTierPriceForm()->getFieldsData(); $productSku = $product->getSku(); + foreach ($tierPrices as $tierPrice) { $resultProductArray[$productSku][] = $tierPrice; } - $resultProductArray[$productSku] = array_reverse($resultProductArray[$productSku]); + if (isset($resultProductArray[$productSku])) { + $resultProductArray[$productSku]= array_reverse($resultProductArray[$productSku]); + } } // Prepare tier prices data from csv file. diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php index 4c24a31757fac..4b6ee5c8fb8ab 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php @@ -8,29 +8,37 @@ use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\Constraint\AbstractConstraint; +use Magento\ImportExport\Test\Fixture\ImportData; /** * Check message after check data click. */ class AssertImportAdvancedPricingCheckData extends AbstractConstraint { + /** + * Success validation result message + */ + const RESULT_MESSAGE = 'Checked rows: %s, checked entities: %s, invalid rows: 0, total errors: 0'; + /** * Assert that validation result message is correct. * - * @param string $expectedMessage * @param AdminImportIndex $adminImportIndex - * @return void + * @param ImportData $import */ - public function processAssert($expectedMessage, AdminImportIndex $adminImportIndex) + public function processAssert(AdminImportIndex $adminImportIndex, ImportData $import) { - $message = $adminImportIndex->getImportResult()->getNoticeMessage(); - \PHPUnit_Framework_Assert::assertNotFalse($message, 'Validation result block is absent.'); + $rowsCount = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['count']; + $entitiesCount = count($import->getDataFieldConfig('import_file')['source']->getEntities()); + + $rowsCount = 2; + $entitiesCount = 0; + + $message = $adminImportIndex->getMessagesBlock()->getNoticeMessage(); \PHPUnit_Framework_Assert::assertEquals( - $expectedMessage, + sprintf(self::RESULT_MESSAGE, $rowsCount, $entitiesCount), $message, - 'Wrong validation result is displayed.' - . "\nExpected: " . $expectedMessage - . "\nActual: " . $message + 'Wrong validation result message is displayed.' ); } diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php index 259083278d3b4..f632dbc8715b8 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php @@ -22,7 +22,7 @@ class AssertImportCheckDataErrorMessagesList extends AbstractConstraint */ public function processAssert(array $patterns, AdminImportIndex $adminImportIndex) { - $messages = $adminImportIndex->getImportResult()->getErrorsList(); + $messages = $adminImportIndex->getMessagesBlock()->getErrorsList(); \PHPUnit_Framework_Assert::assertNotFalse($messages, 'Errors messages block is absent.'); \PHPUnit_Framework_Assert::assertNotEmpty($messages, 'Errors messages is absent.'); diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php index 7fb7b7814c3e7..149bea72564eb 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php @@ -27,8 +27,7 @@ class AssertImportSuccessMessage extends AbstractConstraint */ public function processAssert(AdminImportIndex $adminImportIndex) { - $adminImportIndex->getImportResult()->clickImportButton(); - $validationMessage = $adminImportIndex->getImportResult()->getImportResultMessage(); + $validationMessage = $adminImportIndex->getMessagesBlock()->getImportResultMessage(); \PHPUnit_Framework_Assert::assertEquals( self::SUCCESS_MESSAGE, $validationMessage, diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index 831c8dd48bac2..1273274a5f1ba 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -7,8 +7,7 @@ --> - - Checked rows: 2, checked entities: 0, invalid rows: 0, total errors: 0 + false Advanced Pricing @@ -18,22 +17,19 @@ , , - + catalogProductSimple::default - Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1 + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1 2 - - - Checked rows: 1, checked entities: 0, invalid rows: 0, total errors: 0 + false Advanced Pricing @@ -43,22 +39,19 @@ , , - + catalogProductSimple::simple_with_tier_price_and_qty_10 - Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2 + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2 1 - - - Checked rows: 1, checked entities: 0, invalid rows: 0, total errors: 0 + false Advanced Pricing @@ -68,22 +61,19 @@ , , - - catalogProductSimple::simple_with_one_tier_price + + catalogProductSimple::simple_with_one_fixed_tier_price - Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3 + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3 1 - - - Checked rows: 2, checked entities: 0, invalid rows: 0, total errors: 0 + true Advanced Pricing @@ -93,17 +83,15 @@ , , - + catalogProductSimple::default_in_custom_website - Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 + Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 2 - diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php index 4ed027cd56339..d4994257d43e7 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php @@ -5,9 +5,9 @@ */ return [ - 'product_0' => + 'entity_0' => [ - 'tier_price_0' => + 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php index d08434673ac3b..09a812532c67c 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php @@ -5,9 +5,9 @@ */ return [ - 'product_0' => + 'entity_0' => [ - 'tier_price_0' => + 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", @@ -16,7 +16,7 @@ 'tier_price' => '8.00', 'tier_price_value_type' => 'Fixed', ], - 'tier_price_1' => + 'data_1' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php index 5c617abf15857..cbc9e6719ed78 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php @@ -5,9 +5,9 @@ */ return [ - 'product_0' => + 'entity_0' => [ - 'tier_price_0' => + 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php index ea362c86f710c..5951ce491cbad 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php @@ -5,9 +5,9 @@ */ return [ - 'product_0' => + 'entity_0' => [ - 'tier_price_0' => + 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php index 89b8acbb1e12f..1cb4a2b7e734f 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php @@ -5,9 +5,9 @@ */ return [ - 'product_0' => + 'entity_0' => [ - 'tier_price_0' => + 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => '%code%', @@ -16,7 +16,7 @@ 'tier_price' => '5.00', 'tier_price_value_type' => 'Fixed', ], - 'tier_price_1' => + 'data_1' => [ 'sku' => '%sku%', 'tier_price_website' => 'base', diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php index c0d093316d7c1..514fdbee47291 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php @@ -30,19 +30,12 @@ class OptionTier extends AbstractOptions protected $customerGroup = '//*[contains(@name, "[cust_group]")]'; /** - * Locator for Customer Group Price Rows element. + * Locator for Products Tier Price Rows. * * @var string */ private $tierPriceRows = ".//*[@data-index='tier_price']/tbody/tr"; - /** - * Locator for value type of tier price element. - * - * @var string - */ - private $valueTypePrice = "[name$='[value_type]']"; - /** * Fill product form 'Tier price'. * @@ -81,7 +74,7 @@ public function getDataOptions(array $fields = null, SimpleElement $element = nu } /** - * Get data of the container. + * Get tier price rows data. * * @param array|null $fields * @param SimpleElement|null $element @@ -95,7 +88,7 @@ public function getFieldsData($fields = null, SimpleElement $element = null) if (null !== $rows) { foreach ($rows as $row) { $data = $this->dataMapping($fields); - if ($row->find($this->valueTypePrice)->getValue() == "fixed") { + if ($row->find($data['value_type']['selector'])->getValue() == "fixed") { unset($data['percentage_value']); } $fieldsData[] = $this->_getData($data, $row); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml index 0e07e4c506547..833ab09963f41 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml @@ -1230,7 +1230,7 @@ - + default diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php index 465c5c8524577..621745f995c9e 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php @@ -51,32 +51,8 @@ public function render() throw new \Exception('File "' . $filename . '" does not exist.'); } - $data = include $filename; - - $placeholders = []; - if (!empty($this->config['placeholders'])) { - $placeholders = $this->config['placeholders']; - } - $fh = fopen('php://temp', 'rw'); - fputcsv($fh, array_keys($data['product_0']['tier_price_0'])); - - foreach ($placeholders as $productKey => $tierPrices) { - foreach ($tierPrices as $tierPriceKey => $tierPriceValue) { - $row = array_map( - function ($value) use ($placeholders, $productKey, $tierPriceKey, $tierPriceValue) { - if (is_string($value) && isset($placeholders[$productKey][$tierPriceKey])) { - return strtr($value, $tierPriceValue); - } - return $value; - }, - $data[$productKey][$tierPriceKey] - ); - fputcsv($fh, $row); - - } - } - + $fh = $this->addProductsData($fh); rewind($fh); $this->csv = stream_get_contents($fh); fclose($fh); @@ -96,6 +72,42 @@ public function getName() ); } + /* + * Add product data to stream content. + */ + /** + * @param resource $stream + * @return resource + */ + private function addProductsData($stream) + { + $filename = MTF_TESTS_PATH . $this->config['filename'] . '.php'; + $entitiesData = include $filename; + + $placeholders = []; + if (!empty($this->config['placeholders'])) { + $placeholders = $this->config['placeholders']; + } + + fputcsv($stream, array_keys($entitiesData['entity_0']['data_0'])); + foreach ($placeholders as $entityKey => $entityData) { + foreach ($entityData as $dataKey => $dataValue) { + $row = array_map( + function ($value) use ($placeholders, $entityKey, $dataKey, $dataValue) { + if (is_string($value) && isset($placeholders[$entityKey][$dataKey])) { + return strtr($value, $dataValue); + } + return $value; + }, + $entitiesData[$entityKey][$dataKey] + ); + fputcsv($stream, $row); + + } + } + return $stream; + } + /** * Return csv data. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php index 339b389eb957d..02165714cad66 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Frame/Result.php @@ -19,34 +19,6 @@ class Result extends Block */ private $importButton = 'div > .success > div > button'; - /** - * CSS selector for notice message block. - * - * @var string - */ - private $noticeMessage = '.message-notice'; - - /** - * CSS selector for import message. - * - * @var string - */ - private $importResultMessage = '.messages'; - - /** - * Magento loader. - * - * @var string - */ - private $loader = '[data-role="loader"]'; - - /** - * CSS selector for error message block. - * - * @var string - */ - private $errorMessage = '.message-error'; - /** * CSS selector for validation errors list block. * @@ -54,38 +26,6 @@ class Result extends Block */ private $validationErrorList = '.import-error-list'; - /** - * Get error message text. - * - * @return string|bool - */ - public function getErrorMessage() - { - $element = $this->_rootElement->find($this->errorMessage); - - if (!$element->isVisible()) { - return false; - } - - return (string) $this->_rootElement->find($this->errorMessage)->getText(); - } - - /** - * Get notice message text. - * - * @return string|bool - */ - public function getNoticeMessage() - { - $element = $this->_rootElement->find($this->noticeMessage); - - if (!$element->isVisible()) { - return false; - } - - return (string) $this->_rootElement->find($this->noticeMessage)->getText(); - } - /** * Click import button. * @@ -96,18 +36,6 @@ public function clickImportButton() $this->_rootElement->find($this->importButton)->click(); } - /** - * Get import result message. - * - * @return string - */ - public function getImportResultMessage() - { - $this->waitForElementNotVisible($this->loader); - - return (string) $this->_rootElement->find($this->importResultMessage)->getText(); - } - /** * Get errors messages list. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php new file mode 100644 index 0000000000000..307a9bfa4e0dd --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -0,0 +1,86 @@ +_rootElement->find($this->errorMessage); + + if (!$element->isVisible()) { + return false; + } + + return (string) $this->_rootElement->find($this->errorMessage)->getText(); + } + + /** + * Get notice message text. + * + * @return string|bool + */ + public function getNoticeMessage() + { + $element = $this->_rootElement->find($this->noticeMessage); + + if (!$element->isVisible()) { + return false; + } + + return (string) $this->_rootElement->find($this->noticeMessage)->getText(); + } + + /** + * Get import result message. + * + * @return string + */ + public function getImportResultMessage() + { + $this->waitForElementNotVisible($this->loader); + + return (string) $this->_rootElement->find($this->importResultMessage)->getText(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessage.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessage.php index dcc50c8de72ee..bf41dda2fed9f 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessage.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessage.php @@ -26,7 +26,7 @@ class AssertImportCheckDataErrorMessage extends AbstractConstraint */ public function processAssert(AdminImportIndex $adminImportIndex) { - $actualMessage = $adminImportIndex->getImportResult()->getErrorMessage(); + $actualMessage = $adminImportIndex->getMessagesBlock()->getErrorMessage(); \PHPUnit_Framework_Assert::assertNotFalse($actualMessage, 'Error message is absent.'); diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 67d23f3daf684..b340aaee20853 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -46,11 +46,11 @@ class File extends DataSource private $fixtureFactory; /** - * Products fixtures. + * Entities fixtures. * * @var FixtureInterface[] */ - private $products; + private $entities; /** * Object manager. @@ -105,10 +105,10 @@ public function getData($key = null) $placeholders = []; if (!isset($this->products) - && isset($this->value['products']) - && is_array($this->value['products']) + && isset($this->value['entities']) + && is_array($this->value['entities']) ) { - $this->products = $this->createProducts(); + $this->entities = $this->createEntities(); $placeholders = $this->getPlaceHolders(); } @@ -142,13 +142,23 @@ public function getData($key = null) } /** - * Get products fixtures. + * Get entities fixtures. * * @return FixtureInterface[] */ - public function getProducts() + public function getEntities() { - return $this->products ?: []; + return $this->entities ?: []; + } + + /** + * Get fixture data. + * + * @return array|null + */ + public function getValue() + { + return $this->value; } /** @@ -156,20 +166,20 @@ public function getProducts() * * @return FixtureInterface[] */ - private function createProducts() + private function createEntities() { - $products = []; - foreach ($this->value['products'] as $key => $productDataSet) { + $entities = []; + foreach ($this->value['entities'] as $key => $productDataSet) { list($fixtureCode, $dataset) = explode('::', $productDataSet); /** @var FixtureInterface[] $products */ - $products[$key] = $this->fixtureFactory->createByCode(trim($fixtureCode), ['dataset' => trim($dataset)]); - if ($products[$key]->hasData('id') === false) { - $products[$key]->persist(); + $entities[$key] = $this->fixtureFactory->createByCode(trim($fixtureCode), ['dataset' => trim($dataset)]); + if ($entities[$key]->hasData('id') === false) { + $entities[$key]->persist(); } } - return $products; + return $entities; } /** @@ -180,16 +190,16 @@ private function createProducts() private function getPlaceHolders() { $key = 0; - foreach ($this->products as $product) { - $productData = $product->getData(); - $productData['code'] = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]->getCode(); - foreach ($this->csvTemplate['product_' . $key] as $tierKey => $tier) { + foreach ($this->entities as $entity) { + $entityData = $entity->getData(); + $entityData['code'] = $entity->getDataFieldConfig('website_ids')['source']->getWebsites()[0]->getCode(); + foreach ($this->csvTemplate['entity_' . $key] as $tierKey => $tier) { $values = implode('', array_values($tier)); preg_match_all('/\%(.*)\%/U', $values, $indexes); foreach ($indexes[1] as $index) { - if (isset($productData[$index])) { - $placeholders['product_' . $key][$tierKey]["%{$index}%"] = $productData[$index]; + if (isset($entityData[$index])) { + $placeholders['entity_' . $key][$tierKey]["%{$index}%"] = $entityData[$index]; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminImportIndex.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminImportIndex.xml index f07b7037a5dba..0cd83fd7d4d10 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminImportIndex.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminImportIndex.xml @@ -10,5 +10,6 @@ + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php index 707e6b3968a8e..c444ff3edc324 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ImportDataTest.php @@ -19,6 +19,7 @@ * 5. Perform assertions. * * @group ImportExport + * @ZephyrId MAGETWO-46154, MAGETWO-46156, MAGETWO-46157, MAGETWO-46159 */ class ImportDataTest extends Scenario { diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php index 614a7c6b7380b..f2f9628eb8d18 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php @@ -5,8 +5,10 @@ */ namespace Magento\ImportExport\Test\TestStep; +use Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportAdvancedPricingCheckData as Assert; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\TestStep\TestStepInterface; +use Magento\ImportExport\Test\Fixture\ImportData; /** * Click "Check Data" button. @@ -20,12 +22,30 @@ class ClickCheckDataStep implements TestStepInterface */ private $adminImportIndex; + /** + * Assert that validation result message is correct. + * + * @var AssertImportAdvancedPricingCheckData + */ + private $assert; + + /** + * Import fixture. + * + * @var ImportData + */ + private $import; + /** * @param AdminImportIndex $adminImportIndex + * @param Assert $assert + * @param ImportData $import */ - public function __construct(AdminImportIndex $adminImportIndex) + public function __construct(AdminImportIndex $adminImportIndex, Assert $assert, ImportData $import) { $this->adminImportIndex = $adminImportIndex; + $this->assert = $assert; + $this->import = $import; } /** @@ -36,5 +56,7 @@ public function __construct(AdminImportIndex $adminImportIndex) public function run() { $this->adminImportIndex->getFormPageActions()->clickCheckData(); + $this->assert->processAssert($this->adminImportIndex, $this->import); + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php new file mode 100644 index 0000000000000..f1001c5be80d3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php @@ -0,0 +1,40 @@ +adminImportIndex = $adminImportIndex; + } + + /** + * Click "Check Data" button. + * + * @return void + */ + public function run() + { + $this->adminImportIndex->getImportResult()->clickImportButton(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php index dc4ab25ac3922..55a18b8401d86 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php @@ -15,6 +15,13 @@ */ class CreateCustomStoreStep implements TestStepInterface { + /** + * Website code mapping. + */ + private $codeMapping =[ + 'base' => 'Main Website[USD]' + ]; + /** * Factory for Test Steps. * @@ -64,7 +71,7 @@ public function __construct( /** * Fill import form. * - * @return array + * @return void */ public function run() { @@ -73,7 +80,7 @@ public function run() ['configData' => 'price_scope_website'] )->run(); - $products = $this->import->getDataFieldConfig('import_file')['source']->getProducts(); + $products = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); foreach ($products as $product) { $websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites(); @@ -108,19 +115,16 @@ public function run() * Return refactored csv data with custom store. * * @param array $products - * @return array + * @return void */ public function getCsv(array $products) { - - $mapping['base'] = 'Main Website[USD]'; - foreach ($products as $product) { $website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; - $mapping[$website->getCode()] = $website->getName() . "[{$this->currency}]"; + $this->codeMapping[$website->getCode()] = $website->getName() . "[{$this->currency}]"; } $csv = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); - $this->import->getDataFieldConfig('import_file')['source']->setCsv(strtr($csv, $mapping)); + $this->import->getDataFieldConfig('import_file')['source']->setCsv(strtr($csv, $this->codeMapping)); } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 7f524bcb9ec10..1e1b87a521264 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -30,13 +30,6 @@ class FillImportFormStep implements TestStepInterface */ private $import; - /** - * Csv as array. - * - * @var array - */ - private $csv; - /** * @param AdminImportIndex $adminImportIndex * @param ImportData $import @@ -73,7 +66,7 @@ public function run() $file = $this->import->getDataFieldConfig('import_file')['source']; return [ - 'products' => $file->getProducts(), + 'entities' => $file->getEntities(), 'import' => $this->import ]; } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml index bc4cc58622f80..1ed45487fc64e 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml @@ -15,6 +15,7 @@ - + + From 1718c67901df164d2a4d66a3e43e63422605b5fa Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Thu, 9 Mar 2017 13:12:29 +0300 Subject: [PATCH 04/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../Test/Constraint/AssertImportAdvancedPricingCheckData.php | 3 --- .../ImportExport/Test/TestStep/CreateCustomStoreStep.php | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php index 4b6ee5c8fb8ab..6f3ae53d5dc81 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php @@ -31,9 +31,6 @@ public function processAssert(AdminImportIndex $adminImportIndex, ImportData $im $rowsCount = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['count']; $entitiesCount = count($import->getDataFieldConfig('import_file')['source']->getEntities()); - $rowsCount = 2; - $entitiesCount = 0; - $message = $adminImportIndex->getMessagesBlock()->getNoticeMessage(); \PHPUnit_Framework_Assert::assertEquals( sprintf(self::RESULT_MESSAGE, $rowsCount, $entitiesCount), diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php index 55a18b8401d86..7a8d73137c9bf 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php @@ -108,7 +108,7 @@ public function run() ); $configFixture->persist(); } - $this->getCsv($products); + $this->prepareCsv($products); } /** @@ -117,7 +117,7 @@ public function run() * @param array $products * @return void */ - public function getCsv(array $products) + public function prepareCsv(array $products) { foreach ($products as $product) { $website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; From 3deebde0d0971a75bc2413d44000f145866a1f23 Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Thu, 9 Mar 2017 21:01:46 +0300 Subject: [PATCH 05/29] MTO-138: [Test] Export Advanced Pricing - Test implemented --- dev/tests/functional/etc/di.xml | 6 + .../Magento/Mtf/Util/Command/File/Export.php | 2 +- .../Test/Block/Adminhtml/Product/Grid.php | 21 ++ .../Test/Fixture/Product/TierPrice.php | 24 ++ .../Handler/CatalogProductSimple/Curl.php | 30 +++ .../Test/Block/Adminhtml/Export/Filter.php | 47 ++++ .../AssertExportAdvancedPricing.php | 103 +++++++++ ...xportAdvancedPricingNoDataErrorMessage.php | 49 +++++ .../Test/Page/Adminhtml/AdminExportIndex.xml | 1 + .../Test/Repository/ExportData.xml | 5 + .../TestCase/ExportAdvancedPricingTest.php | 206 ++++++++++++++++++ .../TestCase/ExportAdvancedPricingTest.xml | 85 ++++++++ 12 files changed, 578 insertions(+), 1 deletion(-) create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml diff --git a/dev/tests/functional/etc/di.xml b/dev/tests/functional/etc/di.xml index 575471d34f5ff..39296015cd4fa 100644 --- a/dev/tests/functional/etc/di.xml +++ b/dev/tests/functional/etc/di.xml @@ -110,6 +110,12 @@ + + + advanced_pricing.*?\.csv + + + customer.*?\.csv diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php index 7f6d896b5a1f1..fdbf4a63b97d1 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php @@ -40,7 +40,7 @@ class Export implements ExportInterface * @param ObjectManagerInterface $objectManager * @param string $type [optional] */ - public function __construct(ObjectManagerInterface $objectManager, $type = 'product') + public function __construct(ObjectManagerInterface $objectManager, $type = 'advancedPricing') { $this->objectManager = $objectManager; $this->reader = $this->getReader($type); diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php index 668d8bbe9fbeb..f80b924a2cf86 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php @@ -96,4 +96,25 @@ public function getBaseImageSource() $baseImage = $this->_rootElement->find($this->baseImage); return $baseImage->isVisible() ? $baseImage->getAttribute('src') : ''; } + + /** + * Remove all previously created products. + * + * @return void + */ + public function removeAllProducts() + { + $this->waitLoader(); + if ($this->browser->find($this->noRecords)->isVisible()) { + return; + } + $this->selectMassAction('Select All'); + $this->selectAction('Delete'); + $element = $this->browser->find($this->alertModal); + $modal = $this->blockFactory->create( + \Magento\Ui\Test\Block\Adminhtml\Modal::class, + ['element' => $element] + ); + $modal->acceptAlert(); + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php index 7b08795cbd021..c3389954629dd 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php @@ -26,6 +26,13 @@ class TierPrice extends DataSource */ private $customerGroups; + /** + * Website fixture. + * + * @var \Magento\Store\Test\Fixture\Website + */ + private $website; + /** * Repository Factory instance. * @@ -80,6 +87,13 @@ public function getData($key = null) throw new \Exception("Data must be set"); } $this->data = $this->repositoryFactory->get($this->params['repository'])->get($this->fixtureData['dataset']); + if (!empty($this->fixtureData['data']['website'])) { + $this->website = $this->fixtureData['data']['website']; + $this->fixtureData['data']['website'] = $this->website->getCode(); + foreach ($this->data as $key => $data) { + $this->data[$key] = array_merge($data, $this->fixtureData['data']); + } + } foreach ($this->data as $key => $item) { /** @var CustomerGroup $customerGroup */ $customerGroup = $this->fixtureFactory->createByCode( @@ -105,4 +119,14 @@ public function getCustomerGroups() { return $this->customerGroups; } + + /** + * Return website fixture. + * + * @return \Magento\Store\Test\Fixture\Website + */ + public function getWebsite() + { + return $this->website; + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index 3d38e09916efd..bee6e36c49d6f 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -31,6 +31,13 @@ class Curl extends AbstractCurl implements CatalogProductSimpleInterface */ protected $fields; + /** + * Product website. + * + * @var array + */ + protected $website; + /** * Mapping values for data. * @@ -274,6 +281,7 @@ public function prepareData(FixtureInterface $fixture) $this->fields = ['product' => $fixture->getData()]; $this->prepareProductDetails(); + $this->prepareWebsitesData(); $this->prepareWebsites(); $this->prepareAdvancedPricing(); $this->prepareAdvancedInventory(); @@ -436,6 +444,21 @@ protected function prepareAdvancedPricing() } } + /** + * Update product websites. + * + * @return void + */ + protected function prepareWebsitesData() + { + if (!empty($this->fields['product']['website_ids'])) { + foreach ($this->fixture->getDataFieldConfig('website_ids')['source']->getWebsites() as $key => $website) { + $this->fields['product']['website_ids'][$key] = $website->getWebsiteId(); + } + $this->fields['product']['website_ids'][] = 1; + } + } + /** * Preparation of tier price data. * @@ -444,12 +467,19 @@ protected function prepareAdvancedPricing() */ protected function preparePriceFields(array $fields) { + $this->website = $this->fixture->getDataFieldConfig('tier_price')['source']->getWebsite(); foreach ($fields as $priceKey => &$field) { foreach ($this->priceData as $key => $data) { if ($data['name'] == 'cust_group') { $field[$data['name']] = $this->fixture->getDataFieldConfig('tier_price')['source'] ->getCustomerGroups()[$priceKey]->getCustomerGroupId(); } else { + if ($this->website !== null) { + unset($this->priceData['website']['data']); + $this->priceData['website']['data'][$this->website->getCode()] = $this-> + website->getData('website_id'); + } + $field[$data['name']] = $this->priceData[$key]['data'][$field[$key]]; } unset($field[$key]); diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php index ac96239af02d4..5f43a3c2354ac 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php @@ -27,4 +27,51 @@ class Filter extends Grid 'selector' => 'input[name="attribute_code"]', ], ]; + + /** + * Locator for export attribute. + * + * @var string + */ + protected $attribute = '[name="export_filter[%s]"]'; + + /** + * Locator for "Continue" button. + * + * @var string + */ + private $continueButton = 'button.action-.scalable'; + + /** + * Return row with given attribute label. + * + * @param string $attributeLabel + * @return SimpleElement + */ + public function getGridRow($attributeLabel) + { + return $this->search(['frontend_label' => $attributeLabel]); + } + + /** + * Click on "Continue" button. + * + * @return void + */ + public function clickContinue() + { + $this->_rootElement->find($this->continueButton)->click(); + } + + /** + * Set attribute entity value. + * + * @param string $attribute + * @param string $value + * @return void + */ + public function setAttributeValue($attribute, $value) + { + $this->_rootElement->find(sprintf($this->attribute, $attribute))->setValue($value); + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php new file mode 100644 index 0000000000000..48c4d5ed38f12 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php @@ -0,0 +1,103 @@ +getLatest(); + + if (!empty($advancedPricingAttributes)) { + $products = [$products[$advancedPricingAttributes['product']]]; + } + + foreach ($products as $product) { + \PHPUnit_Framework_Assert::assertTrue( + $this->isProductDataInFile( + $exportedFields, + $product, + $exportData + ), + "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.'; + } + + /** + * Get product data from exported file. + * + * @param array $fields + * @param InjectableFixture $product + * @param Data $exportData + * @param string $quantifiers + * @return void + */ + public function isProductDataInFile( + array $fields, + InjectableFixture $product, + Data $exportData, + $quantifiers = 'U' + ) { + $dataForCheck = []; + for ($i = 0; $i < count($product->getData()['tier_price']); $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 .= '/' . $quantifiers; + + $dataForCheck[] = $regexp; + } + foreach ($dataForCheck as $regexp) { + preg_match($regexp, $exportData->getContent(), $matches); + if (empty($matches)) { + return false; + } + } + return true; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php new file mode 100644 index 0000000000000..4ed89e9959cb4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php @@ -0,0 +1,49 @@ +getMessagesBlock()->getErrorMessage(); + + \PHPUnit_Framework_Assert::assertEquals( + self::ERROR_MESSAGE, + $actualMessage, + 'Wrong error message is displayed.' + . "\nExpected: " . self::ERROR_MESSAGE + . "\nActual: " . $actualMessage + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Correct error message is displayed.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml index f9e5b77dd54c8..ec19686f578dd 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml @@ -9,5 +9,6 @@ + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml index 29ab7c7d95976..0e3882d97b6ec 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml @@ -11,5 +11,10 @@ Products CSV + + + Advanced Pricing + CSV + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php new file mode 100644 index 0000000000000..021c1da23f335 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -0,0 +1,206 @@ + Export. + * 3. Select Entity Type = Advanced Pricing. + * 4. Fill Entity Attributes data. + * 5. Click "Continue". + * 6. Verify exported *.csv file. + * + * @group ImportExport + * @ZephyrId MAGETWO-46147, MAGETWO-46120, MAGETWO-46152, MAGETWO-48298 + */ +class ExportAdvancedPricingTest extends Injectable +{ + /** + * Test step factory. + * + * @var TestStepFactory + */ + private $stepFactory; + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Configuration data. + * + * @var string + */ + private $configData; + + /** + * Product page with a grid. + * + * @var CatalogProductIndex + */ + private $catalogProductIndex; + + /** + * Inject pages. + * + * @param TestStepFactory $stepFactory + * @param FixtureFactory $fixtureFactory + * @param AdminExportIndex $adminExportIndex + * @param CatalogProductIndex $catalogProductIndexPage + * @return void + */ + public function __inject( + TestStepFactory $stepFactory, + FixtureFactory $fixtureFactory, + AdminExportIndex $adminExportIndex, + CatalogProductIndex $catalogProductIndexPage + ) { + $this->stepFactory = $stepFactory; + $this->fixtureFactory = $fixtureFactory; + $this->adminExportIndex = $adminExportIndex; + $this->catalogProductIndex = $catalogProductIndexPage; + } + + /** + * Runs Export Advance Pricing test. + * + * @param array $exportData + * @param string|null $deleteExistingProducts + * @param array $products + * @param string $configData + * @param Store $store + * @param array $advancedPricingAttributes + * @param array|null $currencies + * @return array + */ + public function test( + array $exportData, + $deleteExistingProducts = null, + array $products = [], + $configData = null, + Store $store = null, + array $advancedPricingAttributes = [], + array $currencies = [] + ) { + $this->configData = $configData; + + if ($this->configData != null) { + $this->stepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => $configData] + )->run(); + } + + if ($deleteExistingProducts != null) { + $this->catalogProductIndex->open(); + $this->catalogProductIndex->getProductGrid()->removeAllProducts(); + } + + if ($store !== null) { + $store->persist(); + } + + if (!empty($products)) { + foreach ($products as $product) { + $data = [ + 'website_ids' => [ + ['store' => $store] + ] + ]; + if ($store !== null) { + $data['tier_price'] = [ + 'data' => [ + 'website' => $store->getDataFieldConfig('group_id')['source'] + ->getStoreGroup()->getDataFieldConfig('website_id')['source']->getWebsite() + ] + ]; + } + + $product = $this->fixtureFactory->createByCode( + $product['fixture'], + [ + 'dataset' => $product['dataset'], + 'data' => $data + ] + ); + $product->persist(); + $createdProducts[] = $product; + } + $products = $createdProducts; + } + + if ($store !== null) { + $websites = $createdProducts[0]->getDataFieldConfig('website_ids')['source']->getWebsites(); + $configFixture = $this->fixtureFactory->createByCode( + 'configData', + [ + 'data' => [ + 'currency/options/allow' => [ + 'value' => $currencies[0]['allowedCurrencies'] + ], + 'currency/options/base' => [ + 'value' => $currencies[0]['baseCurrency'] + ], + 'currency/options/default' => [ + 'value' => $currencies[0]['defaultCurrency'] + ], + 'scope' => [ + 'fixture' => $websites[0], + 'scope_type' => 'website', + 'website_id' => $websites[0]->getWebsiteId(), + 'set_level' => 'website', + ] + ] + ] + ); + $configFixture->persist(); + } + $this->adminExportIndex->open(); + $exportData = $this->fixtureFactory->createByCode('exportData', ['dataset' => $exportData['dataset']]); + $this->adminExportIndex->getExportForm()->fill($exportData); + if (!empty($advancedPricingAttributes)) { + $this->adminExportIndex->getFilterExport()->setAttributeValue( + $advancedPricingAttributes['attribute'], + $createdProducts[$advancedPricingAttributes['product']] + ->getData($advancedPricingAttributes['attribute']) + ); + } + $this->adminExportIndex->getFilterExport()->clickContinue(); + + return [ + 'products' => $products + ]; + } + + /** + * Revert settings to the default value. + * + * @return void + */ + public function tearDown() + { + if ($this->configData) { + $this->stepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => 'config_currency_symbols_usd, price_scope_website_rollback'] + )->run(); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml new file mode 100644 index 0000000000000..5c03efa28fb63 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml @@ -0,0 +1,85 @@ + + + + + + Yes + csv_with_advanced_pricing + + + + csv_with_advanced_pricing + + catalogProductSimple + simple_with_tier_price + + + sku + tier_price_website + tier_price_customer_group + tier_price_qty + tier_price + + + + + csv_with_advanced_pricing + + catalogProductSimple + simple_with_tier_price + + + catalogProductSimple + simple_with_tier_price + + + 0 + sku + + + sku + tier_price_website + tier_price_customer_group + tier_price_qty + tier_price + + + + + MAGETWO-65703: Fatal error on creation simple product with tier price in custom website via webapi handler + price_scope_website + csv_with_advanced_pricing + + catalogProductSimple + simple_with_tier_price + + custom_store + + + + EUR + + EUR + EUR + + + + $ + + + + sku + tier_price_website + tier_price_customer_group + tier_price_qty + tier_price + + + + + From d82ca38f8c53d9457f46eb65e7dac9282743a01c Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Thu, 9 Mar 2017 23:10:52 +0300 Subject: [PATCH 06/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../AssertImportAdvancedPricing.php | 16 ++--- .../AssertImportAdvancedPricingCheckData.php | 4 +- .../Test/TestCase/ImportDataTest.xml | 1 + .../Mtf/Util/Import/File/CsvTemplate.php | 7 +-- .../Test/Block/Adminhtml/Import/Messages.php | 52 +--------------- .../ImportExport/Test/Fixture/Import/File.php | 62 ++++++++++++------- .../Test/TestStep/ClickCheckDataStep.php | 1 - .../Test/TestStep/ClickImportDataStep.php | 2 +- .../Test/TestStep/CreateCustomStoreStep.php | 18 ------ 9 files changed, 55 insertions(+), 108 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index 0e46a9bcb7b7b..d1e80fae954de 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -68,7 +68,7 @@ public function processAssert( $this->fixtureFactory = $fixtureFactory; $this->import = $import; - $resultArrays = $this->preparePrices(); + $resultArrays = $this->getPreparePrices(); \PHPUnit_Framework_Assert::assertEquals( $resultArrays['pageData'], @@ -82,11 +82,11 @@ public function processAssert( * * @return array */ - public function preparePrices() + private function getPreparePrices() { $products = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); - // Prepare tier prices data from backend. + // Prepare tier prices data from page form. $resultProductArray = []; foreach ($products as $product) { $this->catalogProductEdit->open(['id' => $product->getId()]); @@ -114,19 +114,13 @@ public function preparePrices() } /** - * Prepare assert data. + * Prepare array from csv file. * * @return array */ private function getResultCsv() { - $rowStreamContent = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); - $csvData = array_map( - function ($value) { - return explode(',', str_replace('"', '', $value)); - }, - str_getcsv($rowStreamContent, "\n") - ); + $csvData = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); $csvKeys = []; foreach (array_shift($csvData) as $csvKey) { diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php index 6f3ae53d5dc81..ad73172913063 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php @@ -16,7 +16,7 @@ class AssertImportAdvancedPricingCheckData extends AbstractConstraint { /** - * Success validation result message + * Success validation result message. */ const RESULT_MESSAGE = 'Checked rows: %s, checked entities: %s, invalid rows: 0, total errors: 0'; @@ -25,11 +25,13 @@ class AssertImportAdvancedPricingCheckData extends AbstractConstraint * * @param AdminImportIndex $adminImportIndex * @param ImportData $import + * @return void */ public function processAssert(AdminImportIndex $adminImportIndex, ImportData $import) { $rowsCount = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['count']; $entitiesCount = count($import->getDataFieldConfig('import_file')['source']->getEntities()); + $entitiesCount = 0; $message = $adminImportIndex->getMessagesBlock()->getNoticeMessage(); \PHPUnit_Framework_Assert::assertEquals( diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index 1273274a5f1ba..d51cfafb0246d 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -89,6 +89,7 @@ Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 2 + [EUR] diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php index 621745f995c9e..c955038c6d5c0 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php @@ -52,7 +52,7 @@ public function render() } $fh = fopen('php://temp', 'rw'); - $fh = $this->addProductsData($fh); + $fh = $this->addEntitiesData($fh); rewind($fh); $this->csv = stream_get_contents($fh); fclose($fh); @@ -73,13 +73,13 @@ public function getName() } /* - * Add product data to stream content. + * Replace placeholders in csv content. */ /** * @param resource $stream * @return resource */ - private function addProductsData($stream) + private function addEntitiesData($stream) { $filename = MTF_TESTS_PATH . $this->config['filename'] . '.php'; $entitiesData = include $filename; @@ -102,7 +102,6 @@ function ($value) use ($placeholders, $entityKey, $dataKey, $dataValue) { $entitiesData[$entityKey][$dataKey] ); fputcsv($stream, $row); - } } return $stream; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php index 307a9bfa4e0dd..0a762a4756bdf 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -5,20 +5,11 @@ */ namespace Magento\ImportExport\Test\Block\Adminhtml\Import; -use Magento\Mtf\Block\Block; - /** - * Global messages block. + * Import messages block. */ -class Messages extends Block +class Messages extends \Magento\Backend\Test\Block\Messages { - /** - * CSS selector for notice message block. - * - * @var string - */ - private $noticeMessage = '.message-notice'; - /** * CSS selector for import message. * @@ -33,45 +24,6 @@ class Messages extends Block */ private $loader = '[data-role="loader"]'; - /** - * CSS selector for error message block. - * - * @var string - */ - private $errorMessage = '.message-error'; - - /** - * Get error message text. - * - * @return string|bool - */ - public function getErrorMessage() - { - $element = $this->_rootElement->find($this->errorMessage); - - if (!$element->isVisible()) { - return false; - } - - return (string) $this->_rootElement->find($this->errorMessage)->getText(); - } - - /** - * Get notice message text. - * - * @return string|bool - */ - public function getNoticeMessage() - { - $element = $this->_rootElement->find($this->noticeMessage); - - if (!$element->isVisible()) { - return false; - } - - return (string) $this->_rootElement->find($this->noticeMessage)->getText(); - } - /** * Get import result message. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index b340aaee20853..7e566c08f8824 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -17,6 +17,13 @@ */ class File extends DataSource { + /** + * Website code mapping. + */ + private $codeMapping =[ + 'base' => 'Main Website[USD]' + ]; + /** * Fixture data. * @@ -66,6 +73,13 @@ class File extends DataSource */ private $csv; + /** + * Placeholders. + * + * @var array + */ + private $placeholders; + /** * @param ObjectManager $objectManager * @param FixtureFactory $fixtureFactory @@ -103,14 +117,13 @@ public function getData($key = null) $this->csvTemplate = include $filename; - $placeholders = []; + $this->placeholders = []; if (!isset($this->products) && isset($this->value['entities']) && is_array($this->value['entities']) ) { $this->entities = $this->createEntities(); - - $placeholders = $this->getPlaceHolders(); + $this->preparePlaceHolders(); } if (isset($this->value['template']) && is_array($this->value['template'])) { @@ -120,7 +133,7 @@ public function getData($key = null) 'config' => array_merge( $this->value['template'], [ - 'placeholders' => $placeholders + 'placeholders' => $this->placeholders ] ) ] @@ -169,8 +182,8 @@ public function getValue() private function createEntities() { $entities = []; - foreach ($this->value['entities'] as $key => $productDataSet) { - list($fixtureCode, $dataset) = explode('::', $productDataSet); + foreach ($this->value['entities'] as $key => $entityDataSet) { + list($fixtureCode, $dataset) = explode('::', $entityDataSet); /** @var FixtureInterface[] $products */ $entities[$key] = $this->fixtureFactory->createByCode(trim($fixtureCode), ['dataset' => trim($dataset)]); @@ -187,12 +200,16 @@ private function createEntities() * * @return array */ - private function getPlaceHolders() + private function preparePlaceHolders() { $key = 0; foreach ($this->entities as $entity) { + $currency = (isset($this->value['template']['websiteCurrency'])) + ? $this->value['template']['websiteCurrency'] + : null; + $website = $entity->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; $entityData = $entity->getData(); - $entityData['code'] = $entity->getDataFieldConfig('website_ids')['source']->getWebsites()[0]->getCode(); + $entityData['code'] = $website->getCode(); foreach ($this->csvTemplate['entity_' . $key] as $tierKey => $tier) { $values = implode('', array_values($tier)); preg_match_all('/\%(.*)\%/U', $values, $indexes); @@ -201,13 +218,14 @@ private function getPlaceHolders() if (isset($entityData[$index])) { $placeholders['entity_' . $key][$tierKey]["%{$index}%"] = $entityData[$index]; } + $placeholders['entity_' . $key][$tierKey][$entityData['code']] = $website->getName() . $currency; } - } + $key++; } - return $placeholders; + $this->placeholders = $placeholders; } /** @@ -217,17 +235,17 @@ private function getPlaceHolders() */ public function getCsv() { - return $this->csv; - } - - /** - * Return csv as array. - * - * @param $csv - * @return void - */ - public function setCsv($csv) - { - $this->csv = $csv; + foreach ($this->placeholders as $placeholderData) { + foreach ($placeholderData as $data) { + $csvContent = strtr($this->csv, $data); + } + } + $csvContent = strtr($csvContent, $this->codeMapping); + return array_map( + function ($value) { + return explode(',', str_replace('"', '', $value)); + }, + str_getcsv($csvContent, "\n") + ); } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php index f2f9628eb8d18..8ee4e76e1e7a7 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php @@ -57,6 +57,5 @@ public function run() { $this->adminImportIndex->getFormPageActions()->clickCheckData(); $this->assert->processAssert($this->adminImportIndex, $this->import); - } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php index f1001c5be80d3..78203c32c7909 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickImportDataStep.php @@ -29,7 +29,7 @@ public function __construct(AdminImportIndex $adminImportIndex) } /** - * Click "Check Data" button. + * Click "Import" button. * * @return void */ diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php index 7a8d73137c9bf..c3107c946ed03 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php @@ -108,23 +108,5 @@ public function run() ); $configFixture->persist(); } - $this->prepareCsv($products); - } - - /** - * Return refactored csv data with custom store. - * - * @param array $products - * @return void - */ - public function prepareCsv(array $products) - { - foreach ($products as $product) { - $website = $product->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; - $this->codeMapping[$website->getCode()] = $website->getName() . "[{$this->currency}]"; - } - - $csv = $this->import->getDataFieldConfig('import_file')['source']->getCsv(); - $this->import->getDataFieldConfig('import_file')['source']->setCsv(strtr($csv, $this->codeMapping)); } } From 3d1116e81f703392359ee0c5fe917850c507eac1 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Thu, 9 Mar 2017 23:20:37 +0300 Subject: [PATCH 07/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../ImportExport/Mtf/Util/Import/File/CsvTemplate.php | 5 ++--- .../ImportExport/Test/Block/Adminhtml/Import/Messages.php | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php index c955038c6d5c0..a8a49a2026050 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Mtf/Util/Import/File/CsvTemplate.php @@ -72,10 +72,9 @@ public function getName() ); } - /* - * Replace placeholders in csv content. - */ /** + * Replace placeholders in csv content. + * * @param resource $stream * @return resource */ diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php index 0a762a4756bdf..9614107740aef 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -33,6 +33,6 @@ public function getImportResultMessage() { $this->waitForElementNotVisible($this->loader); - return (string) $this->_rootElement->find($this->importResultMessage)->getText(); + return $this->_rootElement->find($this->importResultMessage)->getText(); } } From 78273557f110bbe4739e4e5a674c809af0437184 Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Thu, 9 Mar 2017 23:44:33 +0300 Subject: [PATCH 08/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../Magento/Mtf/Util/Command/File/Export.php | 2 +- .../Test/etc/di.xml | 6 +++++ .../Handler/CatalogProductSimple/Curl.php | 4 ++-- .../Test/Block/Adminhtml/Export/Filter.php | 4 ++-- .../AssertExportAdvancedPricing.php | 6 ++--- .../TestCase/ExportAdvancedPricingTest.php | 22 +++++++++++++------ 6 files changed, 29 insertions(+), 15 deletions(-) diff --git a/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php b/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php index fdbf4a63b97d1..7f6d896b5a1f1 100644 --- a/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php +++ b/dev/tests/functional/lib/Magento/Mtf/Util/Command/File/Export.php @@ -40,7 +40,7 @@ class Export implements ExportInterface * @param ObjectManagerInterface $objectManager * @param string $type [optional] */ - public function __construct(ObjectManagerInterface $objectManager, $type = 'advancedPricing') + public function __construct(ObjectManagerInterface $objectManager, $type = 'product') { $this->objectManager = $objectManager; $this->reader = $this->getReader($type); diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml index 35ddc38d4ff30..c1a5b559aa12f 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml @@ -12,4 +12,10 @@ S1 + + + + advancedPricing + + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index bee6e36c49d6f..e6fc1ce185466 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -476,8 +476,8 @@ protected function preparePriceFields(array $fields) } else { if ($this->website !== null) { unset($this->priceData['website']['data']); - $this->priceData['website']['data'][$this->website->getCode()] = $this-> - website->getData('website_id'); + $this->priceData['website']['data'][$this->website->getCode()] + = $this->website->getData('website_id'); } $field[$data['name']] = $this->priceData[$key]['data'][$field[$key]]; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php index 5f43a3c2354ac..6ab437c290e80 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php @@ -33,7 +33,7 @@ class Filter extends Grid * * @var string */ - protected $attribute = '[name="export_filter[%s]"]'; + private $attribute = '[name="export_filter[%s]"]'; /** * Locator for "Continue" button. @@ -46,7 +46,7 @@ class Filter extends Grid * Return row with given attribute label. * * @param string $attributeLabel - * @return SimpleElement + * @return \Magento\Mtf\Client\Element\SimpleElement */ public function getGridRow($attributeLabel) { diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php index 48c4d5ed38f12..3fec0063cdf50 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php @@ -21,7 +21,7 @@ class AssertExportAdvancedPricing extends AbstractConstraint * @param Export $export * @param array $products * @param array $exportedFields - * @param array|null $advancedPricingAttributes + * @param array $advancedPricingAttributes * @return void */ public function processAssert( @@ -43,7 +43,7 @@ public function processAssert( $product, $exportData ), - "A product with name '" . $product->getName() . "' was not found in exported file." + 'A product with name ' . $product->getName() . ' was not found in exported file.' ); } } @@ -65,7 +65,7 @@ public function toString() * @param InjectableFixture $product * @param Data $exportData * @param string $quantifiers - * @return void + * @return bool */ public function isProductDataInFile( array $fields, diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php index 021c1da23f335..2f304f0313df0 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -43,6 +43,13 @@ class ExportAdvancedPricingTest extends Injectable */ private $fixtureFactory; + /** + * Admin export index page. + * + * @var AdminExportIndex + */ + private $adminExportIndex; + /** * Configuration data. * @@ -82,17 +89,17 @@ public function __inject( * Runs Export Advance Pricing test. * * @param array $exportData - * @param string|null $deleteExistingProducts + * @param bool $deleteExistingProducts * @param array $products * @param string $configData * @param Store $store * @param array $advancedPricingAttributes - * @param array|null $currencies + * @param array $currencies * @return array */ public function test( array $exportData, - $deleteExistingProducts = null, + $deleteExistingProducts = false, array $products = [], $configData = null, Store $store = null, @@ -108,23 +115,24 @@ public function test( )->run(); } - if ($deleteExistingProducts != null) { + if ($deleteExistingProducts) { $this->catalogProductIndex->open(); $this->catalogProductIndex->getProductGrid()->removeAllProducts(); } - if ($store !== null) { + if ($store) { $store->persist(); } if (!empty($products)) { + $createdProducts = []; foreach ($products as $product) { $data = [ 'website_ids' => [ ['store' => $store] ] ]; - if ($store !== null) { + if ($store) { $data['tier_price'] = [ 'data' => [ 'website' => $store->getDataFieldConfig('group_id')['source'] @@ -146,7 +154,7 @@ public function test( $products = $createdProducts; } - if ($store !== null) { + if ($store) { $websites = $createdProducts[0]->getDataFieldConfig('website_ids')['source']->getWebsites(); $configFixture = $this->fixtureFactory->createByCode( 'configData', From 7c757b38846004c2556b942c8df5ad9f5b75ecaf Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Fri, 10 Mar 2017 10:53:53 +0300 Subject: [PATCH 09/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../AssertImportAdvancedPricing.php | 3 +- .../AssertImportAdvancedPricingCheckData.php | 1 - .../Test/TestCase/ImportDataTest.xml | 18 ++++++------ .../Test/Block/Adminhtml/Import/Messages.php | 26 +++++++++++++++++ .../ImportExport/Test/Fixture/Import/File.php | 29 +++++++++++++------ ... => ChangeCurrencyOnCustomWebsiteStep.php} | 11 ++----- .../Test/TestStep/ClickCheckDataStep.php | 2 +- .../Test/TestStep/FillImportFormStep.php | 11 +++---- 8 files changed, 65 insertions(+), 36 deletions(-) rename dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/{CreateCustomStoreStep.php => ChangeCurrencyOnCustomWebsiteStep.php} (93%) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index d1e80fae954de..8772235162928 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -31,7 +31,7 @@ class AssertImportAdvancedPricing extends AbstractConstraint ]; /** - * Edit page on backend + * Edit page on backend. * * @var CatalogProductEdit */ @@ -95,7 +95,6 @@ private function getPreparePrices() $tierPrices = $advancedPricing->getTierPriceForm()->getFieldsData(); $productSku = $product->getSku(); - foreach ($tierPrices as $tierPrice) { $resultProductArray[$productSku][] = $tierPrice; } diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php index ad73172913063..9b0fd92bf24b5 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php @@ -31,7 +31,6 @@ public function processAssert(AdminImportIndex $adminImportIndex, ImportData $im { $rowsCount = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['count']; $entitiesCount = count($import->getDataFieldConfig('import_file')['source']->getEntities()); - $entitiesCount = 0; $message = $adminImportIndex->getMessagesBlock()->getNoticeMessage(); \PHPUnit_Framework_Assert::assertEquals( diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index d51cfafb0246d..48f0497935fe4 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -7,8 +7,8 @@ --> - - false + + false Advanced Pricing Add/Update @@ -29,8 +29,8 @@ - - false + + false Advanced Pricing Replace @@ -51,8 +51,8 @@ - - false + + false Advanced Pricing Delete @@ -73,8 +73,8 @@ - - true + + true Advanced Pricing Replace @@ -89,7 +89,7 @@ Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 2 - [EUR] + EUR diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php index 9614107740aef..e19836016cb03 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -24,6 +24,32 @@ class Messages extends \Magento\Backend\Test\Block\Messages */ private $loader = '[data-role="loader"]'; + /** + * Get error message. + * + * @return string + */ + public function getErrorMessage() + { + if (!$this->_rootElement->find($this->errorMessage)->isVisible()) { + return false; + } + return parent::getErrorMessage(); + } + + /** + * Get notice message. + * + * @return array + */ + public function getNoticeMessage() + { + if (!$this->_rootElement->find($this->noticeMessage)->isVisible()) { + return false; + } + return parent::getNoticeMessage(); + } + /** * Get import result message. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 7e566c08f8824..f3c6a33009c5b 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -139,7 +139,7 @@ public function getData($key = null) ] ); $this->data = $this->generator->generate($csvTemplate); - $this->csv = $csvTemplate->getCsv(); + $this->convertCsvToArray($csvTemplate->getCsv()); return parent::getData($key); } @@ -202,11 +202,12 @@ private function createEntities() */ private function preparePlaceHolders() { + $placeholders = []; $key = 0; foreach ($this->entities as $entity) { $currency = (isset($this->value['template']['websiteCurrency'])) - ? $this->value['template']['websiteCurrency'] - : null; + ? "[{$this->value['template']['websiteCurrency']}]" + : '[USD]'; $website = $entity->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; $entityData = $entity->getData(); $entityData['code'] = $website->getCode(); @@ -224,28 +225,38 @@ private function preparePlaceHolders() $key++; } - $this->placeholders = $placeholders; } /** - * Return csv as array. + * Convert csv to array. * - * @return string + * @param string $csvContent + * @return array */ - public function getCsv() + public function convertCsvToArray($csvContent) { foreach ($this->placeholders as $placeholderData) { foreach ($placeholderData as $data) { - $csvContent = strtr($this->csv, $data); + $csvContent = strtr($csvContent, $data); } } $csvContent = strtr($csvContent, $this->codeMapping); - return array_map( + $this->csv = array_map( function ($value) { return explode(',', str_replace('"', '', $value)); }, str_getcsv($csvContent, "\n") ); } + + /** + * Return csv as array. + * + * @return array + */ + public function getCsv() + { + return $this->csv; + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php similarity index 93% rename from dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php rename to dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php index c3107c946ed03..d71050a6f467d 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CreateCustomStoreStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php @@ -13,15 +13,8 @@ /** * Create custom store step. */ -class CreateCustomStoreStep implements TestStepInterface +class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface { - /** - * Website code mapping. - */ - private $codeMapping =[ - 'base' => 'Main Website[USD]' - ]; - /** * Factory for Test Steps. * @@ -60,7 +53,7 @@ public function __construct( TestStepFactory $stepFactory, FixtureFactory $fixtureFactory, ImportData $import, - $currency = 'EUR' + $currency = 'USD' ) { $this->stepFactory = $stepFactory; $this->fixtureFactory = $fixtureFactory; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php index 8ee4e76e1e7a7..b91eb41f63caa 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php @@ -25,7 +25,7 @@ class ClickCheckDataStep implements TestStepInterface /** * Assert that validation result message is correct. * - * @var AssertImportAdvancedPricingCheckData + * @var assert */ private $assert; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 1e1b87a521264..b2db5a322c217 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -34,21 +34,22 @@ class FillImportFormStep implements TestStepInterface * @param AdminImportIndex $adminImportIndex * @param ImportData $import * @param TestStepFactory $stepFactory - * @param bool $createStore + * @param bool $changeCurrency */ public function __construct( AdminImportIndex $adminImportIndex, ImportData $import, TestStepFactory $stepFactory, - $createStore + $changeCurrency ) { $this->adminImportIndex = $adminImportIndex; $this->import = $import; - if ($createStore === true) { + if ($changeCurrency === true) { + $currency = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['websiteCurrency']; $stepFactory->create( - CreateCustomStoreStep::class, - ['import' => $this->import] + ChangeCurrencyOnCustomWebsiteStep::class, + ['import' => $this->import, 'currency' => $currency] )->run(); } } From 3c55dd88d40e4b65bd8827ca4b1527dad26762e1 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Mon, 13 Mar 2017 14:21:19 +0300 Subject: [PATCH 10/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../ImportExport/Test/Block/Adminhtml/Import/Messages.php | 4 ++-- .../ImportExport/Test/TestStep/ClickCheckDataStep.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php index e19836016cb03..e1adb91b6a8e3 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -27,7 +27,7 @@ class Messages extends \Magento\Backend\Test\Block\Messages /** * Get error message. * - * @return string + * @return bool|string */ public function getErrorMessage() { @@ -40,7 +40,7 @@ public function getErrorMessage() /** * Get notice message. * - * @return array + * @return bool|string */ public function getNoticeMessage() { diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php index b91eb41f63caa..497e332908a16 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php @@ -5,7 +5,7 @@ */ namespace Magento\ImportExport\Test\TestStep; -use Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportAdvancedPricingCheckData as Assert; +use Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportAdvancedPricingCheckData as AssertImportCheckData; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\TestStep\TestStepInterface; use Magento\ImportExport\Test\Fixture\ImportData; @@ -25,7 +25,7 @@ class ClickCheckDataStep implements TestStepInterface /** * Assert that validation result message is correct. * - * @var assert + * @var AssertImportCheckData */ private $assert; @@ -38,10 +38,10 @@ class ClickCheckDataStep implements TestStepInterface /** * @param AdminImportIndex $adminImportIndex - * @param Assert $assert + * @param AssertImportCheckData $assert * @param ImportData $import */ - public function __construct(AdminImportIndex $adminImportIndex, Assert $assert, ImportData $import) + public function __construct(AdminImportIndex $adminImportIndex, AssertImportCheckData $assert, ImportData $import) { $this->adminImportIndex = $adminImportIndex; $this->assert = $assert; From 5a0e4de1436741fefdb280bbd95a5c86082a8946 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Mon, 13 Mar 2017 14:50:40 +0300 Subject: [PATCH 11/29] MTO-127: [Test] Import Advanced Pricing - Defects fixed --- .../Test/Constraint/AssertImportAdvancedPricing.php | 2 +- .../Test/_files/template/pricing/advanced_price_variation_1.php | 2 +- .../Test/_files/template/pricing/advanced_price_variation_2.php | 2 +- .../Test/_files/template/pricing/advanced_price_variation_3.php | 2 +- .../Test/_files/template/pricing/advanced_price_variation_4.php | 2 +- .../tests/app/Magento/ImportExport/Test/Fixture/Import/File.php | 2 ++ 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index 8772235162928..2c1c29fe6bbba 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -19,7 +19,7 @@ class AssertImportAdvancedPricing extends AbstractConstraint /** * Array keys mapping for csv file. * - * @param array + * @var array */ private $mappingData = [ 'sku' => 'sku', diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php index 09a812532c67c..1469d211d62f7 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php @@ -26,4 +26,4 @@ 'tier_price_value_type' => 'Fixed', ] ], -]; \ No newline at end of file +]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php index cbc9e6719ed78..330e50a3b0ea5 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php @@ -17,4 +17,4 @@ 'tier_price_value_type' => 'Fixed', ], ], -]; \ No newline at end of file +]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php index 5951ce491cbad..811b6d3fe12aa 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php @@ -17,4 +17,4 @@ 'tier_price_value_type' => 'Fixed', ], ], -]; \ No newline at end of file +]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php index 1cb4a2b7e734f..ebc27650a110d 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php @@ -26,4 +26,4 @@ 'tier_price_value_type' => 'Fixed', ], ], -]; \ No newline at end of file +]; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index f3c6a33009c5b..3e62ee99dc2fa 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -19,6 +19,8 @@ class File extends DataSource { /** * Website code mapping. + * + * @var array */ private $codeMapping =[ 'base' => 'Main Website[USD]' From 6ba166e1b9361e762e30f9c915471f6b079ffd24 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Mon, 13 Mar 2017 17:18:44 +0300 Subject: [PATCH 12/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Test/TestCase/ImportDataTest.xml | 3 --- .../Product/Edit/Section/AdvancedPricing/OptionTier.php | 1 + .../Magento/ImportExport/Test/TestStep/FillImportFormStep.php | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index 48f0497935fe4..a354f09204db4 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -8,7 +8,6 @@ - false Advanced Pricing Add/Update @@ -30,7 +29,6 @@ - false Advanced Pricing Replace @@ -52,7 +50,6 @@ - false Advanced Pricing Delete diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php index 514fdbee47291..3400b95dd8a52 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Section/AdvancedPricing/OptionTier.php @@ -79,6 +79,7 @@ public function getDataOptions(array $fields = null, SimpleElement $element = nu * @param array|null $fields * @param SimpleElement|null $element * @return array + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function getFieldsData($fields = null, SimpleElement $element = null) { diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index b2db5a322c217..0dd920990fa1b 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -34,13 +34,13 @@ class FillImportFormStep implements TestStepInterface * @param AdminImportIndex $adminImportIndex * @param ImportData $import * @param TestStepFactory $stepFactory - * @param bool $changeCurrency + * @param bool|null $changeCurrency */ public function __construct( AdminImportIndex $adminImportIndex, ImportData $import, TestStepFactory $stepFactory, - $changeCurrency + $changeCurrency = false ) { $this->adminImportIndex = $adminImportIndex; $this->import = $import; From 4e2615595f8c0ca361dce3ee2dd96ea87ca885ef Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Tue, 14 Mar 2017 10:11:56 +0300 Subject: [PATCH 13/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../AssertExportAdvancedPricing.php | 66 +++-- ...xportAdvancedPricingNoDataErrorMessage.php | 2 +- .../TestCase/ExportAdvancedPricingTest.php | 258 ++++++++++++++++++ .../TestCase/ExportAdvancedPricingTest.xml | 24 +- .../Test/etc/di.xml | 2 +- .../Test/Fixture/Product/TierPrice.php | 20 +- .../Test/Block/Adminhtml/Export/Edit/Form.php | 41 ++- .../Test/Block/Adminhtml/Export/Edit/Form.xml | 6 + .../Test/Block/Adminhtml/Export/Filter.php | 11 - .../ImportExport/Test/Fixture/ExportData.xml | 2 +- .../Test/Fixture/ExportData/DataExport.php | 35 +++ .../Test/Page/Adminhtml/AdminExportIndex.xml | 2 +- .../TestCase/ExportAdvancedPricingTest.php | 214 --------------- 13 files changed, 405 insertions(+), 278 deletions(-) rename dev/tests/functional/tests/app/Magento/{ImportExport => AdvancedPricingImportExport}/Test/Constraint/AssertExportAdvancedPricing.php (65%) rename dev/tests/functional/tests/app/Magento/{ImportExport => AdvancedPricingImportExport}/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php (95%) create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php rename dev/tests/functional/tests/app/Magento/{ImportExport => AdvancedPricingImportExport}/Test/TestCase/ExportAdvancedPricingTest.xml (78%) create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php delete mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php similarity index 65% rename from dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php rename to dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php index 3fec0063cdf50..9d35b86def9df 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php @@ -3,10 +3,9 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\ImportExport\Test\Constraint; +namespace Magento\AdvancedPricingImportExport\Test\Constraint; use Magento\Mtf\Constraint\AbstractConstraint; -use Magento\Mtf\Util\Command\File\Export\Data; use Magento\Mtf\Fixture\InjectableFixture; use Magento\Mtf\Util\Command\File\Export; @@ -15,34 +14,31 @@ */ class AssertExportAdvancedPricing extends AbstractConstraint { + /** + * Export data. + * + * @var array + */ + private $exportData; + /** * Assert that exported file with advanced pricing options contains product data. * * @param Export $export * @param array $products * @param array $exportedFields - * @param array $advancedPricingAttributes * @return void */ public function processAssert( Export $export, array $products, - array $exportedFields, - array $advancedPricingAttributes = [] + array $exportedFields ) { - $exportData = $export->getLatest(); - - if (!empty($advancedPricingAttributes)) { - $products = [$products[$advancedPricingAttributes['product']]]; - } - + $this->exportData = $export->getLatest(); foreach ($products as $product) { + $regexps = $this->prepareRegexpsForCheck($exportedFields, $product); \PHPUnit_Framework_Assert::assertTrue( - $this->isProductDataInFile( - $exportedFields, - $product, - $exportData - ), + $this->isProductDataExists($regexps), 'A product with name ' . $product->getName() . ' was not found in exported file.' ); } @@ -59,22 +55,19 @@ public function toString() } /** - * Get product data from exported file. + * Prepare regular expressions for product data in exported file. * * @param array $fields * @param InjectableFixture $product - * @param Data $exportData - * @param string $quantifiers - * @return bool + * @return array */ - public function isProductDataInFile( + private function prepareRegexpsForCheck( array $fields, - InjectableFixture $product, - Data $exportData, - $quantifiers = 'U' + InjectableFixture $product ) { - $dataForCheck = []; - for ($i = 0; $i < count($product->getData()['tier_price']); $i++) { + $regexpsForCheck = []; + $tierPrices = count($product->getData()['tier_price']); + for ($i = 0; $i < $tierPrices; $i++) { $regexp = '/'; foreach ($fields as $field) { if (strpos($field, 'tier_price') !== false) { @@ -88,16 +81,29 @@ public function isProductDataInFile( $regexp .= '.*(' . $product->getData($field) . ').*'; } } - $regexp .= '/' . $quantifiers; + $regexp .= '/U'; - $dataForCheck[] = $regexp; + $regexpsForCheck[] = $regexp; } - foreach ($dataForCheck as $regexp) { - preg_match($regexp, $exportData->getContent(), $matches); + + 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; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php similarity index 95% rename from dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php rename to dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php index 4ed89e9959cb4..4119624dbc098 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php @@ -3,7 +3,7 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\ImportExport\Test\Constraint; +namespace Magento\AdvancedPricingImportExport\Test\Constraint; use Magento\ImportExport\Test\Page\Adminhtml\AdminExportIndex; use Magento\Mtf\Constraint\AbstractConstraint; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php new file mode 100644 index 0000000000000..7f62ef572c9b4 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -0,0 +1,258 @@ + Export. + * 3. Select Entity Type = Advanced Pricing. + * 4. Fill Entity Attributes data. + * 5. Click "Continue". + * 6. Verify exported *.csv file. + * + * @group ImportExport + * @ZephyrId MAGETWO-46147, MAGETWO-46120, MAGETWO-46152, MAGETWO-48298 + */ +class ExportAdvancedPricingTest extends Injectable +{ + /** + * Test step factory. + * + * @var TestStepFactory + */ + private $stepFactory; + + /** + * Fixture factory. + * + * @var FixtureFactory + */ + private $fixtureFactory; + + /** + * Admin export index page. + * + * @var AdminExportIndex + */ + private $adminExportIndex; + + /** + * Configuration data. + * + * @var string + */ + private $configData; + + /** + * Product page with a grid. + * + * @var CatalogProductIndex + */ + private $catalogProductIndex; + + /** + * Prepare test data. + * + * @param CatalogProductIndex $catalogProductIndex + * @return void + */ + public function __prepare( + CatalogProductIndex $catalogProductIndex + ) { + $catalogProductIndex->open(); + $catalogProductIndex->getProductGrid()->removeAllProducts(); + } + + /** + * Injection data. + * + * @param TestStepFactory $stepFactory + * @param FixtureFactory $fixtureFactory + * @param AdminExportIndex $adminExportIndex + * @param CatalogProductIndex $catalogProductIndexPage + * @return void + */ + public function __inject( + TestStepFactory $stepFactory, + FixtureFactory $fixtureFactory, + AdminExportIndex $adminExportIndex, + CatalogProductIndex $catalogProductIndexPage + ) { + $this->stepFactory = $stepFactory; + $this->fixtureFactory = $fixtureFactory; + $this->adminExportIndex = $adminExportIndex; + $this->catalogProductIndex = $catalogProductIndexPage; + } + + /** + * Runs Export Advance Pricing test. + * + * @param string $exportData + * @param array $products + * @param string|null $configData + * @param Website|null $website + * @param array $advancedPricingAttributes + * @param array $currencies + * @return array + */ + public function test( + $exportData, + array $products = [], + $configData = null, + Website $website = null, + array $advancedPricingAttributes = [], + array $currencies = [] + ) { + $this->configData = $configData; + + if ($this->configData) { + $this->stepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => $configData] + )->run(); + } + + if ($website) { + $website->persist(); + } + $products = $this->prepareProducts($products, $website); + if ($website) { + $this->setupCurrencyForCustomWebsite($website, $currencies[0]); + } + $this->adminExportIndex->open(); + + $exportData = $this->fixtureFactory->createByCode( + 'exportData', + [ + 'dataset' => $exportData, + 'data' => [ + 'data_export' => $products[0] + ] + ] + ); + $exportData->persist(); + if (!empty($advancedPricingAttributes)) { + $this->adminExportIndex->getExportForm()->prepareAttributeFields($advancedPricingAttributes['attributes']); + } + + $this->adminExportIndex->getExportForm()->fill($exportData); + $this->adminExportIndex->getFilterExport()->clickContinue(); + + if (!empty($advancedPricingAttributes)) { + $products = [$products[0]]; + } + + return [ + 'products' => $products + ]; + } + + /** + * Setup currency of custom website. + * + * @param $website + * @param $currency + * @return void + */ + private function setupCurrencyForCustomWebsite($website, $currency) + { + $configFixture = $this->fixtureFactory->createByCode( + 'configData', + [ + 'data' => [ + 'currency/options/allow' => [ + 'value' => $currency['allowedCurrencies'] + ], + 'currency/options/base' => [ + 'value' => $currency['baseCurrency'] + ], + 'currency/options/default' => [ + 'value' => $currency['defaultCurrency'] + ], + 'scope' => [ + 'fixture' => $website, + 'scope_type' => 'website', + 'website_id' => $website->getWebsiteId(), + 'set_level' => 'website', + ] + ] + ] + ); + $configFixture->persist(); + } + + /** + * Prepare products for test. + * + * @param array $products + * @param Website|null $website + * @return array|null + */ + public function prepareProducts($products, Website $website = null) + { + if (empty($products)) { + return; + } + $createdProducts = []; + foreach ($products as $product) { + $data = [ + 'website_ids' => [ + ['websites' => $website] + ] + ]; + if ($website) { + $data['tier_price'] = [ + 'data' => [ + 'website' => $website + ] + ]; + } + + if (isset($product['data'])) { + $data = array_merge($data, $product['data']); + } + + $product = $this->fixtureFactory->createByCode( + $product['fixture'], + [ + 'dataset' => $product['dataset'], + 'data' => $data + ] + ); + $product->persist(); + $createdProducts[] = $product; + } + + return $createdProducts; + } + + /** + * Revert settings to the default value. + * + * @return void + */ + public function tearDown() + { + if ($this->configData) { + $this->stepFactory->create( + \Magento\Config\Test\TestStep\SetupConfigurationStep::class, + ['configData' => 'config_currency_symbols_usd, price_scope_website_rollback'] + )->run(); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml similarity index 78% rename from dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml rename to dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml index 5c03efa28fb63..97670b9531aec 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml @@ -6,14 +6,13 @@ */ --> - + - Yes - csv_with_advanced_pricing - + csv_with_advanced_pricing + - csv_with_advanced_pricing + csv_with_advanced_pricing catalogProductSimple simple_with_tier_price @@ -25,10 +24,10 @@ tier_price_qty tier_price - + - csv_with_advanced_pricing + csv_with_advanced_pricing catalogProductSimple simple_with_tier_price @@ -38,8 +37,7 @@ simple_with_tier_price - 0 - sku + sku sku @@ -48,17 +46,17 @@ tier_price_qty tier_price - + MAGETWO-65703: Fatal error on creation simple product with tier price in custom website via webapi handler price_scope_website - csv_with_advanced_pricing + csv_with_advanced_pricing catalogProductSimple simple_with_tier_price - custom_store + custom_website @@ -79,7 +77,7 @@ tier_price_qty tier_price - + diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml index c1a5b559aa12f..291c0546f40b3 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml @@ -13,7 +13,7 @@ - + advancedPricing diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php index c3389954629dd..88eccf98a5c63 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php @@ -88,11 +88,7 @@ public function getData($key = null) } $this->data = $this->repositoryFactory->get($this->params['repository'])->get($this->fixtureData['dataset']); if (!empty($this->fixtureData['data']['website'])) { - $this->website = $this->fixtureData['data']['website']; - $this->fixtureData['data']['website'] = $this->website->getCode(); - foreach ($this->data as $key => $data) { - $this->data[$key] = array_merge($data, $this->fixtureData['data']); - } + $this->prepareWebsite(); } foreach ($this->data as $key => $item) { /** @var CustomerGroup $customerGroup */ @@ -110,6 +106,20 @@ public function getData($key = null) return parent::getData($key); } + /** + * Prepare website data. + * + * @return void + */ + private function prepareWebsite() + { + $this->website = $this->fixtureData['data']['website']; + $this->fixtureData['data']['website'] = $this->website->getCode(); + foreach ($this->data as $key => $data) { + $this->data[$key] = array_merge($data, $this->fixtureData['data']); + } + } + /** * Return customer group fixture. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php index f5429ad507048..a51cd59e18311 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php @@ -7,6 +7,8 @@ namespace Magento\ImportExport\Test\Block\Adminhtml\Export\Edit; use Magento\Mtf\Block\Form as AbstractForm; +use Magento\Mtf\Fixture\FixtureInterface; +use Magento\Mtf\Client\Element\SimpleElement; /** * Class Form @@ -14,5 +16,42 @@ */ class Form extends AbstractForm { - // + /** + * Attribute fields. + * + * @var array + */ + private $attributeFields = []; + + /** + * Form filling. + * + * @param FixtureInterface $fixture + * @param SimpleElement|null $element + * @return void + */ + public function fill(FixtureInterface $fixture, SimpleElement $element = null) + { + $data = $fixture->getData(); + $fields = isset($data['fields']) ? $data['fields'] : $data; + if ($this->attributeFields) { + foreach ($this->attributeFields as $field) { + $fields['product'] = [$field => $fixture->getDataExport()[$field]]; + } + } + unset($fields['data_export']); + $mapping = $this->dataMapping($fields); + parent::_fill($mapping, $element); + } + + /** + * Prepare attribute fields. + * + * @param string $attributes + * @return void + */ + public function prepareAttributeFields($attributes) + { + $this->attributeFields = explode(',', $attributes); + } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.xml index df5596b82831c..70f0ff070a766 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.xml @@ -13,5 +13,11 @@ select + + + input + [name="export_filter[sku]"] + + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php index 6ab437c290e80..1f3b4834f3903 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php @@ -42,17 +42,6 @@ class Filter extends Grid */ private $continueButton = 'button.action-.scalable'; - /** - * Return row with given attribute label. - * - * @param string $attributeLabel - * @return \Magento\Mtf\Client\Element\SimpleElement - */ - public function getGridRow($attributeLabel) - { - return $this->search(['frontend_label' => $attributeLabel]); - } - /** * Click on "Continue" button. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData.xml index afc223fa86b56..889ec6f53e5b2 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData.xml @@ -15,6 +15,6 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php new file mode 100644 index 0000000000000..ceff3734df864 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php @@ -0,0 +1,35 @@ +data = $data->getData(); + } + + /** + * Get export data. + * + * @return array + */ + public function getDataExport() + { + return $this->data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml index ec19686f578dd..a255e5ca731e4 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml @@ -8,7 +8,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php deleted file mode 100644 index 2f304f0313df0..0000000000000 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ /dev/null @@ -1,214 +0,0 @@ - Export. - * 3. Select Entity Type = Advanced Pricing. - * 4. Fill Entity Attributes data. - * 5. Click "Continue". - * 6. Verify exported *.csv file. - * - * @group ImportExport - * @ZephyrId MAGETWO-46147, MAGETWO-46120, MAGETWO-46152, MAGETWO-48298 - */ -class ExportAdvancedPricingTest extends Injectable -{ - /** - * Test step factory. - * - * @var TestStepFactory - */ - private $stepFactory; - - /** - * Fixture factory. - * - * @var FixtureFactory - */ - private $fixtureFactory; - - /** - * Admin export index page. - * - * @var AdminExportIndex - */ - private $adminExportIndex; - - /** - * Configuration data. - * - * @var string - */ - private $configData; - - /** - * Product page with a grid. - * - * @var CatalogProductIndex - */ - private $catalogProductIndex; - - /** - * Inject pages. - * - * @param TestStepFactory $stepFactory - * @param FixtureFactory $fixtureFactory - * @param AdminExportIndex $adminExportIndex - * @param CatalogProductIndex $catalogProductIndexPage - * @return void - */ - public function __inject( - TestStepFactory $stepFactory, - FixtureFactory $fixtureFactory, - AdminExportIndex $adminExportIndex, - CatalogProductIndex $catalogProductIndexPage - ) { - $this->stepFactory = $stepFactory; - $this->fixtureFactory = $fixtureFactory; - $this->adminExportIndex = $adminExportIndex; - $this->catalogProductIndex = $catalogProductIndexPage; - } - - /** - * Runs Export Advance Pricing test. - * - * @param array $exportData - * @param bool $deleteExistingProducts - * @param array $products - * @param string $configData - * @param Store $store - * @param array $advancedPricingAttributes - * @param array $currencies - * @return array - */ - public function test( - array $exportData, - $deleteExistingProducts = false, - array $products = [], - $configData = null, - Store $store = null, - array $advancedPricingAttributes = [], - array $currencies = [] - ) { - $this->configData = $configData; - - if ($this->configData != null) { - $this->stepFactory->create( - \Magento\Config\Test\TestStep\SetupConfigurationStep::class, - ['configData' => $configData] - )->run(); - } - - if ($deleteExistingProducts) { - $this->catalogProductIndex->open(); - $this->catalogProductIndex->getProductGrid()->removeAllProducts(); - } - - if ($store) { - $store->persist(); - } - - if (!empty($products)) { - $createdProducts = []; - foreach ($products as $product) { - $data = [ - 'website_ids' => [ - ['store' => $store] - ] - ]; - if ($store) { - $data['tier_price'] = [ - 'data' => [ - 'website' => $store->getDataFieldConfig('group_id')['source'] - ->getStoreGroup()->getDataFieldConfig('website_id')['source']->getWebsite() - ] - ]; - } - - $product = $this->fixtureFactory->createByCode( - $product['fixture'], - [ - 'dataset' => $product['dataset'], - 'data' => $data - ] - ); - $product->persist(); - $createdProducts[] = $product; - } - $products = $createdProducts; - } - - if ($store) { - $websites = $createdProducts[0]->getDataFieldConfig('website_ids')['source']->getWebsites(); - $configFixture = $this->fixtureFactory->createByCode( - 'configData', - [ - 'data' => [ - 'currency/options/allow' => [ - 'value' => $currencies[0]['allowedCurrencies'] - ], - 'currency/options/base' => [ - 'value' => $currencies[0]['baseCurrency'] - ], - 'currency/options/default' => [ - 'value' => $currencies[0]['defaultCurrency'] - ], - 'scope' => [ - 'fixture' => $websites[0], - 'scope_type' => 'website', - 'website_id' => $websites[0]->getWebsiteId(), - 'set_level' => 'website', - ] - ] - ] - ); - $configFixture->persist(); - } - $this->adminExportIndex->open(); - $exportData = $this->fixtureFactory->createByCode('exportData', ['dataset' => $exportData['dataset']]); - $this->adminExportIndex->getExportForm()->fill($exportData); - if (!empty($advancedPricingAttributes)) { - $this->adminExportIndex->getFilterExport()->setAttributeValue( - $advancedPricingAttributes['attribute'], - $createdProducts[$advancedPricingAttributes['product']] - ->getData($advancedPricingAttributes['attribute']) - ); - } - $this->adminExportIndex->getFilterExport()->clickContinue(); - - return [ - 'products' => $products - ]; - } - - /** - * Revert settings to the default value. - * - * @return void - */ - public function tearDown() - { - if ($this->configData) { - $this->stepFactory->create( - \Magento\Config\Test\TestStep\SetupConfigurationStep::class, - ['configData' => 'config_currency_symbols_usd, price_scope_website_rollback'] - )->run(); - } - } -} From 77effe67492020e8054e9d2b65d570c52106e4ac Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Tue, 14 Mar 2017 10:19:20 +0300 Subject: [PATCH 14/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../Test/TestCase/ExportAdvancedPricingTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php index 7f62ef572c9b4..1b80c83186b06 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -165,8 +165,8 @@ public function test( /** * Setup currency of custom website. * - * @param $website - * @param $currency + * @param Website $website + * @param array $currency * @return void */ private function setupCurrencyForCustomWebsite($website, $currency) From fca8a6a0f764096f720ae0fdda0d326c142f5ff7 Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Tue, 14 Mar 2017 11:27:51 +0300 Subject: [PATCH 15/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../Magento/ImportExport/Test/Fixture/ExportData/DataExport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php index ceff3734df864..81d75d6bd8b3b 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php @@ -18,7 +18,7 @@ class DataExport extends DataSource * @constructor * @param InjectableFixture $data */ - public function __construct($data) + public function __construct(InjectableFixture $data) { $this->data = $data->getData(); } From c8dfca1f91c9e037090f5684b5762b654c621187 Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Tue, 14 Mar 2017 12:43:24 +0300 Subject: [PATCH 16/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../AssertExportAdvancedPricing.php | 6 ++--- .../TestCase/ExportAdvancedPricingTest.php | 11 +++----- .../TestCase/ExportAdvancedPricingTest.xml | 2 +- .../Test/Fixture/Product/TierPrice.php | 15 ++++++++++- .../Test/Block/Adminhtml/Export/Edit/Form.php | 27 ++++--------------- 5 files changed, 26 insertions(+), 35 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php index 9d35b86def9df..c860d27deb3ae 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricing.php @@ -7,7 +7,7 @@ use Magento\Mtf\Constraint\AbstractConstraint; use Magento\Mtf\Fixture\InjectableFixture; -use Magento\Mtf\Util\Command\File\Export; +use Magento\Mtf\Util\Command\File\ExportInterface; /** * Assert that exported file with advanced pricing options contains product data. @@ -24,13 +24,13 @@ class AssertExportAdvancedPricing extends AbstractConstraint /** * Assert that exported file with advanced pricing options contains product data. * - * @param Export $export + * @param ExportInterface $export * @param array $products * @param array $exportedFields * @return void */ public function processAssert( - Export $export, + ExportInterface $export, array $products, array $exportedFields ) { diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php index 1b80c83186b06..cbbcd67d26ffd 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -129,11 +129,9 @@ public function test( if ($website) { $website->persist(); - } - $products = $this->prepareProducts($products, $website); - if ($website) { $this->setupCurrencyForCustomWebsite($website, $currencies[0]); } + $products = $this->prepareProducts($products, $website); $this->adminExportIndex->open(); $exportData = $this->fixtureFactory->createByCode( @@ -146,11 +144,8 @@ public function test( ] ); $exportData->persist(); - if (!empty($advancedPricingAttributes)) { - $this->adminExportIndex->getExportForm()->prepareAttributeFields($advancedPricingAttributes['attributes']); - } - $this->adminExportIndex->getExportForm()->fill($exportData); + $this->adminExportIndex->getExportForm()->fill($exportData, null, $advancedPricingAttributes); $this->adminExportIndex->getFilterExport()->clickContinue(); if (!empty($advancedPricingAttributes)) { @@ -203,7 +198,7 @@ private function setupCurrencyForCustomWebsite($website, $currency) * @param Website|null $website * @return array|null */ - public function prepareProducts($products, Website $website = null) + public function prepareProducts(array $products, Website $website = null) { if (empty($products)) { return; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml index 97670b9531aec..6c4c94b5e2efc 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml @@ -37,7 +37,7 @@ simple_with_tier_price - sku + sku sku diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php index 88eccf98a5c63..7590c90451bd1 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php @@ -10,6 +10,7 @@ use Magento\Mtf\Fixture\FixtureFactory; use Magento\Customer\Test\Fixture\CustomerGroup; use Magento\Mtf\Repository\RepositoryFactory; +use Magento\Store\Test\Fixture\Website; /** * TierPrice data source. @@ -113,7 +114,19 @@ public function getData($key = null) */ private function prepareWebsite() { - $this->website = $this->fixtureData['data']['website']; + if (!$this->fixtureData['data']['website'] instanceof Website) { + if (!empty($this->fixtureData['data']['website']['dataset'])) { + /** @var Website $website */ + $this->website = $this->fixtureFactory->createByCode( + 'website', + ['dataset' => $this->fixtureData['data']['website']['dataset']] + ); + $this->website->persist(); + } + } else { + $this->website = $this->fixtureData['data']['website']; + } + $this->fixtureData['data']['website'] = $this->website->getCode(); foreach ($this->data as $key => $data) { $this->data[$key] = array_merge($data, $this->fixtureData['data']); diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php index a51cd59e18311..e875effb07283 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Edit/Form.php @@ -16,42 +16,25 @@ */ class Form extends AbstractForm { - /** - * Attribute fields. - * - * @var array - */ - private $attributeFields = []; - /** * Form filling. * * @param FixtureInterface $fixture * @param SimpleElement|null $element + * @param array $attributes * @return void */ - public function fill(FixtureInterface $fixture, SimpleElement $element = null) + public function fill(FixtureInterface $fixture, SimpleElement $element = null, $attributes = []) { $data = $fixture->getData(); $fields = isset($data['fields']) ? $data['fields'] : $data; - if ($this->attributeFields) { - foreach ($this->attributeFields as $field) { - $fields['product'] = [$field => $fixture->getDataExport()[$field]]; + if (!empty($attributes)) { + foreach ($attributes as $attribute) { + $fields['product'] = [$attribute => $fixture->getDataExport()[$attribute]]; } } unset($fields['data_export']); $mapping = $this->dataMapping($fields); parent::_fill($mapping, $element); } - - /** - * Prepare attribute fields. - * - * @param string $attributes - * @return void - */ - public function prepareAttributeFields($attributes) - { - $this->attributeFields = explode(',', $attributes); - } } From d06cfb1e95a780d26feaba3f3abe9c9d01df709c Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Tue, 14 Mar 2017 15:03:14 +0300 Subject: [PATCH 17/29] MTO-138: [Test] Export Advanced Pricing - Defects fixed --- .../Catalog/Test/Fixture/Product/TierPrice.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php index 7590c90451bd1..0163cfcb47edc 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php @@ -114,15 +114,13 @@ public function getData($key = null) */ private function prepareWebsite() { - if (!$this->fixtureData['data']['website'] instanceof Website) { - if (!empty($this->fixtureData['data']['website']['dataset'])) { - /** @var Website $website */ - $this->website = $this->fixtureFactory->createByCode( - 'website', - ['dataset' => $this->fixtureData['data']['website']['dataset']] - ); - $this->website->persist(); - } + if (isset($this->fixtureData['data']['website']['dataset'])) { + /** @var Website $website */ + $this->website = $this->fixtureFactory->createByCode( + 'website', + ['dataset' => $this->fixtureData['data']['website']['dataset']] + ); + $this->website->persist(); } else { $this->website = $this->fixtureData['data']['website']; } From a06b2693724f5c95f38e079d0aa118b586013dc5 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Tue, 14 Mar 2017 16:06:32 +0300 Subject: [PATCH 18/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Test/TestCase/ImportDataNegativeTest.xml | 2 +- .../Test/TestCase/ImportDataTest.xml | 4 ++ .../Test/Block/Adminhtml/Import/Messages.php | 32 ++++++++++ .../Test/TestStep/CheckResultMessageStep.php | 61 +++++++++++++++++++ .../Test/TestStep/ClickCheckDataStep.php | 23 +------ .../Test/TestStep/FillImportFormStep.php | 3 +- .../ImportExport/Test/etc/testcase.xml | 3 +- 7 files changed, 103 insertions(+), 25 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml index f103c0cbd3dbd..35ec6e5c33327 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml @@ -23,7 +23,7 @@ , , - + catalogProductSimple::default diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index a354f09204db4..efaf17ba99cda 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -8,6 +8,7 @@ + MAGETWO-66134: [Export/Import] Advanced Pricing import works incorrect Advanced Pricing Add/Update @@ -29,6 +30,7 @@ + MAGETWO-66134: [Export/Import] Advanced Pricing import works incorrect Advanced Pricing Replace @@ -50,6 +52,7 @@ + MAGETWO-66134: [Export/Import] Advanced Pricing import works incorrect Advanced Pricing Delete @@ -71,6 +74,7 @@ + MAGETWO-66134: [Export/Import] Advanced Pricing import works incorrect true Advanced Pricing diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php index e1adb91b6a8e3..00e18bc31967b 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Import/Messages.php @@ -10,6 +10,20 @@ */ class Messages extends \Magento\Backend\Test\Block\Messages { + /** + * CSS selector for error message block. + * + * @var string + */ + protected $errorMessage = '.message-error'; + + /** + * CSS selector for validation errors list block. + * + * @var string + */ + private $validationErrorList = '.import-error-list'; + /** * CSS selector for import message. * @@ -24,6 +38,24 @@ class Messages extends \Magento\Backend\Test\Block\Messages */ private $loader = '[data-role="loader"]'; + /** + * Get errors messages list. + * + * @return array|false + */ + public function getErrorsList() + { + $element = $this->_rootElement->find($this->validationErrorList); + + if (!$element->isVisible()) { + return false; + } + + $text = $this->_rootElement->find($this->validationErrorList)->getText(); + + return (array) explode(PHP_EOL, strip_tags($text)); + } + /** * Get error message. * diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php new file mode 100644 index 0000000000000..2af2db178a2f5 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php @@ -0,0 +1,61 @@ +adminImportIndex = $adminImportIndex; + $this->assert = $assert; + $this->import = $import; + } + + /** + * Click "Import" button. + * + * @return void + */ + public function run() + { + $this->assert->processAssert($this->adminImportIndex, $this->import); + } +} diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php index 497e332908a16..614a7c6b7380b 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ClickCheckDataStep.php @@ -5,10 +5,8 @@ */ namespace Magento\ImportExport\Test\TestStep; -use Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportAdvancedPricingCheckData as AssertImportCheckData; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\TestStep\TestStepInterface; -use Magento\ImportExport\Test\Fixture\ImportData; /** * Click "Check Data" button. @@ -22,30 +20,12 @@ class ClickCheckDataStep implements TestStepInterface */ private $adminImportIndex; - /** - * Assert that validation result message is correct. - * - * @var AssertImportCheckData - */ - private $assert; - - /** - * Import fixture. - * - * @var ImportData - */ - private $import; - /** * @param AdminImportIndex $adminImportIndex - * @param AssertImportCheckData $assert - * @param ImportData $import */ - public function __construct(AdminImportIndex $adminImportIndex, AssertImportCheckData $assert, ImportData $import) + public function __construct(AdminImportIndex $adminImportIndex) { $this->adminImportIndex = $adminImportIndex; - $this->assert = $assert; - $this->import = $import; } /** @@ -56,6 +36,5 @@ public function __construct(AdminImportIndex $adminImportIndex, AssertImportChec public function run() { $this->adminImportIndex->getFormPageActions()->clickCheckData(); - $this->assert->processAssert($this->adminImportIndex, $this->import); } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 0dd920990fa1b..eaf30747abcab 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -68,7 +68,8 @@ public function run() return [ 'entities' => $file->getEntities(), - 'import' => $this->import + 'import' => $this->import, + 'products' => $file->getEntities() ]; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml index 1ed45487fc64e..9cfb99d99fc96 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml @@ -15,7 +15,8 @@ - + + From 68132e9ed97b9aaaf27caf7e2d4c7d12e878f50d Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Tue, 14 Mar 2017 18:27:58 +0300 Subject: [PATCH 19/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index e6fc1ce185466..03b9465edfbc3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -455,6 +455,7 @@ protected function prepareWebsitesData() foreach ($this->fixture->getDataFieldConfig('website_ids')['source']->getWebsites() as $key => $website) { $this->fields['product']['website_ids'][$key] = $website->getWebsiteId(); } + } else { $this->fields['product']['website_ids'][] = 1; } } From 719b7ddfc149f672ab8e2f034d954760fd8601db Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Wed, 15 Mar 2017 15:00:39 +0300 Subject: [PATCH 20/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../app/Magento/ImportExport/Test/Fixture/Import/File.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 3e62ee99dc2fa..db0e5818f0543 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -23,7 +23,7 @@ class File extends DataSource * @var array */ private $codeMapping =[ - 'base' => 'Main Website[USD]' + 'base' => 'Main Website' ]; /** @@ -243,6 +243,9 @@ public function convertCsvToArray($csvContent) $csvContent = strtr($csvContent, $data); } } + $this->codeMapping['base'] .= (isset($this->value['template']['mainWebsiteCurrency'])) + ? "[{$this->value['template']['mainWebsiteCurrency']}]" + : '[USD]'; $csvContent = strtr($csvContent, $this->codeMapping); $this->csv = array_map( function ($value) { From 661cd36382e88a4c5326011f4826672746b3b4b1 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Wed, 15 Mar 2017 16:12:37 +0300 Subject: [PATCH 21/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- dev/tests/functional/etc/di.xml | 6 -- .../AssertImportAdvancedPricing.php | 12 --- .../Test/Repository/ExportData.xml | 15 ++++ .../TestCase/ExportAdvancedPricingTest.php | 7 +- .../TestCase/ExportAdvancedPricingTest.xml | 2 +- .../Test/TestCase/ImportDataTest.xml | 4 +- .../template/pricing/advanced_incorrect.php | 20 ++--- .../pricing/advanced_price_variation_1.php | 37 ++++---- .../pricing/advanced_price_variation_2.php | 20 ++--- .../pricing/advanced_price_variation_3.php | 20 ++--- .../pricing/advanced_price_variation_4.php | 38 ++++---- .../Test/etc/di.xml | 6 ++ .../Test/Block/Adminhtml/Export/Filter.php | 19 ---- .../AssertExportNoDataErrorMessage.php} | 8 +- .../Constraint/AssertImportCheckData.php} | 4 +- .../Constraint/AssertImportSuccessMessage.php | 4 +- .../Test/Fixture/ExportData/DataExport.php | 1 - .../ImportExport/Test/Fixture/Import/File.php | 8 +- .../Test/Repository/ExportData.xml | 5 -- .../ChangeCurrencyOnCustomWebsiteStep.php | 87 ++++++++----------- .../Test/TestStep/CheckResultMessageStep.php | 4 +- .../Test/TestStep/FillImportFormStep.php | 15 +--- .../ImportExport/Test/etc/testcase.xml | 6 +- 23 files changed, 146 insertions(+), 202 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Repository/ExportData.xml rename dev/tests/functional/tests/app/Magento/{AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php => ImportExport/Test/Constraint/AssertExportNoDataErrorMessage.php} (78%) rename dev/tests/functional/tests/app/Magento/{AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php => ImportExport/Test/Constraint/AssertImportCheckData.php} (91%) rename dev/tests/functional/tests/app/Magento/{AdvancedPricingImportExport => ImportExport}/Test/Constraint/AssertImportSuccessMessage.php (91%) diff --git a/dev/tests/functional/etc/di.xml b/dev/tests/functional/etc/di.xml index 70335b2c76044..9af1fd3ee8ba6 100644 --- a/dev/tests/functional/etc/di.xml +++ b/dev/tests/functional/etc/di.xml @@ -110,12 +110,6 @@ - - - advanced_pricing.*?\.csv - - - customer.*?\.csv diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index 2c1c29fe6bbba..e9a112d4ebd94 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -9,7 +9,6 @@ use Magento\Mtf\Constraint\AbstractConstraint; use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit; use Magento\ImportExport\Test\Fixture\ImportData; -use Magento\Mtf\Fixture\FixtureFactory; /** * Check imported advanced prices are correct. @@ -37,13 +36,6 @@ class AssertImportAdvancedPricing extends AbstractConstraint */ private $catalogProductEdit; - /** - * Fixture factory. - * - * @var FixtureFactory - */ - private $fixtureFactory; - /** * Import fixture. * @@ -55,17 +47,14 @@ class AssertImportAdvancedPricing extends AbstractConstraint * Assert imported advanced prices are correct. * * @param CatalogProductEdit $catalogProductEdit - * @param FixtureFactory $fixtureFactory * @param ImportData $import * @return void */ public function processAssert( CatalogProductEdit $catalogProductEdit, - FixtureFactory $fixtureFactory, ImportData $import ) { $this->catalogProductEdit = $catalogProductEdit; - $this->fixtureFactory = $fixtureFactory; $this->import = $import; $resultArrays = $this->getPreparePrices(); @@ -93,7 +82,6 @@ private function getPreparePrices() $advancedPricing = $this->catalogProductEdit->getProductForm()->openSection('advanced-pricing') ->getSection('advanced-pricing'); $tierPrices = $advancedPricing->getTierPriceForm()->getFieldsData(); - $productSku = $product->getSku(); foreach ($tierPrices as $tierPrice) { $resultProductArray[$productSku][] = $tierPrice; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Repository/ExportData.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Repository/ExportData.xml new file mode 100644 index 0000000000000..2023c77c96bca --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Repository/ExportData.xml @@ -0,0 +1,15 @@ + + + + + + Advanced Pricing + CSV + + + diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php index cbbcd67d26ffd..90446ae298b7f 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -7,7 +7,6 @@ use Magento\ImportExport\Test\Page\Adminhtml\AdminExportIndex; use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex; -use Magento\ImportExport\Test\Fixture\ExportData; use Magento\Mtf\TestStep\TestStepFactory; use Magento\Mtf\Fixture\FixtureFactory; use Magento\Store\Test\Fixture\Website; @@ -75,7 +74,7 @@ public function __prepare( CatalogProductIndex $catalogProductIndex ) { $catalogProductIndex->open(); - $catalogProductIndex->getProductGrid()->removeAllProducts(); + $catalogProductIndex->getProductGrid()->massaction([], 'Delete', true, 'Select All'); } /** @@ -100,7 +99,7 @@ public function __inject( } /** - * Runs Export Advance Pricing test. + * Runs Export Advanced Pricing test. * * @param string $exportData * @param array $products @@ -201,7 +200,7 @@ private function setupCurrencyForCustomWebsite($website, $currency) public function prepareProducts(array $products, Website $website = null) { if (empty($products)) { - return; + return null; } $createdProducts = []; foreach ($products as $product) { diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml index 6c4c94b5e2efc..60f320d46baba 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml @@ -9,7 +9,7 @@ csv_with_advanced_pricing - + csv_with_advanced_pricing diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index efaf17ba99cda..129622f930f83 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -76,6 +76,8 @@ MAGETWO-66134: [Export/Import] Advanced Pricing import works incorrect true + price_scope_website + true Advanced Pricing Replace @@ -94,7 +96,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php index d4994257d43e7..c3e4bf6a96349 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php @@ -5,16 +5,14 @@ */ return [ - 'entity_0' => - [ - 'data_0' => - [ - 'sku' => '%sku%', - 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '3', - 'tier_price' => 'text', - 'tier_price_value_type' => 'Fixed', - ], + 'entity_0' => [ + 'data_0' => [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '3', + 'tier_price' => 'text', + 'tier_price_value_type' => 'Fixed', ], + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php index 1469d211d62f7..dc95a8b87c7c6 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php @@ -5,25 +5,22 @@ */ return [ - 'entity_0' => - [ - 'data_0' => - [ - 'sku' => '%sku%', - 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => 'General', - 'tier_price_qty' => '10', - 'tier_price' => '8.00', - 'tier_price_value_type' => 'Fixed', - ], - 'data_1' => - [ - 'sku' => '%sku%', - 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => "NOT LOGGED IN", - 'tier_price_qty' => '10', - 'tier_price' => '9.00', - 'tier_price_value_type' => 'Fixed', - ] + 'entity_0' => [ + 'data_0' => [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'General', + 'tier_price_qty' => '10', + 'tier_price' => '8.00', + 'tier_price_value_type' => 'Fixed', ], + 'data_1' => [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => "NOT LOGGED IN", + 'tier_price_qty' => '10', + 'tier_price' => '9.00', + 'tier_price_value_type' => 'Fixed', + ] + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php index 330e50a3b0ea5..7beecb51ce67b 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_2.php @@ -5,16 +5,14 @@ */ return [ - 'entity_0' => - [ - 'data_0' => - [ - 'sku' => '%sku%', - 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '10', - 'tier_price' => '8.00', - 'tier_price_value_type' => 'Fixed', - ], + 'entity_0' => [ + 'data_0' => [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '10', + 'tier_price' => '8.00', + 'tier_price_value_type' => 'Fixed', ], + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php index 811b6d3fe12aa..0eed8d1081d9f 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_3.php @@ -5,16 +5,14 @@ */ return [ - 'entity_0' => - [ - 'data_0' => - [ - 'sku' => '%sku%', - 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '95', - 'tier_price' => '5.00', - 'tier_price_value_type' => 'Fixed', - ], + 'entity_0' => [ + 'data_0' => [ + 'sku' => '%sku%', + 'tier_price_website' => "All Websites [USD]", + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', ], + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php index ebc27650a110d..b7cd648ea4af7 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4.php @@ -5,25 +5,23 @@ */ return [ - 'entity_0' => - [ - 'data_0' => - [ - 'sku' => '%sku%', - 'tier_price_website' => '%code%', - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '95', - 'tier_price' => '5.00', - 'tier_price_value_type' => 'Fixed', - ], - 'data_1' => - [ - 'sku' => '%sku%', - 'tier_price_website' => 'base', - 'tier_price_customer_group' => 'ALL GROUPS', - 'tier_price_qty' => '95', - 'tier_price' => '5.00', - 'tier_price_value_type' => 'Fixed', - ], + 'entity_0' => [ + 'data_0' => [ + 'sku' => '%sku%', + 'tier_price_website' => 'base', + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', + + ], + 'data_1' => [ + 'sku' => '%sku%', + 'tier_price_website' => '%code%', + 'tier_price_customer_group' => 'ALL GROUPS', + 'tier_price_qty' => '95', + 'tier_price' => '5.00', + 'tier_price_value_type' => 'Fixed', ], + ], ]; diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml index 291c0546f40b3..70f5200bfdb80 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml @@ -18,4 +18,10 @@ advancedPricing + + + + advanced_pricing.*?\.csv + + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php index 1f3b4834f3903..3e53fca98e8be 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Block/Adminhtml/Export/Filter.php @@ -28,13 +28,6 @@ class Filter extends Grid ], ]; - /** - * Locator for export attribute. - * - * @var string - */ - private $attribute = '[name="export_filter[%s]"]'; - /** * Locator for "Continue" button. * @@ -51,16 +44,4 @@ public function clickContinue() { $this->_rootElement->find($this->continueButton)->click(); } - - /** - * Set attribute entity value. - * - * @param string $attribute - * @param string $value - * @return void - */ - public function setAttributeValue($attribute, $value) - { - $this->_rootElement->find(sprintf($this->attribute, $attribute))->setValue($value); - } } diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportNoDataErrorMessage.php similarity index 78% rename from dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php rename to dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportNoDataErrorMessage.php index 4119624dbc098..6f23d0d868359 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertExportAdvancedPricingNoDataErrorMessage.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertExportNoDataErrorMessage.php @@ -3,15 +3,15 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\AdvancedPricingImportExport\Test\Constraint; +namespace Magento\ImportExport\Test\Constraint; use Magento\ImportExport\Test\Page\Adminhtml\AdminExportIndex; use Magento\Mtf\Constraint\AbstractConstraint; /** - * Assert that error message is visible after exporting with advanced pricing option without entity attributes data. + * Assert that error message is visible after exporting without entity attributes data. */ -class AssertExportAdvancedPricingNoDataErrorMessage extends AbstractConstraint +class AssertExportNoDataErrorMessage extends AbstractConstraint { /** * Text value to be checked. @@ -19,7 +19,7 @@ class AssertExportAdvancedPricingNoDataErrorMessage extends AbstractConstraint const ERROR_MESSAGE = 'There is no data for the export.'; /** - * Assert that error message is visible after exporting with advanced pricing option without entity attributes data. + * Assert that error message is visible after exporting without entity attributes data. * * @param AdminExportIndex $adminExportIndex * @return void diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckData.php similarity index 91% rename from dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php rename to dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckData.php index 9b0fd92bf24b5..73e2f959deb80 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricingCheckData.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckData.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\AdvancedPricingImportExport\Test\Constraint; +namespace Magento\ImportExport\Test\Constraint; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\Constraint\AbstractConstraint; @@ -13,7 +13,7 @@ /** * Check message after check data click. */ -class AssertImportAdvancedPricingCheckData extends AbstractConstraint +class AssertImportCheckData extends AbstractConstraint { /** * Success validation result message. diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportSuccessMessage.php similarity index 91% rename from dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php rename to dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportSuccessMessage.php index 149bea72564eb..120cd8e275be8 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportSuccessMessage.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportSuccessMessage.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\AdvancedPricingImportExport\Test\Constraint; +namespace Magento\ImportExport\Test\Constraint; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\Constraint\AbstractConstraint; @@ -44,6 +44,6 @@ public function processAssert(AdminImportIndex $adminImportIndex) */ public function toString() { - return 'Displayed import result is correct.'; + return 'Displayed import success message is correct.'; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php index 81d75d6bd8b3b..37104adc31bed 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/ExportData/DataExport.php @@ -15,7 +15,6 @@ class DataExport extends DataSource { /** - * @constructor * @param InjectableFixture $data */ public function __construct(InjectableFixture $data) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index db0e5818f0543..8a827d6a501d0 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -177,7 +177,7 @@ public function getValue() } /** - * Create products from configuration of variation. + * Create entities from configuration of variation. * * @return FixtureInterface[] */ @@ -187,7 +187,7 @@ private function createEntities() foreach ($this->value['entities'] as $key => $entityDataSet) { list($fixtureCode, $dataset) = explode('::', $entityDataSet); - /** @var FixtureInterface[] $products */ + /** @var FixtureInterface[] $entities */ $entities[$key] = $this->fixtureFactory->createByCode(trim($fixtureCode), ['dataset' => trim($dataset)]); if ($entities[$key]->hasData('id') === false) { $entities[$key]->persist(); @@ -198,9 +198,9 @@ private function createEntities() } /** - * Create placeholders for products. + * Create placeholders for entities. * - * @return array + * @return void */ private function preparePlaceHolders() { diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml index 0e3882d97b6ec..29ab7c7d95976 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Repository/ExportData.xml @@ -11,10 +11,5 @@ Products CSV - - - Advanced Pricing - CSV - diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php index d71050a6f467d..28a576ae7ab02 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php @@ -7,7 +7,6 @@ use Magento\ImportExport\Test\Fixture\ImportData; use Magento\Mtf\TestStep\TestStepInterface; -use Magento\Mtf\TestStep\TestStepFactory; use Magento\Mtf\Fixture\FixtureFactory; /** @@ -15,13 +14,6 @@ */ class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface { - /** - * Factory for Test Steps. - * - * @var TestStepFactory - */ - private $stepFactory; - /** * Fixture factory. * @@ -30,35 +22,32 @@ class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface private $fixtureFactory; /** - * Currency. + * Import fixture. * - * @var string + * @var ImportData */ - private $currency; + private $import; /** - * Import fixture. + * Change currency flag. * - * @var ImportData + * @var bool */ - private $import; + private $changeCurrency; /** - * @param TestStepFactory $stepFactory * @param FixtureFactory $fixtureFactory * @param ImportData $import - * @param string $currency + * @param bool|null $changeCurrency */ public function __construct( - TestStepFactory $stepFactory, FixtureFactory $fixtureFactory, ImportData $import, - $currency = 'USD' + $changeCurrency ) { - $this->stepFactory = $stepFactory; $this->fixtureFactory = $fixtureFactory; $this->import = $import; - $this->currency = $currency; + $this->changeCurrency = $changeCurrency; } /** @@ -68,38 +57,36 @@ public function __construct( */ public function run() { - $this->stepFactory->create( - \Magento\Config\Test\TestStep\SetupConfigurationStep::class, - ['configData' => 'price_scope_website'] - )->run(); - - $products = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); - foreach ($products as $product) { - $websites = $product->getDataFieldConfig('website_ids')['source']->getWebsites(); - - $configFixture = $this->fixtureFactory->createByCode( - 'configData', - [ - 'data' => [ - 'currency/options/allow' => [ - 'value' => [$this->currency] - ], - 'currency/options/base' => [ - 'value' => $this->currency - ], - 'currency/options/default' => [ - 'value' => $this->currency - ], - 'scope' => [ - 'fixture' => $websites[0], - 'scope_type' => 'website', - 'website_id' => $websites[0]->getWebsiteId(), - 'set_level' => 'website', + if ($this->changeCurrency === true) { + $currency = $this->import->getDataFieldConfig('import_file')['source'] + ->getValue()['template']['websiteCurrency']; + $entities = $this->import->getDataFieldConfig('import_file')['source']->getEntities(); + foreach ($entities as $entity) { + $websites = $entity->getDataFieldConfig('website_ids')['source']->getWebsites(); + $configFixture = $this->fixtureFactory->createByCode( + 'configData', + [ + 'data' => [ + 'currency/options/allow' => [ + 'value' => [$currency] + ], + 'currency/options/base' => [ + 'value' => $currency + ], + 'currency/options/default' => [ + 'value' => $currency + ], + 'scope' => [ + 'fixture' => $websites[0], + 'scope_type' => 'website', + 'website_id' => $websites[0]->getWebsiteId(), + 'set_level' => 'website', + ] ] ] - ] - ); - $configFixture->persist(); + ); + $configFixture->persist(); + } } } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php index 2af2db178a2f5..bf9a1c829e60c 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php @@ -6,7 +6,7 @@ namespace Magento\ImportExport\Test\TestStep; -use Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportAdvancedPricingCheckData as AssertImportCheckData; +use Magento\ImportExport\Test\Constraint\AssertImportCheckData; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\ImportExport\Test\Fixture\ImportData; use Magento\Mtf\TestStep\TestStepInterface; @@ -56,6 +56,6 @@ public function __construct(AdminImportIndex $adminImportIndex, AssertImportChec */ public function run() { - $this->assert->processAssert($this->adminImportIndex, $this->import); + //$this->assert->processAssert($this->adminImportIndex, $this->import); } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index eaf30747abcab..7d09dfefdd122 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -9,7 +9,6 @@ use Magento\ImportExport\Test\Fixture\ImportData; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\TestStep\TestStepInterface; -use Magento\Mtf\TestStep\TestStepFactory; /** * Fill import form. @@ -33,25 +32,13 @@ class FillImportFormStep implements TestStepInterface /** * @param AdminImportIndex $adminImportIndex * @param ImportData $import - * @param TestStepFactory $stepFactory - * @param bool|null $changeCurrency */ public function __construct( AdminImportIndex $adminImportIndex, - ImportData $import, - TestStepFactory $stepFactory, - $changeCurrency = false + ImportData $import ) { $this->adminImportIndex = $adminImportIndex; $this->import = $import; - - if ($changeCurrency === true) { - $currency = $import->getDataFieldConfig('import_file')['source']->getValue()['template']['websiteCurrency']; - $stepFactory->create( - ChangeCurrencyOnCustomWebsiteStep::class, - ['import' => $this->import, 'currency' => $currency] - )->run(); - } } /** diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml index 9cfb99d99fc96..82c908966bf9a 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/etc/testcase.xml @@ -13,10 +13,12 @@ + + - - + + From dc6fb94e36439d855f1fa5b9ba12e83095483963 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Wed, 15 Mar 2017 16:56:30 +0300 Subject: [PATCH 22/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../AssertImportAdvancedPricing.php | 2 +- .../Test/Block/Adminhtml/Product/Grid.php | 21 ------------------- .../Test/TestStep/CheckResultMessageStep.php | 2 +- 3 files changed, 2 insertions(+), 23 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index e9a112d4ebd94..1ecf9978ce861 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -87,7 +87,7 @@ private function getPreparePrices() $resultProductArray[$productSku][] = $tierPrice; } if (isset($resultProductArray[$productSku])) { - $resultProductArray[$productSku]= array_reverse($resultProductArray[$productSku]); + $resultProductArray[$productSku] = array_reverse($resultProductArray[$productSku]); } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php index f80b924a2cf86..668d8bbe9fbeb 100755 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php @@ -96,25 +96,4 @@ public function getBaseImageSource() $baseImage = $this->_rootElement->find($this->baseImage); return $baseImage->isVisible() ? $baseImage->getAttribute('src') : ''; } - - /** - * Remove all previously created products. - * - * @return void - */ - public function removeAllProducts() - { - $this->waitLoader(); - if ($this->browser->find($this->noRecords)->isVisible()) { - return; - } - $this->selectMassAction('Select All'); - $this->selectAction('Delete'); - $element = $this->browser->find($this->alertModal); - $modal = $this->blockFactory->create( - \Magento\Ui\Test\Block\Adminhtml\Modal::class, - ['element' => $element] - ); - $modal->acceptAlert(); - } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php index bf9a1c829e60c..0368f2a1040e8 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/CheckResultMessageStep.php @@ -56,6 +56,6 @@ public function __construct(AdminImportIndex $adminImportIndex, AssertImportChec */ public function run() { - //$this->assert->processAssert($this->adminImportIndex, $this->import); + $this->assert->processAssert($this->adminImportIndex, $this->import); } } From 695a470f6b6980dd1d472d8cad3db6038ec691e2 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Wed, 15 Mar 2017 17:34:19 +0300 Subject: [PATCH 23/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php index 03b9465edfbc3..3a03db6df0b13 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Handler/CatalogProductSimple/Curl.php @@ -455,8 +455,6 @@ protected function prepareWebsitesData() foreach ($this->fixture->getDataFieldConfig('website_ids')['source']->getWebsites() as $key => $website) { $this->fields['product']['website_ids'][$key] = $website->getWebsiteId(); } - } else { - $this->fields['product']['website_ids'][] = 1; } } From c83afc39de620919a577d716c826e8236209ac87 Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Wed, 15 Mar 2017 18:56:51 +0300 Subject: [PATCH 24/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Test/TestCase/ImportDataTest.xml | 3 +- .../Test/Repository/CatalogProductSimple.xml | 33 +++++++++++++ .../ImportExport/Test/Fixture/Import/File.php | 46 ++++++++++++------- 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index 129622f930f83..18d15004a9aac 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -87,12 +87,13 @@ , - catalogProductSimple::default_in_custom_website + catalogProductSimple::default_in_custom_website_and_main_website Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_4 2 EUR + USD diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml index 289d67cddbd68..7fe4e96da557e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml @@ -1874,6 +1874,39 @@ + + + default + + Simple Product %isolation% + sku_simple_product_%isolation% + This item has weight + 1 + + 25 + In Stock + + + 560 + + + taxable_goods + + + + custom_store + + + custom_group_custom_store + + + Catalog, Search + simple-product-%isolation% + + simple_order_default + + + simple_product_with_category_%isolation% Simple product with category %isolation% diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 8a827d6a501d0..4e4ca7c467100 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -22,9 +22,7 @@ class File extends DataSource * * @var array */ - private $codeMapping =[ - 'base' => 'Main Website' - ]; + private $mainWebsiteMapping; /** * Fixture data. @@ -207,29 +205,48 @@ private function preparePlaceHolders() $placeholders = []; $key = 0; foreach ($this->entities as $entity) { - $currency = (isset($this->value['template']['websiteCurrency'])) - ? "[{$this->value['template']['websiteCurrency']}]" - : '[USD]'; - $website = $entity->getDataFieldConfig('website_ids')['source']->getWebsites()[0]; - $entityData = $entity->getData(); - $entityData['code'] = $website->getCode(); + $entityData = $this->prepareEntityData($entity); foreach ($this->csvTemplate['entity_' . $key] as $tierKey => $tier) { $values = implode('', array_values($tier)); preg_match_all('/\%(.*)\%/U', $values, $indexes); - foreach ($indexes[1] as $index) { if (isset($entityData[$index])) { $placeholders['entity_' . $key][$tierKey]["%{$index}%"] = $entityData[$index]; } - $placeholders['entity_' . $key][$tierKey][$entityData['code']] = $website->getName() . $currency; + $placeholders['entity_' . $key][$tierKey][$entityData['code']] = $entityData[$entityData['code']]; } } - $key++; } $this->placeholders = $placeholders; } + /** + * Prepare entity data. + * + * @param FixtureInterface $entity + * @return array + */ + public function prepareEntityData(FixtureInterface $entity) + { + $currency = (isset($this->value['template']['websiteCurrency'])) + ? "[{$this->value['template']['websiteCurrency']}]" + : '[USD]'; + $entityData = $entity->getData(); + + $websites = $entity->getDataFieldConfig('website_ids')['source']->getWebsites(); + foreach ($websites as $website) { + if ($website->getCode() === 'base') { + $currency = $this->value['template']['mainWebsiteCurrency']; + $this->mainWebsiteMapping['base'] = $website->getName() . "[{$currency}]"; + break; + } + $entityData['code'] = $website->getCode(); + $entityData[$website->getCode()] = $website->getName() . $currency; + } + return $entityData; + } + /** * Convert csv to array. * @@ -243,10 +260,7 @@ public function convertCsvToArray($csvContent) $csvContent = strtr($csvContent, $data); } } - $this->codeMapping['base'] .= (isset($this->value['template']['mainWebsiteCurrency'])) - ? "[{$this->value['template']['mainWebsiteCurrency']}]" - : '[USD]'; - $csvContent = strtr($csvContent, $this->codeMapping); + $csvContent = strtr($csvContent, $this->mainWebsiteMapping); $this->csv = array_map( function ($value) { return explode(',', str_replace('"', '', $value)); From d078233c9d02fd9fcfeeca028e0552a59384d4fd Mon Sep 17 00:00:00 2001 From: Andrei_Ziblitski Date: Wed, 15 Mar 2017 20:33:12 +0300 Subject: [PATCH 25/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php | 1 + .../Magento/ImportExport/Test/TestStep/FillImportFormStep.php | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php index 28a576ae7ab02..2bfd7cb1b7e73 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php @@ -88,5 +88,6 @@ public function run() $configFixture->persist(); } } + return ['import' => $this->import]; } } diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php index 7d09dfefdd122..a5ca1e06c7bbd 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/FillImportFormStep.php @@ -55,8 +55,7 @@ public function run() return [ 'entities' => $file->getEntities(), - 'import' => $this->import, - 'products' => $file->getEntities() + 'import' => $this->import ]; } } From ef8db47093be06063ad86f81da1e1deea88fe4cc Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Wed, 15 Mar 2017 22:33:39 +0300 Subject: [PATCH 26/29] MTO-138: [Test] Export Advanced Pricing - Stabilization --- .../TestCase/ExportAdvancedPricingTest.php | 20 ++++++------------- .../TestCase/ExportAdvancedPricingTest.xml | 10 +--------- .../Test/Fixture/Product/TierPrice.php | 3 ++- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php index 90446ae298b7f..bcc5e40d229fc 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -106,7 +106,7 @@ public function __inject( * @param string|null $configData * @param Website|null $website * @param array $advancedPricingAttributes - * @param array $currencies + * @param string|null $currencyCustomWebsite * @return array */ public function test( @@ -115,7 +115,7 @@ public function test( $configData = null, Website $website = null, array $advancedPricingAttributes = [], - array $currencies = [] + $currencyCustomWebsite = null ) { $this->configData = $configData; @@ -128,7 +128,7 @@ public function test( if ($website) { $website->persist(); - $this->setupCurrencyForCustomWebsite($website, $currencies[0]); + $this->setupCurrencyForCustomWebsite($website, $currencyCustomWebsite); } $products = $this->prepareProducts($products, $website); $this->adminExportIndex->open(); @@ -160,24 +160,16 @@ public function test( * Setup currency of custom website. * * @param Website $website - * @param array $currency + * @param string $currencyDataset * @return void */ - private function setupCurrencyForCustomWebsite($website, $currency) + private function setupCurrencyForCustomWebsite($website, $currencyDataset) { $configFixture = $this->fixtureFactory->createByCode( 'configData', [ + 'dataset' => $currencyDataset, 'data' => [ - 'currency/options/allow' => [ - 'value' => $currency['allowedCurrencies'] - ], - 'currency/options/base' => [ - 'value' => $currency['baseCurrency'] - ], - 'currency/options/default' => [ - 'value' => $currency['defaultCurrency'] - ], 'scope' => [ 'fixture' => $website, 'scope_type' => 'website', diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml index 60f320d46baba..4488899485002 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.xml @@ -57,15 +57,7 @@ simple_with_tier_price custom_website - - - - EUR - - EUR - EUR - - + config_currency_custom_website_eur $ diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php index 0163cfcb47edc..f934a1dcf7d2e 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Fixture/Product/TierPrice.php @@ -114,7 +114,8 @@ public function getData($key = null) */ private function prepareWebsite() { - if (isset($this->fixtureData['data']['website']['dataset'])) { + if (is_array($this->fixtureData['data']['website']) + && isset($this->fixtureData['data']['website']['dataset'])) { /** @var Website $website */ $this->website = $this->fixtureFactory->createByCode( 'website', From 0ae6c38e98c325df4cddcc5e9f97ddc328dae0ab Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Thu, 16 Mar 2017 08:33:06 +0300 Subject: [PATCH 27/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../AssertAdvancedPriceAbsentOnProductForm.php | 6 +++--- .../Magento/ImportExport/Test/Fixture/Import/File.php | 11 +++++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAdvancedPriceAbsentOnProductForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAdvancedPriceAbsentOnProductForm.php index 3a3d9de7337be..74a0f216e6ef1 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAdvancedPriceAbsentOnProductForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertAdvancedPriceAbsentOnProductForm.php @@ -18,13 +18,13 @@ class AssertAdvancedPriceAbsentOnProductForm extends AbstractConstraint /** * Assert advanced price is absent on product page in form. * - * @param FixtureInterface[] $products + * @param FixtureInterface[] $entities * @param CatalogProductEdit $productPage * @return void */ - public function processAssert(array $products, CatalogProductEdit $productPage) + public function processAssert(array $entities, CatalogProductEdit $productPage) { - foreach ($products as $product) { + foreach ($entities as $product) { $productPage->open(['id' => $product->getData('id')]); /** @var AdvancedPricing $advancedPricing */ $advancedPricing = $productPage->getProductForm() diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 4e4ca7c467100..9d2ef80c314ab 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -213,7 +213,12 @@ private function preparePlaceHolders() if (isset($entityData[$index])) { $placeholders['entity_' . $key][$tierKey]["%{$index}%"] = $entityData[$index]; } - $placeholders['entity_' . $key][$tierKey][$entityData['code']] = $entityData[$entityData['code']]; + if (isset($entityData['code'])) { + $placeholders['entity_' . $key][$tierKey][$entityData['code']] + = isset($entityData[$entityData['code']]) + ? $entityData[$entityData['code']] + : 'Main Website'; + } } } $key++; @@ -237,7 +242,9 @@ public function prepareEntityData(FixtureInterface $entity) $websites = $entity->getDataFieldConfig('website_ids')['source']->getWebsites(); foreach ($websites as $website) { if ($website->getCode() === 'base') { - $currency = $this->value['template']['mainWebsiteCurrency']; + $currency = isset($this->value['template']['mainWebsiteCurrency']) + ? $this->value['template']['websiteCurrency'] + : '[USD]'; $this->mainWebsiteMapping['base'] = $website->getName() . "[{$currency}]"; break; } From 56b19c500e24c736f97f05f8d2c55efa6fd3badd Mon Sep 17 00:00:00 2001 From: Vital Sery Date: Thu, 16 Mar 2017 11:13:16 +0300 Subject: [PATCH 28/29] MTO-138: [Test] Export Advanced Pricing - Stabilization --- .../Test/TestCase/ExportAdvancedPricingTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php index bcc5e40d229fc..db59a722649bb 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ExportAdvancedPricingTest.php @@ -237,7 +237,7 @@ public function tearDown() if ($this->configData) { $this->stepFactory->create( \Magento\Config\Test\TestStep\SetupConfigurationStep::class, - ['configData' => 'config_currency_symbols_usd, price_scope_website_rollback'] + ['configData' => 'price_scope_website', 'rollback' => true] )->run(); } } From 8111a0f5eccabeec0bc161ecd3eaba8caf2ee832 Mon Sep 17 00:00:00 2001 From: Siarhei Andreyeu Date: Thu, 16 Mar 2017 13:52:12 +0300 Subject: [PATCH 29/29] MTO-127: [Test] Import Advanced Pricing - Stabilization --- .../Test/Constraint/AssertImportAdvancedPricing.php | 3 --- .../Test/TestCase/ImportDataTest.xml | 6 +++--- .../template/pricing/advanced_price_variation_1.php | 8 ++++---- .../Constraint/AssertImportCheckDataErrorMessagesList.php | 2 +- .../app/Magento/ImportExport/Test/Fixture/Import/File.php | 8 ++++---- .../ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml | 4 ++-- .../Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php | 8 ++++---- 7 files changed, 18 insertions(+), 21 deletions(-) rename dev/tests/functional/tests/app/Magento/{AdvancedPricingImportExport => ImportExport}/Test/Constraint/AssertImportCheckDataErrorMessagesList.php (97%) diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php index 1ecf9978ce861..1604b65d36de6 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportAdvancedPricing.php @@ -86,9 +86,6 @@ private function getPreparePrices() foreach ($tierPrices as $tierPrice) { $resultProductArray[$productSku][] = $tierPrice; } - if (isset($resultProductArray[$productSku])) { - $resultProductArray[$productSku] = array_reverse($resultProductArray[$productSku]); - } } // Prepare tier prices data from csv file. diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml index 18d15004a9aac..0f5b3dc22df33 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataTest.xml @@ -26,7 +26,7 @@ - + @@ -48,7 +48,7 @@ - + @@ -70,7 +70,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php index dc95a8b87c7c6..fd82e3001c0cd 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php +++ b/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_price_variation_1.php @@ -9,17 +9,17 @@ 'data_0' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => 'General', + 'tier_price_customer_group' => "NOT LOGGED IN", 'tier_price_qty' => '10', - 'tier_price' => '8.00', + 'tier_price' => '9.00', 'tier_price_value_type' => 'Fixed', ], 'data_1' => [ 'sku' => '%sku%', 'tier_price_website' => "All Websites [USD]", - 'tier_price_customer_group' => "NOT LOGGED IN", + 'tier_price_customer_group' => 'General', 'tier_price_qty' => '10', - 'tier_price' => '9.00', + 'tier_price' => '8.00', 'tier_price_value_type' => 'Fixed', ] ], diff --git a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php similarity index 97% rename from dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php rename to dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php index f632dbc8715b8..c650748f9de6c 100644 --- a/dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php @@ -3,7 +3,7 @@ * Copyright © 2013-2017 Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ -namespace Magento\AdvancedPricingImportExport\Test\Constraint; +namespace Magento\ImportExport\Test\Constraint; use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; use Magento\Mtf\Constraint\AbstractConstraint; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php index 9d2ef80c314ab..6193dad5d1c71 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Fixture/Import/File.php @@ -206,15 +206,15 @@ private function preparePlaceHolders() $key = 0; foreach ($this->entities as $entity) { $entityData = $this->prepareEntityData($entity); - foreach ($this->csvTemplate['entity_' . $key] as $tierKey => $tier) { - $values = implode('', array_values($tier)); + foreach ($this->csvTemplate['entity_' . $key] as $entityKey => $importedEntityData) { + $values = implode('', array_values($importedEntityData)); preg_match_all('/\%(.*)\%/U', $values, $indexes); foreach ($indexes[1] as $index) { if (isset($entityData[$index])) { - $placeholders['entity_' . $key][$tierKey]["%{$index}%"] = $entityData[$index]; + $placeholders['entity_' . $key][$entityKey]["%{$index}%"] = $entityData[$index]; } if (isset($entityData['code'])) { - $placeholders['entity_' . $key][$tierKey][$entityData['code']] + $placeholders['entity_' . $key][$entityKey][$entityData['code']] = isset($entityData[$entityData['code']]) ? $entityData[$entityData['code']] : 'Main Website'; diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml index a255e5ca731e4..b00a758a650f4 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/Page/Adminhtml/AdminExportIndex.xml @@ -7,8 +7,8 @@ --> - - + + diff --git a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php index 2bfd7cb1b7e73..04496af85de73 100644 --- a/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php +++ b/dev/tests/functional/tests/app/Magento/ImportExport/Test/TestStep/ChangeCurrencyOnCustomWebsiteStep.php @@ -10,7 +10,7 @@ use Magento\Mtf\Fixture\FixtureFactory; /** - * Create custom store step. + * Change currency on custom website step. */ class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface { @@ -38,12 +38,12 @@ class ChangeCurrencyOnCustomWebsiteStep implements TestStepInterface /** * @param FixtureFactory $fixtureFactory * @param ImportData $import - * @param bool|null $changeCurrency + * @param bool $changeCurrency */ public function __construct( FixtureFactory $fixtureFactory, ImportData $import, - $changeCurrency + $changeCurrency = false ) { $this->fixtureFactory = $fixtureFactory; $this->import = $import; @@ -53,7 +53,7 @@ public function __construct( /** * Fill import form. * - * @return void + * @return array */ public function run() {