Security update for permissions_by_term
[yaffs-website] / vendor / behat / mink / src / Element / Element.php
1 <?php
2
3 /*
4  * This file is part of the Mink package.
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\Mink\Element;
12
13 use Behat\Mink\Driver\DriverInterface;
14 use Behat\Mink\Exception\ElementNotFoundException;
15 use Behat\Mink\Selector\SelectorsHandler;
16 use Behat\Mink\Selector\Xpath\Manipulator;
17 use Behat\Mink\Session;
18
19 /**
20  * Base element.
21  *
22  * @author Konstantin Kudryashov <ever.zet@gmail.com>
23  */
24 abstract class Element implements ElementInterface
25 {
26     /**
27      * @var Session
28      */
29     private $session;
30
31     /**
32      * Driver.
33      *
34      * @var DriverInterface
35      */
36     private $driver;
37
38     /**
39      * @var SelectorsHandler
40      */
41     private $selectorsHandler;
42
43     /**
44      * @var Manipulator
45      */
46     private $xpathManipulator;
47
48     /**
49      * Initialize element.
50      *
51      * @param Session $session
52      */
53     public function __construct(Session $session)
54     {
55         $this->xpathManipulator = new Manipulator();
56         $this->session = $session;
57
58         $this->driver = $session->getDriver();
59         $this->selectorsHandler = $session->getSelectorsHandler();
60     }
61
62     /**
63      * Returns element session.
64      *
65      * @return Session
66      *
67      * @deprecated Accessing the session from the element is deprecated as of 1.6 and will be impossible in 2.0.
68      */
69     public function getSession()
70     {
71         @trigger_error(sprintf('The method %s is deprecated as of 1.6 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);
72
73         return $this->session;
74     }
75
76     /**
77      * Returns element's driver.
78      *
79      * @return DriverInterface
80      */
81     protected function getDriver()
82     {
83         return $this->driver;
84     }
85
86     /**
87      * Returns selectors handler.
88      *
89      * @return SelectorsHandler
90      *
91      * @deprecated Accessing the selectors handler in the element is deprecated as of 1.7 and will be impossible in 2.0.
92      */
93     protected function getSelectorsHandler()
94     {
95         @trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);
96
97         return $this->selectorsHandler;
98     }
99
100     /**
101      * {@inheritdoc}
102      */
103     public function has($selector, $locator)
104     {
105         return null !== $this->find($selector, $locator);
106     }
107
108     /**
109      * {@inheritdoc}
110      */
111     public function isValid()
112     {
113         return 1 === count($this->getDriver()->find($this->getXpath()));
114     }
115
116     /**
117      * {@inheritdoc}
118      */
119     public function waitFor($timeout, $callback)
120     {
121         if (!is_callable($callback)) {
122             throw new \InvalidArgumentException('Given callback is not a valid callable');
123         }
124
125         $start = microtime(true);
126         $end = $start + $timeout;
127
128         do {
129             $result = call_user_func($callback, $this);
130
131             if ($result) {
132                 break;
133             }
134
135             usleep(100000);
136         } while (microtime(true) < $end);
137
138         return $result;
139     }
140
141     /**
142      * {@inheritdoc}
143      */
144     public function find($selector, $locator)
145     {
146         $items = $this->findAll($selector, $locator);
147
148         return count($items) ? current($items) : null;
149     }
150
151     /**
152      * {@inheritdoc}
153      */
154     public function findAll($selector, $locator)
155     {
156         if ('named' === $selector) {
157             $items = $this->findAll('named_exact', $locator);
158             if (empty($items)) {
159                 $items = $this->findAll('named_partial', $locator);
160             }
161
162             return $items;
163         }
164
165         $xpath = $this->selectorsHandler->selectorToXpath($selector, $locator);
166         $xpath = $this->xpathManipulator->prepend($xpath, $this->getXpath());
167
168         return $this->getDriver()->find($xpath);
169     }
170
171     /**
172      * {@inheritdoc}
173      */
174     public function getText()
175     {
176         return $this->getDriver()->getText($this->getXpath());
177     }
178
179     /**
180      * {@inheritdoc}
181      */
182     public function getHtml()
183     {
184         return $this->getDriver()->getHtml($this->getXpath());
185     }
186
187     /**
188      * Returns element outer html.
189      *
190      * @return string
191      */
192     public function getOuterHtml()
193     {
194         return $this->getDriver()->getOuterHtml($this->getXpath());
195     }
196
197     /**
198      * Builds an ElementNotFoundException.
199      *
200      * @param string      $type
201      * @param string|null $selector
202      * @param string|null $locator
203      *
204      * @return ElementNotFoundException
205      *
206      * @deprecated as of 1.7, to be removed in 2.0
207      */
208     protected function elementNotFound($type, $selector = null, $locator = null)
209     {
210         @trigger_error(sprintf('The method %s is deprecated as of 1.7 and will be removed in 2.0', __METHOD__), E_USER_DEPRECATED);
211
212         return new ElementNotFoundException($this->driver, $type, $selector, $locator);
213     }
214 }