Esempio n. 1
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');
         }
     }
 }
Esempio n. 2
0
 public function validate(Response $response)
 {
     if ($response->getStatus() <= $this->maxStatusCode) {
         if ($response->hasHeader('Cache-Control') && false !== strpos($response->getHeader('Cache-Control')[0], 'max-age=0')) {
             throw new ValidationFailedException('max-age=0 was found');
         }
     }
 }
Esempio n. 3
0
 protected function doValidation(Response $response)
 {
     if ($response->getStatus() >= 300) {
         return;
     }
     $crawler = new Crawler($response->getBody());
     $metaTags = $crawler->filterXPath("//meta[@name='robots']/@content");
     foreach ($metaTags as $metaTag) {
         $this->assert(strpos($metaTag->nodeValue, 'no-index') === false, 'A meta tag "robots" with the value "no-index" was found');
     }
 }
Esempio n. 4
0
 public function validate(Response $response)
 {
     if ($response->getStatus() <= $this->maxStatusCode) {
         if ($response->hasHeader('Pragma') && 'no-cache' === $response->getHeader('Pragma')[0]) {
             throw new ValidationFailedException('pragma:no-cache was found');
         }
         if ($response->hasHeader('Cache-Control') && false !== strpos($response->getHeader('Cache-Control')[0], 'no-cache')) {
             throw new ValidationFailedException('cache-control:no-cache was found');
         }
     }
 }
Esempio n. 5
0
 public function validate(Response $response)
 {
     if ($response->getStatus() <= $this->maxStatusCode) {
         if ($response->hasHeader('Expires')) {
             $expireRaw = preg_replace('/[^A-Za-z0-9\\-\\/,]/', '', $response->getHeader('Expires')[0]);
             if ($expireRaw !== '') {
                 $expires = strtotime($response->getHeader('Expires')[0]);
                 if ($expires < time()) {
                     throw new ValidationFailedException('expires in the past');
                 }
             }
         }
     }
 }
Esempio n. 6
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());
 }
Esempio n. 7
0
 public function validate(Response $response)
 {
     if ($response->getStatus() !== $this->expectedStatus) {
         throw new ValidationFailedException('Status code ' . $response->getStatus() . ' found, ' . $this->expectedStatus . ' expected.');
     }
 }
Esempio n. 8
0
 public function validate(Response $response)
 {
     if ($response->getStatus() > $this->maxStatusCode) {
         throw new ValidationFailedException('Status code ' . $response->getStatus() . ' found.');
     }
 }