20 "Merge Error - Step could not be found in either TestXML or DeltaXML. 21 \t%s: '%s'\tTestStep: '%s'\tLinkedStep: '%s'";
38 private $orderedSteps = [];
45 private $stepsToMerge = [];
69 $this->
name = $contextName;
70 $this->type = $contextType;
84 $this->mergeActions($parsedSteps);
86 $this->insertReadinessSkips();
88 if ($skipActionGroupResolution) {
89 return $this->orderedSteps;
92 $resolvedActions = $this->resolveActionGroups($this->orderedSteps);
93 return $this->resolveSecretFieldAccess($resolvedActions);
104 private function resolveSecretFieldAccess($resolvedActions)
107 foreach ($resolvedActions as $resolvedAction) {
108 $action = $resolvedAction;
109 $hasSecretRef = $this->actionAttributeContainsSecretRef($resolvedAction->getCustomActionAttributes());
111 if ($resolvedAction->getType() !==
'fillField' && $hasSecretRef) {
115 if ($resolvedAction->getType() ===
'fillField' && $hasSecretRef) {
116 $action =
new ActionObject(
117 $action->getStepKey(),
119 $action->getCustomActionAttributes(),
120 $action->getLinkedAction(),
121 $action->getActionOrigin()
125 $actions[$action->getStepKey()] = $action;
137 private function actionAttributeContainsSecretRef($actionAttributes)
139 foreach ($actionAttributes as $actionAttribute) {
140 if (is_array($actionAttribute)) {
141 return $this->actionAttributeContainsSecretRef($actionAttribute);
144 preg_match_all(
"/{{_CREDS\.([\w]+)}}/", $actionAttribute, $matches);
146 if (!empty($matches[0])) {
161 private function resolveActionGroups($mergedSteps)
163 $newOrderedList = [];
165 foreach ($mergedSteps as $key => $mergedStep) {
170 if ($actionGroup ==
null) {
171 throw new TestReferenceException(
"Could not find ActionGroup by ref \"{$actionGroupRef}\"");
174 $actionsToMerge = $actionGroup->getSteps($args, $key);
175 $newOrderedList = $newOrderedList + $actionsToMerge;
177 $newOrderedList[$key] = $mergedStep;
181 return $newOrderedList;
191 private function mergeActions($parsedSteps)
193 $this->sortActions($parsedSteps);
195 foreach ($this->stepsToMerge as $stepName => $stepToMerge) {
196 if (!array_key_exists($stepName, $this->orderedSteps)) {
197 $this->mergeAction($stepToMerge);
209 private function insertWaits()
211 foreach ($this->orderedSteps as $step) {
212 if ($step->getTimeout()) {
213 $waitStepAttributes = [self::WAIT_ATTR => $step->getTimeout()];
214 $waitStep =
new ActionObject(
221 $this->insertStep($waitStep);
231 private function insertReadinessSkips()
233 foreach ($this->orderedSteps as $step) {
234 if (array_key_exists(
"skipReadiness", $step->getCustomActionAttributes())) {
235 if ($step->getCustomActionAttributes()[
'skipReadiness'] ==
"true") {
236 $skipReadinessOn =
new ActionObject(
244 $skipReadinessOff =
new ActionObject(
247 [
'state' =>
"false"],
252 $this->insertStep($skipReadinessOn);
253 $this->insertStep($skipReadinessOff);
266 private function sortActions($parsedSteps)
268 foreach ($parsedSteps as $parsedStep) {
270 $parsedStep->resolveReferences();
272 if ($parsedStep->getLinkedAction()) {
273 $this->stepsToMerge[$parsedStep->getStepKey()] = $parsedStep;
275 $this->orderedSteps[$parsedStep->getStepKey()] = $parsedStep;
277 }
catch (\Exception $e) {
278 throw new TestReferenceException(
280 ".\nException occurred parsing action at StepKey \"" . $parsedStep->getStepKey() .
"\"" 293 private function mergeAction($stepToMerge)
295 $linkedStep = $stepToMerge->getLinkedAction();
297 if (!array_key_exists($linkedStep, $this->orderedSteps)
299 !array_key_exists($linkedStep, $this->stepsToMerge)) {
300 throw new XmlException(sprintf(
301 self::STEP_MISSING_ERROR_MSG,
304 $stepToMerge->getStepKey(),
307 }
elseif (!array_key_exists($linkedStep, $this->orderedSteps)) {
308 $this->mergeAction($this->stepsToMerge[$linkedStep]);
311 $this->insertStep($stepToMerge);
320 private function insertStep($stepToMerge)
322 $position = array_search(
323 $stepToMerge->getLinkedAction(),
324 array_keys($this->orderedSteps)
325 ) + $stepToMerge->getOrderOffset();
326 $previous_items = array_slice($this->orderedSteps, 0, $position,
true);
327 $next_items = array_slice($this->orderedSteps, $position,
null,
true);
328 $this->orderedSteps = $previous_items + [$stepToMerge->getStepKey() => $stepToMerge] + $next_items;
const SKIP_READINESS_ACTION_NAME
elseif(isset( $params[ 'redirect_parent']))
const STEP_MISSING_ERROR_MSG
const SKIP_READINESS_ON_SUFFIX
const DEFAULT_SKIP_OFF_ORDER
__construct($contextName, $contextType)
resolveActionSteps($parsedSteps, $skipActionGroupResolution=false)
const DEFAULT_SKIP_ON_ORDER
const SKIP_READINESS_OFF_SUFFIX