Fix unit tests

This commit is contained in:
Will Rossiter 2018-01-18 17:00:10 +13:00
parent 38c489c931
commit 742724dad4
3 changed files with 10 additions and 8 deletions

View File

@ -35,7 +35,7 @@ class GoogleSitemapExtension extends DataExtension
} }
if ($can) { if ($can) {
$can = $this->owner->getGooglePriority(); $can = ($this->owner->getGooglePriority() !== false);
} }
if ($can === false) { if ($can === false) {
@ -81,8 +81,10 @@ class GoogleSitemapExtension extends DataExtension
{ {
$field = $this->owner->hasField('Priority'); $field = $this->owner->hasField('Priority');
if (isset($this->Priority) || ($field && $this->Priority = $this->owner->getField('Priority'))) { if ($field) {
return ($this->Priority < 0) ? false : $this->Priority; $priority = $this->owner->getField('Priority');
return ($priority < 0) ? false : $priority;
} }
return GoogleSitemap::get_priority_for_class($this->owner->class); return GoogleSitemap::get_priority_for_class($this->owner->class);

View File

@ -103,10 +103,10 @@ class GoogleSitemap
if (!self::is_registered($className)) { if (!self::is_registered($className)) {
$className::add_extension(GoogleSitemapExtension::class); $className::add_extension(GoogleSitemapExtension::class);
self::$dataobjects[$className] = array( self::$dataobjects[$className] = [
'frequency' => ($changeFreq) ? $changeFreq : 'monthly', 'frequency' => ($changeFreq) ? $changeFreq : 'monthly',
'priority' => ($priority) ? $priority : '0.6' 'priority' => ($priority) ? $priority : '0.6'
); ];
} }
} }

View File

@ -294,16 +294,16 @@ class GoogleSitemapTest extends FunctionalTest
public function testUnpublishedPage() public function testUnpublishedPage()
{ {
if (!class_exists('SilverStripe\CMS\SiteTree')) { if (!class_exists('SilverStripe\CMS\Model\SiteTree')) {
$this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage'); $this->markTestSkipped('Test skipped; CMS module required for testUnpublishedPage');
} }
$orphanedPage = new \SilverStripe\CMS\SiteTree(); $orphanedPage = new \SilverStripe\CMS\Model\SiteTree();
$orphanedPage->ParentID = 999999; // missing parent id $orphanedPage->ParentID = 999999; // missing parent id
$orphanedPage->write(); $orphanedPage->write();
$orphanedPage->publish("Stage", "Live"); $orphanedPage->publish("Stage", "Live");
$rootPage = new \SilverStripe\CMS\SiteTree(); $rootPage = new \SilverStripe\CMS\Model\SiteTree();
$rootPage->ParentID = 0; $rootPage->ParentID = 0;
$rootPage->write(); $rootPage->write();
$rootPage->publish("Stage", "Live"); $rootPage->publish("Stage", "Live");