Skip to content

Commit daa890f

Browse files
authored
MQE-820: MSI form posts use a single "/admin/" vs "/admin/admin/" URLs used in other areas of the Admin. (#43)
- added removeBackend attribute that removes addition of MAGENTO_BACKEND_NAME to metadata of type adminFormKey
1 parent 9b87581 commit daa890f

File tree

6 files changed

+47
-3
lines changed

6 files changed

+47
-3
lines changed

dev/tests/unit/Util/OperationDefinitionBuilder.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class OperationDefinitionBuilder
3737
*/
3838
private $metadata = [];
3939

40+
/**
41+
* Determines if api URL should remove magento_backend_name.
42+
* @var bool
43+
*/
44+
private $removeBackend;
45+
4046
/**
4147
* Function which builds an operation defintions based on the fields set by the user.
4248
*
@@ -54,7 +60,8 @@ public function build()
5460
null,
5561
null,
5662
$this->metadata,
57-
null
63+
null,
64+
false
5865
);
5966
}
6067

src/Magento/FunctionalTestingFramework/DataGenerator/Handlers/OperationDefinitionObjectHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class OperationDefinitionObjectHandler implements ObjectHandlerInterface
4242
const ENTITY_OPERATION_OBJECT_KEY = 'key';
4343
const ENTITY_OPERATION_OBJECT_VALUE = 'value';
4444
const ENTITY_OPERATION_REQUIRED = 'required';
45+
const ENTITY_OPERATION_BACKEND_REMOVE = 'removeBackend';
4546

4647
/**
4748
* The singleton instance of this class
@@ -149,6 +150,7 @@ private function initialize()
149150
$headers = [];
150151
$params = [];
151152
$operationElements = [];
153+
$removeBackend = $opDefArray[OperationDefinitionObjectHandler::ENTITY_OPERATION_BACKEND_REMOVE] ?? false;
152154

153155
// TODO remove this warning with 2.1.0 release
154156
$backendName = getenv('MAGENTO_BACKEND_NAME');
@@ -238,6 +240,7 @@ private function initialize()
238240
$params,
239241
$operationElements,
240242
$contentType,
243+
$removeBackend,
241244
$successRegex,
242245
$returnRegex
243246
);

src/Magento/FunctionalTestingFramework/DataGenerator/Objects/OperationDefinitionObject.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ class OperationDefinitionObject
104104
*/
105105
private $returnRegex;
106106

107+
/**
108+
* Determines if operation should remove backend_name from URL.
109+
* @var bool
110+
*/
111+
private $removeBackend;
112+
107113
/**
108114
* OperationDefinitionObject constructor.
109115
* @param string $name
@@ -116,6 +122,7 @@ class OperationDefinitionObject
116122
* @param array $params
117123
* @param array $metaData
118124
* @param string $contentType
125+
* @param bool $removeBackend
119126
* @param string $successRegex
120127
* @param string $returnRegex
121128
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -131,6 +138,7 @@ public function __construct(
131138
$params,
132139
$metaData,
133140
$contentType,
141+
$removeBackend,
134142
$successRegex = null,
135143
$returnRegex = null
136144
) {
@@ -145,13 +153,15 @@ public function __construct(
145153
$this->operationMetadata = $metaData;
146154
$this->successRegex = $successRegex;
147155
$this->returnRegex = $returnRegex;
156+
$this->removeBackend = $removeBackend;
148157
$this->apiUrl = null;
149158

150159
if (!empty($contentType)) {
151160
$this->contentType = $contentType;
152161
} else {
153162
$this->contentType = 'application/x-www-form-urlencoded';
154163
}
164+
155165
// add content type as a header
156166
$this->headers[] = self::HTTP_CONTENT_TYPE_HEADER . ': ' . $this->contentType;
157167
}
@@ -231,6 +241,16 @@ public function getHeaders()
231241
return $this->headers;
232242
}
233243

244+
/**
245+
* Getter for removeBackend
246+
*
247+
* @return bool
248+
*/
249+
public function removeUrlBackend()
250+
{
251+
return $this->removeBackend;
252+
}
253+
234254
/**
235255
* Getter for Content-type
236256
*

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/Curl/AdminExecutor.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
3636
*/
3737
private $response;
3838

39+
/**
40+
* Should executor remove backend_name from api url
41+
* @var bool
42+
*/
43+
private $removeBackend;
44+
3945
/**
4046
* Backend url.
4147
*
@@ -45,15 +51,17 @@ class AdminExecutor extends AbstractExecutor implements CurlInterface
4551

4652
/**
4753
* Constructor.
54+
* @param bool $removeBackend
4855
*
4956
* @constructor
5057
*/
51-
public function __construct()
58+
public function __construct($removeBackend)
5259
{
5360
if (!isset(parent::$baseUrl)) {
5461
parent::resolveBaseUrl();
5562
}
5663
self::$adminUrl = parent::$baseUrl . getenv('MAGENTO_BACKEND_NAME') . '/';
64+
$this->removeBackend = $removeBackend;
5765
$this->transport = new CurlTransport();
5866
$this->authorize();
5967
}
@@ -110,6 +118,11 @@ private function setFormKey()
110118
public function write($url, $data = [], $method = CurlInterface::POST, $headers = [])
111119
{
112120
$apiUrl = self::$adminUrl . $url;
121+
122+
if ($this->removeBackend) {
123+
$apiUrl = parent::$baseUrl . ltrim($url, '/');
124+
}
125+
113126
if ($this->formKey) {
114127
$data['form_key'] = $this->formKey;
115128
} else {

src/Magento/FunctionalTestingFramework/DataGenerator/Persist/CurlHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function executeRequest($dependentEntities)
131131
$this->isJson = true;
132132
$executor = new WebapiExecutor($this->storeCode);
133133
} elseif ($authorization === 'adminFormKey') {
134-
$executor = new AdminExecutor();
134+
$executor = new AdminExecutor($this->operationDefinition->removeUrlBackend());
135135
} elseif ($authorization === 'customerFormKey') {
136136
$executor = new FrontendExecutor(
137137
$this->requestData['customer_email'],

src/Magento/FunctionalTestingFramework/DataGenerator/etc/dataOperation.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<xs:attribute type="operationEnum" name="type" use="required"/>
2626
<xs:attribute type="xs:string" name="url"/>
2727
<xs:attribute type="authEnum" name="auth"/>
28+
<xs:attribute type="xs:boolean" name="removeBackend" use="optional" default="true"/>
2829
<xs:attribute type="xs:string" name="method"/>
2930
<xs:attribute type="xs:string" name="successRegex"/>
3031
<xs:attribute type="xs:string" name="returnRegex"/>

0 commit comments

Comments
 (0)