示例#1
0
 private static function reverseControls(NodeElement $content, dTable $dt)
 {
     $wrap = $content->getParent();
     self::reverseHeader($wrap, $dt);
     self::reverseFooter($wrap, $dt);
 }
示例#2
0
 /**
  * Returns the closest parent element having a specific class attribute.
  *
  * @param  NodeElement $el
  * @param  String  $class
  * @return Element|null
  */
 protected function findParentByClass(NodeElement $el, $class)
 {
     $container = $el->getParent();
     while ($container && $container->getTagName() != 'body') {
         if ($container->isVisible() && in_array($class, explode(' ', $container->getAttribute('class')))) {
             return $container;
         }
         $container = $container->getParent();
     }
     return null;
 }
示例#3
0
 /**
  * @param NodeElement $reply
  * @param NodeElement $comment
  *
  * @return bool
  */
 public function isReplyOfComment(NodeElement $reply, NodeElement $comment)
 {
     return $reply->getParent()->getText() === $comment->getParent()->getText();
 }
示例#4
0
 /**
  * Fills a select element with $value, identified by its $label.
  *
  * @param NodeElement $label
  * @param string      $value
  */
 protected function fillSelectField(NodeElement $label, $value)
 {
     $field = $label->getParent()->find('css', 'select');
     $field->selectOption($value);
 }
示例#5
0
 /**
  * Recursive method to find the field type.
  *
  * Depending on the field the felement class node is in a level or in another. We
  * look recursively for a parent node with a 'felement' class to find the field type.
  *
  * @param NodeElement $fieldnode The current node.
  * @param Session $session The behat browser session
  * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done.
  */
 protected static function get_field_node_type(NodeElement $fieldnode, Session $session)
 {
     // Special handling for availability field which requires custom JavaScript.
     if ($fieldnode->getAttribute('name') === 'availabilityconditionsjson') {
         return 'availability';
     }
     if ($fieldnode->getTagName() == 'html') {
         return false;
     }
     // If the type is explictly set on the element pointed to by the label - use it.
     if ($type = $fieldnode->getParent()->getAttribute('data-fieldtype')) {
         if ($type == 'tags') {
             return 'autocomplete';
         }
         return $type;
     }
     // We look for a parent node with 'felement' class.
     if ($class = $fieldnode->getParent()->getAttribute('class')) {
         if (strstr($class, 'felement') != false) {
             // Remove 'felement f' from class value.
             return substr($class, 10);
         }
         // Stop propagation through the DOM, if it does not have a felement is not part of a moodle form.
         if (strstr($class, 'fcontainer') != false) {
             return false;
         }
     }
     return self::get_field_node_type($fieldnode->getParent(), $session);
 }
 /**
  * Recursive method to find the field type.
  *
  * Depending on the field the felement class node is in a level or in another. We
  * look recursively for a parent node with a 'felement' class to find the field type.
  *
  * @param NodeElement $fieldnode The current node.
  * @param Session $session The behat browser session
  * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done.
  */
 protected static function get_field_node_type(NodeElement $fieldnode, Session $session)
 {
     // We look for a parent node with 'felement' class.
     if ($class = $fieldnode->getParent()->getAttribute('class')) {
         if (strstr($class, 'felement') != false) {
             // Remove 'felement f' from class value.
             return substr($class, 10);
         }
         // Stop propagation through the DOM, if it does not have a felement is not part of a moodle form.
         if (strstr($class, 'fcontainer') != false) {
             return false;
         }
     }
     return self::get_field_node_type($fieldnode->getParent(), $session);
 }
示例#7
0
 public function testGetParent()
 {
     $node = new NodeElement('elem', $this->session);
     $parent = $this->getMockBuilder('Behat\\Mink\\Element\\NodeElement')->disableOriginalConstructor()->getMock();
     $this->driver->expects($this->once())->method('find')->with('elem/..')->will($this->returnValue(array($parent)));
     $this->selectors->expects($this->once())->method('selectorToXpath')->with('xpath', '..')->will($this->returnValue('..'));
     $this->assertSame($parent, $node->getParent());
 }
 /**
  * @param NodeElement $resource
  */
 public function toggleResource(NodeElement $resource)
 {
     $groupTitleElement = $this->spin(function () use($resource) {
         return $resource->getParent()->getParent()->getParent()->find('css', 'h3');
     }, 'Group title not found for resource.');
     $groupTitle = $groupTitleElement->getHtml();
     $this->navigateToGroup($groupTitle);
     $this->spin(function () use($resource) {
         return $resource->isVisible();
     }, sprintf('Resource is not visible on the group %s.', $groupTitle));
     $resource->click();
 }
示例#9
0
    /**
     * Recursive method to find the field type.
     *
     * Depending on the field the felement class node is a level or in another. We
     * look recursively for a parent node with a 'felement' class to find the field type.
     *
     * @throws ExpectationException
     * @param NodeElement $fieldnode The current node
     * @param string $locator Just to send an exception that makes sense for the user
     * @return mixed String or NodeElement depending if we have reached the felement node
     */
    protected function get_node_type(NodeElement $fieldnode, $locator) {

        // We look for a parent node with 'felement' class.
        if ($class = $fieldnode->getParent()->getAttribute('class')) {

            if (strstr($class, 'felement') != false) {
                // Remove 'felement f' from class value.
                return substr($class, 10);
            }

            // Stop propagation through the DOM, something went wrong!.
            if (strstr($class, 'fcontainer') != false) {
                throw new ExpectationException('No field type for ' . $locator . ' found, ensure the field exists', $this->getSession());
            }
        }

        return $this->get_node_type($fieldnode->getParent(), $locator);
    }
示例#10
0
 /**
  * Fills a text field element with $value, identified by its container or label.
  *
  * @param NodeElement $fieldContainerOrLabel
  * @param string      $value
  */
 protected function fillTextField(NodeElement $fieldContainerOrLabel, $value)
 {
     $field = $fieldContainerOrLabel->find('css', 'div.field-input input');
     // no field found, we're using a label
     if (!$field) {
         $field = $fieldContainerOrLabel->getParent()->getParent()->find('css', 'div.field-input input');
     }
     if (!$field) {
         $field = $fieldContainerOrLabel->getParent()->find('css', 'div.controls input');
     }
     $field->setValue($value);
     $this->getSession()->executeScript('$(\'.field-input input[type="text"]\').trigger(\'change\');');
 }
 /**
  * Fills a text field element with $value, identified by its container or label.
  *
  * @param NodeElement $fieldContainerOrLabel
  * @param string      $value
  *
  * @throws ElementNotFoundException
  */
 protected function fillTextField(NodeElement $fieldContainerOrLabel, $value)
 {
     $field = $fieldContainerOrLabel->find('css', 'div.field-input input');
     // no field found, we're using a label
     if (!$field) {
         $field = $fieldContainerOrLabel->getParent()->getParent()->find('css', 'div.field-input input');
     }
     if (!$field) {
         $field = $fieldContainerOrLabel->getParent()->find('css', 'div.controls input');
     }
     if (null === $field) {
         throw new ElementNotFoundException(sprintf('No text field can be found from "%s".', $fieldContainerOrLabel->getText()));
     }
     $field->setValue($value);
     $this->getSession()->executeScript('$(\'.field-input input[type="text"]\').trigger(\'change\');');
 }
示例#12
0
 /**
  * Recursive method to find the field type.
  *
  * Depending on the field the felement class node is in a level or in another. We
  * look recursively for a parent node with a 'felement' class to find the field type.
  *
  * @param NodeElement $fieldnode The current node.
  * @param Session $session The behat browser session
  * @return mixed A NodeElement if we continue looking for the element type and String or false when we are done.
  */
 protected static function get_field_node_type(NodeElement $fieldnode, Session $session)
 {
     // Special handling for availability field which requires custom JavaScript.
     if ($fieldnode->getAttribute('name') === 'availabilityconditionsjson') {
         return 'availability';
     }
     // We look for a parent node with 'felement' class.
     if ($class = $fieldnode->getParent()->getAttribute('class')) {
         if (strstr($class, 'felement') != false) {
             // Remove 'felement f' from class value.
             return substr($class, 10);
         }
         // Stop propagation through the DOM, if it does not have a felement is not part of a moodle form.
         if (strstr($class, 'fcontainer') != false) {
             return false;
         }
     }
     return self::get_field_node_type($fieldnode->getParent(), $session);
 }