Ejemplo n.º 1
0
 public function testGetText()
 {
     $expected = 'val1';
     $node = new NodeElement('text_tag', $this->session);
     $this->driver->expects($this->once())->method('getText')->with('text_tag')->will($this->returnValue($expected));
     $this->assertEquals($expected, $node->getText());
 }
Ejemplo n.º 2
0
 /**
  * Check if the given node has the given text.
  *
  * @param NodeElement $element
  * @param string      $text
  *
  * @throws \PHPUnit_Framework_AssertionFailedError
  */
 private function assertNodeElementContainsText(NodeElement $element, $text)
 {
     $actual = $element->getText();
     $regex = '/' . preg_quote($text, '/') . '/ui';
     $message = sprintf('The text "%s" was not found in the text of the %s.', $text, $actual);
     PHPUnit::assertTrue((bool) preg_match($regex, $actual), $message);
 }
Ejemplo n.º 3
0
 /**
  * @param NodeElement $comment
  *
  * @throws \LogicException
  */
 public function deleteComment(NodeElement $comment)
 {
     $link = $comment->find('css', 'span.remove-comment');
     if (null === $link) {
         throw new \LogicException(sprintf('Delete link of comment "%s" not found.', $comment->getText()));
     }
     $link->click();
 }
Ejemplo n.º 4
0
 /**
  * @param NodeElement $element
  * @return string
  */
 protected function getComment(NodeElement $element)
 {
     return $element->getText();
 }
Ejemplo n.º 5
0
 /**
  * Fills a multivalues Select2 field with $value, identified by its $label.
  * It deletes existing selected values from field if not present in $value.
  *
  * $value can be a string of multiple values. Each value must be separated with comma, eg :
  * 'Hot, Dry, Fresh'
  *
  * @param NodeElement $label
  * @param string      $value
  *
  * @throws \InvalidArgumentException
  */
 protected function fillMultiSelect2Field(NodeElement $label, $value)
 {
     $allValues = explode(',', $value);
     $selectedValues = $label->getParent()->findAll('css', '.select2-search-choice');
     $selectedTextValues = array_map(function ($selectedValue) {
         return $selectedValue->getText();
     }, $selectedValues);
     // Delete tag from right to left to prevent select2 DOM change
     $selectedValues = array_reverse($selectedValues);
     foreach ($selectedValues as $selectedValue) {
         if (false === in_array($selectedValue->getText(), $allValues)) {
             $closeButton = $selectedValue->find('css', 'a');
             if (!$closeButton) {
                 throw new \InvalidArgumentException(sprintf('Could not find "%s" close button for "%s"', trim($selectedValue->getText()), $label->getText()));
             }
             $closeButton->click();
         }
     }
     $allValues = array_filter($allValues);
     if (1 === count($allValues) && null !== $label->getParent()->find('css', 'select')) {
         $value = array_shift($allValues);
         $this->fillSelectField($label, $value);
     }
     // Fill in remaining values
     $remainingValues = array_diff($allValues, $selectedTextValues);
     foreach ($remainingValues as $value) {
         if (trim($value)) {
             $label->click();
             $label->click();
             $option = $this->spin(function () use($value) {
                 return $this->find('css', sprintf('.select2-result:not(.select2-selected) .select2-result-label:contains("%s")', trim($value)));
             }, sprintf('Could not find option "%s" for "%s"', trim($value), $label->getText()));
             $option->click();
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Fills a multivalues Select2 field with $value, identified by its $label.
  * It deletes existing selected values from field if not present in $value.
  *
  * $value can be a string of multiple values. Each value must be separated with comma, eg :
  * 'Hot, Dry, Fresh'
  *
  * @param NodeElement $label
  * @param string      $value
  *
  * @throws \InvalidArgumentException
  */
 protected function fillMultiSelect2Field(NodeElement $label, $value)
 {
     $allValues = explode(',', $value);
     $selectedValues = $label->getParent()->findAll('css', '.select2-search-choice');
     $selectedTextValues = array_map(function ($selectedValue) {
         return $selectedValue->getText();
     }, $selectedValues);
     // Delete tag from right to left to prevent select2 DOM change
     $selectedValues = array_reverse($selectedValues);
     foreach ($selectedValues as $selectedValue) {
         if (false === in_array($selectedValue->getText(), $allValues)) {
             $closeButton = $selectedValue->find('css', 'a');
             if (!$closeButton) {
                 throw new \InvalidArgumentException(sprintf('Could not find "%s" close button for "%s"', trim($selectedValue->getText()), $label->getText()));
             }
             $closeButton->click();
         }
     }
     // Removing tags in MultiSelect2 drops an "animation" with opacity, we must
     // wait for it to completly vanish in order to reopen select list
     $this->getSession()->wait(2000);
     $allValues = array_filter($allValues);
     if (1 === count($allValues) && null !== $label->getParent()->find('css', 'select')) {
         $value = array_shift($allValues);
         $this->fillSelectField($label, $value);
     }
     // Fill in remaining values
     $remainingValues = array_diff($allValues, $selectedTextValues);
     foreach ($remainingValues as $value) {
         if (trim($value)) {
             $label->getParent()->find('css', 'input[type="text"]')->click();
             $this->getSession()->wait(100000, "\$('div:contains(\"Searching\")').length == 0");
             $option = $this->find('css', sprintf('.select2-result:not(.select2-selected) .select2-result-label:contains("%s")', trim($value)));
             if (!$option) {
                 throw new \InvalidArgumentException(sprintf('Could not find option "%s" for "%s"', trim($value), $label->getText()));
             }
             $option->click();
         }
     }
 }
Ejemplo n.º 7
0
 /**
  * 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\');');
 }
 private function getAttributesFromElement(NodeElement $element)
 {
     $attr = array();
     $attr['id'] = strtolower($element->getAttribute('id'));
     $attr['name'] = strtolower($element->getAttribute('name'));
     $attr['label'] = strtolower($element->getAttribute('label'));
     $attr['value'] = strtolower($element->getAttribute('value'));
     $attr['text'] = strtolower($element->getText());
     $attr['title'] = strtolower($element->getAttribute('title'));
     return $attr;
 }