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
|
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,7 +20,9 @@ class URLSegmentExtension extends DataExtension
|
|||||||
*/
|
*/
|
||||||
public function onBeforeWrite()
|
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;
|
$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,16 +473,38 @@ 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));
|
||||||
|
|
||||||
$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) {
|
if (DB::$getConnectionMethod() instanceof MySQLDatabase) {
|
||||||
$query->where(sprintf('DAY("PublishDate") = \'%s\'', Convert::raw2sql($day)));
|
$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);
|
return $this->getBlogPosts()->setDataQuery($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ class BlogPost extends Page
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The default sorting lists BlogPosts with an empty PublishDate at the top.
|
* The default sorting lists BlogPosts with an empty PublishDate at the top.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC';
|
private static $default_sort = '"PublishDate" IS NULL DESC, "PublishDate" DESC';
|
||||||
|
@ -34,7 +34,7 @@ class BlogPostTest extends SapphireTest
|
|||||||
SS_Datetime::set_mock_now($date);
|
SS_Datetime::set_mock_now($date);
|
||||||
$this->assertEquals($canView, $pageRecord->canView($userRecord));
|
$this->assertEquals($canView, $pageRecord->canView($userRecord));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canViewProvider()
|
public function canViewProvider()
|
||||||
{
|
{
|
||||||
$someFutureDate = '2013-10-10 20:00:00';
|
$someFutureDate = '2013-10-10 20:00:00';
|
||||||
@ -45,13 +45,13 @@ class BlogPostTest extends SapphireTest
|
|||||||
array($someFutureDate, 'Contributor', 'PostA', true),
|
array($someFutureDate, 'Contributor', 'PostA', true),
|
||||||
array($someFutureDate, 'BlogEditor', 'PostA', true),
|
array($someFutureDate, 'BlogEditor', 'PostA', true),
|
||||||
array($someFutureDate, 'Writer', 'PostA', true),
|
array($someFutureDate, 'Writer', 'PostA', true),
|
||||||
|
|
||||||
// Check unpublished pages
|
// Check unpublished pages
|
||||||
array($somePastDate, 'Editor', 'PostA', true),
|
array($somePastDate, 'Editor', 'PostA', true),
|
||||||
array($somePastDate, 'Contributor', 'PostA', true),
|
array($somePastDate, 'Contributor', 'PostA', true),
|
||||||
array($somePastDate, 'BlogEditor', 'PostA', true),
|
array($somePastDate, 'BlogEditor', 'PostA', true),
|
||||||
array($somePastDate, 'Writer', 'PostA', true),
|
array($somePastDate, 'Writer', 'PostA', true),
|
||||||
|
|
||||||
// Test a page that was authored by another user
|
// Test a page that was authored by another user
|
||||||
|
|
||||||
// Check this post given the date has passed
|
// Check this post given the date has passed
|
||||||
@ -59,7 +59,7 @@ class BlogPostTest extends SapphireTest
|
|||||||
array($someFutureDate, 'Contributor', 'FirstBlogPost', true),
|
array($someFutureDate, 'Contributor', 'FirstBlogPost', true),
|
||||||
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true),
|
array($someFutureDate, 'BlogEditor', 'FirstBlogPost', true),
|
||||||
array($someFutureDate, 'Writer', 'FirstBlogPost', true),
|
array($someFutureDate, 'Writer', 'FirstBlogPost', true),
|
||||||
|
|
||||||
// Check future pages - non-editors shouldn't be able to see this
|
// Check future pages - non-editors shouldn't be able to see this
|
||||||
array($somePastDate, 'Editor', 'FirstBlogPost', true),
|
array($somePastDate, 'Editor', 'FirstBlogPost', true),
|
||||||
array($somePastDate, 'Contributor', 'FirstBlogPost', false),
|
array($somePastDate, 'Contributor', 'FirstBlogPost', false),
|
||||||
@ -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