Exemple #1
0
 public function getLink(array $linkData, Domain $domain, Link $origin)
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver($linkData['href'], $origin->getLinkHref());
     $link = new Link((string) $deriver->getAbsoluteUrl());
     $link->setOriginDomain($domain);
     $link->setLinkText($linkData['text']);
     $link->setOrigin($origin);
     return $link;
 }
 private function getMetaRedirectUrlFromLastResponse()
 {
     $webPage = $this->getWebPageFromLastResponse();
     if (is_null($webPage)) {
         return null;
     }
     $redirectUrl = null;
     $webPage->find('meta[http-equiv=refresh]')->each(function ($index, \DOMElement $domElement) use(&$redirectUrl) {
         if ($domElement->hasAttribute('content')) {
             $contentAttribute = $domElement->getAttribute('content');
             $urlMarkerPosition = stripos($contentAttribute, 'url=');
             if ($urlMarkerPosition !== false) {
                 $redirectUrl = substr($contentAttribute, $urlMarkerPosition + strlen('url='));
             }
         }
     });
     if (is_null($redirectUrl)) {
         return null;
     }
     $absoluteUrlDeriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver($redirectUrl, $this->getLastResponse()->getEffectiveUrl());
     return (string) $absoluteUrlDeriver->getAbsoluteUrl();
 }
 public function testAbsolutePathHasDotDirecoryAndSourceHasDirectoryWithoutTrailingSlash()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('./jquery.js', 'http://www.example.com/pathOne');
     $this->assertEquals('http://www.example.com/pathOne/jquery.js', (string) $deriver->getAbsoluteUrl());
 }
 public function testThingy()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('#startcontent', 'http://news.bbc.co.uk/1/hi/help/3681938.stm');
     $this->assertEquals('http://news.bbc.co.uk/1/hi/help/3681938.stm#startcontent', (string) $deriver->getAbsoluteUrl());
 }
 /**
  * 
  * @return string
  */
 private function findSitemapUrlsFromRobotsTxt()
 {
     $robotsTxtParser = new \webignition\RobotsTxt\File\Parser();
     $robotsTxtParser->setSource($this->getRobotsTxtContent());
     $robotsTxtFile = $robotsTxtParser->getFile();
     $urls = array();
     if ($robotsTxtFile->directiveList()->containsField('sitemap')) {
         $sitemapDirectives = $robotsTxtFile->directiveList()->filter(array('field' => 'sitemap'));
         foreach ($sitemapDirectives->get() as $sitemapDirective) {
             /* @var $sitemapDirective \webignition\RobotsTxt\Directive\Directive */
             $sitemapUrl = new \webignition\Url\Url((string) $sitemapDirective->getValue());
             if ($sitemapUrl->isRelative()) {
                 $absoluteUrlDeriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver((string) $sitemapUrl, $this->getConfiguration()->getRootUrl());
                 $urls[] = (string) $absoluteUrlDeriver->getAbsoluteUrl();
             } else {
                 $urls[] = (string) $sitemapUrl;
             }
         }
     }
     return $urls;
 }
 public function testAddSchemeHostFromSource()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('http://blog.limegreentangerine.co.uk', 'http://www.limegreentangerine.co.uk/branding/');
     $this->assertEquals('http://blog.limegreentangerine.co.uk', (string) $deriver->getAbsoluteUrl());
 }
 public function testAbsoluteUrlWithPath()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('http://www.example.com/pathOne', 'http://www.example.com/');
     $this->assertEquals('http://www.example.com/pathOne', (string) $deriver->getAbsoluteUrl());
 }
 /**
  * 
  * @param \Guzzle\Http\Message\Response $response
  * @return string
  */
 private function getResponseLocation(\Guzzle\Http\Message\Response $response)
 {
     $absoluteUrlDeriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver($response->getLocation(), $this->currentUrl);
     return (string) $absoluteUrlDeriver->getAbsoluteUrl();
 }
 public function testInitialiseViaInitInsteadOfConstructor()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver();
     $deriver->init('/foo/bar.html', 'http://example.com/');
     $this->assertEquals('http://example.com/foo/bar.html', (string) $deriver->getAbsoluteUrl());
 }
 public function testSourceHasFilePath()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('example.html', 'http://example.com/index.html');
     $this->assertEquals('http://example.com/example.html', (string) $deriver->getAbsoluteUrl());
 }
 public function testAbsolutePathIsTransformedIntoCorrectAbsoluteUrl()
 {
     $deriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver('/server.php?param1=value1', 'http://www.example.com/pathOne/pathTwo/pathThree');
     $this->assertEquals('http://www.example.com/server.php?param1=value1', $deriver->getAbsoluteUrl());
 }