/**
  * Test execution.
  *
  * @param Document $htmlDocument the HTML dokument to test
  */
 public function runTest(Document $htmlDocument)
 {
     static $requestedDependecies = array();
     $failedUrls = array();
     $files = $htmlDocument->getExternalDependencies();
     $requestUri = new Uri($this->getRequest()->getUri());
     $domain = $requestUri->getDomain();
     foreach ($files as $file) {
         $absoluteFile = $domain->concatUri($file);
         if (!$this->isIgnored($absoluteFile->toString())) {
             if (array_key_exists($absoluteFile->toString(), $requestedDependecies)) {
                 $status = $requestedDependecies[$absoluteFile->toString()];
             } else {
                 $request = Symfony::create($absoluteFile, Request::GET);
                 $client = new Zend();
                 $response = $client->request($request);
                 $status = $response->getStatus();
                 $requestedDependecies[$absoluteFile->toString()] = $response->getStatus();
             }
             if ($status >= 400) {
                 $failedUrls[] = $absoluteFile->toString();
             }
         }
     }
     if (count($failedUrls) > 0) {
         $this->handleFailures($failedUrls);
     }
 }
Example #2
0
 /**
  * This function checks if the regEx is not found in the html document. 
  * 
  * @see LiveTest\TestCase\General\Html.TestCase::runTest()
  */
 protected function runTest(Document $htmlDocument)
 {
     $htmlCode = $htmlDocument->getHtml();
     if (1 == preg_match($this->regEx, $htmlCode)) {
         throw new Exception('The given RegEx "' . $this->regEx . '" was found.');
     }
 }
Example #3
0
 /**
  * Checks if a givent string is not found.
  *
  * @see LiveTest\TestCase.HtmlTestCase::runTest()
  */
 protected function runTest(Document $htmlDocument)
 {
     $htmlCode = $htmlDocument->getHtml();
     if (strpos($htmlCode, $this->text) !== false) {
         throw new Exception('The given text "' . $this->text . '" was found.');
     }
 }
Example #4
0
 /**
  *
  * @see Base\Validator.Html::validateHtml()
  *
  * @param string markup to validate
  * @return bool Is valid markup?
  */
 public function validate(Document $htmlDocument)
 {
     $rawDocument = $htmlDocument->getHtml();
     $postVars = array('output' => 'soap12', 'fragment' => $rawDocument);
     $request = Symfony::create(new Uri($this->_validatorUri), \Base\Http\Request\Request::POST, $postVars);
     $response = $this->_httpClient->request($request);
     return $this->_parseReponse($response->getBody());
 }
Example #5
0
 /**
  *
  * @param string markup to validate
  * @return bool Is valid?
  */
 public function validate(Document $htmlDocument)
 {
     $rawDocument = $htmlDocument->getHtml();
     $postVars = array('htmlcontent' => $rawDocument);
     $request = Symfony::create(new Uri($this->richTextValidatorUri), \Base\Http\Request\Request::POST, $postVars);
     $response = $this->httpClient->request($request);
     return $this->parseValidationReponse($response->getBody());
 }
Example #6
0
 /**
  * This function checks if the regEx is found in the html document.
  *
  * @see LiveTest\TestCase\General\Html.TestCase::runTest()
  */
 protected function runTest(Document $htmlDocument)
 {
     // @todo use regExOccurance
     $htmlCode = $htmlDocument->getHtml();
     if (0 == preg_match($this->regEx, $htmlCode)) {
         throw new Exception('The given RegEx "' . $this->regEx . '" was not found.');
     }
 }
Example #7
0
 /**
  * Checks the size of the given html document
  *
  * @see LiveTest\TestCase\General\Html.TestCase::runTest()
  */
 protected function runTest(Document $htmlDocument)
 {
     $size = strlen($htmlDocument->getHtml());
     // @todo use two functions for validating (ccn)
     if (!is_null($this->minSize)) {
         if ($this->minSize >= $size) {
             throw new Exception('The given document is too small (expected min size: ' . $this->minSize . '; actual size: ' . $size . ')');
         }
     }
     if (!is_null($this->maxSize)) {
         if ($this->maxSize <= $size) {
             throw new Exception('The given document is too big (expected max size: ' . $this->maxSize . '; actual size: ' . $size . ')');
         }
     }
 }
 /**
  * This function checks if the regEx is found in the html document.
  *
  * @see LiveTest\TestCase\General\Html.TestCase::runTest()
  */
 protected function runTest(Document $htmlDocument)
 {
     $htmlCode = $htmlDocument->getHtml();
     if (($this->maxOccur === null || $this->maxOccur === 0) && ($this->minOccur === null || $this->minOccur <= 1)) {
         $res = preg_match($this->regEx, $htmlCode);
     } else {
         $res = preg_match_all($this->regEx, $htmlCode, $matches);
     }
     if ($res === false) {
         throw new \LiveTest\ConfigurationException('The RegEx Pattern created a Error.');
     }
     if ($this->minOccur !== null && $res < $this->minOccur) {
         throw new Exception('The given RegEx "' . $this->regEx . '" did not match at least ' . $this->minOccur . ' times ( found ' . $res . ' ).');
     }
     if ($this->maxOccur !== null && $res > $this->maxOccur) {
         throw new Exception('The given RegEx "' . $this->regEx . '" matched ' . $res . '  times. Allowed: ' . $this->maxOccur . ' times.');
     }
 }
Example #9
0
 /**
  * Executes the test case
  *
  * @param Base\Www\Html\Document $htmlDocument the document to inspect
  *
  * @throws LiveTest\TestCase\Exception on failed tests
  */
 protected function runTest(Document $htmlDocument)
 {
     $htmlCode = $htmlDocument->getHtml();
     $doc = new \DOMDocument();
     if (!@$doc->loadHTML($htmlCode)) {
         throw new Exception('Can\'t create DOMDocument from HTML');
     }
     if (!$this->matchXPath($doc)) {
         throw new Exception('The result of the given XPath "' . $this->xPath . '" doesn\'t match the RegEx "' . $this->regEx . '"');
     }
 }