public function testFormatUrl()
 {
     $formatter = new TextFormatter();
     $url = new Url();
     $url->setLoc('http://www.google.fr');
     $this->assertEquals('http://www.google.fr' . "\n", $formatter->formatUrl($url));
 }
 /**
  * @dataProvider lastmodProvider
  */
 public function testLastmodFormatting($lastmod, $changefreq, $expected_lastmod)
 {
     $url = new Url();
     $url->setLastmod($lastmod);
     $url->setChangefreq($changefreq);
     $this->assertEquals($expected_lastmod, $url->getLastmod());
 }
 public function testFormatUrl()
 {
     $formatter = new SpacelessFormatter(new TestableFormatter());
     $url = new Url();
     $url->setLoc('http://www.google.fr');
     $this->assertEquals('http://www.google.fr', $formatter->formatUrl($url));
 }
 public function newsDataProvider()
 {
     $first = new News();
     $first->slug = 'first';
     $second = new News();
     $second->slug = 'second';
     $urlFirst = new Url();
     $urlFirst->setLoc('/news/first');
     $urlSecond = new Url();
     $urlSecond->setLoc('/news/second');
     return array(array(array(), array()), array(array($first, $second), array($urlFirst, $urlSecond)));
 }
 public function populate(Sitemap $sitemap)
 {
     $url = new Url();
     $url->setLoc('http://www.google.fr');
     $url->setChangefreq(Url::CHANGEFREQ_NEVER);
     $url->setLastmod('2012-12-19 02:28');
     $video = new Video();
     $video->setThumbnailLoc('http://www.example.com/thumbs/123.jpg');
     $video->setTitle('Grilling steaks for summer');
     $video->setDescription('Alkis shows you how to get perfectly done steaks every time');
     $url->addVideo($video);
     $sitemap->add($url);
     $url = new Url();
     $url->setLoc('http://github.com');
     $url->setChangefreq(Url::CHANGEFREQ_ALWAYS);
     $url->setPriority(0.2);
     $sitemap->add($url);
 }
 protected function formatBody(Url $url)
 {
     $buffer = "\t" . '<loc>' . $this->escape($url->getLoc()) . '</loc>' . "\n";
     if ($url->getLastmod() !== null) {
         $buffer .= "\t" . '<lastmod>' . $this->escape($url->getLastmod()) . '</lastmod>' . "\n";
     }
     if ($url->getChangefreq() !== null) {
         $buffer .= "\t" . '<changefreq>' . $this->escape($url->getChangefreq()) . '</changefreq>' . "\n";
     }
     if ($url->getPriority() !== null) {
         $buffer .= "\t" . '<priority>' . $this->escape($url->getPriority()) . '</priority>' . "\n";
     }
     foreach ($url->getVideos() as $video) {
         $buffer .= $this->formatVideo($video);
     }
     foreach ($url->getImages() as $image) {
         $buffer .= $this->formatImage($image);
     }
     return $buffer;
 }
 public function populate(Sitemap $sitemap)
 {
     foreach ($this->options['routes'] as $route) {
         $route = array_merge($this->defaultRoute, $route);
         $url = new Url();
         $url->setLoc($this->router->generate($route['name'], $route['params']));
         $url->setChangefreq($route['changefreq'] ?: $this->options['changefreq']);
         $url->setLastmod($route['lastmod'] ?: $this->options['lastmod']);
         $url->setPriority($route['priority'] ?: $this->options['priority']);
         $sitemap->add($url);
     }
 }
 protected function resultToUrl($result)
 {
     $url = new Url();
     $url->setLoc($this->getResultLoc($result));
     if ($this->options['priority'] !== null) {
         $url->setPriority($this->options['priority']);
     }
     if ($this->options['changefreq'] !== null) {
         $url->setChangefreq($this->options['changefreq']);
     }
     if ($this->options['lastmod'] !== null) {
         $url->setLastmod($this->getColumnValue($result, $this->options['lastmod']));
     }
     return $url;
 }
 public function formatUrl(Url $url)
 {
     return $this->escape($url->getLoc()) . "\n";
 }
 public function testAddUrlBaseHostToVideos()
 {
     $dumper = new TestableMemoryDumper();
     $sitemap = new TestableSitemap($dumper, new TextFormatter(), 'http://www.google.fr');
     $url = new Url();
     $url->setLoc('http://www.joe.fr/search');
     $video = new Video();
     $video->setThumbnailLoc('/thumbs/123.jpg');
     $video->setContentLoc('/content/123.avi');
     $video->setPlayerLoc('/player/123.swf');
     $video->setGalleryLoc('/gallery/123');
     $url->addVideo($video);
     $sitemap->add($url);
     $this->assertEquals('http://www.google.fr/thumbs/123.jpg', $video->getThumbnailLoc());
     $this->assertEquals('http://www.google.fr/content/123.avi', $video->getContentLoc());
     $player = $video->getPlayerLoc();
     $this->assertEquals('http://www.google.fr/player/123.swf', $player['loc']);
     $gallery = $video->getGalleryLoc();
     $this->assertEquals('http://www.google.fr/gallery/123', $gallery['loc']);
 }
 /**
  * Add an entry to the sitemap.
  *
  * @param Url $url The URL to add. If the URL is relative, the base host will be prepended.
  *
  * @return Sitemap The current sitemap (for fluent interface).
  */
 public function add(Url $url)
 {
     if ($this->isSitemapIndexable() && $this->getCurrentSitemapIndex()->getUrlCount() >= $this->limit) {
         $this->addSitemapIndex($this->createSitemapIndex());
     }
     $loc = $url->getLoc();
     if (empty($loc)) {
         throw new \InvalidArgumentException('The url MUST have a loc attribute');
     }
     if ($this->baseHost !== null) {
         if ($this->needHost($loc)) {
             $url->setLoc($this->baseHost . $loc);
         }
         foreach ($url->getVideos() as $video) {
             if ($this->needHost($video->getThumbnailLoc())) {
                 $video->setThumbnailLoc($this->baseHost . $video->getThumbnailLoc());
             }
             if ($this->needHost($video->getContentLoc())) {
                 $video->setContentLoc($this->baseHost . $video->getContentLoc());
             }
             $player = $video->getPlayerLoc();
             if ($player !== null && $this->needHost($player['loc'])) {
                 $video->setPlayerLoc($this->baseHost . $player['loc'], $player['allow_embed'], $player['autoplay']);
             }
             $gallery = $video->getGalleryLoc();
             if ($gallery !== null && $this->needHost($gallery['loc'])) {
                 $video->setGalleryLoc($this->baseHost . $gallery['loc'], $gallery['title']);
             }
         }
         foreach ($url->getImages() as $image) {
             if ($this->needHost($image->getLoc())) {
                 $image->setLoc($this->baseHost . $image->getLoc());
             }
             if ($this->needHost($image->getLicense())) {
                 $image->setLicense($this->baseHost . $image->getLicense());
             }
         }
     }
     $this->dumper->dump($this->formatter->formatUrl($url));
     if ($this->isSitemapIndexable()) {
         $this->getCurrentSitemapIndex()->incrementUrl();
     }
     return $this;
 }
 public function testFormatUrlWithFullImage()
 {
     $url = new Url();
     $url->setLoc('http://www.google.fr/?s=joe"');
     $url->setPriority(0.2);
     $url->setChangefreq(Url::CHANGEFREQ_NEVER);
     $image = new Image();
     $image->setLoc('http://www.example.com/thumbs/123.jpg');
     $image->setTitle('Grilling steaks for "summer"');
     $image->setCaption('Some caption');
     $image->setLicense('http://opensource.org/licenses/mit-license.php');
     $image->setGeoLocation('France');
     $url->addImage($image);
     $this->assertEquals("<url>\n" . "\t<loc>http://www.google.fr/?s=joe&quot;</loc>\n" . "\t<changefreq>never</changefreq>\n" . "\t<priority>0.2</priority>\n" . "\t<image:image>\n" . "\t\t<image:loc>http://www.example.com/thumbs/123.jpg</image:loc>\n" . "\t\t<image:caption>Some caption</image:caption>\n" . "\t\t<image:geo_location>France</image:geo_location>\n" . "\t\t<image:title>Grilling steaks for &quot;summer&quot;</image:title>\n" . "\t\t<image:license>http://opensource.org/licenses/mit-license.php</image:license>\n" . "\t</image:image>\n" . "</url>\n", $this->formatter->formatUrl($url));
 }