Skip to content

Commit 469e2bb

Browse files
authored
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
2 parents b180d87 + 7114a8e commit 469e2bb

File tree

33 files changed

+1209
-15
lines changed

33 files changed

+1209
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Filesystem;
7+
8+
/**
9+
* Filesystem helper.
10+
*/
11+
class FileHelper
12+
{
13+
/**
14+
* Normalizes a file/directory path.
15+
*
16+
* @param string $path
17+
* @param string $ds
18+
* @return string
19+
*/
20+
public function normalizePath($path, $ds = DIRECTORY_SEPARATOR)
21+
{
22+
$path = rtrim(strtr($path, '/\\', $ds . $ds), $ds);
23+
if (strpos($ds . $path, "{$ds}.") === false && strpos($path, "{$ds}{$ds}") === false) {
24+
return $path;
25+
}
26+
27+
return $this->realpath($ds, $path);
28+
}
29+
30+
/**
31+
* Returns canonicalized pathname.
32+
*
33+
* @param string $ds
34+
* @param string $path
35+
* @return string
36+
*/
37+
private function realpath($ds, $path)
38+
{
39+
$parts = [];
40+
foreach (explode($ds, $path) as $part) {
41+
if ($part === '..' && !empty($parts) && end($parts) !== '..') {
42+
array_pop($parts);
43+
} elseif ($part === '.' || $part === '' && !empty($parts)) {
44+
continue;
45+
} else {
46+
$parts[] = $part;
47+
}
48+
}
49+
50+
$path = implode($ds, $parts);
51+
52+
return $path === '' ? '.' : $path;
53+
}
54+
55+
/**
56+
* Creates a new directory.
57+
*
58+
* @param string $path
59+
* @param int $mode
60+
* @param bool $recursive
61+
* @return bool
62+
* @throws \Exception
63+
*/
64+
public function createDirectory($path, $mode = 0775, $recursive = true)
65+
{
66+
if (is_dir($path)) {
67+
return true;
68+
}
69+
$parentDir = dirname($path);
70+
71+
if ($recursive && !is_dir($parentDir) && $parentDir !== $path) {
72+
$this->createDirectory($parentDir, $mode, true);
73+
}
74+
75+
try {
76+
if (!mkdir($path, $mode)) {
77+
return false;
78+
}
79+
} catch (\Exception $e) {
80+
if (!is_dir($path)) {
81+
throw new \Exception("Failed to create directory \"$path\"");
82+
}
83+
}
84+
85+
try {
86+
return chmod($path, $mode);
87+
} catch (\Exception $e) {
88+
throw new \Exception("Failed to change permissions for directory \"$path\"");
89+
}
90+
}
91+
92+
/**
93+
* Create a new file with content.
94+
*
95+
* @param string $filename
96+
* @param string $content
97+
* @return bool
98+
*/
99+
public function createFile($filename, $content)
100+
{
101+
return file_put_contents($filename, $content) !== false;
102+
}
103+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Generate\File;
7+
8+
use Magento\Mtf\Util\Filesystem\FileHelper;
9+
10+
/**
11+
* File generator.
12+
*/
13+
class Generator
14+
{
15+
/**
16+
* Base directory for files.
17+
*/
18+
const ROOT_DIRECTORY = '/var/tests/data/';
19+
20+
/**
21+
* Directory for saving files.
22+
*
23+
* @var string
24+
*/
25+
private $directory;
26+
27+
/**
28+
* Filesystem helper.
29+
*
30+
* @var FileHelper
31+
*/
32+
private $fileHelper;
33+
34+
/**
35+
* @param FileHelper $fileHelper
36+
* @param string $directory
37+
*/
38+
public function __construct(FileHelper $fileHelper, $directory)
39+
{
40+
$this->fileHelper = $fileHelper;
41+
$this->directory = $this->fileHelper->normalizePath(MTF_BP . static::ROOT_DIRECTORY . $directory);
42+
}
43+
44+
/**
45+
* Method is generate file by template.
46+
*
47+
* @param TemplateInterface $template
48+
* @return string Full path to the generated file.
49+
* @throws \Exception
50+
*/
51+
public function generate(TemplateInterface $template)
52+
{
53+
$filename = $this->fileHelper->normalizePath($this->directory . '/' . $template->getName());
54+
if (!$this->fileHelper->createDirectory($this->directory)
55+
|| !$this->fileHelper->createFile($filename, $template->render())
56+
) {
57+
throw new \Exception(
58+
'Can’t create file with "' . get_class($template) .'" (file "' . $filename . '").'
59+
);
60+
}
61+
62+
return $filename;
63+
}
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Mtf\Util\Generate\File;
7+
8+
/**
9+
* Interface for file template.
10+
*/
11+
interface TemplateInterface
12+
{
13+
/**
14+
* Create and return file content.
15+
*
16+
* @return string
17+
*/
18+
public function render();
19+
20+
/**
21+
* Get filename. Without directory.
22+
*
23+
* @return string
24+
*/
25+
public function getName();
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AdvancedPricingImportExport\Test\Constraint;
7+
8+
use Magento\ImportExport\Test\Page\Adminhtml\AdminImportIndex;
9+
use Magento\Mtf\Constraint\AbstractConstraint;
10+
11+
/**
12+
* Check error message list after check data fail.
13+
*/
14+
class AssertImportCheckDataErrorMessagesList extends AbstractConstraint
15+
{
16+
/**
17+
* Assert that error message is present.
18+
*
19+
* @param array $patterns
20+
* @param AdminImportIndex $adminImportIndex
21+
* @return void
22+
*/
23+
public function processAssert(array $patterns, AdminImportIndex $adminImportIndex)
24+
{
25+
$messages = $adminImportIndex->getImportResult()->getErrorsList();
26+
27+
\PHPUnit_Framework_Assert::assertNotFalse($messages, 'Errors messages block is absent.');
28+
\PHPUnit_Framework_Assert::assertNotEmpty($messages, 'Errors messages is absent.');
29+
30+
$errors = [];
31+
foreach ($messages as $message) {
32+
if ($this->isNotMatched($patterns, $message)) {
33+
$errors[] = sprintf('This message "%s" mismatch with any pattern', $message);
34+
}
35+
}
36+
37+
\PHPUnit_Framework_Assert::assertEmpty(
38+
$errors,
39+
'This assertions contains next errors:' . PHP_EOL . implode(PHP_EOL, $errors)
40+
);
41+
}
42+
43+
/**
44+
* Checking message.
45+
*
46+
* @param array $patterns
47+
* @param string $message
48+
* @return bool
49+
*/
50+
private function isNotMatched(array $patterns, $message)
51+
{
52+
$isNotMatch = true;
53+
foreach ($patterns as $parts) {
54+
$parts = (array) $parts;
55+
if ($isNotMatch && $this->match($message, $parts) === count($parts)) {
56+
$isNotMatch = false;
57+
}
58+
}
59+
60+
return $isNotMatch;
61+
}
62+
63+
/**
64+
* Check if patterns are contained in a message.
65+
*
66+
* @param string $message
67+
* @param array $patterns
68+
* @return int
69+
*/
70+
private function match($message, array $patterns)
71+
{
72+
$matchCount = 0;
73+
foreach ($patterns as $pattern) {
74+
if (strpos($message, $pattern) !== false) {
75+
++$matchCount;
76+
}
77+
}
78+
79+
return $matchCount;
80+
}
81+
82+
/**
83+
* Return string representation of object.
84+
*
85+
* @return string
86+
*/
87+
public function toString()
88+
{
89+
return 'All messages for errors match the patterns.';
90+
}
91+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd">
9+
<testCase name="Magento\ImportExport\Test\TestCase\ImportDataNegativeTest" summary="Import data">
10+
<variation name="PreventImportAdvancedPricingIfIncorrectData" ticketId="MAGETWO-46155" summary="Import advanced pricing if incorrect data">
11+
<data name="tag" xsi:type="string">severity:S1</data>
12+
<data name="patterns" xsi:type="array">
13+
<item name="0" xsi:type="array">
14+
<item name="0" xsi:type="string">Value for 'tier_price' attribute</item>
15+
<item name="1" xsi:type="string">in row(s): 1</item>
16+
</item>
17+
</data>
18+
<data name="import/data" xsi:type="array">
19+
<item name="entity" xsi:type="string">Advanced Pricing</item>
20+
<item name="behavior" xsi:type="string">Add/Update</item>
21+
<item name="validation_strategy" xsi:type="string">Stop on Error</item>
22+
<item name="allowed_error_count" xsi:type="string">10</item>
23+
<item name="import_field_separator" xsi:type="string">,</item>
24+
<item name="import_multiple_value_separator" xsi:type="string">,</item>
25+
<item name="import_file" xsi:type="array">
26+
<item name="products" xsi:type="array">
27+
<item name="0" xsi:type="string">catalogProductSimple::default</item>
28+
</item>
29+
<item name="template" xsi:type="array">
30+
<item name="filename"
31+
xsi:type="string">Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect</item>
32+
<item name="count" xsi:type="number">1</item>
33+
</item>
34+
</item>
35+
</data>
36+
<constraint name="Magento\ImportExport\Test\Constraint\AssertImportCheckDataErrorMessage" />
37+
<constraint name="Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportCheckDataErrorMessagesList" />
38+
<constraint name="Magento\Catalog\Test\Constraint\AssertAdvancedPriceAbsentOnProductForm" />
39+
</variation>
40+
</testCase>
41+
</config>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
return [
8+
'sku' => '%sku%',
9+
'tier_price_website' => 'All Websites [USD]',
10+
'tier_price_customer_group' => 'ALL GROUPS',
11+
'tier_price_qty' => '3',
12+
'tier_price' => 'text',
13+
'tier_price_value_type' => 'Fixed',
14+
];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/**
4+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
10+
<type name="Magento\AdvancedPricingImportExport\Test\Constraint\AssertImportCheckDataErrorMessagesList">
11+
<arguments>
12+
<argument name="severity" xsi:type="string">S1</argument>
13+
</arguments>
14+
</type>
15+
</config>

dev/tests/functional/tests/app/Magento/Braintree/Test/Repository/ConfigData.xml

+18
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,24 @@
263263
</field>
264264
</dataset>
265265

266+
<dataset name="braintree_paypal_require_billing_address">
267+
<field name="payment/braintree_paypal/require_billing_address" xsi:type="array">
268+
<item name="scope" xsi:type="string">payment</item>
269+
<item name="scope_id" xsi:type="number">1</item>
270+
<item name="label" xsi:type="string">Yes</item>
271+
<item name="value" xsi:type="number">1</item>
272+
</field>
273+
</dataset>
274+
275+
<dataset name="braintree_paypal_require_billing_address_rollback">
276+
<field name="payment/braintree_paypal/require_billing_address" xsi:type="array">
277+
<item name="scope" xsi:type="string">payment</item>
278+
<item name="scope_id" xsi:type="number">1</item>
279+
<item name="label" xsi:type="string">No</item>
280+
<item name="value" xsi:type="number">0</item>
281+
</field>
282+
</dataset>
283+
266284
<dataset name="braintree_fraudprotection">
267285
<field name="payment/braintree/fraudprotection" xsi:type="array">
268286
<item name="scope" xsi:type="string">payment</item>

0 commit comments

Comments
 (0)