Merge pull request #362 from gordonbanderson/postgresfixes

FIX: Tests now pass in Postgres on 3.1 and 3.2
This commit is contained in:
Daniel Hensby 2016-01-22 17:20:01 +00:00
commit 694b41176a
6 changed files with 66 additions and 13 deletions

View File

@ -28,13 +28,18 @@ matrix:
env: DB=MYSQL COVERAGE=1
- php: 5.5
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
env: DB=MYSQL
- php: 5.3
env: DB=MYSQL
- php: hhvm
env: DB=MYSQL
before_install:
before_script:

View File

@ -20,7 +20,9 @@ class URLSegmentExtension extends DataExtension
*/
public function onBeforeWrite()
{
$this->owner->generateURLSegment();
if ($this->owner->BlogID) {
$this->owner->generateURLSegment();
}
}
/**
@ -40,6 +42,12 @@ class URLSegmentExtension extends DataExtension
$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(
'URLSegment' => $this->owner->URLSegment,
'BlogID' => $this->owner->BlogID,

View File

@ -473,16 +473,38 @@ class Blog extends Page implements PermissionProvider
$query->innerJoin('BlogPost', sprintf('"SiteTree%s"."ID" = "BlogPost%s"."ID"', $stage, $stage));
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
// getConn is deprecated, but not get_conn in 3.1
$getConnectionMethod = 'getConn';
if (method_exists('DB','get_conn')) {
$getConnectionMethod = 'get_conn';
};
if ($month) {
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
if ($day) {
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
if (DB::$getConnectionMethod() instanceof MySQLDatabase) {
$query->where(sprintf('YEAR("PublishDate") = \'%s\'', Convert::raw2sql($year)));
if ($month) {
$query->where(sprintf('MONTH("PublishDate") = \'%s\'', Convert::raw2sql($month)));
if ($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);
}

View File

@ -75,7 +75,7 @@ class BlogPostTest extends SapphireTest
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
//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());

View File

@ -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($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);
}
}