|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\DrupalExtension; |
|
4
|
|
|
|
|
5
|
|
|
use Behat\Behat\Hook\Scope\BeforeFeatureScope; |
|
6
|
|
|
use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
|
7
|
|
|
use Behat\Behat\Hook\Scope\BeforeStepScope; |
|
8
|
|
|
use Behat\Behat\Hook\Scope\StepScope; |
|
9
|
|
|
use Behat\Gherkin\Node\ScenarioInterface; |
|
10
|
|
|
use Behat\Testwork\Hook\Scope\HookScope; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Helper methods to check the tags that are present on a feature or scenario. |
|
14
|
|
|
*/ |
|
15
|
|
|
trait TagTrait |
|
16
|
|
|
{ |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var \Drupal\DrupalExtension\TagTraitHelper |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $tagTraitHelper; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Tracks the scopes that can be tagged. |
|
25
|
|
|
* |
|
26
|
|
|
* Tags can be put on features as well as scenarios. This hook will fire |
|
27
|
|
|
* when a new feature or scenario is being executed and will keep track of |
|
28
|
|
|
* both so that the tags can be inspected during the test. |
|
29
|
|
|
* |
|
30
|
|
|
* @param \Behat\Testwork\Hook\Scope\HookScope $scope |
|
31
|
|
|
* |
|
32
|
|
|
* @BeforeScenario |
|
33
|
|
|
* @BeforeStep |
|
34
|
|
|
*/ |
|
35
|
|
|
public function registerTagContainingScopes(HookScope $scope) |
|
36
|
|
|
{ |
|
37
|
|
|
if ($scope instanceof BeforeScenarioScope) { |
|
38
|
|
|
$this->getTagTraitHelper()->registerScenario($scope); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($scope instanceof BeforeStepScope) { |
|
42
|
|
|
$this->getTagTraitHelper()->registerFeature($scope); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns the helper class as a singleton. |
|
48
|
|
|
* |
|
49
|
|
|
* @return \Drupal\DrupalExtension\TagTraitHelper |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function getTagTraitHelper() |
|
52
|
|
|
{ |
|
53
|
|
|
if (empty($this->tagTraitHelper)) { |
|
54
|
|
|
$this->tagTraitHelper = new TagTraitHelper(); |
|
55
|
|
|
} |
|
56
|
|
|
return $this->tagTraitHelper; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns all tags for the current scenario and feature. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string[] |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function getTags() |
|
65
|
|
|
{ |
|
66
|
|
|
$featureTags = $this->getTagTraitHelper()->getFeature()->getTags(); |
|
|
|
|
|
|
67
|
|
|
$scenarioTags = $this->getTagTraitHelper()->getScenario()->getTags(); |
|
|
|
|
|
|
68
|
|
|
return array_unique(array_merge($featureTags, $scenarioTags)); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Checks whether the current scenario or feature has the given tag. |
|
73
|
|
|
* |
|
74
|
|
|
* @param string $tag |
|
75
|
|
|
* |
|
76
|
|
|
* @return bool |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function hasTag($tag) |
|
79
|
|
|
{ |
|
80
|
|
|
return in_array($tag, $this->getTags()); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.