mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
FIX: Tests now pass in Postgres on 3.1 and 3.2
Problems resolved: 1) Case sensitivy of check on Code field of Group 2) MySQL and Postgres have different date functions 3) When BlogID is empty, explicitly set it to 0. If not then all tests break under Postgres
This commit is contained in:
parent
7248d21b31
commit
cb45815fbd
@ -28,13 +28,18 @@ matrix:
|
|||||||
env: DB=MYSQL COVERAGE=1
|
env: DB=MYSQL COVERAGE=1
|
||||||
- php: 5.5
|
- php: 5.5
|
||||||
env: DB=MYSQL
|
env: DB=MYSQL
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=PGSQL
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=MYSQL CORE_RELEASE=3.2
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=PGSQL CORE_RELEASE=3.2
|
||||||
- php: 5.4
|
- php: 5.4
|
||||||
env: DB=MYSQL
|
env: DB=MYSQL
|
||||||
- php: 5.3
|
- php: 5.3
|
||||||
env: DB=MYSQL
|
env: DB=MYSQL
|
||||||
- php: hhvm
|
- php: hhvm
|
||||||
env: DB=MYSQL
|
env: DB=MYSQL
|
||||||
before_install:
|
|
||||||
|
|
||||||
|
|
||||||
before_script:
|
before_script:
|
||||||
|
@ -20,8 +20,10 @@ class URLSegmentExtension extends DataExtension
|
|||||||
*/
|
*/
|
||||||
public function onBeforeWrite()
|
public function onBeforeWrite()
|
||||||
{
|
{
|
||||||
|
if ($this->owner->BlogID) {
|
||||||
$this->owner->generateURLSegment();
|
$this->owner->generateURLSegment();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a unique URLSegment from the title.
|
* Generates a unique URLSegment from the title.
|
||||||
@ -40,6 +42,12 @@ class URLSegmentExtension extends DataExtension
|
|||||||
$this->owner->URLSegment .= '-' . $increment;
|
$this->owner->URLSegment .= '-' . $increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Postgres use '' instead of 0 as an emtpy blog ID
|
||||||
|
// Without this all the tests fail
|
||||||
|
if (!$this->owner->BlogID) {
|
||||||
|
$this->owner->BlogID = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$duplicate = DataList::create($this->owner->ClassName)->filter(array(
|
$duplicate = DataList::create($this->owner->ClassName)->filter(array(
|
||||||
'URLSegment' => $this->owner->URLSegment,
|
'URLSegment' => $this->owner->URLSegment,
|
||||||
'BlogID' => $this->owner->BlogID,
|
'BlogID' => $this->owner->BlogID,
|
||||||
|
@ -473,6 +473,14 @@ class Blog extends Page implements PermissionProvider
|
|||||||
|
|
||||||
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
|
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
|
||||||
|
|
||||||
|
// getConn is deprecated, but not get_conn in 3.1
|
||||||
|
$getConnectionMethod = 'getConn';
|
||||||
|
if (method_exists('DB','get_conn')) {
|
||||||
|
$getConnectionMethod = 'get_conn';
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (DB::$getConnectionMethod() instanceof MySQLDatabase) {
|
||||||
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
|
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
|
||||||
|
|
||||||
if ($month) {
|
if ($month) {
|
||||||
@ -482,6 +490,20 @@ class Blog extends Page implements PermissionProvider
|
|||||||
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} elseif (DB::$getConnectionMethod() instanceof PostgreSQLDatabase) {
|
||||||
|
$where = sprintf('EXTRACT(YEAR FROM "PublishDate") = \'%s\'', Convert::raw2sql($year));
|
||||||
|
|
||||||
|
if ($month) {
|
||||||
|
$where .= sprintf(' AND EXTRACT(MONTH FROM "PublishDate") = \'%s\'', Convert::raw2sql($month));
|
||||||
|
|
||||||
|
if ($day) {
|
||||||
|
$where .= sprintf(' AND EXTRACT(DAY FROM "PublishDate") = \'%s\'', Convert::raw2sql($day));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$query->where($where);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return $this->getBlogPosts()->setDataQuery($query);
|
return $this->getBlogPosts()->setDataQuery($query);
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class BlogPostTest extends SapphireTest
|
|||||||
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
|
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
|
||||||
|
|
||||||
//Set the group to draw Members from
|
//Set the group to draw Members from
|
||||||
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'BlogUsers');
|
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'blogusers');
|
||||||
|
|
||||||
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
|
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
|
||||||
|
|
||||||
|
@ -131,4 +131,22 @@ class BlogTagTest extends FunctionalTest
|
|||||||
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
|
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
|
||||||
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDuplicateTagsForURLSegment() {
|
||||||
|
$blog = new Blog();
|
||||||
|
$blog->Title = 'Testing for duplicates blog';
|
||||||
|
$blog->write();
|
||||||
|
$tag1 = new BlogTag();
|
||||||
|
$tag1->Title = 'Cat';
|
||||||
|
$tag1->BlogID = $blog->ID;
|
||||||
|
$tag1->write();
|
||||||
|
$this->assertEquals('cat', $tag1->URLSegment);
|
||||||
|
|
||||||
|
$tag2 = new BlogTag();
|
||||||
|
$tag2->Title = 'Cat';
|
||||||
|
$tag2->BlogID = $blog->ID;
|
||||||
|
$tag2->write();
|
||||||
|
$this->assertEquals('cat-0', $tag2->URLSegment);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user