From 01c1ead069825c383fd31e72b35d835da65be558 Mon Sep 17 00:00:00 2001 From: 3Dgoo Date: Tue, 26 Jun 2018 13:17:47 +0930 Subject: [PATCH 1/6] Fix blog archive widget bug Fixes blog archive widget bug to only get the archive months for the blog linked to in this widget. --- src/Widgets/BlogArchiveWidget.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Widgets/BlogArchiveWidget.php b/src/Widgets/BlogArchiveWidget.php index 878450f..f3a3763 100644 --- a/src/Widgets/BlogArchiveWidget.php +++ b/src/Widgets/BlogArchiveWidget.php @@ -124,7 +124,11 @@ class BlogArchiveWidget extends Widget $query = SQLSelect::create($fields, '"BlogPost' . $suffix . '"') ->addGroupBy($publishDate) ->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(); $result = ArrayList::create(); From ebd135b02947bdc4550659d705a137a9c5f08246 Mon Sep 17 00:00:00 2001 From: 3Dgoo Date: Fri, 29 Jun 2018 21:29:11 +0930 Subject: [PATCH 2/6] Adding tests Adding tests to check that archive widget correctly only shows blog posts from the related blog and not any other blog. --- tests/Widgets/BlogArchiveWidgetTest.yml | 36 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/tests/Widgets/BlogArchiveWidgetTest.yml b/tests/Widgets/BlogArchiveWidgetTest.yml index d0a0a89..03c4194 100644 --- a/tests/Widgets/BlogArchiveWidgetTest.yml +++ b/tests/Widgets/BlogArchiveWidgetTest.yml @@ -1,27 +1,45 @@ SilverStripe\Blog\Model\Blog: - my-blog: - Title: My Blog + blog-a: + Title: Blog A + blog-b: + Title: Blog B SilverStripe\Blog\Model\BlogPost: post-a: Title: September Digest PublishDate: 2017-09-01 00:00:00 - ParentID: =>SilverStripe\Blog\Model\Blog.my-blog + ParentID: =>SilverStripe\Blog\Model\Blog.blog-a post-b: Title: August is Awesome PublishDate: 2017-08-01 00:00:00 - ParentID: =>SilverStripe\Blog\Model\Blog.my-blog + ParentID: =>SilverStripe\Blog\Model\Blog.blog-a post-c: Title: 2015 is so two years ago 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: - archive-monthly: + archive-monthly-a: NumberToDisplay: 5 ArchiveType: Monthly - BlogID: =>SilverStripe\Blog\Model\Blog.my-blog - archive-yearly: + BlogID: =>SilverStripe\Blog\Model\Blog.blog-a + archive-monthly-b: + NumberToDisplay: 5 + ArchiveType: Monthly + BlogID: =>SilverStripe\Blog\Model\Blog.blog-b + archive-yearly-a: NumberToDisplay: 5 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 From 317729604dd52bd90085ba3db16a7341b660a09b Mon Sep 17 00:00:00 2001 From: 3Dgoo Date: Fri, 29 Jun 2018 21:30:38 +0930 Subject: [PATCH 3/6] Adding tests Adding tests to check that archive widget correctly only shows blog posts from the related blog and not any other blog. --- tests/Widgets/BlogArchiveWidgetTest.php | 45 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/tests/Widgets/BlogArchiveWidgetTest.php b/tests/Widgets/BlogArchiveWidgetTest.php index b3d1060..845968c 100644 --- a/tests/Widgets/BlogArchiveWidgetTest.php +++ b/tests/Widgets/BlogArchiveWidgetTest.php @@ -37,16 +37,26 @@ class BlogArchiveWidgetTest extends SapphireTest public function testArchiveMonthlyFromStage() { - $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); - $archive = $widget->getArchive(); + $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a'); + $archiveA = $widgetA->getArchive(); - $this->assertInstanceOf(SS_List::class, $archive); - $this->assertCount(3, $archive); + $this->assertInstanceOf(SS_List::class, $archiveA); + $this->assertCount(3, $archiveA); $this->assertListContains([ ['Title' => 'August 2017'], ['Title' => 'September 2017'], ['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() @@ -57,7 +67,7 @@ class BlogArchiveWidgetTest extends SapphireTest $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly')->publishRecursive(); Versioned::set_stage(Versioned::LIVE); - $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); + $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a'); $archive = $widget->getArchive(); $this->assertCount(1, $archive); @@ -72,15 +82,24 @@ class BlogArchiveWidgetTest extends SapphireTest public function testArchiveYearly() { - $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly'); - $archive = $widget->getArchive(); + $widgetA = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-a'); + $archiveA = $widgetA->getArchive(); - $this->assertInstanceOf(SS_List::class, $archive); - $this->assertCount(2, $archive); + $this->assertInstanceOf(SS_List::class, $archiveA); + $this->assertCount(2, $archiveA); $this->assertListContains([ ['Title' => '2017'], ['Title' => '2015'], - ], $archive); + ], $archiveA); + + $widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-b'); + $archiveB = $widgetB->getArchive(); + + $this->assertInstanceOf('SS_List', $archiveB); + $this->assertCount(1, $archiveB); + $this->assertListContains([ + ['Title' => '2016'], + ], $archiveB); } public function testArchiveMonthlyWithNewPostsAdded() @@ -88,7 +107,7 @@ class BlogArchiveWidgetTest extends SapphireTest $original = Versioned::get_stage(); Versioned::set_stage('Stage'); - $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly'); + $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a'); $archive = $widget->getArchive(); $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'); $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->PublishDate = '2018-01-01 08:00:00'; // Same day as the mocked now, but slightly earlier $newPost->write(); From 3d9031aaacc19312628141c6303446361a7bd981 Mon Sep 17 00:00:00 2001 From: 3Dgoo Date: Fri, 6 Jul 2018 15:17:38 +0930 Subject: [PATCH 4/6] Adding ansi quote to identifier --- src/Widgets/BlogArchiveWidget.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/BlogArchiveWidget.php b/src/Widgets/BlogArchiveWidget.php index f3a3763..135faaf 100644 --- a/src/Widgets/BlogArchiveWidget.php +++ b/src/Widgets/BlogArchiveWidget.php @@ -127,7 +127,7 @@ class BlogArchiveWidget extends Widget ->addLeftJoin('SiteTree' . $suffix, '"SiteTree' . $suffix . '"."ID" = "BlogPost' . $suffix . '"."ID"') ->addWhere([ '"PublishDate" <= ?' => DBDatetime::now()->Format(DBDatetime::ISO_DATETIME), - 'SiteTree' . $suffix . '.ParentID' => $this->BlogID, + '"SiteTree' . $suffix . '"."ParentID"' => $this->BlogID, ]); $posts = $query->execute(); From 98183ad6775bec92739f7956850054d3de67578f Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 13 May 2019 09:18:27 +1200 Subject: [PATCH 5/6] Update references to text fixtures and SS_List class namespace from cherry-picked SilverStripe 3 commit --- tests/Widgets/BlogArchiveWidgetTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Widgets/BlogArchiveWidgetTest.php b/tests/Widgets/BlogArchiveWidgetTest.php index 845968c..767d18f 100644 --- a/tests/Widgets/BlogArchiveWidgetTest.php +++ b/tests/Widgets/BlogArchiveWidgetTest.php @@ -64,7 +64,7 @@ class BlogArchiveWidgetTest extends SapphireTest $original = Versioned::get_stage(); $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); $widget = $this->objFromFixture(BlogArchiveWidget::class, 'archive-monthly-a'); @@ -95,7 +95,7 @@ class BlogArchiveWidgetTest extends SapphireTest $widgetB = $this->objFromFixture(BlogArchiveWidget::class, 'archive-yearly-b'); $archiveB = $widgetB->getArchive(); - $this->assertInstanceOf('SS_List', $archiveB); + $this->assertInstanceOf(SS_List::class, $archiveB); $this->assertCount(1, $archiveB); $this->assertListContains([ ['Title' => '2016'], From e6a7a4c8e8ae6ec0da4b65315d0cc6453b022f36 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 1 Jul 2019 10:15:17 +1200 Subject: [PATCH 6/6] Update SilverStripe versions in Travis builds --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f6d71a..27aedf3 100755 --- a/.travis.yml +++ b/.travis.yml @@ -5,13 +5,13 @@ language: php matrix: include: - 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 - 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 - 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 - 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 env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1 @@ -24,7 +24,7 @@ before_script: # Install composer dependencies - composer validate - 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 script: