Skip to content

Commit 7824eef

Browse files
committed
Merge remote-tracking branch 'arcticfoxes/B2B-1704' into B2B-1652
2 parents 8f68dfd + 798c6fb commit 7824eef

20 files changed

+726
-15
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminAwsS3ExportTaxRatesTest" extends="AdminExportTaxRatesTest">
12+
<annotations>
13+
<features value="AwsS3"/>
14+
<stories value="Export Tax"/>
15+
<title value="S3 - Export Tax Rates"/>
16+
<description value="Exports tax rates from the System > Data Transfer > Import/Export Tax Rates page, from
17+
the Tax Rule page, from the Tax Rates grid page as a .csv, and from the Tax Rates grid page as an .xml.
18+
Validates contents in downloaded file for each export area. Note that MFTF cannot simply click export and
19+
have access to the file that is downloaded in the browser due to the test not having access to the server
20+
that is running the test browser. Therefore, this test verifies that the Export button can be successfully
21+
clicked, grabs the request URL from the Export button's form, executes the request on the magento machine
22+
via a curl request, and verifies the contents of the exported file. Uses S3 for the file system."/>
23+
<severity value="MAJOR"/>
24+
<testCaseId value="MC-38621"/>
25+
<group value="importExport"/>
26+
<group value="tax"/>
27+
</annotations>
28+
29+
<before>
30+
<!-- Enable AWS S3 Remote Storage -->
31+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage" before="revertInitialTaxRateCA"/>
32+
</before>
33+
34+
<after>
35+
<!-- Disable AWS S3 Remote Storage -->
36+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>
37+
</after>
38+
</test>
39+
</tests>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminAwsS3ImportTaxRatesTest" extends="AdminImportTaxRatesTest">
12+
<annotations>
13+
<features value="AwsS3"/>
14+
<stories value="Import Tax"/>
15+
<title value="S3 - Import and Update Tax Rates"/>
16+
<description value="Imports tax rates from the System > Data Transfer > Import/Export Tax Rates page and
17+
from the Tax Rule page, to create new tax rates and update existing tax rates. Verifies results on the Tax
18+
Rates grid page. Uses S3 for the file system."/>
19+
<severity value="MAJOR"/>
20+
<testCaseId value="MC-38621"/>
21+
<group value="importExport"/>
22+
<group value="tax"/>
23+
</annotations>
24+
25+
<before>
26+
<!-- Enable AWS S3 Remote Storage -->
27+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.enable_options}}" stepKey="enableRemoteStorage" before="revertInitialTaxRateCA"/>
28+
</before>
29+
30+
<after>
31+
<!-- Disable AWS S3 Remote Storage -->
32+
<magentoCLI command="setup:config:set {{RemoteStorageAwsS3ConfigData.disable_options}}" stepKey="disableRemoteStorage" after="logoutFromAdmin"/>
33+
</after>
34+
</test>
35+
</tests>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Backend\Test\Mftf\Helper;
9+
10+
use Magento\FunctionalTestingFramework\Helper\Helper;
11+
12+
/**
13+
* Class for MFTF helpers for curl requests.
14+
*/
15+
class CurlHelpers extends Helper
16+
{
17+
/**
18+
* Assert a that a curl request's response contains an expected string
19+
*
20+
* @param string $url
21+
* @param string $expectedString
22+
* @param string $postBody
23+
* @param string $cookieName
24+
* @return void
25+
*
26+
*/
27+
public function assertCurlResponseContainsString($url, $expectedString, $postBody = null, $cookieName = 'admin'): void
28+
{
29+
$cookie = $this->getCookie($cookieName);
30+
$curlResponse = $this->getCurlResponse($url, $cookie, $postBody);
31+
$this->assertStringContainsString($expectedString, $curlResponse);
32+
}
33+
34+
/**
35+
* Sends a curl request with the provided URL & cookie. Returns the response
36+
*
37+
* @param string $url
38+
* @param string $cookie
39+
* @param string $postBody
40+
* @return string
41+
*
42+
*/
43+
private function getCurlResponse($url, $cookie = null, $postBody = null): string
44+
{
45+
// Start Session
46+
$session = curl_init($url);
47+
48+
// Set Options
49+
if ($postBody) {
50+
$data = json_decode($postBody, true);
51+
curl_setopt($session, CURLOPT_POST, true);
52+
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
53+
}
54+
curl_setopt($session, CURLOPT_COOKIE, $cookie);
55+
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
56+
57+
// Execute
58+
$response = curl_exec($session);
59+
curl_close($session);
60+
61+
return $response;
62+
}
63+
64+
/**
65+
* Gets the value of the specified cookie and returns the key value pair of the cookie
66+
*
67+
* @param string $cookieName
68+
* @return string
69+
*
70+
*/
71+
private function getCookie($cookieName = 'admin'): string
72+
{
73+
try {
74+
$webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
75+
$cookieValue = $webDriver->grabCookie($cookieName);
76+
77+
return $cookieName . '=' . $cookieValue;
78+
} catch (\Exception $exception) {
79+
$this->fail($exception->getMessage());
80+
return '';
81+
}
82+
}
83+
}

app/code/Magento/Rule/Test/Mftf/Helper/RuleHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class RuleHelper extends Helper
1919
{
2020
/**
21-
* Delete all Catalog Price Rules obe by one.
21+
* Deletes all Catalog Price Rules one by one.
2222
*
2323
* @param string $emptyRow
2424
* @param string $modalAceptButton
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminAssertTaxRateInGridActionGroup">
12+
<annotations>
13+
<description>Verifies the specified data is in the specified row on the the admin Tax Zones and Rates page.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="taxIdentifier" defaultValue="{{US_CA_Rate_1.code}}" type="string"/>
17+
<argument name="country" defaultValue="{{US_CA_Rate_1.tax_country}}" type="string"/>
18+
<argument name="region" defaultValue="{{US_CA_Rate_1.tax_region}}" type="string"/>
19+
<argument name="zip" defaultValue="{{US_CA_Rate_1.tax_postcode}}" type="string"/>
20+
<argument name="rate" defaultValue="{{US_CA_Rate_1.rate}}" type="string"/>
21+
<argument name="rowIndex" defaultValue="1" type="string"/>
22+
</arguments>
23+
<waitForElementVisible selector="{{AdminTaxRateGridSection.nthRow(rowIndex)}}" stepKey="waitForRow"/>
24+
<see userInput="{{taxIdentifier}}" selector="{{AdminTaxRateGridSection.taxIdentifierByRow(rowIndex)}}" stepKey="seeTaxIdentifier"/>
25+
<see userInput="{{country}}" selector="{{AdminTaxRateGridSection.countryByRow(rowIndex)}}" stepKey="seeCountry"/>
26+
<see userInput="{{region}}" selector="{{AdminTaxRateGridSection.regionByRow(rowIndex)}}" stepKey="seeRegion"/>
27+
<see userInput="{{zip}}" selector="{{AdminTaxRateGridSection.zipByRow(rowIndex)}}" stepKey="seeZip"/>
28+
<see userInput="{{rate}}" selector="{{AdminTaxRateGridSection.rateByRow(rowIndex)}}" stepKey="seeRate"/>
29+
</actionGroup>
30+
</actionGroups>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminDeleteMultipleTaxRatesActionGroup">
11+
<annotations>
12+
<description>Navigates to the 'Tax Zones and Rates' page and deletes all specified rows one by one. Defaults
13+
to delete all rows except the defaults of 'US-CA-*-Rate 1' and 'US-NY-*-Rate 1'.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="rowsToDelete" defaultValue="{{AdminTaxRateGridSection.allNonDefaultTaxRates}}" type="string"/>
17+
<argument name="expectedRemainingRows" defaultValue="2" type="string"/>
18+
</arguments>
19+
<waitForElementVisible selector="{{AdminLegacyDataGridFilterSection.clear}}" stepKey="waitForResetFilter"/>
20+
<click selector="{{AdminLegacyDataGridFilterSection.clear}}" stepKey="clickResetFilter"/>
21+
<waitForPageLoad stepKey="waitForGridReset"/>
22+
<helper class="\Magento\Tax\Test\Mftf\Helper\TaxHelpers" method="deleteAllSpecifiedTaxRuleRows" stepKey="deleteAllSpecifiedTaxRules">
23+
<argument name="rowsToDelete">{{rowsToDelete}}</argument>
24+
<argument name="deleteButton">{{AdminMainActionsSection.delete}}</argument>
25+
<argument name="modalAcceptButton">{{AdminConfirmationModalSection.ok}}</argument>
26+
<argument name="successMessage">You deleted the tax rate.</argument>
27+
<argument name="successMessageContainer">{{AdminMessagesSection.success}}</argument>
28+
</helper>
29+
<waitForPageLoad stepKey="waitForGridLoad"/>
30+
<seeNumberOfElements userInput="{{expectedRemainingRows}}" selector="{{AdminTaxRateGridSection.allRows}}" stepKey="seeExpectedFinalTotalRows"/>
31+
</actionGroup>
32+
</actionGroups>

app/code/Magento/Tax/Test/Mftf/Data/TaxRateData.xml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,39 @@
77
-->
88
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
99
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
10-
<entity name="SimpleTaxRate" type="taxRate">
11-
<data key="code" unique="suffix">TaxRate</data>
12-
</entity>
13-
<entity name="defaultTaxRate" type="taxRate">
14-
<data key="code" unique="suffix">Tax Rate </data>
15-
<data key="tax_country_id">US</data>
16-
<data key="tax_region_id">12</data>
17-
<data key="tax_postcode">*</data>
18-
<data key="zip_is_range">0</data>
19-
<data key="rate">10</data>
20-
</entity>
10+
<!-- These Tax Rates Are Installed by Default with Magento -->
2111
<entity name="US_CA_Rate_1" type="taxRate">
2212
<data key="id">1</data>
2313
<data key="code">US-CA-*-Rate 1</data>
2414
<data key="tax_country_id">US</data>
15+
<data key="tax_country">United States</data>
16+
<data key="tax_region_id">12</data>
17+
<data key="tax_region">CA</data>
2518
<data key="tax_postcode">*</data>
2619
<data key="rate">8.2500</data>
2720
</entity>
2821
<entity name="US_NY_Rate_1" type="taxRate">
22+
<data key="id">2</data>
2923
<data key="code">US-NY-*-Rate 1</data>
3024
<data key="tax_country_id">US</data>
25+
<data key="tax_country">United States</data>
26+
<data key="tax_region_id">43</data>
27+
<data key="tax_region">NY</data>
3128
<data key="tax_postcode">*</data>
3229
<data key="rate">8.3750</data>
33-
<data key="id">2</data>
30+
</entity>
31+
32+
<!-- Test Tax Rates -->
33+
<entity name="SimpleTaxRate" type="taxRate">
34+
<data key="code" unique="suffix">TaxRate</data>
35+
</entity>
36+
<entity name="defaultTaxRate" type="taxRate">
37+
<data key="code" unique="suffix">Tax Rate </data>
38+
<data key="tax_country_id">US</data>
39+
<data key="tax_region_id">12</data>
40+
<data key="tax_postcode">*</data>
41+
<data key="zip_is_range">0</data>
42+
<data key="rate">10</data>
3443
</entity>
3544
<entity name="taxRate_US_NY_8_1" type="taxRate">
3645
<data key="code" unique="suffix">US-NY-*-</data>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Tax\Test\Mftf\Helper;
9+
10+
use Facebook\WebDriver\Remote\RemoteWebDriver as FacebookWebDriver;
11+
use Facebook\WebDriver\WebDriverBy;
12+
use Magento\FunctionalTestingFramework\Helper\Helper;
13+
use Magento\FunctionalTestingFramework\Module\MagentoWebDriver;
14+
15+
/**
16+
* Class for MFTF helpers for Tax module.
17+
*/
18+
class TaxHelpers extends Helper
19+
{
20+
/**
21+
* Delete all specified Tax Rules one by one from the Tax Zones and Rates page.
22+
*
23+
* @param string $rowsToDelete
24+
* @param string $deleteButton
25+
* @param string $modalAcceptButton
26+
* @param string $successMessage
27+
* @param string $successMessageContainer
28+
*
29+
* @return void
30+
*/
31+
public function deleteAllSpecifiedTaxRuleRows(
32+
string $rowsToDelete,
33+
string $deleteButton,
34+
string $modalAcceptButton,
35+
string $successMessage,
36+
string $successMessageContainer
37+
): void {
38+
try {
39+
/** @var MagentoWebDriver $webDriver */
40+
$magentoWebDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
41+
/** @var FacebookWebDriver $webDriver */
42+
$webDriver = $magentoWebDriver->webDriver;
43+
44+
$magentoWebDriver->waitForPageLoad(30);
45+
$rows = $webDriver->findElements(WebDriverBy::xpath($rowsToDelete));
46+
while (!empty($rows)) {
47+
$rows[0]->click();
48+
$magentoWebDriver->waitForPageLoad(30);
49+
$magentoWebDriver->waitForElementVisible($deleteButton, 10);
50+
$magentoWebDriver->click($deleteButton);
51+
$magentoWebDriver->waitForPageLoad(30);
52+
$magentoWebDriver->waitForElementVisible($modalAcceptButton, 10);
53+
$magentoWebDriver->click($modalAcceptButton);
54+
$magentoWebDriver->waitForPageLoad(60);
55+
$magentoWebDriver->waitForText($successMessage, 10, $successMessageContainer);
56+
$rows = $webDriver->findElements(WebDriverBy::xpath($rowsToDelete));
57+
}
58+
} catch (\Exception $exception) {
59+
$this->fail($exception->getMessage());
60+
}
61+
}
62+
}

app/code/Magento/Tax/Test/Mftf/Section/AdminTaxRateGridSection.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@
1515
<element name="filterByTaxIdentifier" type="input" selector="#tax_rate_grid_filter_code"/>
1616
<element name="filterByCountry" type="input" selector="#tax_rate_grid_filter_tax_country_id"/>
1717
<element name="filterByPostCode" type="input" selector="#tax_rate_grid_filter_tax_postcode"/>
18-
<element name="nthRow" type="block" selector="tr[data-role='row']:nth-of-type({{var}})" parameterized="true" timeout="30"/>
18+
<element name="allRows" type="block" selector="#tax_rate_grid_table tbody tr"/>
19+
<element name="nthRow" type="block" parameterized="true" timeout="30" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}})"/>
20+
<element name="taxIdentifierByRow" type="text" parameterized="true" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}}) [data-column=code]"/>
21+
<element name="countryByRow" type="text" parameterized="true" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}}) [data-column=tax_country_id]"/>
22+
<element name="regionByRow" type="text" parameterized="true" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}}) [data-column=region_name]"/>
23+
<element name="zipByRow" type="text" parameterized="true" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}}) [data-column=tax_postcode]"/>
24+
<element name="rateByRow" type="text" parameterized="true" selector="#tax_rate_grid_table tbody tr:nth-of-type({{rowIndex}}) [data-column=rate]"/>
25+
<element name="allNonDefaultTaxRates" type="block" selector="//table[@id='tax_rate_grid_table']//tbody//tr//td[@data-column='code' and not(contains(.,'US-CA-*-Rate 1')) and not(contains(.,'US-NY-*-Rate 1'))]"/>
1926
<element name="emptyText" type="text" selector=".empty-text"/>
2027
</section>
21-
</sections>
28+
</sections>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminClickExportTaxRatesActionGroup">
12+
<annotations>
13+
<description>Clicks the 'Export Tax Rates' button.</description>
14+
</annotations>
15+
<waitForElementVisible selector="{{AdminImportExportTaxRatesSection.exportTaxRatesButton}}" stepKey="waitForExportTaxRates"/>
16+
<click selector="{{AdminImportExportTaxRatesSection.exportTaxRatesButton}}" stepKey="clickExportTaxRates"/>
17+
<waitForPageLoad stepKey="waitForExport"/>
18+
</actionGroup>
19+
</actionGroups>

0 commit comments

Comments
 (0)