Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Hook / Call / RuntimeScenarioHook.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Hook\Call;
12
13 use Behat\Behat\Hook\Scope\ScenarioScope;
14 use Behat\Gherkin\Filter\NameFilter;
15 use Behat\Gherkin\Filter\TagFilter;
16 use Behat\Gherkin\Node\FeatureNode;
17 use Behat\Gherkin\Node\ScenarioInterface;
18 use Behat\Testwork\Hook\Call\RuntimeFilterableHook;
19 use Behat\Testwork\Hook\Scope\HookScope;
20
21 /**
22  * Represents a scenario hook.
23  *
24  * @author Konstantin Kudryashov <ever.zet@gmail.com>
25  */
26 abstract class RuntimeScenarioHook extends RuntimeFilterableHook
27 {
28     /**
29      * {@inheritdoc}
30      */
31     public function filterMatches(HookScope $scope)
32     {
33         if (!$scope instanceof ScenarioScope) {
34             return false;
35         }
36
37         if (null === ($filterString = $this->getFilterString())) {
38             return true;
39         }
40
41         return $this->isMatch($scope->getFeature(), $scope->getScenario(), $filterString);
42     }
43
44     /**
45      * Checks if nodes match filter.
46      *
47      * @param FeatureNode       $feature
48      * @param ScenarioInterface $scenario
49      * @param string            $filterString
50      *
51      * @return Boolean
52      */
53     protected function isMatch(FeatureNode $feature, ScenarioInterface $scenario, $filterString)
54     {
55         if (false !== strpos($filterString, '@')) {
56             return $this->isMatchTagFilter($feature, $scenario, $filterString);
57         }
58
59         if (!empty($filterString)) {
60             return $this->isMatchNameFilter($scenario, $filterString);
61         }
62
63         return false;
64     }
65
66     /**
67      * Checks if node match tag filter.
68      *
69      * @param FeatureNode       $feature
70      * @param ScenarioInterface $scenario
71      * @param string            $filterString
72      *
73      * @return Boolean
74      */
75     protected function isMatchTagFilter(FeatureNode $feature, ScenarioInterface $scenario, $filterString)
76     {
77         $filter = new TagFilter($filterString);
78
79         if ($filter->isFeatureMatch($feature)) {
80             return true;
81         }
82
83         return $filter->isScenarioMatch($feature, $scenario);
84     }
85
86     /**
87      * Checks if scenario matches name filter.
88      *
89      * @param ScenarioInterface $scenario
90      * @param string            $filterString
91      *
92      * @return Boolean
93      */
94     protected function isMatchNameFilter(ScenarioInterface $scenario, $filterString)
95     {
96         $filter = new NameFilter($filterString);
97
98         return $filter->isScenarioMatch($scenario);
99     }
100 }