2011-06-12 16:14:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2011-06-20 15:56:01 +02:00
|
|
|
* @package googlesitemaps
|
2012-06-30 11:39:35 +02:00
|
|
|
* @subpackage tests
|
2011-06-12 16:14:29 +02:00
|
|
|
*/
|
2011-06-20 15:56:01 +02:00
|
|
|
class GoogleSitemapTest extends FunctionalTest {
|
|
|
|
|
|
|
|
public static $fixture_file = 'googlesitemaps/tests/GoogleSitemapTest.yml';
|
|
|
|
|
|
|
|
protected $extraDataObjects = array(
|
|
|
|
'GoogleSitemapTest_DataObject',
|
|
|
|
'GoogleSitemapTest_OtherDataObject',
|
|
|
|
'GoogleSitemapTest_UnviewableDataObject'
|
|
|
|
);
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function setUp() {
|
2012-06-30 11:39:35 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
if(class_exists('Page')) {
|
|
|
|
$this->loadFixture('googlesitemaps/tests/GoogleSitemapPageTest.yml');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function testItems() {
|
2012-06-30 11:39:35 +02:00
|
|
|
$sitemap = new GoogleSitemap();
|
|
|
|
|
|
|
|
// register a DataObject and see if its aded to the sitemap
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_DataObject", '');
|
|
|
|
|
|
|
|
$this->assertEquals(2, $sitemap->Items()->Count());
|
|
|
|
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_OtherDataObject");
|
|
|
|
$this->assertEquals(3, $sitemap->Items()->Count());
|
|
|
|
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_UnviewableDataObject");
|
|
|
|
$this->assertEquals(3, $sitemap->Items()->Count());
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function testItemsWithPages() {
|
2012-06-30 11:39:35 +02:00
|
|
|
if(!class_exists('Page')) {
|
|
|
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
|
|
|
}
|
|
|
|
|
|
|
|
$sitemap = new GoogleSitemap();
|
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$page = $this->objFromFixture('Page', 'Page1');
|
|
|
|
$page->publish('Stage', 'Live');
|
|
|
|
$page->flushCache();
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$page2 = $this->objFromFixture('Page', 'Page2');
|
|
|
|
$page2->publish('Stage', 'Live');
|
|
|
|
$page2->flushCache();
|
|
|
|
|
|
|
|
$this->assertDOSEquals(array(
|
|
|
|
array('Title' => 'Testpage1'),
|
|
|
|
array('Title' => 'Testpage2')
|
|
|
|
), $sitemap->Items(), "There should be 2 pages in the sitemap after publishing");
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
// check if we make a page readonly that it is hidden
|
|
|
|
$page2->CanViewType = 'LoggedInUsers';
|
|
|
|
$page2->write();
|
|
|
|
$page2->publish('Stage', 'Live');
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$this->session()->inst_set('loggedInAs', null);
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$this->assertDOSEquals(array(
|
|
|
|
array('Title' => 'Testpage1')
|
|
|
|
), $sitemap->Items(), "There should be only 1 page, other is logged in only");
|
|
|
|
|
|
|
|
// register a DataObject and see if its aded to the sitemap
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_DataObject", '');
|
|
|
|
|
|
|
|
// check to see if we have the GoogleSitemapTest_DataObject objects
|
|
|
|
$this->assertEquals(3, $sitemap->Items()->Count());
|
|
|
|
|
|
|
|
// register another dataobject
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_OtherDataObject");
|
|
|
|
$this->assertEquals(4, $sitemap->Items()->Count());
|
|
|
|
|
|
|
|
// check if we register objects that are unreadable they don't end up
|
|
|
|
// in the sitemap
|
|
|
|
GoogleSitemap::register_dataobject("GoogleSitemapTest_UnviewableDataObject");
|
|
|
|
$this->assertEquals(4, $sitemap->Items()->Count());
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function testAccess() {
|
2011-06-20 15:56:01 +02:00
|
|
|
GoogleSitemap::enable();
|
|
|
|
|
|
|
|
$response = $this->get('sitemap.xml');
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$this->assertEquals(200, $response->getStatusCode(), 'Sitemap returns a 200 success when enabled');
|
|
|
|
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));
|
|
|
|
|
|
|
|
GoogleSitemap::disable();
|
|
|
|
|
|
|
|
$response = $this->get('sitemap.xml');
|
|
|
|
$this->assertEquals(404, $response->getStatusCode(), 'Sitemap returns a 404 when disabled');
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function testDecoratorAddsFields() {
|
2012-06-30 11:39:35 +02:00
|
|
|
if(!class_exists("Page")) {
|
|
|
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
|
|
|
}
|
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$page = $this->objFromFixture('Page', 'Page1');
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2012-03-26 11:50:30 +02:00
|
|
|
$fields = $page->getSettingsFields();
|
|
|
|
$tab = $fields->fieldByName('Root')->fieldByName('Settings')->fieldByName('GoogleSitemap');
|
2012-06-30 11:39:35 +02:00
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
$this->assertInstanceOf('Tab', $tab);
|
|
|
|
$this->assertInstanceOf('DropdownField', $tab->fieldByName('Priority'));
|
|
|
|
$this->assertInstanceOf('LiteralField', $tab->fieldByName('GoogleSitemapIntro'));
|
|
|
|
}
|
|
|
|
|
2012-07-06 06:44:26 +02:00
|
|
|
public function testGetPriority() {
|
2012-06-30 11:39:35 +02:00
|
|
|
if(!class_exists("Page")) {
|
|
|
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
|
|
|
}
|
2011-06-20 15:56:01 +02:00
|
|
|
|
2012-06-30 11:39:35 +02:00
|
|
|
$page = $this->objFromFixture('Page', 'Page1');
|
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
// invalid field doesn't break google
|
|
|
|
$page->Priority = 'foo';
|
|
|
|
$this->assertEquals(0.5, $page->getPriority());
|
|
|
|
|
|
|
|
// google doesn't like -1 but we use it to indicate the minimum
|
|
|
|
$page->Priority = -1;
|
|
|
|
$this->assertEquals(0, $page->getPriority());
|
|
|
|
}
|
2011-06-12 16:14:29 +02:00
|
|
|
}
|
|
|
|
|
2011-06-20 15:56:01 +02:00
|
|
|
/**
|
|
|
|
* @package googlesitemaps
|
2012-06-30 11:39:35 +02:00
|
|
|
* @subpackage tests
|
2011-06-20 15:56:01 +02:00
|
|
|
*/
|
|
|
|
class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
|
|
|
|
|
|
|
|
public static $db = array(
|
|
|
|
'Priority' => 'Varchar(10)'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function canView($member = null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AbsoluteLink() {
|
|
|
|
return Director::baseURL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package googlesitemaps
|
2012-06-30 11:39:35 +02:00
|
|
|
* @subpackage tests
|
2011-06-20 15:56:01 +02:00
|
|
|
*/
|
|
|
|
class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
|
|
|
|
|
|
|
|
public static $db = array(
|
|
|
|
'Priority' => 'Varchar(10)'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function canView($member = null) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AbsoluteLink() {
|
|
|
|
return Director::baseURL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @package googlesitemaps
|
2012-06-30 11:39:35 +02:00
|
|
|
* @subpackage tests
|
2011-06-20 15:56:01 +02:00
|
|
|
*/
|
|
|
|
class GoogleSitemapTest_UnviewableDataObject extends DataObject implements TestOnly {
|
|
|
|
|
|
|
|
public static $db = array(
|
|
|
|
'Priority' => 'Varchar(10)'
|
|
|
|
);
|
|
|
|
|
|
|
|
public function canView($member = null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function AbsoluteLink() {
|
|
|
|
return Director::baseURL();
|
|
|
|
}
|
|
|
|
}
|