mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 09:05:48 +00:00
ENHANCEMENT: unittests added #ignore codesniffer
This commit is contained in:
parent
a298994da9
commit
e3e5e9ff89
@ -7,14 +7,103 @@
|
||||
* @since 11.06.2011
|
||||
*/
|
||||
class GoogleSitemapTest extends SapphireTest {
|
||||
|
||||
|
||||
public static $fixture_file = 'googlesitemaps/tests/GoogleSitemapTest.yml';
|
||||
|
||||
protected $extraDataObjects = array(
|
||||
'GoogleSitemapTest_DataObject',
|
||||
'GoogleSitemapTest_OtherDataObject'
|
||||
);
|
||||
|
||||
public function testItems() {
|
||||
//Register a DataObject and see if its aded to the sitemap
|
||||
GoogleSitemap::register_dataobject("GoogleSitemapTest_DataObject");
|
||||
$obj = new GoogleSitemapTest_DataObject();
|
||||
$obj->Priority = 0.4;
|
||||
$obj->write();
|
||||
|
||||
//Publish a page and check if it returns
|
||||
$obj = $this->objFromFixture("Page", "Page1");
|
||||
$page = DataObject::get_by_id("Page", $obj->ID);
|
||||
#$page->publish();
|
||||
#$sitemap = new GoogleSitemap();
|
||||
#$this->assertEquals(1, $sitemap->Items()->Count());
|
||||
$page = DataObject::get_one("Page", "`Title` = 'Testpage1'");
|
||||
$page->doPublish();
|
||||
$sitemap = new GoogleSitemap();
|
||||
$this->assertEquals(2, $sitemap->Items()->Count(), "There should be two items in the sitemap");
|
||||
|
||||
//Publish a second page
|
||||
$page2 = DataObject::get_one("Page", "`Title` = 'Testpage2'");
|
||||
$page2->doPublish();
|
||||
$this->assertEquals(3, $sitemap->Items()->Count(), "There should be three items in the sitemap");
|
||||
|
||||
//Can two different subclasses of DataObjects be registered for the sitemap?
|
||||
GoogleSitemap::register_dataobject("GoogleSitemapTest_OtherDataObject");
|
||||
$otherObj = new GoogleSitemapTest_OtherDataObject();
|
||||
$otherObj->Priority = 0.3;
|
||||
$otherObj->write();
|
||||
$this->assertEquals(4, $sitemap->Items()->Count(), "There should be four items in the sitemap");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test object class for dataobjects that should appear in the google sitemap
|
||||
*
|
||||
* @author Roland Lehmann <rlehmann@pixeltricks.de>
|
||||
* @since 28.6.2011
|
||||
*/
|
||||
class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
|
||||
public static $db = array(
|
||||
'Priority' => 'VarChar(10)'
|
||||
);
|
||||
|
||||
/**
|
||||
* Each DataObject that should be shown in the sitemap must be viewable
|
||||
*
|
||||
* @param Member $member logged in member
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the link to this object with protocol and domain
|
||||
*
|
||||
* @return string the absolute link to this product
|
||||
*/
|
||||
public function AbsoluteLink() {
|
||||
return Director::baseURL();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Second test object class for dataobjects that should appear in the google sitemap
|
||||
*
|
||||
* @author Roland Lehmann <rlehmann@pixeltricks.de>
|
||||
* @since 28.6.2011
|
||||
*/
|
||||
class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
|
||||
public static $db = array(
|
||||
'Priority' => 'VarChar(10)'
|
||||
);
|
||||
|
||||
/**
|
||||
* Each DataObject that should be shown in the sitemap must be viewable
|
||||
*
|
||||
* @param Member $member logged in member
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canView($member = null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the link to this object with protocol and domain
|
||||
*
|
||||
* @return string the absolute link to this product
|
||||
*/
|
||||
public function AbsoluteLink() {
|
||||
return Director::baseURL();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,7 @@
|
||||
Page:
|
||||
Page1:
|
||||
Title: Testpage1
|
||||
Priority: 0.2
|
||||
Page2:
|
||||
Page3:
|
||||
Title: Testpage2
|
||||
|
||||
DataObject:
|
||||
DataObject1:
|
||||
DataObject2:
|
||||
DataObject3:
|
||||
|
Loading…
x
Reference in New Issue
Block a user