public function testGetSitemapsOrgXmlSitemapType()
 {
     $sitemap = new Sitemap();
     $sitemap->setHttpResponse($this->getHttpFixture('SitemapsOrgXmlContent', 'application/xml'));
     $sitemap->setUrl('http://webignition.net/sitemap.xml');
     $this->assertEquals('sitemaps.org.xml', $sitemap->getType());
 }
 public function testIsIndexForSitemapsOrgXmlSitemapType()
 {
     $sitemap = new Sitemap();
     $sitemap->setHttpResponse($this->getHttpFixture('SitemapsOrgXmlContent', 'application/xml'));
     $sitemap->setUrl('http://webignition.net/sitemap.xml');
     $this->assertFalse($sitemap->isIndex());
 }
 public function testIsSitemapForNonSitemapContent()
 {
     $sitemap = new Sitemap();
     $sitemap->setHttpResponse($this->getHttpFixture());
     $sitemap->setUrl('http://webignition.net/sitemap.xml');
     $this->assertFalse($sitemap->isSitemap());
     $sitemap->setContent("one\ntwo\nthree");
     $this->assertFalse($sitemap->isSitemap());
     $sitemap->setContent("<!DOCTYPE html>\n<html>\n  <head>\n    <title>Hello HTML</title>\n  </head>\n  <body>\n    <p>Hello World!</p>\n  </body>\n</html>");
     $this->assertFalse($sitemap->isSitemap());
 }
 /**
  * 
  * @param \webignition\WebResource\Sitemap\Sitemap $sitemap
  * @return boolean
  */
 public function retrieve(Sitemap $sitemap)
 {
     if ($this->getConfiguration()->getShouldHalt()) {
         return false;
     }
     $request = clone $this->getConfiguration()->getBaseRequest();
     $request->setUrl($sitemap->getUrl());
     $this->setRequestCookies($request);
     $this->setRequestTimeout($request);
     $events = $this->getPreAndPostTransferEvents();
     $this->dispatcher->dispatch(Events::TRANSFER_PRE, $events['pre']);
     $lastRequestException = null;
     try {
         $response = $request->send();
     } catch (\Guzzle\Http\Exception\CurlException $curlException) {
         $lastRequestException = $curlException;
     } catch (\Guzzle\Http\Exception\RequestException $requestException) {
         $lastRequestException = $requestException;
     }
     $this->dispatcher->dispatch(Events::TRANSFER_POST, $events['post']);
     if ($lastRequestException instanceof \Exception || $response->getStatusCode() !== 200) {
         return false;
     }
     $sitemap->setHttpResponse($response);
     if ($sitemap->isIndex()) {
         $childUrls = $sitemap->getUrls();
         foreach ($childUrls as $childUrl) {
             $childSitemap = new Sitemap();
             $childSitemap->setConfiguration($sitemap->getConfiguration());
             $childSitemap->setUrl($childUrl);
             $sitemap->addChild($childSitemap);
             if ($this->getConfiguration()->getRetrieveChildSitemaps()) {
                 $this->retrieve($childSitemap);
             }
         }
     }
     return true;
 }