/** * Checks that this page is open in the browser. * * Default implementaion checks current URL against either `$this->url` * or `$this->presenterName` and `$this->parameters`. * * When testing some brually ajaxified application, this might be useful * to redefine in descendants. * * It is performed by each access to an element through a shortcut. * * @throws ViewStateException */ public function checkState() { if ($this->url) { if (($actualUrl = $this->session->url()) !== $this->url) { throw new ViewStateException(__METHOD__ . ": URL '{$this->url}' was expected, actual URL is '{$actualUrl}'."); } } else { $appRequest = $this->session->appRequest; if ($appRequest->presenterName !== $this->presenterName) { throw new ViewStateException(__METHOD__ . ": Presenter '{$this->presenterName}' was expected, actual presenter is '{$appRequest->presenterName}'."); } foreach (Utils::strToArray($this->presenterParameters) as $name => $value) { if ($appRequest->parameters[$name] !== $value) { throw new ViewStateException(__METHOD__ . ": Parameter '{$name}' is expected to be '{$value}', but is '{$appRequest->parameters[$name]}'."); } } } }
/** * Checks attributes of an element (only listed attributes are checked). * * @param array|string $expectedAttributes * @param Element $element */ public function assertTagAttributes($expectedAttributes, Element $element) { foreach (Utils::strToArray($expectedAttributes) as $attributeName => $expectedValue) { $this->assertSame($expectedValue, $actualValue = $element->attribute($attributeName), __FUNCTION__ . ": Atribut '{$attributeName}' by měl být '{$expectedValue}', je '{$actualValue}'."); } }
/** * Creates an URL. * * Parameters can be either a PHP array, or a Neon array without brackets. * Ie. Instead of `array('a' => 'b', 'c' => 'd')` you can pass `'a=b,c=d'`. * * @param string $presenterName * @param array|string $parameters */ public function getLink($presenterName, $parameters = array()) { $url = new \Nette\Http\UrlScript($this->context->parameters['selenium']['baseUrl']); $url->scriptPath = $url->path; $appRequest = new \Nette\Application\Request($presenterName, 'GET', Utils::strToArray($parameters)); return $this->context->router->constructUrl($appRequest, $url); }
/** * Provides processed shortcuts definitions (property-read annotations). * * @return array */ private function getShortcuts() { if (!isset($this->shortcuts)) { foreach ($this->getThisClasses() as $className) { $annotations = Utils::getClassAnnotations($className); $readOnlyProperties = isset($annotations['property-read']) ? $annotations['property-read'] : array(); foreach ($readOnlyProperties as $property) { // Splitting @property-read $propertyType $propertyName $propertyDescription list($propertyType, $propertyName, $propertyDescription) = preg_split('~\\s+~', $property, 3) + array(NULL, NULL, NULL); if (substr($propertyName, 0, 1) === '$') { list($propertyDescription) = preg_split('~\\s+#~', $propertyDescription, 2); // Throw away the comment $definition = Utils::strToArray($propertyDescription); if ($definition) { // array('id' => 'foo', 'x', 'y') ==> array('id', 'foo', 'x', 'y') $strategy = key($definition); $strategyValue = array_shift($definition); array_unshift($definition, substr($propertyType, -2) === '[]'); // array of elements array_unshift($definition, $strategyValue); // strategy value array_unshift($definition, $strategy); // strategy $this->shortcuts[substr($propertyName, 1)] = $definition; } } } } } return $this->shortcuts; }