mirror of
https://github.com/wilr/silverstripe-googlesitemaps.git
synced 2024-10-22 11:05:48 +02:00
FIX: skip unit tests and loading page objects if cms module is not installed.
This commit is contained in:
parent
c5c92abad2
commit
df9b224937
@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// add the extension to pages
|
// add the extension to pages
|
||||||
if (class_exists('SiteTree'))
|
if (class_exists('SiteTree')) {
|
||||||
Object::add_extension('SiteTree', 'GoogleSitemapSiteTreeDecorator');
|
Object::add_extension('SiteTree', 'GoogleSitemapSiteTreeDecorator');
|
||||||
|
}
|
||||||
|
|
||||||
// if you need to add this to DataObjects include the following in
|
// if you need to add this to DataObjects include the following in
|
||||||
// your own _config:
|
// your own _config:
|
||||||
|
@ -21,6 +21,13 @@
|
|||||||
*/
|
*/
|
||||||
class GoogleSitemap extends Controller {
|
class GoogleSitemap extends Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $allowed_actions = array(
|
||||||
|
'index'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
|
6
tests/GoogleSitemapPageTest.yml
Normal file
6
tests/GoogleSitemapPageTest.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
Page:
|
||||||
|
Page1:
|
||||||
|
Title: Testpage1
|
||||||
|
Priority: 0.2
|
||||||
|
Page2:
|
||||||
|
Title: Testpage2
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class GoogleSitemapTest extends FunctionalTest {
|
class GoogleSitemapTest extends FunctionalTest {
|
||||||
|
|
||||||
@ -13,7 +14,36 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
'GoogleSitemapTest_UnviewableDataObject'
|
'GoogleSitemapTest_UnviewableDataObject'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
if(class_exists('Page')) {
|
||||||
|
$this->loadFixture('googlesitemaps/tests/GoogleSitemapPageTest.yml');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function testItems() {
|
function testItems() {
|
||||||
|
$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());
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItemsWithPages() {
|
||||||
|
if(!class_exists('Page')) {
|
||||||
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sitemap = new GoogleSitemap();
|
||||||
|
|
||||||
$page = $this->objFromFixture('Page', 'Page1');
|
$page = $this->objFromFixture('Page', 'Page1');
|
||||||
$page->publish('Stage', 'Live');
|
$page->publish('Stage', 'Live');
|
||||||
$page->flushCache();
|
$page->flushCache();
|
||||||
@ -22,7 +52,6 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
$page2->publish('Stage', 'Live');
|
$page2->publish('Stage', 'Live');
|
||||||
$page2->flushCache();
|
$page2->flushCache();
|
||||||
|
|
||||||
$sitemap = new GoogleSitemap();
|
|
||||||
$this->assertDOSEquals(array(
|
$this->assertDOSEquals(array(
|
||||||
array('Title' => 'Testpage1'),
|
array('Title' => 'Testpage1'),
|
||||||
array('Title' => 'Testpage2')
|
array('Title' => 'Testpage2')
|
||||||
@ -59,6 +88,7 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
GoogleSitemap::enable();
|
GoogleSitemap::enable();
|
||||||
|
|
||||||
$response = $this->get('sitemap.xml');
|
$response = $this->get('sitemap.xml');
|
||||||
|
|
||||||
$this->assertEquals(200, $response->getStatusCode(), 'Sitemap returns a 200 success when enabled');
|
$this->assertEquals(200, $response->getStatusCode(), 'Sitemap returns a 200 success when enabled');
|
||||||
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));
|
$this->assertEquals('application/xml; charset="utf-8"', $response->getHeader('Content-Type'));
|
||||||
|
|
||||||
@ -69,6 +99,10 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testDecoratorAddsFields() {
|
function testDecoratorAddsFields() {
|
||||||
|
if(!class_exists("Page")) {
|
||||||
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
|
}
|
||||||
|
|
||||||
$page = $this->objFromFixture('Page', 'Page1');
|
$page = $this->objFromFixture('Page', 'Page1');
|
||||||
|
|
||||||
$fields = $page->getSettingsFields();
|
$fields = $page->getSettingsFields();
|
||||||
@ -80,6 +114,10 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testGetPriority() {
|
function testGetPriority() {
|
||||||
|
if(!class_exists("Page")) {
|
||||||
|
$this->markTestIncomplete('No cms module installed, page related test skipped');
|
||||||
|
}
|
||||||
|
|
||||||
$page = $this->objFromFixture('Page', 'Page1');
|
$page = $this->objFromFixture('Page', 'Page1');
|
||||||
|
|
||||||
// invalid field doesn't break google
|
// invalid field doesn't break google
|
||||||
@ -94,6 +132,7 @@ class GoogleSitemapTest extends FunctionalTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
|
class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
|
||||||
|
|
||||||
@ -112,6 +151,7 @@ class GoogleSitemapTest_DataObject extends DataObject implements TestOnly {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
|
class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
|
||||||
|
|
||||||
@ -130,6 +170,7 @@ class GoogleSitemapTest_OtherDataObject extends DataObject implements TestOnly {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @package googlesitemaps
|
* @package googlesitemaps
|
||||||
|
* @subpackage tests
|
||||||
*/
|
*/
|
||||||
class GoogleSitemapTest_UnviewableDataObject extends DataObject implements TestOnly {
|
class GoogleSitemapTest_UnviewableDataObject extends DataObject implements TestOnly {
|
||||||
|
|
||||||
|
@ -1,10 +1,3 @@
|
|||||||
Page:
|
|
||||||
Page1:
|
|
||||||
Title: Testpage1
|
|
||||||
Priority: 0.2
|
|
||||||
Page2:
|
|
||||||
Title: Testpage2
|
|
||||||
|
|
||||||
GoogleSitemapTest_DataObject:
|
GoogleSitemapTest_DataObject:
|
||||||
DataObjectTest1:
|
DataObjectTest1:
|
||||||
Priority: 0.4
|
Priority: 0.4
|
||||||
|
Loading…
Reference in New Issue
Block a user