Skip to content

Commit

Permalink
Merge pull request #859 from magento-qmt/Stabilization
Browse files Browse the repository at this point in the history
[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
okolesnyk authored Feb 21, 2017
2 parents b180d87 + 7114a8e commit 469e2bb
Show file tree
Hide file tree
Showing 33 changed files with 1,209 additions and 15 deletions.
103 changes: 103 additions & 0 deletions dev/tests/functional/lib/Magento/Mtf/Util/Filesystem/FileHelper.php
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;
}
}
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;
}
}
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();
}
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.';
}
}
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>
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',
];
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>
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,24 @@
</field>
</dataset>

<dataset name="braintree_paypal_require_billing_address">
<field name="payment/braintree_paypal/require_billing_address" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">Yes</item>
<item name="value" xsi:type="number">1</item>
</field>
</dataset>

<dataset name="braintree_paypal_require_billing_address_rollback">
<field name="payment/braintree_paypal/require_billing_address" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
<item name="scope_id" xsi:type="number">1</item>
<item name="label" xsi:type="string">No</item>
<item name="value" xsi:type="number">0</item>
</field>
</dataset>

<dataset name="braintree_fraudprotection">
<field name="payment/braintree/fraudprotection" xsi:type="array">
<item name="scope" xsi:type="string">payment</item>
Expand Down
Loading

0 comments on commit 469e2bb

Please sign in to comment.