/** * URL of the page. This URL must begin with the protocol (such as http) and end * with a trailing slash, if your web server requires it. This value must be * less than 2,048 characters. * @see http://www.sitemaps.org/protocol.php * @param string $location */ public function set_loc($location) { if (!Validate::max_length($location, 2048)) { throw new LengthException('The location was too long, maximum length of 2,048 characters.'); } $location = Sitemap::encode($location); if (!Validate::url($location)) { throw new InvalidArgumentException('The location was not a valid URL'); } $this->attributes['loc'] = $location; return $this; }
/** * @test * @group sitemap * @dataProvider provider_create * @param string $location * @param integer $lastmod * @param string $change_frequency * @param integer|float $priority */ public function test_create($location, $lastmod, $change_frequency, $priority) { $instance = new Sitemap_URL(); $instance->set_loc($location)->set_last_mod($lastmod)->set_change_frequency($change_frequency)->set_priority($priority); $return = $instance->create(); // This solution allows me to see failure results displayed in the // CLI runner. Using assertTag or assertSelectEquals only gives me a boolean // value back and makes it very hard to track down errors. $xml = simplexml_import_dom($return); $this->assertEquals(Sitemap::encode($location), (string) $xml->loc); $this->assertEquals(Sitemap::date_format($lastmod), (string) $xml->lastmod); $this->assertEquals($change_frequency, (string) $xml->changefreq); $this->assertEquals($priority, (string) $xml->priority); }
/** * @test * @group sitemap * @dataProvider provider_encode */ public function test_encode($string, $expected) { $return = Sitemap::encode($string); $this->assertSame($expected, $return); }