Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / tests / Behat / Gherkin / GherkinTest.php
1 <?php
2
3 namespace Tests\Behat\Gherkin;
4
5 use Behat\Gherkin\Gherkin;
6 use Behat\Gherkin\Node\FeatureNode;
7 use Behat\Gherkin\Node\ScenarioNode;
8
9 class GherkinTest extends \PHPUnit_Framework_TestCase
10 {
11     public function testLoader()
12     {
13         $customFilter1 = $this->getCustomFilterMock();
14         $customFilter2 = $this->getCustomFilterMock();
15
16         $gherkin = new Gherkin();
17         $gherkin->addLoader($loader = $this->getLoaderMock());
18         $gherkin->addFilter($nameFilter = $this->getNameFilterMock());
19         $gherkin->addFilter($tagFilter = $this->getTagFilterMock());
20
21         $scenario = new ScenarioNode(null, array(), array(), null, null);
22         $feature = new FeatureNode(null, null, array(), null, array($scenario), null, null, null, null);
23
24         $loader
25             ->expects($this->once())
26             ->method('supports')
27             ->with($resource = 'some/feature/resource')
28             ->will($this->returnValue(true));
29         $loader
30             ->expects($this->once())
31             ->method('load')
32             ->with($resource)
33             ->will($this->returnValue(array($feature)));
34
35         $nameFilter
36             ->expects($this->once())
37             ->method('filterFeature')
38             ->with($this->identicalTo($feature))
39             ->will($this->returnValue($feature));
40         $tagFilter
41             ->expects($this->once())
42             ->method('filterFeature')
43             ->with($this->identicalTo($feature))
44             ->will($this->returnValue($feature));
45         $customFilter1
46             ->expects($this->once())
47             ->method('filterFeature')
48             ->with($this->identicalTo($feature))
49             ->will($this->returnValue($feature));
50         $customFilter2
51             ->expects($this->once())
52             ->method('filterFeature')
53             ->with($this->identicalTo($feature))
54             ->will($this->returnValue($feature));
55
56         $features = $gherkin->load($resource, array($customFilter1, $customFilter2));
57         $this->assertEquals(1, count($features));
58
59         $scenarios = $features[0]->getScenarios();
60         $this->assertEquals(1, count($scenarios));
61         $this->assertSame($scenario, $scenarios[0]);
62     }
63
64     public function testNotFoundLoader()
65     {
66         $gherkin = new Gherkin();
67
68         $this->assertEquals(array(), $gherkin->load('some/feature/resource'));
69     }
70
71     public function testLoaderFiltersFeatures()
72     {
73         $gherkin = new Gherkin();
74         $gherkin->addLoader($loader = $this->getLoaderMock());
75         $gherkin->addFilter($nameFilter = $this->getNameFilterMock());
76
77         $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
78
79         $loader
80             ->expects($this->once())
81             ->method('supports')
82             ->with($resource = 'some/feature/resource')
83             ->will($this->returnValue(true));
84         $loader
85             ->expects($this->once())
86             ->method('load')
87             ->with($resource)
88             ->will($this->returnValue(array($feature)));
89
90         $nameFilter
91             ->expects($this->once())
92             ->method('filterFeature')
93             ->with($this->identicalTo($feature))
94             ->will($this->returnValue($feature));
95         $nameFilter
96             ->expects($this->once())
97             ->method('isFeatureMatch')
98             ->with($this->identicalTo($feature))
99             ->will($this->returnValue(false));
100
101         $features = $gherkin->load($resource);
102         $this->assertEquals(0, count($features));
103     }
104
105     public function testSetFiltersOverridesAllFilters()
106     {
107         $gherkin = new Gherkin();
108         $gherkin->addLoader($loader = $this->getLoaderMock());
109         $gherkin->addFilter($nameFilter = $this->getNameFilterMock());
110         $gherkin->setFilters(array());
111
112         $feature = new FeatureNode(null, null, array(), null, array(), null, null, null, null);
113
114         $loader
115             ->expects($this->once())
116             ->method('supports')
117             ->with($resource = 'some/feature/resource')
118             ->will($this->returnValue(true));
119         $loader
120             ->expects($this->once())
121             ->method('load')
122             ->with($resource)
123             ->will($this->returnValue(array($feature)));
124
125         $nameFilter
126             ->expects($this->never())
127             ->method('filterFeature');
128         $nameFilter
129             ->expects($this->never())
130             ->method('isFeatureMatch');
131
132         $features = $gherkin->load($resource);
133         $this->assertEquals(1, count($features));
134     }
135
136     public function testSetBasePath()
137     {
138         $gherkin = new Gherkin();
139         $gherkin->addLoader($loader1 = $this->getLoaderMock());
140         $gherkin->addLoader($loader2 = $this->getLoaderMock());
141
142         $loader1
143             ->expects($this->once())
144             ->method('setBasePath')
145             ->with($basePath = '/base/path')
146             ->will($this->returnValue(null));
147
148         $loader2
149             ->expects($this->once())
150             ->method('setBasePath')
151             ->with($basePath = '/base/path')
152             ->will($this->returnValue(null));
153
154         $gherkin->setBasePath($basePath);
155     }
156
157     protected function getLoaderMock()
158     {
159         return $this->getMockBuilder('Behat\Gherkin\Loader\GherkinFileLoader')
160             ->disableOriginalConstructor()
161             ->getMock();
162     }
163
164     protected function getCustomFilterMock()
165     {
166         return $this->getMockBuilder('Behat\Gherkin\Filter\FilterInterface')
167             ->disableOriginalConstructor()
168             ->getMock();
169     }
170
171     protected function getNameFilterMock()
172     {
173         return $this->getMockBuilder('Behat\Gherkin\Filter\NameFilter')
174             ->disableOriginalConstructor()
175             ->getMock();
176     }
177
178     protected function getTagFilterMock()
179     {
180         return $this->getMockBuilder('Behat\Gherkin\Filter\TagFilter')
181             ->disableOriginalConstructor()
182             ->getMock();
183     }
184 }