Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Filter / NameFilter.php
1 <?php
2
3 /*
4  * This file is part of the Behat Gherkin.
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\Gherkin\Filter;
12
13 use Behat\Gherkin\Node\FeatureNode;
14 use Behat\Gherkin\Node\ScenarioInterface;
15
16 /**
17  * Filters scenarios by feature/scenario name.
18  *
19  * @author Konstantin Kudryashov <ever.zet@gmail.com>
20  */
21 class NameFilter extends SimpleFilter
22 {
23     protected $filterString;
24
25     /**
26      * Initializes filter.
27      *
28      * @param string $filterString Name filter string
29      */
30     public function __construct($filterString)
31     {
32         $this->filterString = trim($filterString);
33     }
34
35     /**
36      * Checks if Feature matches specified filter.
37      *
38      * @param FeatureNode $feature Feature instance
39      *
40      * @return Boolean
41      */
42     public function isFeatureMatch(FeatureNode $feature)
43     {
44         if ('/' === $this->filterString[0]) {
45             return 1 === preg_match($this->filterString, $feature->getTitle());
46         }
47
48         return false !== mb_strpos($feature->getTitle(), $this->filterString, 0, 'utf8');
49     }
50
51     /**
52      * Checks if scenario or outline matches specified filter.
53      *
54      * @param ScenarioInterface $scenario Scenario or Outline node instance
55      *
56      * @return Boolean
57      */
58     public function isScenarioMatch(ScenarioInterface $scenario)
59     {
60         if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) {
61             return true;
62         } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) {
63             return true;
64         }
65
66         return false;
67     }
68 }