Merge branch '3.3' into 3

This commit is contained in:
Robbie Averill 2019-07-01 10:16:09 +12:00
commit a9a7c21751
4 changed files with 70 additions and 29 deletions

View File

@ -5,13 +5,13 @@ language: php
matrix: matrix:
include: include:
- php: 5.6 - php: 5.6
env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0 - php: 7.0
env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1 env: DB=PGSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_TEST=1
- php: 7.1 - php: 7.1
env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev PHPUNIT_COVERAGE_TEST=1
- php: 7.2 - php: 7.2
env: DB=MYSQL INSTALLER_VERSION=4.3.x-dev PHPUNIT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.4.x-dev PHPUNIT_TEST=1
- php: 7.3 - php: 7.3
env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1
@ -24,7 +24,7 @@ before_script:
# Install composer dependencies # Install composer dependencies
- composer validate - composer validate
- composer require --no-update silverstripe/installer:$INSTALLER_VERSION silverstripe/widgets:2.x-dev - composer require --no-update silverstripe/installer:$INSTALLER_VERSION silverstripe/widgets:2.x-dev
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.2.x-dev; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
script: script:

View File

@ -124,7 +124,11 @@ class BlogArchiveWidget extends Widget
$query = SQLSelect::create($fields, '"BlogPost' . $suffix . '"') $query = SQLSelect::create($fields, '"BlogPost' . $suffix . '"')
->addGroupBy($publishDate) ->addGroupBy($publishDate)
->addOrderBy('"PublishDate" DESC') ->addOrderBy('"PublishDate" DESC')
->addWhere(['"PublishDate" <= ?' => DBDatetime::now()->Format(DBDatetime::ISO_DATETIME)]); ->addLeftJoin('SiteTree' . $suffix, '"SiteTree' . $suffix . '"."ID" = "BlogPost' . $suffix . '"."ID"')
->addWhere([
'"PublishDate" <= ?' => DBDatetime::now()->Format(DBDatetime::ISO_DATETIME),
'"SiteTree' . $suffix . '"."ParentID"' => $this->BlogID,
]);
$posts = $query->execute(); $posts = $query->execute();
$result = ArrayList::create(); $result = ArrayList::create();

View File

@ -37,16 +37,26 @@ class BlogArchiveWidgetTest extends SapphireTest
public function testArchiveMonthlyFromStage() public function testArchiveMonthlyFromStage()
{ {
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archiveA = $widgetA->getArchive();
$this->assertInstanceOf(SS_List::class, $archive); $this->assertInstanceOf(SS_List::class, $archiveA);
$this->assertCount(3, $archive); $this->assertCount(3, $archiveA);
$this->assertListContains([ $this->assertListContains([
['Title' => 'August 2017'], ['Title' => 'August 2017'],
['Title' => 'September 2017'], ['Title' => 'September 2017'],
['Title' => 'May 2015'], ['Title' => 'May 2015'],
], $archive); ], $archiveA);
$widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-b');
$archiveB = $widgetB->getArchive();
$this->assertInstanceOf(SS_List::class, $archiveB);
$this->assertCount(2, $archiveB);
$this->assertListContains([
['Title' => 'March 2016'],
['Title' => 'June 2016'],
], $archiveB);
} }
public function testArchiveMonthlyFromLive() public function testArchiveMonthlyFromLive()
@ -54,10 +64,10 @@ class BlogArchiveWidgetTest extends SapphireTest
$original = Versioned::get_stage(); $original = Versioned::get_stage();
$this->objFromFixture(BlogPost::class, 'post-b')->publishRecursive(); $this->objFromFixture(BlogPost::class, 'post-b')->publishRecursive();
$this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive(); $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a')->publishRecursive();
Versioned::set_stage(Versioned::LIVE); Versioned::set_stage(Versioned::LIVE);
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archive = $widget->getArchive();
$this->assertCount(1, $archive); $this->assertCount(1, $archive);
@ -72,15 +82,24 @@ class BlogArchiveWidgetTest extends SapphireTest
public function testArchiveYearly() public function testArchiveYearly()
{ {
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly'); $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-a');
$archive = $widget->getArchive(); $archiveA = $widgetA->getArchive();
$this->assertInstanceOf(SS_List::class, $archive); $this->assertInstanceOf(SS_List::class, $archiveA);
$this->assertCount(2, $archive); $this->assertCount(2, $archiveA);
$this->assertListContains([ $this->assertListContains([
['Title' => '2017'], ['Title' => '2017'],
['Title' => '2015'], ['Title' => '2015'],
], $archive); ], $archiveA);
$widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-b');
$archiveB = $widgetB->getArchive();
$this->assertInstanceOf(SS_List::class, $archiveB);
$this->assertCount(1, $archiveB);
$this->assertListContains([
['Title' => '2016'],
], $archiveB);
} }
public function testArchiveMonthlyWithNewPostsAdded() public function testArchiveMonthlyWithNewPostsAdded()
@ -88,7 +107,7 @@ class BlogArchiveWidgetTest extends SapphireTest
$original = Versioned::get_stage(); $original = Versioned::get_stage();
Versioned::set_stage('Stage'); Versioned::set_stage('Stage');
$widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a');
$archive = $widget->getArchive(); $archive = $widget->getArchive();
$this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures'); $this->assertCount(3, $archive, 'Three months are shown in the blog archive list from fixtures');
@ -96,7 +115,7 @@ class BlogArchiveWidgetTest extends SapphireTest
DBDatetime::set_mock_now('2018-01-01 12:00:00'); DBDatetime::set_mock_now('2018-01-01 12:00:00');
$newPost = new BlogPost; $newPost = new BlogPost;
$newPost->ParentID = $this->objFromFixture(Blog::class, 'my-blog')->ID; $newPost->ParentID = $this->objFromFixture(Blog::class, 'blog-a')->ID;
$newPost->Title = 'My new blog post'; $newPost->Title = 'My new blog post';
$newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier $newPost->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier
$newPost->write(); $newPost->write();

View File

@ -1,27 +1,45 @@
SilverStripe\Blog\Model\Blog: SilverStripe\Blog\Model\Blog:
my-blog: blog-a:
Title: My Blog Title: Blog A
blog-b:
Title: Blog B
SilverStripe\Blog\Model\BlogPost: SilverStripe\Blog\Model\BlogPost:
post-a: post-a:
Title: September Digest Title: September Digest
PublishDate: 2017-09-01 00:00:00 PublishDate: 2017-09-01 00:00:00
ParentID: =>SilverStripe\Blog\Model\Blog.my-blog ParentID: =>SilverStripe\Blog\Model\Blog.blog-a
post-b: post-b:
Title: August is Awesome Title: August is Awesome
PublishDate: 2017-08-01 00:00:00 PublishDate: 2017-08-01 00:00:00
ParentID: =>SilverStripe\Blog\Model\Blog.my-blog ParentID: =>SilverStripe\Blog\Model\Blog.blog-a
post-c: post-c:
Title: 2015 is so two years ago Title: 2015 is so two years ago
PublishDate: 2015-05-02 00:01:02 PublishDate: 2015-05-02 00:01:02
ParentID: =>SilverStripe\Blog\Model\Blog.my-blog ParentID: =>SilverStripe\Blog\Model\Blog.blog-a
post-d:
Title: Blog post on Blog B
PublishDate: 2016-03-13 21:05:36
ParentID: =>SilverStripe\Blog\Model\Blog.blog-b
post-e:
Title: Blog post 2 on Blog B
PublishDate: 2016-06-15 10:00:00
ParentID: =>SilverStripe\Blog\Model\Blog.blog-b
SilverStripe\Blog\Widgets\BlogArchiveWidget: SilverStripe\Blog\Widgets\BlogArchiveWidget:
archive-monthly: archive-monthly-a:
NumberToDisplay: 5 NumberToDisplay: 5
ArchiveType: Monthly ArchiveType: Monthly
BlogID: =>SilverStripe\Blog\Model\Blog.my-blog BlogID: =>SilverStripe\Blog\Model\Blog.blog-a
archive-yearly: archive-monthly-b:
NumberToDisplay: 5
ArchiveType: Monthly
BlogID: =>SilverStripe\Blog\Model\Blog.blog-b
archive-yearly-a:
NumberToDisplay: 5 NumberToDisplay: 5
ArchiveType: Yearly ArchiveType: Yearly
BlogID: =>SilverStripe\Blog\Model\Blog.my-blog BlogID: =>SilverStripe\Blog\Model\Blog.blog-a
archive-yearly-b:
NumberToDisplay: 5
ArchiveType: Yearly
BlogID: =>SilverStripe\Blog\Model\Blog.blog-b