Skip to content

Commit e1fa06a

Browse files
committed
B2B-1704: Add MFTF test for MC-38621
- Adding curl helpers
1 parent 39c269b commit e1fa06a

File tree

2 files changed

+99
-37
lines changed

2 files changed

+99
-37
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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\TaxImportExport\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 $uri
21+
* @param string $expectedString
22+
* @return void
23+
*
24+
* @throws \Magento\Framework\Exception\FileSystemException
25+
*/
26+
public function assertCurlResponseContainsString($uri, $expectedString): void
27+
{
28+
$cookie = $this->getCookie();
29+
echo $cookie;
30+
$curlResponse = $this->getCurlResponse($uri, $cookie);
31+
echo $curlResponse;
32+
$this->assertStringContainsString($expectedString, $curlResponse);
33+
}
34+
35+
/**
36+
* Sends a curl request with the provided URI & cookie. Returns the response
37+
*
38+
* @param string $uri
39+
* @param string $cookie
40+
* @return string
41+
*
42+
* @throws \Magento\Framework\Exception\FileSystemException
43+
*/
44+
public function getCurlResponse($uri, $cookie): string
45+
{
46+
try {
47+
// Start Session
48+
$session = curl_init($uri);
49+
50+
// Set Options
51+
curl_setopt($session, CURLOPT_COOKIE, $cookie);
52+
// curl_setopt($session, CURLOPT_POST, true);
53+
curl_setopt($session, CURLOPT_HEADER, false);
54+
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
55+
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
56+
57+
// Execute
58+
$response = curl_exec($session);
59+
curl_close($session);
60+
61+
return $response;
62+
} catch (\Exception $exception) {
63+
$this->fail($exception->getMessage());
64+
}
65+
}
66+
67+
/**
68+
* Sends a curl request with the provided URI & cookie. Returns the response in JSON format
69+
*
70+
* @return string
71+
*
72+
* @throws \Magento\Framework\Exception\FileSystemException
73+
*/
74+
public function getCookie($cookieName = 'admin'): string
75+
{
76+
try {
77+
$webDriver = $this->getModule('\Magento\FunctionalTestingFramework\Module\MagentoWebDriver');
78+
$cookieValue = $webDriver->grabCookie($cookieName);
79+
80+
return $cookieName . '=' . $cookieValue;
81+
} catch (\Exception $exception) {
82+
$this->fail($exception->getMessage());
83+
}
84+
}
85+
}

app/code/Magento/TaxImportExport/Test/Mftf/Test/AdminExportTaxRatesTest.xml

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
<stories value="Export"/>
1515
<title value="Export Tax Rates"/>
1616
<description value="Exports tax rates from the System > Data Transfer > Import/Export Tax Rates page and
17-
validates contents in downloaded file."/>
17+
validates contents in downloaded file. Note that MFTF cannot simply click export and have access to the file
18+
that is downloaded in the browser due to the test not having access to the server that is running the test
19+
browser. Therefore, this test clicks the Export button, grabs the request URI from the browser, and executes
20+
the same request on the magento machine via a curl request to download the same file there so that the test
21+
has access to the exported file."/>
1822
<severity value="MAJOR"/>
1923
<testCaseId value="MC-38949"/>
2024
<group value="importExport"/>
@@ -31,50 +35,23 @@
3135
</before>
3236

3337
<after>
34-
<!-- Delete Data & Logout -->
35-
<!-- <helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="deleteFileIfExists" stepKey="deleteExportFile">-->
36-
<!-- <argument name="filePath">/var/tmp/tax_rates.csv</argument>-->
37-
<!-- </helper>-->
38-
<helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="deleteFileIfExists" stepKey="deleteExportFile">
39-
<argument name="filePath">/home/centos/Downloads/tax_rates.csv</argument>
40-
</helper>
38+
<!-- Logout -->
4139
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
4240
</after>
4341

4442
<!-- Export Tax Rates & Validate Export -->
4543
<actionGroup ref="AdminNavigateImportExportTaxRatesActionGroup" stepKey="navigateToImportExportTaxRatesPage"/>
4644
<actionGroup ref="AdminExportTaxRatesActionGroup" stepKey="exportTaxRates"/>
4745
<executeJS function="return window.performance.getEntriesByName('mousedown')[0].target.baseURI" stepKey="exportURI"/>
48-
49-
<comment userInput="{$exportURI}" stepKey="commentTest"/>
50-
<!-- <assertEquals stepKey="test">-->
51-
<!-- <actualResult type="variable">exportURI</actualResult>-->
52-
<!-- <expectedResult type="string">http://git24develop3.test/admin/tax/rate/importExport/</expectedResult>-->
53-
<!-- </assertEquals>-->
54-
55-
<!-- todo: curl command to go to URI to download file -->
56-
57-
<assertFileExists stepKey="assertExportFileExists">
58-
<actualResult type="string">/home/centos/Downloads/tax_rates.csv</actualResult>
59-
</assertFileExists>
60-
<helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportedFileContainsCATaxRate">
61-
<argument name="filePath">/home/centos/Downloads/tax_rates.csv</argument>
62-
<argument name="text">{{US_CA_Rate_1.code}}</argument>
46+
<comment userInput="{$exportURI}" stepKey="commentExportURI"/>
47+
<executeJS function="return window.location.origin" stepKey="baseUrl"/>
48+
<helper class="\Magento\TaxImportExport\Test\Mftf\Helper\CurlHelpers" method="assertCurlResponseContainsString" stepKey="assertExportedFileContainsCATaxRate">
49+
<argument name="uri">{$baseUrl}/admin/tax/rate/exportPost/</argument>
50+
<argument name="expectedString">{{US_CA_Rate_1.code}}</argument>
6351
</helper>
64-
<helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportedFileContainsNYTaxRate">
65-
<argument name="filePath">/home/centos/Downloads/tax_rates.csv</argument>
66-
<argument name="text">{{US_NY_Rate_1.code}}</argument>
52+
<helper class="\Magento\TaxImportExport\Test\Mftf\Helper\CurlHelpers" method="assertCurlResponseContainsString" stepKey="assertExportedFileContainsNYTaxRate">
53+
<argument name="uri">{$baseUrl}/admin/tax/rate/exportPost/</argument>
54+
<argument name="expectedString">{{US_NY_Rate_1.code}}</argument>
6755
</helper>
68-
<!-- <assertFileExists stepKey="assertExportFileExists">-->
69-
<!-- <actualResult type="string">/var/tmp/tax_rates.csv</actualResult>-->
70-
<!-- </assertFileExists>-->
71-
<!-- <helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportedFileContainsCATaxRate">-->
72-
<!-- <argument name="filePath">/var/tmp/tax_rates.csv</argument>-->
73-
<!-- <argument name="text">{{US_CA_Rate_1.code}}</argument>-->
74-
<!-- </helper>-->
75-
<!-- <helper class="\Magento\Catalog\Test\Mftf\Helper\LocalFileAssertions" method="assertFileContainsString" stepKey="assertExportedFileContainsNYTaxRate">-->
76-
<!-- <argument name="filePath">/var/tmp/tax_rates.csv</argument>-->
77-
<!-- <argument name="text">{{US_NY_Rate_1.code}}</argument>-->
78-
<!-- </helper>-->
7956
</test>
8057
</tests>

0 commit comments

Comments
 (0)