1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Behat\Service; |
13
|
|
|
|
14
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
15
|
|
|
use Behat\Mink\Element\NodeElement; |
16
|
|
|
use Behat\Mink\Session; |
17
|
|
|
use Webmozart\Assert\Assert; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Jan Góralski <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class SlugGenerationHelper |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param Session $session |
26
|
|
|
* @param NodeElement $element |
27
|
|
|
*/ |
28
|
|
|
public static function waitForSlugGeneration(Session $session, NodeElement $element) |
29
|
|
|
{ |
30
|
|
|
Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); |
31
|
|
|
|
32
|
|
|
static::waitForAsynchronousActionsToFinish($session); |
|
|
|
|
33
|
|
|
static::isElementReadonly($session, $element); |
|
|
|
|
34
|
|
|
static::waitForAsynchronousActionsToFinish($session); |
|
|
|
|
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param Session $session |
39
|
|
|
* @param NodeElement $element |
40
|
|
|
*/ |
41
|
|
|
public static function enableSlugModification(Session $session, NodeElement $element) |
42
|
|
|
{ |
43
|
|
|
Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); |
44
|
|
|
|
45
|
|
|
static::waitForAsynchronousActionsToFinish($session); |
|
|
|
|
46
|
|
|
static::waitForElementToBeClickable($session, $element); |
|
|
|
|
47
|
|
|
|
48
|
|
|
$element->click(); |
49
|
|
|
|
50
|
|
|
static::waitForAsynchronousActionsToFinish($session); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param Session $session |
55
|
|
|
* @param NodeElement $element |
56
|
|
|
* |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
|
|
public static function isSlugReadonly(Session $session, NodeElement $element) |
60
|
|
|
{ |
61
|
|
|
if (!$session->getDriver() instanceof Selenium2Driver) { |
62
|
|
|
return $element->hasAttribute('readonly'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
static::waitForAsynchronousActionsToFinish($session); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return static::isElementReadonly($session, $element); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param Session $session |
72
|
|
|
* @param NodeElement $element |
73
|
|
|
*/ |
74
|
|
|
private static function waitForElementToBeClickable(Session $session, NodeElement $element) |
75
|
|
|
{ |
76
|
|
|
$session->wait(5000, sprintf( |
77
|
|
|
'false === $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).hasClass("loading")', |
78
|
|
|
$element->getParent()->getParent()->getXpath() |
79
|
|
|
)); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Session $session |
84
|
|
|
* @param NodeElement $element |
85
|
|
|
* |
86
|
|
|
* @return bool |
87
|
|
|
*/ |
88
|
|
|
private static function isElementReadonly(Session $session, NodeElement $element) |
89
|
|
|
{ |
90
|
|
|
return $session->wait(5000, sprintf( |
91
|
|
|
'undefined != $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")', |
92
|
|
|
$element->getXpath() |
93
|
|
|
)); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param Session $session |
98
|
|
|
*/ |
99
|
|
|
private static function waitForAsynchronousActionsToFinish(Session $session) |
100
|
|
|
{ |
101
|
|
|
$session->wait(5000, '0 === jQuery.active'); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.