-
Notifications
You must be signed in to change notification settings - Fork 131
MQE-1065: Persisted data are not resolved correctly when using with ParameterArray #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ class TestGenerator | |
const TEST_SCOPE = 'test'; | ||
const HOOK_SCOPE = 'hook'; | ||
const SUITE_SCOPE = 'suite'; | ||
const PRESSKEY_ARRAY_ANCHOR_KEY = '987654321098765432109876543210'; | ||
|
||
/** | ||
* Path to the export dir. | ||
|
@@ -960,24 +961,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato | |
case "pressKey": | ||
$parameterArray = $customActionAttributes['parameterArray'] ?? null; | ||
if ($parameterArray) { | ||
// validate the param array is in the correct format | ||
$this->validateParameterArray($parameterArray); | ||
|
||
// trim off the outer braces and add commas for the regex match | ||
$params = "," . substr($parameterArray, 1, strlen($parameterArray) - 2) . ","; | ||
|
||
// we are matching any nested arrays for a simultaneous press, any string literals, and any | ||
// explicit function calls from a class. | ||
preg_match_all('/(\[.*?\])|(\'.*?\')|(\\\\.*?\,)/', $params, $paramInput); | ||
|
||
//clean up the input by trimming any extra commas | ||
$tmpParameterArray = []; | ||
foreach ($paramInput[0] as $params) { | ||
$tmpParameterArray[] = trim($params, ","); | ||
} | ||
|
||
// put the array together as a string to be passed as args | ||
$parameterArray = implode(",", $tmpParameterArray); | ||
$parameterArray = $this->processPressKey($parameterArray); | ||
} | ||
$testSteps .= $this->wrapFunctionCall( | ||
$actor, | ||
|
@@ -1642,6 +1626,69 @@ private function addUniquenessToParamArray($input) | |
return implode(", ", $result); | ||
} | ||
|
||
/** | ||
* Process pressKey parameterArray attribute for uniqueness function call and necessary data resolutions | ||
* | ||
* @param string $input | ||
* @return string | ||
*/ | ||
private function processPressKey($input) | ||
{ | ||
// validate the param array is in the correct format | ||
$input = trim($input); | ||
$this->validateParameterArray($input); | ||
// trim off the outer braces | ||
$input = substr($input, 1, strlen($input) - 2); | ||
|
||
$result = []; | ||
$arrayResult = []; | ||
$count = 0; | ||
|
||
// matches arrays | ||
preg_match_all('/[\[][^\]]*?[\]]/', $input, $paramInput); | ||
if (!empty($paramInput)) { | ||
foreach ($paramInput[0] as $param) { | ||
$arrayResult[static::PRESSKEY_ARRAY_ANCHOR_KEY . $count] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We call class constants as |
||
'[' . trim($this->addUniquenessToParamArray($param)) . ']'; | ||
$input = str_replace($param, static::PRESSKEY_ARRAY_ANCHOR_KEY . $count, $input); | ||
$count++; | ||
} | ||
} | ||
|
||
$paramArray = explode(",", $input); | ||
foreach ($paramArray as $param) { | ||
// matches strings wrapped in ', we assume these are string literals | ||
if (preg_match('/^[\s]*(\'.*?\')[\s]*$/', $param)) { | ||
$result[] = trim($param); | ||
continue; | ||
} | ||
|
||
// matches \ for Facebook WebDriverKeys classes | ||
if (substr(trim($param), 0, 1) === '\\') { | ||
$result[] = trim($param); | ||
continue; | ||
} | ||
|
||
// matches numbers | ||
if (preg_match('/^[\s]*(\d+?)[\s]*$/', $param)) { | ||
$result[] = $param; | ||
continue; | ||
} | ||
|
||
$replacement = $this->addUniquenessFunctionCall(trim($param)); | ||
|
||
$result[] = $replacement; | ||
} | ||
|
||
$result = implode(',', $result); | ||
if (!empty($arrayResult)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment here: |
||
foreach ($arrayResult as $key => $value) { | ||
$result = str_replace($key, $value, $result); | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Add uniqueness function call to input string based on regex pattern. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a little more commenting on here, what's actually happening is more like
find arrays, replace them with placeholder to prevent manipulation in foreach below