1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Mink\Element\NodeElement; |
4
|
|
|
use Behat\MinkExtension\Context\MinkContext as BaseMinkContext; |
5
|
|
|
|
6
|
|
|
class MinkContext extends BaseMinkContext |
|
|
|
|
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Updated version of MinkContext::checkOption which correctly deal with iCheck fields. |
10
|
|
|
* |
11
|
|
|
* {@inheritdoc} |
12
|
|
|
*/ |
13
|
|
|
public function checkOption($option) |
14
|
|
|
{ |
15
|
|
|
$option = $this->fixStepArgument($option); |
16
|
|
|
$element = $this->getSession()->getPage()->findField($option); |
17
|
|
|
|
18
|
|
|
if (!$element) { |
19
|
|
|
throw new \InvalidArgumentException(sprintf("Field '%s' not found", $option)); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
$parent = $element->getParent(); |
23
|
|
|
|
24
|
|
|
if ($parent && $parent->hasClass('icheckbox_square-blue')) { |
25
|
|
|
$iCheckElement = $parent->find('css', '.iCheck-helper'); |
26
|
|
|
|
27
|
|
|
if (!$iCheckElement) { |
28
|
|
|
throw new \InvalidArgumentException(sprintf("iCheck element '.iCheck-helper' not found for '%s'", $option)); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$iCheckElement->click(); |
32
|
|
|
} else { |
33
|
|
|
$element->check(); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Updated version of MinkContext::fillField which correctly deal with CKEDITOR fields. |
39
|
|
|
* |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
*/ |
42
|
|
|
public function fillField($field, $value) |
43
|
|
|
{ |
44
|
|
|
$field = $this->fixStepArgument($field); |
45
|
|
|
$value = $this->fixStepArgument($value); |
46
|
|
|
/** @var NodeElement[] $elements */ |
47
|
|
|
$element = $this->getSession()->getPage()->find('named', ['field', $field]); |
48
|
|
|
|
49
|
|
|
if (!$element) { |
50
|
|
|
throw new \InvalidArgumentException(sprintf("Field '%s' not found", $field)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
if ($element->getTagName() === 'textarea' && $element->hasClass('ckeditor')) { |
54
|
|
|
$fieldId = $element->getAttribute('id'); |
55
|
|
|
|
56
|
|
|
if ($fieldId === null || $fieldId === '') { |
57
|
|
|
throw new \LogicException(sprintf("Unable to fill in CKEDITOR field '%s' as it's id attribute is missing.", $field)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$this->getSession()->executeScript(sprintf('CKEDITOR && CKEDITOR.instances["%s"].setData("%s");', $fieldId, $value)); |
61
|
|
|
} else { |
62
|
|
|
$element->setValue($value); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @When I scroll to ":locator" |
68
|
|
|
* @param string $locator |
69
|
|
|
*/ |
70
|
|
|
public function scrollIntoView($locator) |
71
|
|
|
{ |
72
|
|
|
$element = $this->getSession()->getPage()->find('named', ['field', $locator]); |
73
|
|
|
$xpath = str_replace("\n", '', $element->getXpath()); |
74
|
|
|
$function = "document.evaluate(\"{$xpath}\", document).iterateNext().scrollIntoView();"; |
75
|
|
|
$this->getSession()->executeScript($function); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.