|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NuvoleWeb\Drupal\DrupalExtension\Context; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Component\Render\FormattableMarkup; |
|
6
|
|
|
use Drupal\DrupalExtension\Context\RawDrupalContext as OriginalRawDrupalContext; |
|
7
|
|
|
use Drupal\node\Entity\Node; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class RawDrupalContext. |
|
11
|
|
|
* |
|
12
|
|
|
* @package NuvoleWeb\Drupal\DrupalExtension\Context |
|
13
|
|
|
*/ |
|
14
|
|
|
class RawDrupalContext extends OriginalRawDrupalContext { |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Get current Drupal core. |
|
18
|
|
|
* |
|
19
|
|
|
* @return \NuvoleWeb\Drupal\Driver\Cores\CoreInterface |
|
20
|
|
|
* Drupal core object instance. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getCore() { |
|
23
|
|
|
return $this->getDriver()->getCore(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Assert access denied page. |
|
28
|
|
|
* |
|
29
|
|
|
* @Then I should get an access denied error |
|
30
|
|
|
*/ |
|
31
|
|
|
public function assertAccessDenied() { |
|
32
|
|
|
$this->assertSession()->statusCodeEquals(403); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Pause execution for given number of seconds. |
|
37
|
|
|
* |
|
38
|
|
|
* @Then I wait :seconds seconds |
|
39
|
|
|
*/ |
|
40
|
|
|
public function iWaitSeconds($seconds) { |
|
41
|
|
|
sleep((int) $seconds); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Loads a node by name. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $title |
|
48
|
|
|
* The title of the node to load. |
|
49
|
|
|
* |
|
50
|
|
|
* @return Node |
|
51
|
|
|
* The loaded node. |
|
52
|
|
|
* |
|
53
|
|
|
* @throws \Exception |
|
54
|
|
|
* Thrown when no node with the given title can be loaded. |
|
55
|
|
|
*/ |
|
56
|
|
|
public function loadNodeByName($title) { |
|
57
|
|
|
|
|
58
|
|
|
$result = \Drupal::entityQuery('node') |
|
59
|
|
|
->condition('title', $title) |
|
60
|
|
|
->condition('status', NODE_PUBLISHED) |
|
61
|
|
|
->range(0, 1) |
|
62
|
|
|
->execute(); |
|
63
|
|
|
|
|
64
|
|
|
if (empty($result)) { |
|
65
|
|
|
$params = array( |
|
66
|
|
|
'@title' => $title, |
|
67
|
|
|
); |
|
68
|
|
|
throw new \Exception(new FormattableMarkup("Node @title not found.", $params)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
$nid = current($result); |
|
72
|
|
|
return Node::load($nid); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|