예제 #1
0
 /**
  * This function is used to create the html document out of the response. It
  * calls the runTest method where all checks shouls be made.
  *
  * @see LiveTest\TestCase.TestCase::test()
  */
 public final function test(Response $httpResponse, Request $request)
 {
     $this->httpResponse = $httpResponse;
     $this->request = $request;
     $htmlDocument = new Document($httpResponse->getBody());
     $this->runTest($htmlDocument);
 }
예제 #2
0
 public function test(Response $response, Request $request)
 {
     $loadTime = $response->getDuration();
     if ($loadTime > $this->maxLoadTime) {
         throw new Exception('The time to load the website is too long (current: ' . $loadTime . ', max: ' . $this->maxLoadTime . ')');
     }
 }
예제 #3
0
 public function test(Response $response, Request $request)
 {
     $result = json_decode($response->getBody());
     if ($result === null) {
         throw new Exception("The given JSON Data is not well formed (last error: " . $this->json_errors[json_last_error()] . ").");
     }
 }
예제 #4
0
 /**
  * Checks if the actual http status equals the expected.
  *
  * @see LiveTest\TestCase.HttpTestCase::test()
  */
 public function test(Response $response, Request $request)
 {
     $status = $response->getStatus();
     if ($status != $this->statusCode) {
         throw new Exception('The http status code ' . $status . ' was found, expected code was ' . $this->statusCode);
     }
 }
예제 #5
0
 /**
  * Checks if a specified http header is existing
  *
  * @see LiveTest\TestCase.HttpTestCase::test()
  */
 public function test(Response $response, Request $request)
 {
     $header = $response->getHeader();
     if (!$header->hasField($this->headerName)) {
         throw new Exception('The expected header "' . $this->headerName . '" was not found.');
     }
 }
예제 #6
0
 /**
  * This function checks if the status code is < 400
  *
  * @see LiveTest\TestCase.HttpTestCase::test()
  */
 public function test(Response $response, Request $request)
 {
     $status = (int) $response->getStatus();
     if ($status >= 400) {
         throw new Exception('The http status code ' . $status . ' was found (<400 expected).');
     }
 }
예제 #7
0
 public final function test(Response $response, Request $request)
 {
     $doc = new DOMDocument();
     if (!@$doc->loadHTML($response->getBody())) {
         throw new \Exception("Can't create DOMDocument from HTML");
     }
     $this->doDomTest($doc);
 }
예제 #8
0
 public function test(Response $response, Request $request)
 {
     libxml_clear_errors();
     $dom = new \DOMDocument();
     @$dom->loadXML($response->getBody());
     $lastError = libxml_get_last_error();
     if ($lastError) {
         throw new Exception("The given xml file is not well formed (last error: " . str_replace("\n", '', $lastError->message) . ").");
     }
 }
예제 #9
0
 /**
  * Checks for given directives in the cache control header
  *
  * @param Response $response
  *            recieved response
  * @param Request $request
  *            request we sent
  */
 public function test(Response $response, Request $request)
 {
     $header = $response->getHeader();
     $missing = array();
     foreach ($this->values as $value) {
         if (!$header->hasField($this->fieldName) && !$header->getField($this->fieldName) == $value) {
             $missing[] = $value;
         }
     }
     if (!empty($missing)) {
         throw new Exception("Expected header fields not set correct \"" . implode(', ', $missing) . ")");
     }
 }
 /**
  * Checks for given directives in the cache control header
  *
  * @param Response $response
  *            recieved response
  * @param Request $request
  *            request we sent
  */
 public function test(Response $response, Request $request)
 {
     $header = $response->getHeader();
     $missing = array();
     foreach ($this->directives as $directive) {
         if (!$header->directiveExists(self::FIELD_NAME, $directive)) {
             $missing[] = $directive;
         }
     }
     if (!empty($missing)) {
         throw new Exception("Expected cache directives \"" . implode(', ', $missing) . "\" not found in response header field " . self::FIELD_NAME);
     }
 }
예제 #11
0
 /**
  * This function writes the html documents to a specified directory
  *
  * @Event("LiveTest.Run.HandleResult")
  */
 public function handleResult(Result $result, Response $response)
 {
     if (in_array($result->getStatus(), $this->logStatuses)) {
         $filename = $this->logPath . urlencode($result->getRequest()->getIdentifier() . '.html');
         $file = new File($filename);
         $file->setContent($response->getBody());
         try {
             $this->createLogDirIfNotExists($this->logPath);
             $file->save();
         } catch (\Exception $e) {
             throw new ConfigurationException('Unable to write the html response to file "' . $filename . '"');
         }
     }
 }
예제 #12
0
 public function test(Response $response, Request $request)
 {
     // @todo same code a in the well formed test case
     libxml_clear_errors();
     $dom = new \DOMDocument();
     @$dom->loadXML($response->getBody());
     $lastError = libxml_get_last_error();
     if ($lastError) {
         throw new Exception("The given xml file is not well formed (last error: " . str_replace("\n", '', $lastError->message) . ").");
     }
     $valid = @$dom->schemaValidate($this->xsdSchemaFile);
     if (!$valid) {
         $lastError = libxml_get_last_error();
         $lastErrorMessage = str_replace("\n", '', $lastError->message);
         throw new Exception("The given xml file did not Validate vs. " . $this->xsdSchemaFile . " (last error: " . $lastErrorMessage . ").");
     }
 }
예제 #13
0
 /**
  * Checks if a specified http header is existing
  *
  * @see LiveTest\TestCase.HttpTestCase::test()
  */
 public function test(Response $response, Request $request)
 {
     if (!array_key_exists($this->headerName, $response->getHeaders())) {
         throw new Exception('The expected header "' . $this->headerName . '" was not found.');
     }
 }