Skip to content

Commit ab525ae

Browse files
committed
B2B-1704: Add MFTF test for MC-38621
- Adding form_key to curl request
1 parent 0778e2d commit ab525ae

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

app/code/Magento/Catalog/Test/Mftf/Helper/CurlHelpers.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class CurlHelpers extends Helper
1919
*
2020
* @param string $url
2121
* @param string $expectedString
22+
* @param string $formKey
2223
* @return void
2324
*
2425
*/
25-
public function assertCurlResponseContainsString($url, $expectedString): void
26+
public function assertCurlResponseContainsString($url, $expectedString, $formKey = null): void
2627
{
2728
$cookie = $this->getCookie('admin');
28-
$curlResponse = $this->getCurlResponse($url, $cookie);
29+
$curlResponse = $this->getCurlResponse($url, $cookie, $formKey);
2930
$this->assertStringContainsString($expectedString, $curlResponse);
3031
}
3132

@@ -34,29 +35,31 @@ public function assertCurlResponseContainsString($url, $expectedString): void
3435
*
3536
* @param string $url
3637
* @param string $cookie
38+
* @param string $formKey
3739
* @return string
3840
*
3941
*/
40-
public function getCurlResponse($url, $cookie): string
42+
public function getCurlResponse($url, $cookie = null, $formKey = null): string
4143
{
42-
try {
43-
// Start Session
44-
$session = curl_init($url);
44+
// Start Session
45+
$session = curl_init($url);
4546

46-
// Set Options
47-
curl_setopt($session, CURLOPT_COOKIE, $cookie);
48-
curl_setopt($session, CURLOPT_HEADER, false);
49-
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
50-
curl_setopt($session, CURLOPT_FOLLOWLOCATION, true);
47+
// Set Options
48+
if ($formKey) {
49+
$data = [
50+
'form_key' => $formKey
51+
];
52+
curl_setopt($session, CURLOPT_POST, true);
53+
curl_setopt($session, CURLOPT_POSTFIELDS, $data);
54+
}
55+
curl_setopt($session, CURLOPT_COOKIE, $cookie);
56+
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
5157

52-
// Execute
53-
$response = curl_exec($session);
54-
curl_close($session);
58+
// Execute
59+
$response = curl_exec($session);
60+
curl_close($session);
5561

56-
return $response;
57-
} catch (\Exception $exception) {
58-
$this->fail($exception->getMessage());
59-
}
62+
return $response;
6063
}
6164

6265
/**
@@ -75,6 +78,7 @@ public function getCookie($cookieName = 'admin'): string
7578
return $cookieName . '=' . $cookieValue;
7679
} catch (\Exception $exception) {
7780
$this->fail($exception->getMessage());
81+
return '';
7882
}
7983
}
8084
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@
4343
<actionGroup ref="AdminNavigateImportExportTaxRatesActionGroup" stepKey="navigateToImportExportTaxRatesPage"/>
4444
<actionGroup ref="AdminClickExportTaxRatesActionGroup" stepKey="exportTaxRates"/>
4545
<grabAttributeFrom userInput="action" selector="{{AdminImportExportTaxRatesSection.exportTaxRatesButtonForm}}" stepKey="grabExportUrl"/>
46+
<executeJS function="return window.FORM_KEY" stepKey="grabFormKey"/>
4647
<helper class="\Magento\Catalog\Test\Mftf\Helper\CurlHelpers" method="assertCurlResponseContainsString" stepKey="assertExportedFileContainsCATaxRate">
4748
<argument name="url">{$grabExportUrl}</argument>
49+
<argument name="formKey">{$grabFormKey}</argument>
4850
<argument name="expectedString">{{US_CA_Rate_1.code}}</argument>
4951
</helper>
5052
<helper class="\Magento\Catalog\Test\Mftf\Helper\CurlHelpers" method="assertCurlResponseContainsString" stepKey="assertExportedFileContainsNYTaxRate">
5153
<argument name="url">{$grabExportUrl}</argument>
54+
<argument name="formKey">{$grabFormKey}</argument>
5255
<argument name="expectedString">{{US_NY_Rate_1.code}}</argument>
5356
</helper>
5457
</test>

0 commit comments

Comments
 (0)