예제 #1
0
 /**
  * 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);
     }
 }
예제 #2
0
 public function testBadIsValid()
 {
     $invalidUriStrings = array('', 'www..examplepage', '#', ';', 'http://', 'http:/www.example.com', 'ftp:/www.example.com', 'tp://www.example.com');
     foreach ($invalidUriStrings as $invalidUriString) {
         $this->assertFalse(Uri::isValid($invalidUriString), 'The uri "' . $invalidUriString . '" was accepted as valid uri, but isn\'t.');
     }
 }
예제 #3
0
 public function getExternalDependencies($uri = null)
 {
     $pattern = '/[^\'](<link|<script).*(href|src)=["\']([\\S]+)[\'"][^\']/i';
     $result = array();
     $matches = array();
     preg_match_all($pattern, $this->content, $matches);
     $files = $matches[3];
     if (!is_null($uri)) {
         $uri = new Uri($uri);
         $cleanFiles = array();
         foreach ($files as $file) {
             $cleanFiles[] = $uri->concatUri($file);
         }
     } else {
         $cleanFiles = $files;
     }
     return $cleanFiles;
 }
예제 #4
0
 /**
  * Creates new LiveTest-Symfony-Requests by using (delegation) the
  * original SymfonyRequest.
  *
  * @param Uri $uri
  * @param String $method
  * @param array $requestParameters
  */
 public static function create(Uri $uri, $method = 'get', $requestParameters = array())
 {
     $request = SymfonyRequest::create($uri->toString(), $method, $requestParameters);
     return new static($request, $requestParameters);
 }