Skip to content

Commit

Permalink
Update not null assumption, tests, travis, and namespaces
Browse files Browse the repository at this point in the history
- Fixed some methods that assumed not null values
- Updated tests
- Remove php 7.0 test
- Update \Tests namespace to match composer declaration
  • Loading branch information
cpenny authored and chrispenny committed Jan 6, 2022
1 parent 9c4029d commit 59bf355
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 21 deletions.
22 changes: 12 additions & 10 deletions src/Elements/ElementBlogOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,16 +448,18 @@ public function getCacheKey(): ?string
return $this->cacheKey;
}

$cacheKey = implode(
'-',
[
static::class,
$this->ID,
$this->LastEdited,
$this->getBlogPosts()->count(),
$this->getBlogPosts()->max('LastEdited')
]
);
$pieces = [
static::class,
$this->ID,
$this->LastEdited,
];

if ($this->getBlogPosts() !== null) {
$pieces[] = $this->getBlogPosts()->count();
$pieces[] = $this->getBlogPosts()->max('LastEdited');
}

$cacheKey = implode('-', $pieces);

$this->invokeWithExtensions('updateCacheKey', $cacheKey);

Expand Down
9 changes: 8 additions & 1 deletion tests/Elements/ElementBlogOverviewTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

namespace Dynamic\Elements\Blog\Elements\Tests;
namespace Dynamic\Elements\Blog\Tests\Elements;

use DNADesign\Elemental\Extensions\ElementalPageExtension;
use Dynamic\Elements\Blog\Elements\ElementBlogOverview;
use Page;
use SilverStripe\Blog\Model\Blog;
Expand All @@ -25,6 +26,7 @@ class ElementBlogOverviewTest extends SapphireTest
protected static $required_extensions = [
Page::class => [
WidgetPageExtension::class,
ElementalPageExtension::class,
],
];

Expand All @@ -51,6 +53,7 @@ public function testGetBlogPosts(): void
/** @var ElementBlogOverview $block */
$block = $this->objFromFixture(ElementBlogOverview::class, 'block1');

$this->assertNotNull($block->getBlogPosts());
$this->assertCount(4, $block->getBlogPosts());
}

Expand Down Expand Up @@ -127,6 +130,8 @@ public function testSideBarView(): void

$expectedWidgets = $widgets->map('ID', 'Title')->toArray();

$this->assertNotNull($block->SideBarView());

$this->assertEquals(
$expectedWidgets,
$block->SideBarView()->Widgets()->map('ID', 'Title')->toArray()
Expand Down Expand Up @@ -156,6 +161,8 @@ public function testSideBarViewInheriting(): void

$expectedWidgets = $widgets->map('ID', 'Title')->toArray();

$this->assertNotNull($block->SideBarView());

$this->assertEquals(
$expectedWidgets,
$block->SideBarView()->Widgets()->map('ID', 'Title')->toArray()
Expand Down
8 changes: 6 additions & 2 deletions tests/Elements/ElementBlogOverviewTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DNADesign\Elemental\Models\ElementalArea:
blog2:
OwnerClassName: SilverStripe\Blog\Model\Blog
fakePage1:
OwnerClassName: Dynamic\Elements\Blog\Elements\Tests\Fake\Page
OwnerClassName: Dynamic\Elements\Blog\Tests\Fake\Page

SilverStripe\Widgets\Model\WidgetArea:
area1:
Expand Down Expand Up @@ -52,19 +52,23 @@ SilverStripe\Blog\Model\BlogPost:
URLSegment: post4
ParentID: =>SilverStripe\Blog\Model\Blog.blog1

Dynamic\Elements\Blog\Elements\Tests\Fake\Page:
Dynamic\Elements\Blog\Tests\Fake\Page:
fakePage1:
Title: Fake Page 1
ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.fakePage1

Dynamic\Elements\Blog\Elements\ElementBlogOverview:
block1:
Title: Overview block 1
ParentID: =>DNADesign\Elemental\Models\ElementalArea.blog1
block2:
Title: Overview block 2
ParentID: =>DNADesign\Elemental\Models\ElementalArea.blog2
block3:
Title: Overview block 3
ParentID: =>DNADesign\Elemental\Models\ElementalArea.page1
block4:
Title: Overview block 4
ParentID: =>DNADesign\Elemental\Models\ElementalArea.fakePage1

SilverStripe\Blog\Widgets\BlogCategoriesWidget:
Expand Down
5 changes: 3 additions & 2 deletions tests/Elements/ElementBlogPaginationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\Elements\Blog\Elements\Tests;
namespace Dynamic\Elements\Blog\Tests\Elements;

use Dynamic\Elements\Blog\Elements\ElementBlogPagination;
use SilverStripe\Dev\SapphireTest;
Expand All @@ -17,7 +17,8 @@ class ElementBlogPaginationTest extends SapphireTest
*/
protected $usesDatabase = true;

public function testPopulateDefaults(): void {
public function testPopulateDefaults(): void
{
$block = ElementBlogPagination::create();

$this->assertFalse((bool) $block->ShowTitle);
Expand Down
4 changes: 2 additions & 2 deletions tests/Elements/ElementBlogPostsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\Elements\Blog\Elements\Tests;
namespace Dynamic\Elements\Blog\Tests\Elements;

use Dynamic\Elements\Blog\Elements\ElementBlogPosts;
use SilverStripe\Blog\Model\Blog;
Expand All @@ -16,7 +16,7 @@ class ElementBlogPostsTest extends SapphireTest
/**
* @var string
*/
protected static $fixture_file = '../fixtures.yml';
protected static $fixture_file = 'ElementBlogPostsTest.yml';

/**
*
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions tests/Elements/ElementBlogWidgetsTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\Elements\Blog\Elements\Tests;
namespace Dynamic\Elements\Blog\Tests\Elements;

use Dynamic\Elements\Blog\Elements\ElementBlogWidgets;
use SilverStripe\Dev\SapphireTest;
Expand All @@ -17,7 +17,8 @@ class ElementBlogWidgetsTest extends SapphireTest
*/
protected $usesDatabase = true;

public function testPopulateDefaults(): void {
public function testPopulateDefaults(): void
{
$block = ElementBlogWidgets::create();

$this->assertFalse((bool) $block->ShowTitle);
Expand Down
4 changes: 2 additions & 2 deletions tests/Fake/Page.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Dynamic\Elements\Blog\Elements\Tests\Fake;
namespace Dynamic\Elements\Blog\Tests\Fake;

use Page as BasePage;
use SilverStripe\Blog\Model\BlogPost;
Expand All @@ -13,7 +13,7 @@
*
* Class Page
*
* @package Dynamic\Elements\Blog\Elements\Tests\Fake
* @package Dynamic\Elements\Blog\Tests\Fake
*/
class Page extends BasePage implements TestOnly
{
Expand Down

0 comments on commit 59bf355

Please sign in to comment.