/** * @param array $data */ public function unsubscribeNewsletter(array $data) { $mode = array(array('field' => 'subscribeToNewsletter', 'value' => -1)); $data = array_merge($data, $mode); Helper::fillForm($this, 'newsletterForm', $data); Helper::pressNamedButton($this, 'newsletterFormSubmit'); }
/** * @throws \Exception */ private function pressShowResults() { $elements = Helper::findElements($this, ['filterShowResults']); /** @var NodeElement $showResults */ $showResults = $elements['filterShowResults']; $showResults->press(); }
/** * Fills the notification form and submits it * @param string $email */ public function submitNotification($email) { $data = [['field' => 'sNotificationEmail', 'value' => $email]]; Helper::fillForm($this, 'notificationForm', $data); $elements = Helper::findElements($this, ['notificationSubmit']); $elements['notificationSubmit']->press(); }
/** * Returns the name * @param NodeElement $slide * @return string */ public function getNameProperty(NodeElement $slide) { $selectors = Helper::getRequiredSelectors($this, ['slideImage', 'slideLink', 'slideName']); $nameElement = $slide->find('css', $selectors['slideName']); $names = ['imageAlt' => $slide->find('css', $selectors['slideImage'])->getAttribute('alt'), 'linkTitle' => $slide->find('css', $selectors['slideLink'])->getAttribute('title'), 'name' => $nameElement->getText(), 'nameTitle' => $nameElement->getAttribute('title')]; return Helper::getUnique($names); }
/** * Changes the shipping method * @param array $data */ public function changeShippingMethod(array $data = []) { $element = $this->getElement('CheckoutPayment'); Helper::clickNamedLink($element, 'changeButton'); Helper::fillForm($this, 'shippingPaymentForm', $data); Helper::pressNamedButton($this, 'changePaymentButton'); }
/** * Returns the current payment method * @return string */ public function getPaymentMethodProperty() { $element = Helper::findElements($this, ['currentMethod']); $currentMethod = $element['currentMethod']->getText(); $currentMethod = str_word_count($currentMethod, 1); return $currentMethod[0]; }
/** * Changes the shipping method * @param array $data */ public function changeShippingMethod($data = array()) { $element = $this->getElement('CheckoutPayment'); $language = Helper::getCurrentLanguage($this); Helper::clickNamedLink($element, 'changeButton', $language); Helper::fillForm($this, 'shippingPaymentForm', $data); Helper::pressNamedButton($this, 'changePaymentButton'); }
/** * @When /^I order the article on position (?P<position>\d+)$/ */ public function iOrderTheArticleOnPosition($position) { /** @var Listing $page */ $page = $this->getPage('Listing'); /** @var ArticleBox $articleBox */ $articleBox = $this->getMultipleElement($page, 'ArticleBox', $position); Helper::clickNamedLink($articleBox, 'order'); }
/** * @Given /^I click to read the blog article on position (\d+)$/ */ public function iClickToReadTheBlogArticleOnPosition($position) { /** @var Blog $page */ $page = $this->getPage('Blog'); /** @var BlogBox $blogBox */ $blogBox = $this->getMultipleElement($page, 'BlogBox', $position); Helper::clickNamedLink($blogBox, 'readMore'); }
private function clickActionLink($position, $name) { /** @var Note $page */ $page = $this->getPage('Note'); /** @var NotePosition $notePosition */ $notePosition = $this->getMultipleElement($page, 'NotePosition', $position); Helper::clickNamedLink($notePosition, $name); }
/** * Fills the notification form and submits it * @param string $email */ public function submitNotification($email) { $data = array(array('field' => 'sNotificationEmail', 'value' => $email)); Helper::fillForm($this, 'notificationForm', $data); $locators = array('notificationSubmit'); $elements = Helper::findElements($this, $locators); $elements['notificationSubmit']->press(); }
/** * Proceeds to the confirmation page with login * @param string $eMail * @param string $password */ public function proceedToOrderConfirmationWithLogin($eMail, $password) { if ($this->verifyPage()) { Helper::clickNamedLink($this, 'checkout'); } $this->getPage('Account')->login($eMail, $password); $this->getPage('CheckoutConfirm')->verifyPage(); }
/** * Changes the currency * @param string $currency * @throws \Behat\Mink\Exception\ElementNotFoundException */ public function changeCurrency($currency) { if (!$this->getDriver() instanceof Selenium2Driver) { Helper::throwException('Changing the currency in Responsive template requires Javascript!'); } $valid = ['EUR' => '€ EUR', 'USD' => '$ USD']; $this->selectFieldOption('__currency', $valid[$currency]); }
/** * Submits the filters * @throws \Exception */ private function pressShowResults() { $this->getSession()->wait(5000, "\$('.filter--btn-apply:not(.is--loading):not([disabled=disabled])').length > 0"); $elements = Helper::findElements($this, ['filterShowResults']); /** @var NodeElement $showResults */ $showResults = $elements['filterShowResults']; $showResults->press(); }
/** * @param array $locators * @return array */ public function getProperties(array $locators) { $return = array(); $elements = Helper::findElements($this, $locators); foreach ($elements as $locator => $element) { $funcName = 'get' . ucfirst($locator); $return[$locator] = $this->{$funcName}($element); } return $return; }
/** * @param string $propertyName * @return bool */ public function setProperty($propertyName) { $elements = Helper::findElements($this, ['properties']); /** @var NodeElement $propertyContainer */ $propertyContainer = $elements['properties']; if (!$propertyContainer->hasLink($propertyName)) { return false; } $propertyContainer->clickLink($propertyName); return true; }
/** * @inheritdoc */ protected function checkRating(BlogComment $blogComments, $average) { $elements = Helper::findElements($this, ['articleRating', 'articleRatingCount']); $check = ['articleRating' => [$elements['articleRating']->getAttribute('content'), $average], 'articleRatingCount' => [$elements['articleRatingCount']->getText(), count($blogComments)]]; $check = Helper::floatArray($check); $result = Helper::checkArray($check); if ($result !== true) { $message = sprintf('There was a different value of the rating! (%s: "%s" instead of "%s")', $result, $check[$result][0], $check[$result][1]); Helper::throwException($message); } }
/** * Helper function returns the data of an order position * @param NodeElement $position * @param string[] $selectors * @return array */ private function getOrderPositionData(NodeElement $position, array $selectors) { $data = []; foreach ($selectors as $key => $selector) { $element = $position->find('css', $selector); $data[$key] = $element->getText(); if ($key !== 'product') { $data[$key] = Helper::floatValue($data[$key]); } } return $data; }
public function checkCaptcha() { $locators = array('captchaPlaceholder', 'captchaImage', 'captchaHidden'); $element = Helper::findElements($this, $locators); $captchaPlaceholder = $element['captchaPlaceholder']->getAttribute('data-src'); $captchaImage = $element['captchaImage']->getAttribute('src'); $captchaHidden = $element['captchaHidden']->getValue(); if ($captchaPlaceholder !== '/shopware/widgets/Captcha/refreshCaptcha' || strpos($captchaImage, 'data:image/png;base64') === false || empty($captchaHidden)) { $message = 'There is no capture in this form!'; Helper::throwException($message); } }
/** * @param NotePosition $notePositions * @param array $items */ public function checkNoteProducts(NotePosition $notePositions, array $items) { Helper::assertElementCount($notePositions, count($items)); $result = Helper::searchElements($items, $notePositions); if ($result !== true) { $messages = ['The following articles were not found:']; foreach ($result as $product) { $messages[] = $product['number'] . ' - ' . $product['name']; } Helper::throwException($messages); } }
/** * @Given /^my finished order should look like this:$/ */ public function myFinishedOrderShouldLookLikeThis(TableNode $positions) { $orderNumber = $this->getPage('CheckoutConfirm')->getOrderNumber(); $values = $positions->getHash(); /** @var \Shopware\Tests\Mink\Page\Emotion\Account $page */ $page = $this->getPage('Account'); $page->open(); Helper::clickNamedLink($page, 'myOrdersLink'); /** @var \Shopware\Tests\Mink\Element\Emotion\AccountOrder $order */ $order = $this->getMultipleElement($page, 'AccountOrder'); $page->checkOrder($order, $orderNumber, $values); }
/** * Sets a property, returns false, if the property doesn't exist, otherwise true on success * @param string $propertyName * @return bool */ public function setProperty($propertyName) { $this->expandProperties(); $elements = Helper::findElements($this, ['properties']); /** @var NodeElement $propertyContainer */ $propertyContainer = $elements['properties']; if (!$propertyContainer->hasField($propertyName)) { return false; } $propertyContainer->checkField($propertyName); return true; }
/** * Checks the evaluations of the current article * @param BlogComment $blogComments * @param $average * @param array $comments * @throws \Exception */ public function checkComments(BlogComment $blogComments, $average, array $comments) { $this->checkRating($blogComments, $average); $comments = Helper::floatArray($comments, ['stars']); $result = Helper::assertElements($comments, $blogComments); if ($result === true) { return; } $messages = array('The following comments are wrong:'); foreach ($result as $evaluation) { $messages[] = sprintf('%s - Bewertung: %s (%s is "%s", should be "%s")', $evaluation['properties']['author'], $evaluation['properties']['stars'], $evaluation['result']['key'], $evaluation['result']['value'], $evaluation['result']['value2']); } Helper::throwException($messages); }
/** * Returns the slides * @param string[] $properties * @return array[] */ public function getSlides(array $properties) { $elements = Helper::findAllOfElements($this, ['slide']); $slides = []; /** @var NodeElement $slide */ foreach ($elements['slide'] as $slide) { $slideProperties = []; foreach ($properties as $property) { $method = 'get' . ucfirst($property) . 'Property'; $slideProperties[$property] = $this->{$method}($slide); } $slides[] = $slideProperties; } return $slides; }
/** * @param NotePosition $notePositions * @param array $items */ public function checkNoteProducts(NotePosition $notePositions, array $items) { if (count($notePositions) !== count($items)) { $message = sprintf('There are %d products on the note! (should be %d)', count($notePositions), count($items)); Helper::throwException($message); } $result = Helper::searchElements($items, $notePositions); if ($result !== true) { $messages = array('The following articles were not found:'); foreach ($result as $product) { $messages[] = $product['number'] . ' - ' . $product['name']; } Helper::throwException($messages); } }
/** * Checks if the robots meta exists and matches the expected content * * @param $content */ public function checkRobots($content = []) { $elements = Helper::findElements($this, ['robots']); $robotsElement = $elements['robots']; $robotsValue = $robotsElement->getAttribute('content'); $robotsParts = explode(',', $robotsValue); $robotsParts = array_map('trim', $robotsParts); if (empty($robotsParts)) { Helper::throwException(['Missing robots data']); } if ($robotsParts != $content) { $message = sprintf('Canonical link "%s" does not match expected value "%s"', implode(', ', $robotsParts), implode(', ', $content)); Helper::throwException([$message]); } }
/** * @When /^I follow the link "(?P<linkName>[^"]*)" of the element "(?P<elementClass>[^"]*)"$/ * @When /^I follow the link "(?P<linkName>[^"]*)" of the element "(?P<elementClass>[^"]*)" on position (?P<position>\d+)$/ */ public function iFollowTheLinkOfTheElementOnPosition($linkName, $elementClass, $position = 1) { /** @var HelperSelectorInterface $element */ $element = $this->getElement($elementClass); if ($element instanceof MultipleElement) { /** @var Homepage $page */ $page = $this->getPage('Homepage'); /** @var MultipleElement $element */ $element->setParent($page); $element = $element->setInstance($position); } if (empty($linkName)) { $element->click(); return; } Helper::clickNamedLink($element, $linkName); }
/** * @Then /^I should see an article slider:$/ */ public function iShouldSeeAnArticleSlider(TableNode $articles) { /** @var Homepage $page */ $page = $this->getPage('Homepage'); /** @var \Shopware\Tests\Mink\Element\Emotion\ManufacturerSlider $slider */ $slider = $this->getMultipleElement($page, 'ArticleSlider', 1); $products = Helper::floatArray($articles->getHash(), ['price']); $page->checkSlider($slider, $products); }
/** * Helper method to get the unique title * @param string[] $titles * @return string * @throws \Exception */ protected function getUniqueTitle(array $titles) { $title = array_unique($titles); switch (count($title)) { //normal case case 1: return current($title); //if blog article name is too long, it will be cut. So it's different from the other and has to be checked separately //if blog article name is too long, it will be cut. So it's different from the other and has to be checked separately case 2: $check = [$title]; $result = Helper::checkArray($check); break; default: $result = false; break; } if ($result !== true) { $messages = ['The blog article has different titles!']; foreach ($title as $key => $value) { $messages[] = sprintf('"%s" (Key: "%s")', $value, $key); } Helper::throwException($messages); } return $title['titleTitle']; }
/** * Returns the video code * @return array */ public function getCodeProperty() { $elements = Helper::findElements($this, ['code']); return $elements['code']->getAttribute('src'); }