Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TestObject.php
Go to the documentation of this file.
1 <?php
8 
14 
19 {
20  const WAIT_TIME_ATTRIBUTE = 'time';
21 
23  'waitForPageLoad' => 1500,
24  'amOnPage' => 1000,
25  'waitForLoadingMaskToDisappear' => 500,
26  'wait' => self::WAIT_TIME_ATTRIBUTE,
27  'comment' => 5,
28  'assertCount' => 5,
29  'closeAdminNotification' => 10
30  ];
31 
37  private $name;
38 
44  private $parsedSteps = [];
45 
51  private $annotations = [];
52 
58  private $hooks = [];
59 
65  private $filename;
66 
72  private $parentTest;
73 
84  public function __construct($name, $parsedSteps, $annotations, $hooks, $filename = null, $parentTest = null)
85  {
86  $this->name = $name;
87  $this->parsedSteps = $parsedSteps;
88  $this->annotations = $annotations;
89  $this->hooks = $hooks;
90  $this->filename = $filename;
91  $this->parentTest = $parentTest;
92  }
93 
99  public function getName()
100  {
101  return $this->name;
102  }
103 
109  public function getFilename()
110  {
111  return $this->filename;
112  }
113 
119  public function getParentName()
120  {
121  return $this->parentTest;
122  }
123 
129  public function isSkipped()
130  {
131  // TODO deprecation|deprecate MFTF 3.0.0 remove elseif when group skip is no longer allowed
132  if (array_key_exists('skip', $this->annotations)) {
133  return true;
134  } elseif (array_key_exists('group', $this->annotations) && (in_array("skip", $this->annotations['group']))) {
135  return true;
136  }
137  return false;
138  }
139 
145  public function getCodeceptionName()
146  {
147  if (strpos($this->name, 'Cest') && substr($this->name, -4) == 'Cest') {
148  return $this->name;
149  }
150 
151  return $this->name . 'Cest';
152  }
153 
159  public function getAnnotations()
160  {
161  return $this->annotations;
162  }
163 
169  public function getHooks()
170  {
171  return $this->hooks;
172  }
173 
179  public function getEstimatedDuration()
180  {
181  // a skipped action results in a single skip being appended to the beginning of the test and no execution
182  if ($this->isSkipped()) {
183  return 1;
184  }
185 
186  $hookTime = 0;
188  if (array_key_exists($hookName, $this->hooks)) {
189  $hookTime += $this->calculateWeightedActionTimes($this->hooks[$hookName]->getActions());
190  }
191  }
192 
193  $testTime = $this->calculateWeightedActionTimes($this->getOrderedActions());
194 
195  return $hookTime + $testTime;
196  }
197 
204  private function calculateWeightedActionTimes($actions)
205  {
206  $actionTime = 0;
207  // search for any actions of special type
208  foreach ($actions as $action) {
210  if (array_key_exists($action->getType(), self::TEST_ACTION_WEIGHT)) {
211  $weight = self::TEST_ACTION_WEIGHT[$action->getType()];
212  if ($weight === self::WAIT_TIME_ATTRIBUTE) {
213  $weight = intval($action->getCustomActionAttributes()[$weight]) * 1000;
214  }
215 
216  $actionTime += $weight;
217  continue;
218  }
219 
220  $actionTime += 50;
221  }
222 
223  return $actionTime;
224  }
225 
232  public function getAnnotationByName($name)
233  {
234  if (array_key_exists($name, $this->annotations)) {
235  return $this->annotations[$name];
236  }
237 
238  return [];
239  }
240 
246  public function getCustomData()
247  {
248  return $this->customData;
249  }
250 
256  public function getOrderedActions()
257  {
258  $mergeUtil = new ActionMergeUtil($this->getName(), "Test");
259  return $mergeUtil->resolveActionSteps($this->parsedSteps);
260  }
261 
267  public function getUnresolvedSteps()
268  {
269  return $this->parsedSteps;
270  }
271 
277  public function getDebugInformation()
278  {
279  $debugInformation = [];
280  $orderList = $this->getOrderedActions();
281 
282  foreach ($orderList as $action) {
283  $debugInformation[] = "\t" . $action->getType() . ' ' . $action->getStepKey();
284  }
285 
286  return $debugInformation;
287  }
288 }
__construct($name, $parsedSteps, $annotations, $hooks, $filename=null, $parentTest=null)
Definition: TestObject.php:84
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17