mirror of
https://github.com/silverstripe/silverstripe-blog
synced 2024-10-22 11:05:58 +02:00
Merge branch '2.4' into 2
This commit is contained in:
commit
385fe9572a
12
.travis.yml
12
.travis.yml
@ -14,7 +14,7 @@ before_install:
|
|||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- DB=MYSQL CORE_RELEASE=3.1
|
- DB=MYSQL CORE_RELEASE=3.6
|
||||||
|
|
||||||
# Turn coverage off by default, as it's expensive time wise
|
# Turn coverage off by default, as it's expensive time wise
|
||||||
- COVERAGE=0
|
- COVERAGE=0
|
||||||
@ -27,13 +27,13 @@ matrix:
|
|||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=MYSQL COVERAGE=1
|
env: DB=MYSQL COVERAGE=1
|
||||||
- php: 5.5
|
- php: 5.5
|
||||||
env: DB=MYSQL
|
|
||||||
- php: 5.6
|
|
||||||
env: DB=PGSQL
|
|
||||||
- php: 5.6
|
|
||||||
env: DB=MYSQL CORE_RELEASE=3.2
|
env: DB=MYSQL CORE_RELEASE=3.2
|
||||||
- php: 5.6
|
- php: 5.6
|
||||||
env: DB=PGSQL CORE_RELEASE=3.2
|
env: DB=PGSQL CORE_RELEASE=3.3
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=MYSQL CORE_RELEASE=3.4
|
||||||
|
- php: 5.6
|
||||||
|
env: DB=PGSQL CORE_RELEASE=3.5
|
||||||
- php: 5.4
|
- php: 5.4
|
||||||
env: DB=SQLITE
|
env: DB=SQLITE
|
||||||
- php: 5.3
|
- php: 5.3
|
||||||
|
@ -92,27 +92,28 @@ class BlogArchiveWidget extends Widget
|
|||||||
$publishDate = DB::get_conn()->formattedDatetimeClause('"PublishDate"', $format);
|
$publishDate = DB::get_conn()->formattedDatetimeClause('"PublishDate"', $format);
|
||||||
$fields = array(
|
$fields = array(
|
||||||
'PublishDate' => $publishDate,
|
'PublishDate' => $publishDate,
|
||||||
'Total' => "Count('PublishDate')"
|
'Total' => "COUNT('\"PublishDate\"')"
|
||||||
);
|
);
|
||||||
|
|
||||||
$stage = Versioned::current_stage();
|
$stage = Versioned::current_stage();
|
||||||
$suffix = ($stage == 'Stage') ? '' : "_{$stage}";
|
$suffix = ($stage === 'Live') ? '_Live' : '';
|
||||||
$query = SQLSelect::create($fields, "BlogPost{$suffix}")
|
$query = SQLSelect::create($fields, '"BlogPost' . $suffix . '"')
|
||||||
->addGroupBy($publishDate)
|
->addGroupBy($publishDate)
|
||||||
->addOrderBy('PublishDate Desc')
|
->addOrderBy('"PublishDate" DESC')
|
||||||
->addWhere(array('PublishDate < ?' => SS_Datetime::now()->Format('Y-m-d')));
|
->addWhere(array('"PublishDate" < ?' => SS_Datetime::now()->Format('Y-m-d')));
|
||||||
|
|
||||||
$posts = $query->execute();
|
$posts = $query->execute();
|
||||||
$result = new ArrayList();
|
$result = new ArrayList();
|
||||||
while ($next = $posts->next()) {
|
while ($next = $posts->next()) {
|
||||||
$date = Date::create();
|
|
||||||
$date->setValue(strtotime($next['PublishDate']));
|
|
||||||
$year = $date->Format('Y');
|
|
||||||
|
|
||||||
if ($this->ArchiveType == 'Yearly') {
|
if ($this->ArchiveType == 'Yearly') {
|
||||||
|
$year = $next['PublishDate'];
|
||||||
$month = null;
|
$month = null;
|
||||||
$title = $year;
|
$title = $year;
|
||||||
} else {
|
} else {
|
||||||
|
$date = Date::create();
|
||||||
|
$date->setValue(strtotime($next['PublishDate']));
|
||||||
|
|
||||||
|
$year = $date->Format('Y');
|
||||||
$month = $date->Format('m');
|
$month = $date->Format('m');
|
||||||
$title = $date->FormatI18N('%B %Y');
|
$title = $date->FormatI18N('%B %Y');
|
||||||
}
|
}
|
||||||
@ -124,6 +125,7 @@ class BlogArchiveWidget extends Widget
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->extend('updateGetArchive', $result);
|
$this->extend('updateGetArchive', $result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
{
|
{
|
||||||
"name": "silverstripe/blog",
|
"name": "silverstripe/blog",
|
||||||
"description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.",
|
"description": "A fresh take on blogging in Silverstripe set out to tackle the issue of a cluttered Site Tree.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"silverstripe",
|
"silverstripe",
|
||||||
"blog",
|
"blog",
|
||||||
"news"
|
"news"
|
||||||
],
|
],
|
||||||
"type": "silverstripe-module",
|
"type": "silverstripe-module",
|
||||||
"require": {
|
"require": {
|
||||||
"silverstripe/cms": "^3.1.0",
|
"silverstripe/cms": "^3.2.0",
|
||||||
"silverstripe/lumberjack": "~1.1",
|
"silverstripe/lumberjack": "~1.1",
|
||||||
"silverstripe/tagfield": "^1.0"
|
"silverstripe/tagfield": "^1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/PHPUnit": "~3.7@stable"
|
"phpunit/PHPUnit": "~3.7@stable"
|
||||||
},
|
},
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"2.x-dev": "2.5.x-dev"
|
"2.x-dev": "2.5.x-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Michael Strong",
|
"name": "Michael Strong",
|
||||||
"email": "github@michaelstrong.co.uk"
|
"email": "github@michaelstrong.co.uk"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"suggest": {
|
"suggest": {
|
||||||
"silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.",
|
"silverstripe/widgets": "Some widgets come with the blog which are compatible with the widgets module.",
|
||||||
"silverstripe/comments": "This module adds comments to your blog."
|
"silverstripe/comments": "This module adds comments to your blog."
|
||||||
},
|
},
|
||||||
"replace": {
|
"replace": {
|
||||||
"micmania1/silverstripe-blog": "*"
|
"micmania1/silverstripe-blog": "*"
|
||||||
},
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
71
tests/Widgets/BlogArchiveWidgetTest.php
Normal file
71
tests/Widgets/BlogArchiveWidgetTest.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class BlogArchiveWidgetTest extends SapphireTest
|
||||||
|
{
|
||||||
|
protected static $fixture_file = 'BlogArchiveWidgetTest.yml';
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
if (!class_exists('Widget')) {
|
||||||
|
self::$fixture_file = null;
|
||||||
|
parent::setUp();
|
||||||
|
$this->markTestSkipped('Test requires silverstripe/widgets to be installed.');
|
||||||
|
}
|
||||||
|
|
||||||
|
SS_Datetime::set_mock_now('2017-09-20 00:00:00');
|
||||||
|
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
|
||||||
|
SS_Datetime::clear_mock_now();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArchiveMonthlyFromStage()
|
||||||
|
{
|
||||||
|
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
||||||
|
$archive = $widget->getArchive();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SS_List', $archive);
|
||||||
|
$this->assertCount(3, $archive);
|
||||||
|
$this->assertDOSContains(array(
|
||||||
|
array('Title' => 'August 2017'),
|
||||||
|
array('Title' => 'September 2017'),
|
||||||
|
array('Title' => 'May 2015'),
|
||||||
|
), $archive);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArchiveMonthlyFromLive()
|
||||||
|
{
|
||||||
|
$original = Versioned::current_stage();
|
||||||
|
|
||||||
|
$this->objFromFixture('BlogPost', 'post-b')->doPublish();
|
||||||
|
Versioned::reading_stage('Live');
|
||||||
|
|
||||||
|
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-monthly');
|
||||||
|
$archive = $widget->getArchive();
|
||||||
|
|
||||||
|
$this->assertCount(1, $archive);
|
||||||
|
$this->assertDOSContains(array(
|
||||||
|
array('Title' => 'August 2017'),
|
||||||
|
), $archive);
|
||||||
|
|
||||||
|
Versioned::reading_stage($original);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArchiveYearly()
|
||||||
|
{
|
||||||
|
$widget = $this->objFromFixture('BlogArchiveWidget', 'archive-yearly');
|
||||||
|
$archive = $widget->getArchive();
|
||||||
|
|
||||||
|
$this->assertInstanceOf('SS_List', $archive);
|
||||||
|
$this->assertCount(2, $archive);
|
||||||
|
$this->assertDOSContains(array(
|
||||||
|
array('Title' => '2017'),
|
||||||
|
array('Title' => '2015'),
|
||||||
|
), $archive);
|
||||||
|
}
|
||||||
|
}
|
27
tests/Widgets/BlogArchiveWidgetTest.yml
Normal file
27
tests/Widgets/BlogArchiveWidgetTest.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
Blog:
|
||||||
|
my-blog:
|
||||||
|
Title: My Blog
|
||||||
|
|
||||||
|
BlogPost:
|
||||||
|
post-a:
|
||||||
|
Title: September Digest
|
||||||
|
PublishDate: 2017-09-01 00:00:00
|
||||||
|
ParentID: =>Blog.my-blog
|
||||||
|
post-b:
|
||||||
|
Title: August is Awesome
|
||||||
|
PublishDate: 2017-08-01 00:00:00
|
||||||
|
ParentID: =>Blog.my-blog
|
||||||
|
post-c:
|
||||||
|
Title: 2015 is so two years ago
|
||||||
|
PublishDate: 2015-05-02 00:01:02
|
||||||
|
ParentID: =>Blog.my-blog
|
||||||
|
|
||||||
|
BlogArchiveWidget:
|
||||||
|
archive-monthly:
|
||||||
|
NumberToDisplay: 5
|
||||||
|
ArchiveType: Monthly
|
||||||
|
BlogID: =>Blog.my-blog
|
||||||
|
archive-yearly:
|
||||||
|
NumberToDisplay: 5
|
||||||
|
ArchiveType: Yearly
|
||||||
|
BlogID: =>Blog.my-blog
|
Loading…
Reference in New Issue
Block a user