Security update for permissions_by_term
[yaffs-website] / vendor / behat / gherkin / src / Behat / Gherkin / Node / OutlineNode.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\Node;
12
13 /**
14  * Represents Gherkin Outline.
15  *
16  * @author Konstantin Kudryashov <ever.zet@gmail.com>
17  */
18 class OutlineNode implements ScenarioInterface
19 {
20     /**
21      * @var string
22      */
23     private $title;
24     /**
25      * @var string[]
26      */
27     private $tags;
28     /**
29      * @var StepNode[]
30      */
31     private $steps;
32     /**
33      * @var ExampleTableNode
34      */
35     private $table;
36     /**
37      * @var string
38      */
39     private $keyword;
40     /**
41      * @var integer
42      */
43     private $line;
44     /**
45      * @var null|ExampleNode[]
46      */
47     private $examples;
48
49     /**
50      * Initializes outline.
51      *
52      * @param null|string      $title
53      * @param string[]         $tags
54      * @param StepNode[]       $steps
55      * @param ExampleTableNode $table
56      * @param string           $keyword
57      * @param integer          $line
58      */
59     public function __construct(
60         $title,
61         array $tags,
62         array $steps,
63         ExampleTableNode $table,
64         $keyword,
65         $line
66     ) {
67         $this->title = $title;
68         $this->tags = $tags;
69         $this->steps = $steps;
70         $this->table = $table;
71         $this->keyword = $keyword;
72         $this->line = $line;
73     }
74
75     /**
76      * Returns node type string
77      *
78      * @return string
79      */
80     public function getNodeType()
81     {
82         return 'Outline';
83     }
84
85     /**
86      * Returns outline title.
87      *
88      * @return null|string
89      */
90     public function getTitle()
91     {
92         return $this->title;
93     }
94
95     /**
96      * Checks if outline is tagged with tag.
97      *
98      * @param string $tag
99      *
100      * @return Boolean
101      */
102     public function hasTag($tag)
103     {
104         return in_array($tag, $this->getTags());
105     }
106
107     /**
108      * Checks if outline has tags (both inherited from feature and own).
109      *
110      * @return Boolean
111      */
112     public function hasTags()
113     {
114         return 0 < count($this->getTags());
115     }
116
117     /**
118      * Returns outline tags (including inherited from feature).
119      *
120      * @return string[]
121      */
122     public function getTags()
123     {
124         return $this->tags;
125     }
126
127     /**
128      * Checks if outline has steps.
129      *
130      * @return Boolean
131      */
132     public function hasSteps()
133     {
134         return 0 < count($this->steps);
135     }
136
137     /**
138      * Returns outline steps.
139      *
140      * @return StepNode[]
141      */
142     public function getSteps()
143     {
144         return $this->steps;
145     }
146
147     /**
148      * Checks if outline has examples.
149      *
150      * @return Boolean
151      */
152     public function hasExamples()
153     {
154         return 0 < count($this->table->getColumnsHash());
155     }
156
157     /**
158      * Returns examples table.
159      *
160      * @return ExampleTableNode
161      */
162     public function getExampleTable()
163     {
164         return $this->table;
165     }
166
167     /**
168      * Returns list of examples for the outline.
169      *
170      * @return ExampleNode[]
171      */
172     public function getExamples()
173     {
174         return $this->examples = $this->examples ? : $this->createExamples();
175     }
176
177     /**
178      * Returns outline keyword.
179      *
180      * @return string
181      */
182     public function getKeyword()
183     {
184         return $this->keyword;
185     }
186
187     /**
188      * Returns outline declaration line number.
189      *
190      * @return integer
191      */
192     public function getLine()
193     {
194         return $this->line;
195     }
196
197     /**
198      * Creates examples for this outline using examples table.
199      *
200      * @return ExampleNode[]
201      */
202     protected function createExamples()
203     {
204         $examples = array();
205         foreach ($this->table->getColumnsHash() as $rowNum => $row) {
206             $examples[] = new ExampleNode(
207                 $this->table->getRowAsString($rowNum + 1),
208                 $this->tags,
209                 $this->getSteps(),
210                 $row,
211                 $this->table->getRowLine($rowNum + 1),
212                 $this->getTitle()
213             );
214         }
215
216         return $examples;
217     }
218 }