/** * @param RawTqContext $context * Behat context. * @param string $selector * Field selector. * @param bool $not * Negate the condition. * @param string $expected * Expected value. */ public function __construct(RawTqContext $context, $selector, $not, $expected = '') { $this->not = (bool) $not; $this->context = $context; $this->selector = $selector; $this->expected = $expected; $this->element = $this->context->element('field', $selector); $this->value = $this->element->getValue(); $this->tag = $this->element->getTagName(); }
public static function reverse(NodeElement $buttonNode, Button $buttonObj, Elements $elements = null) { if ($buttonNode->getTagName() === 'button') { $buttonObj->setNode($buttonNode); } else { throw new \LogicException('tag mismatch'); } $parents = $buttonObj->getParents(); $outer = $buttonNode->getOuterHtml(); $label = $buttonNode->getText(); if ($label) { $buttonObj->setLabel($label); } else { $x = 1; } //return; /* $elem = []; $id = $button->getAttribute('id'); $html = $button->getOuterHtml(); $test = '/<[a-z]+\s([^>]*)/'; if (preg_match($test, $html, $matches)) { preg_match_all('/([a-z]+=".*?")/', $matches[1], $attribs1); $attribs = preg_split('/ /', $matches[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $elem['attr'] = $attribs; } if ($button->getTagName() === 'a') { $href = $button->getAttribute('href'); $elem['href'] = $href; } if (!$id) { $dt = $content->find('css', 'table.table-columnfilter'); if ($dt) { //skip datatable; //continue; } $label = $button->getText(); $xpath = $button->getXpath(); $elem['xpath'] = $xpath; $elem['label'] = $label; } else { $label = $button->getText(); $elements['buttons'][] = ['id' => $id, 'label' => $label]; } $elements['buttons'][] = $elem;*/ }
/** * 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); }
/** * Checks that the given element is of the given type. * * @param NodeElement $element * The element to check. * @param string $type * The expected type. * * @throws ExpectationException * Thrown when the given element is not of the expected type. */ public function assertElementType(NodeElement $element, $type) { if ($element->getTagName() !== $type) { throw new ExpectationException("The element is not a '{$type}'' field.", $this->getSession()); } }
public function testGetTagName() { $node = new NodeElement('html//h3', $this->session); $this->driver->expects($this->once())->method('getTagName')->with('html//h3')->will($this->returnValue('h3')); $this->assertEquals('h3', $node->getTagName()); }
public static function reverse(NodeElement $content, Elements $elements = null) { $tag = $content->getTagName(); if ($tag === 'select') { $input = new Select(); } elseif ($tag === 'textarea') { $input = new Textarea(); } elseif ($tag === 'input') { $input = new Input(); $input->setNode($content); switch ($input->getAttribute('type')) { case 'checkbox': $input = new Checkbox(); break; case 'submit': $input = new Submit(); break; case 'text': $input = new Text(); break; case 'radio': $input = new Radio(); break; case 'file': $input = new File(); break; case 'hidden': return false; case 'search': $input = new Text(); $input->setLabel('dtsearch'); $input->setNode($content); return $input; break; default: //hidden $x = 1; return false; break; } } else { //hidden $x = 1; return false; } /** @var Input $input */ $input->setNode($content); if ($elements && $elements->isRegisteredInput($input)) { return false; } $outer = $content->getOuterHtml(); $inner = $content->getHtml(); $txt = $content->getText(); $parents = $input->getParents(); $res = self::findLabelByParent($input); if ($res) { $input->setLabel($res); return $input; } $res = self::findLabelByPlaceholder($input); if ($res) { $input->setLabel($res); return $input; } $res = self::findLabelByStdForm($input); if ($res) { $input->setLabel($res); return $input; } $res = self::findLabelByValue($input); if ($res) { $input->setLabel($res); return $input; } if (!$input->getId() && !$input->getName()) { if (false !== $input->hasClass('dtSearch')) { //datatables column filter $x = 1; } /* $dt = $content->find('css', 'table.table-columnfilter'); if ($dt) { //skip datatable; $x =1; }*/ $class = $content->getAttribute('class'); if ($class && $class === 'select2-search__field') { $x = 1; } if (false !== strpos($content->getParent()->getParent()->getAttribute('class'), 'CodeMirror')) { $x = 1; $p = $content->getParent()->getParent()->getParent()->getParent(); } else { if ($input->getType() === 'search') { $x = 1; } $x = 1; $p = $content; } $label = $p->find('css', 'label'); if ($label) { $label = $label->getText(); } else { $label = $content->getAttribute('placeholder'); } //self::addNotNull($elem, 'label', $label); $xpath = $input->getXpath(); //self::addNotNull($elem, 'xpath', $xpath); } else { if (false !== strpos($input->getName(), '_length')) { //datatables per page $x = 1; } if ($input->getName()) { $label = $content->find('css', 'label[for="' . $input->getName() . '"]'); if (!$label) { if ($input->getType() === 'checkbox') { $p = $content->getParent()->getParent()->getParent(); $h = $p->getHtml(); $h = $p->getOuterHtml(); $label = $p->getText(); } else { $x = 1; } } } else { $label = $content->find('css', 'label[for=' . $input->getId() . ']'); } if (!is_string($label)) { if ($label) { $label = $label->getText(); } else { $label = $content->getValue(); } } //self::addNotNull($elem, 'label', $label); } return $input; }
/** * Guesses a basic field type and returns it. * * This method is intended to detect HTML form fields when no * maharaform-specific elements have been detected. * * @param NodeElement $fieldnode * @param Session $session * @return string|bool The field type or false. */ public static function guess_field_type(NodeElement $fieldnode, Session $session) { // Textareas are considered text based elements. $tagname = strtolower($fieldnode->getTagName()); if ($tagname == 'textarea') { // If there is an iframe with $id + _ifr there a TinyMCE editor loaded. $xpath = '//iframe[@id="' . $fieldnode->getAttribute('id') . '_ifr"]'; if ($session->getPage()->find('xpath', $xpath)) { return 'editor'; } return 'textarea'; } else { if ($tagname == 'input') { $type = $fieldnode->getAttribute('type'); switch ($type) { case 'text': case 'password': case 'email': case 'file': return 'text'; case 'checkbox': return 'checkbox'; break; case 'radio': return 'radio'; break; default: // Here we return false because all text-based // fields should be included in the first switch case. return false; } } else { if ($tagname == 'select') { // Select tag. return 'select'; } } } // We can not provide a closer field type. return false; }
/** * @param $node */ public static function parseAttribs(NodeElement $node) { $tagName = $node->getTagName(); $outer = $node->getOuterHtml(); $dom = new \DOMDocument(); $dom->loadHTML('<?xml encoding="UTF-8">' . $outer); $sxe = simplexml_import_dom($dom); /** @var \SimpleXMLElement $tag */ $tag = $sxe->body->{$tagName}; $a = (array) $tag->attributes(); $attributes = $a['@attributes']; return $attributes; }
/** * Find and return the row (<tr>) where the passed element is * This is useful when you intend to know if another element is in the same * row * * @param \Behat\Mink\Element\NodeElement $element The element in the intended row * * @return \Behat\Mink\Element\NodeElement The <tr> element node * * @throws \PHPUnit_Framework_AssertionFailedError */ public function findRow(NodeElement $element) { $initialTag = $element->getTagName(); while (strtolower($element->getTagName()) !== "tr" && strtolower($element->getTagName()) !== "body") { $element = $element->getParent(); } Assertion::assertEquals(strtolower($element->getTagName()), "tr", "Couldn't find a parent of '{$initialTag}' that is a table row"); return $element; }
public static function reverse(NodeElement $selectNode, InputSelect $select) { if ($selectNode->getTagName() === 'select') { $select->setNode($selectNode); } else { throw new LogicException('tag mismatch'); } $parents = $select->getParents(); if ($select->hasAttribute('name')) { $select->setName($select->getAttribute('name')); } $res = self::findLabelByParent($select); if (!$res) { $x = 1; } $select->setLabel($res); //return; /*if (!$id && !$name) { if (false !== strpos($selectNode->getAttribute('class'), 'dtSearch')) { //datatables column filter continue; } $dt = $content->find('css', 'table.table-columnfilter'); if ($dt) { //skip datatable; continue; } $class = $selectNode->getAttribute('class'); if ($class && $class == 'select2-search__field') { continue; } if (false !== strpos($selectNode->getParent()->getParent()->getAttribute('class'), 'CodeMirror')) { continue; $p = $selectNode->getParent()->getParent()->getParent()->getParent(); } else { if ($type == 'search') { continue; } $x = 1; $p = $selectNode; } $label = $p->find('css', 'label'); if ($label) { $label = $label->getText(); } else { $label = $selectNode->getAttribute('placeholder'); } self::addNotNull($elem, 'label', $label); $xpath = $selectNode->getXpath(); self::addNotNull($elem, 'xpath', $xpath); } else { if (false !== strpos($name, '_length')) { //datatables per page continue; } if ($name) { $label = $selectNode->find('css', 'label[for="' . $name . '"]'); if (!$label) { if ($type == 'checkbox') { $p = $selectNode->getParent()->getParent()->getParent(); $h = $p->getHtml(); $h = $p->getOuterHtml(); $label = $p->getText(); } } } else { $label = $selectNode->find('css', 'label[for=' . $id . ']'); } if (!is_string($label)) { if ($label) { $label = $label->getText(); } else { $label = $selectNode->getValue(); } } self::addNotNull($elem, 'label', $label); } $elements['inputs'][] = $elem;*/ }