Exemple #1
0
 public function doValidation(Response $response)
 {
     if (strpos($response->getContentType(), 'image') === false && strpos($response->getContentType(), 'pdf') === false && strlen((string) $response->getBody()) >= $this->minFileSize) {
         if (!$response->hasHeader('Content-Encoding') || $response->getHeader('Content-Encoding')[0] !== 'gzip') {
             throw new ValidationFailedException('gzip compression not active');
         }
     }
 }
Exemple #2
0
 public function validate(Response $response)
 {
     if (($response->getStatus() < 300 || $response->getStatus() >= 400) && $response->getContentType() === 'text/html') {
         if (stripos($response->getBody(), '</html>') === false) {
             throw new ValidationFailedException('Closing html tag is missing');
         }
     }
 }
Exemple #3
0
 public function testResponse()
 {
     $testBody = 'TestBodyWith<strong>special</strong>Chäräctörs';
     $testHeader = HeadersParser::parse(['Header1' => 'Test Header']);
     $testStatus = 200;
     $testUri = new Uri('http://smoke.phmlabs.com');
     $testRequest = new Request($testUri);
     $stream = fopen('data://text/plain,' . $testBody, 'r');
     $response = new Response($stream, $testStatus, array(), ['request' => $testRequest]);
     $this->assertEquals($testBody, $response->getBody());
     $this->assertEquals([], $response->getHeader('Test Header'));
     $this->assertEquals($testStatus, $response->getStatus());
     $this->assertEmpty($response->getContentType());
     $this->assertEquals($testRequest, $response->getRequest());
 }
Exemple #4
0
 public function validate(Response $response)
 {
     if ($response->getContentType() !== 'application/javascript') {
         return;
     }
     $filename = $this->tmpDir . DIRECTORY_SEPARATOR . md5($response->getBody()) . '.js';
     file_put_contents($filename, $response->getBody());
     $conf = __DIR__ . DIRECTORY_SEPARATOR . 'jsHint.conf';
     $command = $this->jsHintExecutable . ' --config ' . $conf . ' --verbose ' . $filename . ' | grep -E E[0-9]+.$';
     $validationResult = shell_exec($command);
     unlink($filename);
     if (!is_null($validationResult)) {
         $errorMsg = str_replace($filename . ':', '', $validationResult);
         throw new ValidationFailedException('JavaScript error found: ' . $errorMsg);
     }
 }
Exemple #5
0
 public function validate(Response $response)
 {
     if (count($this->contentTypes) > 0) {
         $valid = false;
         foreach ($this->contentTypes as $validContentType) {
             if (strpos($response->getContentType(), $validContentType) !== false) {
                 $valid = true;
                 break;
             }
         }
         if (!$valid) {
             return;
         }
     }
     $this->doValidation($response);
 }
Exemple #6
0
 public function validate(Response $response)
 {
     if ($response->getContentType() !== 'text/xml') {
         return;
     }
     $body = $response->getBody();
     if (preg_match('/<rss/', $body)) {
         libxml_clear_errors();
         $dom = new \DOMDocument();
         @$dom->loadXML($body);
         $lastError = libxml_get_last_error();
         if ($lastError) {
             throw new ValidationFailedException('The given xml file is not well formed (last error: ' . str_replace("\n", '', $lastError->message) . ').');
         }
         $valid = @$dom->schemaValidate($this->getSchema());
         if (!$valid) {
             $lastError = libxml_get_last_error();
             $lastErrorMessage = str_replace("\n", '', $lastError->message);
             throw new ValidationFailedException('The given xml file did not Validate vs. ' . $this->getSchema() . ' (last error: ' . $lastErrorMessage . ').');
         }
     }
 }
Exemple #7
0
 public function validate(Response $response)
 {
     if ($response->getContentType() !== 'text/html') {
         return;
     }
     $crawler = new Crawler($response->getBody());
     $idList = $crawler->filterXPath('//*[@id!=""]');
     $foundIds = array();
     $duplicatedIds = array();
     foreach ($idList as $idElement) {
         $id = $idElement->getAttribute('id');
         if (array_key_exists($id, $foundIds)) {
             $duplicatedIds[$id] = true;
         } else {
             $foundIds[$id] = true;
         }
     }
     if (count($duplicatedIds) > 0) {
         unset($duplicatedIds['']);
         throw new ValidationFailedException('Duplicate ids found (' . implode(', ', array_keys($duplicatedIds)) . ')');
     }
 }
Exemple #8
0
 public function testContentTypeHeader()
 {
     $stream = fopen('data://text/plain,' . '', 'r');
     $response = new \whm\Smoke\Http\Response($stream, 200, ['Content-Type' => ['application/xml']]);
     $this->assertEquals('application/xml', $response->getContentType());
 }