Esempio n. 1
0
 public function testShouldInitializeUrlWithData()
 {
     $loc = 'http://www.google.com';
     $lastmod = \DateTime::createFromFormat('Y-m-d', '2011-10-10');
     $changefreq = 'monthly';
     $priority = '2';
     $images = new ArrayCollection();
     $url = new Url($loc);
     $this->assertEquals($loc, $url->getLoc());
     $this->assertInstanceOf('Doctrine\\Common\\Collections\\Collection', $url->all());
     $this->assertEquals(0, count($url->all()));
     $this->assertInstanceOf('DateTime', $url->getLastmod());
     $this->assertNull($url->getChangefreq());
     $this->assertNull($url->getPriority());
     $url->setLastmod($lastmod);
     $url->setChangefreq($changefreq);
     $url->setPriority($priority);
     $this->assertEquals($lastmod, $url->getLastmod());
     $this->assertEquals($changefreq, $url->getChangefreq());
     $this->assertEquals($priority, $url->getPriority());
     $url = new Url($loc, $lastmod, $changefreq, $priority, $images);
     $this->assertEquals($loc, $url->getLoc());
     $this->assertEquals($lastmod, $url->getLastmod());
     $this->assertEquals($changefreq, $url->getChangefreq());
     $this->assertEquals($priority, $url->getPriority());
     $this->assertSame($images, $url->all());
     $image = new Image($loc . '/logo.jpg');
     $url->add($image);
     $this->assertEquals(1, count($url->all()));
     $url->remove($image);
     $this->assertEquals(0, count($url->all()));
 }
 public function populate(Sitemap $sitemap)
 {
     for ($i = 1; $i <= 20000; $i++) {
         $url = new Url('/urls/' . $i);
         while ((bool) round(rand(0, 2))) {
             $image = new Image('/urls/' . $i . '/images/' . microtime(true) . '.jpg');
             $url->add($image);
         }
         $url->setLastmod(new \DateTime());
         $sitemap->add($url);
         if ($i % 200 == 0) {
             $sitemap->save();
         }
     }
 }