Esempio n. 1
0
 /**
  * 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}'.");
     }
 }
Esempio n. 2
0
 /**
  * Performs calling "magic" methods from annotations.
  *
  * For example, annotation `method SomePage clickFoo()` defines a magic
  * method that calls `$this->foo->click()` and returns an object of type
  * `SomePage`. If `$this` is instance of that type, it will return `$this`.
  * Otherwise it instantiates a new object.
  *
  * Either way it calls the method {@see self::checkState()} afterwise on the
  * return object.
  *
  * The annotation may contain more return types, separated by vertical bar.
  * First that match is returned back.
  *
  * Another magic method is fillShortcut - if it is defined such a shortcut,
  * it will translate to `$this->shortcut->value($input)`, but it returns
  * `$this`.
  *
  * @param string $name Name of called method.
  * @param array $args
  * @return mixed
  */
 public function __call($name, $args)
 {
     if (!isset($this->methods)) {
         foreach ($this->getThisClasses() as $className) {
             $annotations = Utils::getClassAnnotations($className);
             $methodAnnotations = isset($annotations['method']) ? $annotations['method'] : array();
             foreach ($methodAnnotations as $methodAnnotation) {
                 if (preg_match('~^(?<type>[^\\s]+)\\s+(?<methodName>[^\\s(]+)~', $methodAnnotation, $matches)) {
                     $returnType = $matches['type'];
                     $fullMethodName = $matches['methodName'];
                     if (preg_match('~^(?<elementMethod>[[:lower:]]+)(?<elementShortcut>.*)~', $fullMethodName, $matches)) {
                         $elementMethod = $matches['elementMethod'];
                         $elementShortcut = isset($this->{$matches['elementShortcut']}) ? $matches['elementShortcut'] : lcfirst($matches['elementShortcut']);
                         if (isset($this->{$elementShortcut})) {
                             $this->methods[$fullMethodName] = array($elementShortcut, $elementMethod, $returnType, $className);
                         }
                     }
                 }
             }
         }
     }
     if (isset($this->methods[$name])) {
         $elementShortcut = $this->methods[$name][0];
         $elementMethod = $this->methods[$name][1];
         callback($this->{$elementShortcut}, $elementMethod)->invokeArgs($args);
         $this->session->waitForDocument();
         return $this->getNextPageFromList(explode('|', $this->methods[$name][2]), $this->methods[$name][3]);
     } elseif (substr($name, 0, 4) === 'fill' && (isset($this->{$shortcut = substr($name, 4)}) || isset($this->{$shortcut = lcfirst(substr($name, 4))}))) {
         callback($this->{$shortcut}, 'value')->invokeArgs($args);
         return $this;
     } else {
         return parent::__call($name, $args);
     }
 }
Esempio n. 3
0
 /**
  * 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);
 }
Esempio n. 4
0
 private function parseNavigationAnnotations()
 {
     foreach (Utils::getWholeLineageOfClass(get_class($this)) as $className) {
         $classAnnotations = Utils::getClassAnnotations($className);
         if (isset($classAnnotations['presenterName'])) {
             $this->presenterName = reset($classAnnotations['presenterName']);
         }
         if (isset($classAnnotations['presenterParameters'])) {
             $this->presenterParameters = reset($classAnnotations['presenterParameters']);
         }
         if (isset($classAnnotations['url'])) {
             $this->url = reset($classAnnotations['url']);
         }
     }
 }