-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #859 from magento-qmt/Stabilization
[Mavericks] Extend functional tests coverage - Tasks: - MTA-3977: Create auto test for Checkout using PayPal Braintree button if Require Customer's Billing Address = Yes - MTA-4065: Import Advanced Pricing if Incorrect Data
- Loading branch information
Showing
33 changed files
with
1,209 additions
and
15 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
dev/tests/functional/lib/Magento/Mtf/Util/Filesystem/FileHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Mtf\Util\Filesystem; | ||
|
||
/** | ||
* Filesystem helper. | ||
*/ | ||
class FileHelper | ||
{ | ||
/** | ||
* Normalizes a file/directory path. | ||
* | ||
* @param string $path | ||
* @param string $ds | ||
* @return string | ||
*/ | ||
public function normalizePath($path, $ds = DIRECTORY_SEPARATOR) | ||
{ | ||
$path = rtrim(strtr($path, '/\\', $ds . $ds), $ds); | ||
if (strpos($ds . $path, "{$ds}.") === false && strpos($path, "{$ds}{$ds}") === false) { | ||
return $path; | ||
} | ||
|
||
return $this->realpath($ds, $path); | ||
} | ||
|
||
/** | ||
* Returns canonicalized pathname. | ||
* | ||
* @param string $ds | ||
* @param string $path | ||
* @return string | ||
*/ | ||
private function realpath($ds, $path) | ||
{ | ||
$parts = []; | ||
foreach (explode($ds, $path) as $part) { | ||
if ($part === '..' && !empty($parts) && end($parts) !== '..') { | ||
array_pop($parts); | ||
} elseif ($part === '.' || $part === '' && !empty($parts)) { | ||
continue; | ||
} else { | ||
$parts[] = $part; | ||
} | ||
} | ||
|
||
$path = implode($ds, $parts); | ||
|
||
return $path === '' ? '.' : $path; | ||
} | ||
|
||
/** | ||
* Creates a new directory. | ||
* | ||
* @param string $path | ||
* @param int $mode | ||
* @param bool $recursive | ||
* @return bool | ||
* @throws \Exception | ||
*/ | ||
public function createDirectory($path, $mode = 0775, $recursive = true) | ||
{ | ||
if (is_dir($path)) { | ||
return true; | ||
} | ||
$parentDir = dirname($path); | ||
|
||
if ($recursive && !is_dir($parentDir) && $parentDir !== $path) { | ||
$this->createDirectory($parentDir, $mode, true); | ||
} | ||
|
||
try { | ||
if (!mkdir($path, $mode)) { | ||
return false; | ||
} | ||
} catch (\Exception $e) { | ||
if (!is_dir($path)) { | ||
throw new \Exception("Failed to create directory \"$path\""); | ||
} | ||
} | ||
|
||
try { | ||
return chmod($path, $mode); | ||
} catch (\Exception $e) { | ||
throw new \Exception("Failed to change permissions for directory \"$path\""); | ||
} | ||
} | ||
|
||
/** | ||
* Create a new file with content. | ||
* | ||
* @param string $filename | ||
* @param string $content | ||
* @return bool | ||
*/ | ||
public function createFile($filename, $content) | ||
{ | ||
return file_put_contents($filename, $content) !== false; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
dev/tests/functional/lib/Magento/Mtf/Util/Generate/File/Generator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Mtf\Util\Generate\File; | ||
|
||
use Magento\Mtf\Util\Filesystem\FileHelper; | ||
|
||
/** | ||
* File generator. | ||
*/ | ||
class Generator | ||
{ | ||
/** | ||
* Base directory for files. | ||
*/ | ||
const ROOT_DIRECTORY = '/var/tests/data/'; | ||
|
||
/** | ||
* Directory for saving files. | ||
* | ||
* @var string | ||
*/ | ||
private $directory; | ||
|
||
/** | ||
* Filesystem helper. | ||
* | ||
* @var FileHelper | ||
*/ | ||
private $fileHelper; | ||
|
||
/** | ||
* @param FileHelper $fileHelper | ||
* @param string $directory | ||
*/ | ||
public function __construct(FileHelper $fileHelper, $directory) | ||
{ | ||
$this->fileHelper = $fileHelper; | ||
$this->directory = $this->fileHelper->normalizePath(MTF_BP . static::ROOT_DIRECTORY . $directory); | ||
} | ||
|
||
/** | ||
* Method is generate file by template. | ||
* | ||
* @param TemplateInterface $template | ||
* @return string Full path to the generated file. | ||
* @throws \Exception | ||
*/ | ||
public function generate(TemplateInterface $template) | ||
{ | ||
$filename = $this->fileHelper->normalizePath($this->directory . '/' . $template->getName()); | ||
if (!$this->fileHelper->createDirectory($this->directory) | ||
|| !$this->fileHelper->createFile($filename, $template->render()) | ||
) { | ||
throw new \Exception( | ||
'Can’t create file with "' . get_class($template) .'" (file "' . $filename . '").' | ||
); | ||
} | ||
|
||
return $filename; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
dev/tests/functional/lib/Magento/Mtf/Util/Generate/File/TemplateInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Mtf\Util\Generate\File; | ||
|
||
/** | ||
* Interface for file template. | ||
*/ | ||
interface TemplateInterface | ||
{ | ||
/** | ||
* Create and return file content. | ||
* | ||
* @return string | ||
*/ | ||
public function render(); | ||
|
||
/** | ||
* Get filename. Without directory. | ||
* | ||
* @return string | ||
*/ | ||
public function getName(); | ||
} |
91 changes: 91 additions & 0 deletions
91
...to/AdvancedPricingImportExport/Test/Constraint/AssertImportCheckDataErrorMessagesList.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\AdvancedPricingImportExport\Test\Constraint; | ||
|
||
use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex; | ||
use Magento\Mtf\Constraint\AbstractConstraint; | ||
|
||
/** | ||
* Check error message list after check data fail. | ||
*/ | ||
class AssertImportCheckDataErrorMessagesList extends AbstractConstraint | ||
{ | ||
/** | ||
* Assert that error message is present. | ||
* | ||
* @param array $patterns | ||
* @param AdminImportIndex $adminImportIndex | ||
* @return void | ||
*/ | ||
public function processAssert(array $patterns, AdminImportIndex $adminImportIndex) | ||
{ | ||
$messages = $adminImportIndex->getImportResult()->getErrorsList(); | ||
|
||
\PHPUnit_Framework_Assert::assertNotFalse($messages, 'Errors messages block is absent.'); | ||
\PHPUnit_Framework_Assert::assertNotEmpty($messages, 'Errors messages is absent.'); | ||
|
||
$errors = []; | ||
foreach ($messages as $message) { | ||
if ($this->isNotMatched($patterns, $message)) { | ||
$errors[] = sprintf('This message "%s" mismatch with any pattern', $message); | ||
} | ||
} | ||
|
||
\PHPUnit_Framework_Assert::assertEmpty( | ||
$errors, | ||
'This assertions contains next errors:' . PHP_EOL . implode(PHP_EOL, $errors) | ||
); | ||
} | ||
|
||
/** | ||
* Checking message. | ||
* | ||
* @param array $patterns | ||
* @param string $message | ||
* @return bool | ||
*/ | ||
private function isNotMatched(array $patterns, $message) | ||
{ | ||
$isNotMatch = true; | ||
foreach ($patterns as $parts) { | ||
$parts = (array) $parts; | ||
if ($isNotMatch && $this->match($message, $parts) === count($parts)) { | ||
$isNotMatch = false; | ||
} | ||
} | ||
|
||
return $isNotMatch; | ||
} | ||
|
||
/** | ||
* Check if patterns are contained in a message. | ||
* | ||
* @param string $message | ||
* @param array $patterns | ||
* @return int | ||
*/ | ||
private function match($message, array $patterns) | ||
{ | ||
$matchCount = 0; | ||
foreach ($patterns as $pattern) { | ||
if (strpos($message, $pattern) !== false) { | ||
++$matchCount; | ||
} | ||
} | ||
|
||
return $matchCount; | ||
} | ||
|
||
/** | ||
* Return string representation of object. | ||
* | ||
* @return string | ||
*/ | ||
public function toString() | ||
{ | ||
return 'All messages for errors match the patterns.'; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...al/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> | ||
<testCase name="Magento\ImportExport\Test\TestCase\ImportDataNegativeTest" summary="Import data"> | ||
<variation name="PreventImportAdvancedPricingIfIncorrectData" ticketId="MAGETWO-46155" summary="Import advanced pricing if incorrect data"> | ||
<data name="tag" xsi:type="string">severity:S1</data> | ||
<data name="patterns" xsi:type="array"> | ||
<item name="0" xsi:type="array"> | ||
<item name="0" xsi:type="string">Value for 'tier_price' attribute</item> | ||
<item name="1" xsi:type="string">in row(s): 1</item> | ||
</item> | ||
</data> | ||
<data name="import/data" xsi:type="array"> | ||
<item name="entity" xsi:type="string">Advanced Pricing</item> | ||
<item name="behavior" xsi:type="string">Add/Update</item> | ||
<item name="validation_strategy" xsi:type="string">Stop on Error</item> | ||
<item name="allowed_error_count" xsi:type="string">10</item> | ||
<item name="import_field_separator" xsi:type="string">,</item> | ||
<item name="import_multiple_value_separator" xsi:type="string">,</item> | ||
<item name="import_file" xsi:type="array"> | ||
<item name="products" xsi:type="array"> | ||
<item name="0" xsi:type="string">catalogProductSimple::default</item> | ||
</item> | ||
<item name="template" xsi:type="array"> | ||
<item name="filename" | ||
xsi:type="string">Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect</item> | ||
<item name="count" xsi:type="number">1</item> | ||
</item> | ||
</item> | ||
</data> | ||
<constraint name="Magento\ImportExport\Test\Constraint\AssertImportCheckDataErrorMessage" /> | ||
<constraint name="Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportCheckDataErrorMessagesList" /> | ||
<constraint name="Magento\Catalog\Test\Constraint\AssertAdvancedPriceAbsentOnProductForm" /> | ||
</variation> | ||
</testCase> | ||
</config> |
14 changes: 14 additions & 0 deletions
14
...p/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
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', | ||
]; |
15 changes: 15 additions & 0 deletions
15
dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/etc/di.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
/** | ||
* Copyright © 2013-2017 Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportCheckDataErrorMessagesList"> | ||
<arguments> | ||
<argument name="severity" xsi:type="string">S1</argument> | ||
</arguments> | ||
</type> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.