9 use Magento\Mtf\ObjectManager;
10 use Magento\Mtf\Client\Locator;
11 use Magento\Mtf\Client\ElementInterface;
66 protected $addNew =
'.//*[contains(@class,"rule-param-new-child")]/a';
73 protected $remove =
'.//*/a[@class="rule-param-remove"]';
80 protected $newCondition =
'./ul/li/span[contains(@class,"rule-param-new-child")]/..';
87 protected $typeNew =
'.//*[@class="element"]/select';
94 protected $created =
'./ul/li[span[contains(@class,"rule-param-new-child")]]/preceding-sibling::li[1]';
101 protected $children =
'.//ul[contains(@id,"conditions__")]';
108 protected $param =
'./span[span[*[substring(@id,(string-length(@id)-%d+1))="%s"]]]';
166 '\[' =>
'&lbracket;',
167 '\]' =>
'&rbracket;',
199 $this->eventManager->dispatchEvent([
'set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
202 $context = $this->
find($this->mainCondition, Locator::SELECTOR_XPATH);
203 if (!empty($conditions[0][
'TopLevelCondition'])) {
204 array_unshift($this->mapParams,
'aggregator');
206 $this->fillCondition($condition[
'rules'], $context);
207 unset($conditions[0]);
208 array_shift($this->mapParams);
224 $createdCondition = $context->find($this->created, Locator::SELECTOR_XPATH);
226 if (!empty($condition[
'rules'])) {
227 $this->fillCondition($condition[
'rules'], $createdCondition);
229 return $createdCondition;
241 foreach ($conditions as $key => $condition) {
243 if (is_string($condition)) {
262 $createdCondition = $context->find($this->created, Locator::SELECTOR_XPATH);
264 $this->fillCondition($condition[
'rules'], $createdCondition);
277 $newCondition = $context->find($this->newCondition, Locator::SELECTOR_XPATH);
281 $newCondition->find($this->addNew, Locator::SELECTOR_XPATH)->click();
284 $newCondition->find($this->typeNew, Locator::SELECTOR_XPATH,
'select')->setValue(
$type);
286 }
catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
288 $this->exception = $e;
289 $this->eventManager->dispatchEvent([
'exception'], [__METHOD__, $this->getAbsoluteSelector()]);
292 }
while (!$isSetType &&
$count < self::TRY_COUNT);
295 $exception = $this->exception ? $this->exception : (new \Exception(
"Can not add condition: {$type}"));
311 protected function fillCondition(array
$rules, ElementInterface
$element)
314 foreach ($rules as
$rule) {
322 $openParamLink =
$param->find(
'a');
323 if ($openParamLink->isVisible()) {
324 $openParamLink->click();
326 $this->waitUntil(
function () use (
$param) {
327 return $param->find($this->ruleParamInput)->isVisible() ? true :
null;
337 }
catch (\PHPUnit_Extensions_Selenium2TestCase_WebDriverException $e) {
339 $this->exception = $e;
340 $this->eventManager->dispatchEvent([
'exception'], [__METHOD__, $this->getAbsoluteSelector()]);
343 }
while (!$isSet &&
$count < self::TRY_COUNT);
346 $exception = $this->exception ? $this->exception : (new \Exception(
'Can not set value: ' .
$rule));
361 if (preg_match(
'`%(.*?)%`',
$rule, $chooserGrid)) {
362 $chooserConfig = explode(
'#', $chooserGrid[1]);
365 $param->find($this->chooserLocator)->click();
366 $grid = ObjectManager::getInstance()->create(
367 str_replace(
'/',
'\\', $chooserConfig[0]),
369 'element' => $this->
find($this->chooserGridLocator)
372 $grid->searchAndSelect([$chooserConfig[1] =>
$rule]);
374 $apply =
$param->find($this->applyRuleParam, Locator::SELECTOR_XPATH);
375 if ($apply->isVisible()) {
393 $value =
$param->find(
'select', Locator::SELECTOR_TAG_NAME,
'select');
394 if (
$value->isVisible()) {
412 $value =
$param->find(
'input', Locator::SELECTOR_TAG_NAME);
413 if (
$value->isVisible()) {
416 $apply =
$param->find(
'.//*[@class="rule-param-apply"]', Locator::SELECTOR_XPATH);
417 if ($apply->isVisible()) {
435 $value = str_replace(array_keys($this->encodeChars), $this->encodeChars,
$value);
436 $value = preg_replace(
'/(\]|})({|\[)/',
'$1,$2',
$value);
440 $value = str_replace(array_keys($this->decodeChars), $this->decodeChars,
$value);
444 throw new \Exception(
'Bad format value.');
458 if (!preg_match_all(
'/([^|]+\|?)/', $condition, $match)) {
459 throw new \Exception(
'Bad format condition');
461 foreach ($match[1] as $key =>
$value) {
462 $match[1][$key] = rtrim(
$value,
'|');
466 'type' => array_shift($match[1]),
467 'rules' => array_values($match[1]),
480 if (preg_match_all(
'/([^|]+)\|?/', $condition, $match) ===
false) {
481 throw new \Exception(
'Bad format condition');
485 'rules' => $match[1],
499 if (!isset($this->mapParams[$this->findKeyParam])) {
500 throw new \Exception(
"Empty map of params");
503 $element = $context->find(sprintf($this->param, strlen(
$param),
$param), Locator::SELECTOR_XPATH);
504 $this->findKeyParam += 1;
517 $this->findKeyParam = 0;
530 return $element->getAttribute(
'class') ==
'rule-param-wait' ? null :
true;
542 $remote = $this->
find($this->
remove, Locator::SELECTOR_XPATH);
543 while ($remote->isVisible()) {
545 $remote = $this->
find($this->
remove, Locator::SELECTOR_XPATH);
addMultipleCondition(array $conditions, ElementInterface $context)
addSingleCondition($condition, ElementInterface $context)
addCondition($type, ElementInterface $context)
elseif(isset( $params[ 'redirect_parent']))
fillSelect($rule, ElementInterface $param)
addConditionsCombination($condition, ElementInterface $context)
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
fillText($rule, ElementInterface $param)
parseTopLevelCondition($condition)
waitForCondition(ElementInterface $element)
findNextParam(ElementInterface $context)
fillGrid($rule, ElementInterface $param)
parseCondition($condition)