mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge pull request #362 from gordonbanderson/postgresfixes
FIX: Tests now pass in Postgres on 3.1 and 3.2
This commit is contained in:
commit
694b41176a
@ -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:
|
||||
|
@ -20,8 +20,10 @@ class URLSegmentExtension extends DataExtension
|
||||
*/
|
||||
public function onBeforeWrite()
|
||||
{
|
||||
if ($this->owner->BlogID) {
|
||||
$this->owner->generateURLSegment();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a unique URLSegment from the title.
|
||||
@ -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,
|
||||
|
@ -473,6 +473,14 @@ class Blog extends Page implements PermissionProvider
|
||||
|
||||
$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)));
|
||||
|
||||
if ($month) {
|
||||
@ -482,6 +490,20 @@ class Blog extends Page implements PermissionProvider
|
||||
$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);
|
||||
}
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user