Exemplo n.º 1
0
 /**
  * @param array $names
  * @return string
  * @throws \Exception
  */
 protected function getUniqueName(array $names)
 {
     $name = array_unique($names);
     switch (count($name)) {
         //normal case
         case 1:
             return current($name);
             //if articleName is too long, it will be cut. So it's different from the other and has to be checked separately
         //if articleName is too long, it will be cut. So it's different from the other and has to be checked separately
         case 2:
             $check = array($name);
             $result = Helper::checkArray($check);
             break;
         default:
             $result = false;
             break;
     }
     if ($result !== true) {
         $messages = ['The cart item has different names!'];
         foreach ($name as $key => $value) {
             $messages[] = sprintf('"%s" (Key: "%s")', $value, $key);
         }
         Helper::throwException($messages);
     }
     return $name['articleTitle'];
 }
Exemplo n.º 2
0
 /**
  *
  * @param string $quantity
  * @param float $amount
  * @throws \Exception
  */
 public function checkCart($quantity, $amount)
 {
     $element = Helper::findElements($this, ['quantity', 'amount']);
     $check = array('quantity' => array($element['quantity']->getText(), $quantity), 'amount' => Helper::floatArray(array($element['amount']->getText(), $amount)));
     $result = Helper::checkArray($check);
     if ($result !== true) {
         $message = sprintf('The %s of the header cart is wrong! (%s instead of %s)', $result, $check[$result][0], $check[$result][1]);
         Helper::throwException($message);
     }
 }
Exemplo n.º 3
0
 /**
  * @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);
     }
 }
Exemplo n.º 4
0
 /**
  * Checks the aggregation
  * @param $aggregation
  * @throws \Exception
  */
 public function checkAggregation($aggregation)
 {
     $elements = Helper::findAllOfElements($this, ['aggregationLabels', 'aggregationValues']);
     $lang = Helper::getCurrentLanguage();
     $check = [];
     foreach ($aggregation as $property) {
         $key = $this->getAggregationPosition($elements['aggregationLabels'], $property['label'], $lang);
         $check[$property['label']] = Helper::floatArray([$property['value'], $elements['aggregationValues'][$key]->getText()]);
         unset($elements['aggregationLabels'][$key]);
         unset($elements['aggregationValues'][$key]);
     }
     $result = Helper::checkArray($check);
     if ($result !== true) {
         $message = sprintf('The value of "%s" is "%s"! (should be "%s")', $result, $check[$result][1], $check[$result][0]);
         Helper::throwException($message);
     }
 }
Exemplo n.º 5
0
 protected function checkRating(MultipleElement $articleEvaluations, $average)
 {
     $locators = array('productRating', 'productRatingCount');
     $elements = Helper::findElements($this, $locators);
     $check = array();
     foreach ($elements as $locator => $element) {
         switch ($locator) {
             case 'productRating':
                 $rating = $element->getAttribute('content');
                 $rating = floatval($rating);
                 $check[$locator] = array($rating, $average);
                 break;
             case 'productRatingCount':
                 $check[$locator] = array($element->getText(), count($articleEvaluations));
                 break;
         }
     }
     $check = Helper::floatArray($check);
     $result = Helper::checkArray($check);
     if ($result !== true) {
         $message = sprintf('There was a different value of the evaluation! (%s: "%s" instead of %s)', $result, $check[$result][0], $check[$result][1]);
         Helper::throwException($message);
     }
 }
Exemplo n.º 6
0
 /**
  * @param array $links
  * @throws \Exception
  */
 public function checkXml(array $links)
 {
     $homepageUrl = rtrim($this->getParameter('base_url'), '/');
     $xml = new \SimpleXMLElement($this->getContent());
     $check = [];
     $i = 0;
     foreach ($xml as $link) {
         if (empty($links[$i])) {
             $messages = ['There are more links in the sitemap.xml as expected!', sprintf('(%d sites in sitemap.xml, %d in test data', count($xml), count($links))];
             Helper::throwException($messages);
         }
         $check[] = [(string) $link->loc, $homepageUrl . $links[$i]['link']];
         $i++;
     }
     $result = Helper::checkArray($check, true);
     if ($result === true) {
         return;
     }
     $messages = ['A link is different!', 'Read: ' . $check[$result][0], 'Expected: ' . $check[$result][1]];
     Helper::throwException($messages);
 }
Exemplo n.º 7
0
 /**
  * @param ArticleEvaluation $articleEvaluations
  * @param $average
  * @throws \Exception
  */
 protected function checkRating(ArticleEvaluation $articleEvaluations, $average)
 {
     $elements = Helper::findElements($this, ['productRating', 'productRatingCount', 'productEvaluationAverage', 'productEvaluationCount']);
     $check = ['productRating' => [$elements['productRating']->getAttribute('class'), $average], 'productRatingCount' => [$elements['productRatingCount']->getText(), count($articleEvaluations)], 'productEvaluationAverage' => [$elements['productEvaluationAverage']->getAttribute('class'), $average], 'productEvaluationCount' => [$elements['productEvaluationCount']->getText(), count($articleEvaluations)]];
     $check = Helper::floatArray($check);
     $result = Helper::checkArray($check);
     if ($result !== true) {
         $message = sprintf('There was a different value of the evaluation! (%s: "%s" instead of %s)', $result, $check[$result][0], $check[$result][1]);
         Helper::throwException($message);
     }
 }