Пример #1
0
 /**
  * Mink support function: assert a warning message in the lightbox.
  *
  * @param Element $page    Page element
  * @param string  $message Expected message
  *
  * @return void
  */
 protected function assertLightboxWarning(Element $page, $message)
 {
     $warning = $page->find('css', '.modal-body .alert-danger .message');
     if (!$warning || strlen(trim($warning->getText())) == 0) {
         $warning = $this->findCss($page, '.modal-body .alert-danger');
     }
     $this->assertEquals($message, $warning->getText());
 }
Пример #2
0
 /**
  * {@inheritdoc}
  *
  * @throws TimeoutException
  */
 public function fillField($locator, $value, Element $modal = null)
 {
     $selectContainer = $this->spin(function () use($modal) {
         return $modal->find('css', '.select2-container');
     });
     $placeholder = $selectContainer->find('css', sprintf('.select2-chosen:contains("%s")', $locator));
     if ($placeholder) {
         $this->fillSelect2Field($selectContainer, $value);
     } else {
         parent::fillField($locator, $value, $modal);
     }
 }
Пример #3
0
 /**
  * Select all of the items currently in the cart lightbox.
  *
  * @param Element $page Page element
  *
  * @return void
  */
 protected function selectAllItemsInCart(Element $page)
 {
     $cartSelectAll = $page->find('css', '.modal-dialog .checkbox-select-all');
     $cartSelectAll->check();
 }
Пример #4
0
 /**
  * Wait for an element to exist, then retrieve it.
  *
  * @param Element $page     Page element
  * @param string  $selector CSS selector
  * @param int     $timeout  Wait timeout (in ms)
  *
  * @return mixed
  */
 protected function findCss(Element $page, $selector, $timeout = 1000)
 {
     $session = $this->getMinkSession();
     $session->wait($timeout, "\$('{$selector}').length > 0");
     $result = $page->find('css', $selector);
     $this->assertTrue(is_object($result));
     return $result;
 }
Пример #5
0
 /**
  * Try to find value in element and retry for a given time.
  *
  * @param Element $element
  * @param string  $selectorType xpath|css
  * @param string  $value
  * @param int     $timeout
  */
 protected function findOrRetry(Element $element, $selectorType, $value, $timeout = 10000)
 {
     if ($timeout <= 0) {
         return;
     }
     $item = $element->find($selectorType, $value);
     if ($item) {
         return $item;
     } else {
         $this->getSession()->wait(100);
         return $this->findOrRetry($element, $selectorType, $value, $timeout - 100);
     }
 }
Пример #6
0
 /**
  * Sets callnumber_handler to true
  *
  * @param string                      $type        dewey or lcc
  * @param \Behat\Mink\Element\Element $page        page element
  * @param boolean                     $expectLinks links on multiple?
  *
  * @return void
  */
 protected function activateAndTestLinks($type, $page, $expectLinks)
 {
     // Single callnumbers (Sample)
     $this->changeConfigs(['config' => ['Catalog' => ['driver' => 'Sample'], 'Item_Status' => ['callnumber_handler' => $type]]]);
     $this->getMinkSession()->reload();
     $this->snooze();
     $link = $page->find('css', '.callnumber a,.groupCallnumber a,.fullCallnumber a');
     $this->checkLink($link, $type);
     // Multiple callnumbers
     $this->setupMultipleCallnumbers();
     $this->getMinkSession()->reload();
     $this->snooze();
     $link = $page->find('css', '.callnumber a,.groupCallnumber a,.fullCallnumber a');
     if ($expectLinks) {
         $this->checkLink($link, $type);
         // TODO
         // if 'all'
         // - refresh until multiple
         // - test multiple
         // else
     } else {
         $this->assertTrue(is_null($link));
     }
 }
Пример #7
0
 /**
  * Extracts and returns the label NodeElement, identified by $field content and $element
  *
  * @param string  $field
  * @param Element $element
  *
  * @return NodeElement
  */
 protected function extractLabelElement($field, $element)
 {
     $subLabelContent = null;
     $labelContent = $field;
     if (strstr($field, 'USD') || strstr($field, 'EUR')) {
         if (false !== strpos($field, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $field);
         }
     }
     if ($element) {
         $label = $this->spin(function () use($element, $labelContent) {
             return $element->find('css', sprintf('label:contains("%s")', $labelContent));
         }, 10, sprintf('unable to find label %s in element : %s', $labelContent, $element->getHtml()));
     } else {
         $label = $this->spin(function () use($labelContent) {
             return $this->find('css', sprintf('label:contains("%s")', $labelContent));
         }, 10, sprintf('unable to find label %s', $labelContent));
     }
     if (!$label) {
         $label = new \StdClass();
     }
     $label->labelContent = $labelContent;
     $label->subLabelContent = $subLabelContent;
     return $label;
 }
Пример #8
0
 protected function findLinkByContent(Element $page, $link)
 {
     $literal = $this->session->getSelectorsHandler()->xpathLiteral($link);
     return $page->find('xpath', './/a[normalize-space(.)=normalize-space(' . $literal . ')]');
 }
Пример #9
0
 /**
  * This method allows to fill a compound field by passing the label in reversed order separated
  * with whitespaces.
  *
  * Example:
  * We have a field "$" embedded inside a "Price" field
  * We can call fillField('$ Price', 26) to set the "$" value of parent field "Price"
  *
  * @param string  $labelContent
  * @param string  $value
  * @param Element $element
  *
  * @return null
  */
 public function fillField($labelContent, $value, Element $element = null)
 {
     $subLabelContent = null;
     if (false !== strpbrk($labelContent, '€$')) {
         if (false !== strpos($labelContent, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $labelContent);
         }
     }
     if ($element) {
         $label = $element->find('css', sprintf('label:contains("%s")', $labelContent));
     } else {
         $label = $this->find('css', sprintf('label:contains("%s")', $labelContent));
     }
     if (null === $label) {
         return parent::fillField($labelContent, $value);
     }
     if ($label->hasAttribute('for')) {
         if (false === strpos($value, ',')) {
             $for = $label->getAttribute('for');
             if (0 === strpos($for, 's2id_')) {
                 // We are playing with a select2 widget
                 if (null !== ($field = $label->getParent()->find('css', 'select'))) {
                     return $field->selectOption($value);
                 }
                 // Maybe it's an ajax select2?
                 if (null !== ($link = $label->getParent()->find('css', 'a.select2-choice'))) {
                     $link->click();
                     // Wait for the ajax request to finish
                     $this->getSession()->wait(5000, '!$.active');
                     // Select the value in the displayed dropdown
                     if (null !== ($item = $this->find('css', sprintf('#select2-drop li:contains("%s")', $value)))) {
                         return $item->click();
                     }
                 }
                 throw new \InvalidArgumentException(sprintf('Could not find select2 widget inside %s', $label->getParent()->getHtml()));
             } elseif (preg_match('/_date$/', $for)) {
                 $this->getSession()->executeScript(sprintf("\$('#%s').val('%s').trigger('change');", $for, $value));
             } else {
                 $field = $this->find('css', sprintf('#%s', $for));
                 if ($field->getTagName() === 'select') {
                     $field->selectOption($value);
                 } else {
                     if (strpos($field->getAttribute('class'), 'wysiwyg') !== false) {
                         $this->getSession()->executeScript(sprintf("\$('#%s').val('%s');", $for, $value));
                     } else {
                         $field->setValue($value);
                     }
                 }
             }
         } else {
             foreach (explode(',', $value) as $value) {
                 $label->getParent()->find('css', 'input[type="text"]')->click();
                 $this->getSession()->wait(100000, "\$('div:contains(\"Searching\")').length == 0");
                 $option = $this->find('css', sprintf('li:contains("%s")', trim($value)));
                 if (!$option) {
                     throw new \InvalidArgumentException(sprintf('Could not find option "%s" for "%s"', trim($value), $label->getText()));
                 }
                 $option->click();
             }
         }
     } else {
         if (!$subLabelContent) {
             throw new \InvalidArgumentException(sprintf('The "%s" field is compound but the sub label was not provided', $labelContent));
         }
         // it is a compound field, so let's expand the values
         $this->expand($label);
         $field = $this->findPriceField($labelContent, $subLabelContent);
         $field->setValue($value);
     }
 }
Пример #10
0
 /**
  * Extracts and return the label NodeElement, identified by $field content and $element
  *
  * @param string  $field
  * @param Element $element
  *
  * @return \Behat\Mink\Element\NodeElement
  */
 protected function extractLabelElement($field, $element)
 {
     $subLabelContent = null;
     $channel = null;
     $labelContent = $field;
     if (false !== strpbrk($field, '€$')) {
         if (false !== strpos($field, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $field);
         }
     }
     if ($element) {
         $label = $this->spin(function () use($element, $labelContent) {
             return $element->find('css', sprintf('label:contains("%s")', $labelContent));
         });
     } else {
         $labeParts = explode(' ', $labelContent);
         $channel = in_array(reset($labeParts), ['mobile', 'ecommerce', 'print', 'tablet']) ? reset($labeParts) : null;
         if (null !== $channel) {
             $labelContent = substr($labelContent, strlen($channel . ' '));
         }
         $label = $this->spin(function () use($labelContent) {
             return $this->find('css', sprintf('label:contains("%s")', $labelContent));
         });
     }
     if (!$label) {
         $label = new \stdClass();
     }
     $label->channel = $channel;
     $label->labelContent = $labelContent;
     $label->subLabelContent = $subLabelContent;
     return $label;
 }
Пример #11
0
 /**
  * Assert that the "login required" message is visible in the lightbox.
  *
  * @param Element $page Page element
  *
  * @return void
  */
 protected function checkForLoginMessage(Element $page)
 {
     $warning = $page->find('css', '.modal-body .alert-danger');
     $this->assertTrue(is_object($warning));
     $this->assertEquals('You must be logged in first', $warning->getText());
 }
Пример #12
0
 /**
  * @param string  $locator
  * @param string  $selector
  * @param Element $container
  *
  * @return NodeElement
  *
  * @throws ElementNotFoundException
  */
 protected function findElement($locator, $selector = 'xpath', Element $container = null)
 {
     if (null !== $container) {
         $field = $container->find($selector, $locator);
     } else {
         $field = $this->getSession()->getPage()->find($selector, $locator);
     }
     if (null === $field) {
         throw new ElementNotFoundException($this->getSession(), 'element', 'xpath', $this->getSession()->getSelectorsHandler()->xpathLiteral($locator));
     }
     return $field;
 }
Пример #13
0
 /**
  * Extracts and return the label NodeElement, identified by $field content and $element
  *
  * @param string    $field
  * @param Element   $element
  *
  * @return \Behat\Mink\Element\NodeElement
  */
 protected function extractLabelElement($field, $element)
 {
     $subLabelContent = null;
     $labelContent = $field;
     if (false !== strpbrk($field, '€$')) {
         if (false !== strpos($field, ' ')) {
             list($subLabelContent, $labelContent) = explode(' ', $field);
         }
     }
     if ($element) {
         $label = $element->find('css', sprintf('label:contains("%s")', $labelContent));
     } else {
         $label = $this->find('css', sprintf('label:contains("%s")', $labelContent));
     }
     if (!$label) {
         $label = new \stdClass();
     }
     $label->labelContent = $labelContent;
     $label->subLabelContent = $subLabelContent;
     return $label;
 }
Пример #14
0
 /**
  * Submit the login form (assuming it's open).
  *
  * @param Element $page Page element.
  *
  * @return void
  */
 protected function submitLoginForm(Element $page)
 {
     $button = $page->find('css', '.modal-body .btn.btn-primary');
     $this->assertNotNull($button);
     $button->click();
 }