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
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Sylius\Behat\Service; |
15
|
|
|
|
16
|
|
|
use Behat\Mink\Driver\Selenium2Driver; |
17
|
|
|
use Behat\Mink\Element\NodeElement; |
18
|
|
|
use Behat\Mink\Session; |
19
|
|
|
use DMore\ChromeDriver\ChromeDriver; |
20
|
|
|
use Webmozart\Assert\Assert; |
21
|
|
|
|
22
|
|
|
abstract class SlugGenerationHelper |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
public static function waitForSlugGeneration(Session $session, NodeElement $element): void |
25
|
|
|
{ |
26
|
|
|
JQueryHelper::waitForAsynchronousActionsToFinish($session); |
27
|
|
|
|
28
|
|
|
static::isElementReadonly($session, $element); |
|
|
|
|
29
|
|
|
|
30
|
|
|
JQueryHelper::waitForAsynchronousActionsToFinish($session); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public static function enableSlugModification(Session $session, NodeElement $element): void |
34
|
|
|
{ |
35
|
|
|
JQueryHelper::waitForAsynchronousActionsToFinish($session); |
36
|
|
|
|
37
|
|
|
static::isElementReadonly($session, $element); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$element->click(); |
40
|
|
|
|
41
|
|
|
static::isElementNotReadonly($session, $element); |
|
|
|
|
42
|
|
|
|
43
|
|
|
JQueryHelper::waitForAsynchronousActionsToFinish($session); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public static function isSlugReadonly(Session $session, NodeElement $element): bool |
47
|
|
|
{ |
48
|
|
|
if (!$session->getDriver() instanceof Selenium2Driver && !$session->getDriver() instanceof ChromeDriver) { |
|
|
|
|
49
|
|
|
return $element->hasAttribute('readonly'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
JQueryHelper::waitForAsynchronousActionsToFinish($session); |
53
|
|
|
|
54
|
|
|
return static::isElementReadonly($session, $element); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
private static function isElementReadonly(Session $session, NodeElement $element): bool |
58
|
|
|
{ |
59
|
|
|
return $session->wait(1000, sprintf( |
60
|
|
|
'undefined != $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")', |
61
|
|
|
str_replace('"', '\"', $element->getXpath()) |
62
|
|
|
)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private static function isElementNotReadonly(Session $session, NodeElement $element): bool |
66
|
|
|
{ |
67
|
|
|
return $session->wait(1000, sprintf( |
68
|
|
|
'undefined == $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")', |
69
|
|
|
str_replace('"', '\"', $element->getXpath()) |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.