-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increase test coverage of PaginatedList and BlogPosts
- Loading branch information
1 parent
59bf355
commit 5078364
Showing
6 changed files
with
180 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Dynamic\Elements\Blog\Tests\Elements; | ||
|
||
use DNADesign\Elemental\Extensions\ElementalPageExtension; | ||
use Dynamic\Elements\Blog\Elements\ElementBlogOverview; | ||
use Dynamic\Elements\Blog\Tests\Fake\PageController; | ||
use Page; | ||
use PageController as BasePageController; | ||
use SilverStripe\Blog\Model\BlogController; | ||
use SilverStripe\Dev\SapphireTest; | ||
use SilverStripe\ORM\ValidationException; | ||
use SilverStripe\Widgets\Extensions\WidgetPageExtension; | ||
|
||
/** | ||
* Class ElementBlogOverviewFunctionalTest | ||
* | ||
* @package Dynamic\Elements\Blog\Tests\Elements | ||
*/ | ||
class ElementBlogOverviewFunctionalTest extends SapphireTest | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected static $fixture_file = 'ElementBlogOverviewFunctionalTest.yml'; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
protected static $use_draft_site = true; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected static $required_extensions = [ | ||
Page::class => [ | ||
WidgetPageExtension::class, | ||
ElementalPageExtension::class, | ||
], | ||
]; | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
public function testPaginatedListAvailable(): void | ||
{ | ||
/** @var ElementBlogOverview $block */ | ||
$block = $this->objFromFixture(ElementBlogOverview::class, 'block1'); | ||
$controller = new BlogController(); | ||
|
||
// Pass the controller through for the first get | ||
$this->assertNotNull($block->getPaginatedList($controller)); | ||
// Our cache should now be set, so we shouldn't need the controller this time | ||
$this->assertNotNull($block->getPaginatedList()); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
public function testPaginatedListDenied(): void | ||
{ | ||
/** @var ElementBlogOverview $block */ | ||
$block = $this->objFromFixture(ElementBlogOverview::class, 'block2'); | ||
$controller = new PageController(); | ||
|
||
// We have not allowed usage outside of BlogController, so this should be null | ||
$this->assertNull($block->getPaginatedList($controller)); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
public function testPaginatedListCustom(): void | ||
{ | ||
// Update our config to allow this Block type to be used outside of the Blog | ||
ElementBlogOverview::config()->update('allow_use_outside_of_blog', true); | ||
|
||
/** @var ElementBlogOverview $block */ | ||
$block = $this->objFromFixture(ElementBlogOverview::class, 'block2'); | ||
$controller = new PageController(); | ||
|
||
// We have not allowed usage outside of BlogController, so this should be null | ||
$this->assertNotNull($block->getPaginatedList($controller)); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
public function testPaginatedListDefault(): void | ||
{ | ||
// Update our config to allow this Block type to be used outside of the Blog | ||
ElementBlogOverview::config()->update('allow_use_outside_of_blog', true); | ||
|
||
/** @var ElementBlogOverview $block */ | ||
$block = $this->objFromFixture(ElementBlogOverview::class, 'block2'); | ||
$controller = new BasePageController(); | ||
|
||
// We have not allowed usage outside of BlogController, so this should be null | ||
$this->assertNotNull($block->getPaginatedList($controller)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
DNADesign\Elemental\Models\ElementalArea: | ||
blog1: | ||
OwnerClassName: SilverStripe\Blog\Model\Blog | ||
fakePage1: | ||
OwnerClassName: Dynamic\Elements\Blog\Tests\Fake\Page | ||
|
||
SilverStripe\Blog\Model\Blog: | ||
blog1: | ||
Title: Blog 1 | ||
URLSegment: blog1 | ||
ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.blog1 | ||
|
||
SilverStripe\Blog\Model\BlogPost: | ||
post1: | ||
Title: Post 1 | ||
URLSegment: post1 | ||
ParentID: =>SilverStripe\Blog\Model\Blog.blog1 | ||
|
||
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.fakePage1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Dynamic\Elements\Blog\Tests\Fake; | ||
|
||
use PageController as BasePageController; | ||
use SilverStripe\Dev\TestOnly; | ||
use SilverStripe\ORM\ArrayList; | ||
use SilverStripe\ORM\PaginatedList; | ||
|
||
/** | ||
* Test only class used to test that the Overview block can be used outside of a Blog page | ||
* | ||
* Class Page | ||
* | ||
* @package Dynamic\Elements\Blog\Tests\Fake | ||
*/ | ||
class PageController extends BasePageController implements TestOnly | ||
{ | ||
/** | ||
* @return PaginatedList | ||
*/ | ||
public function PaginatedList(): PaginatedList | ||
{ | ||
return PaginatedList::create(ArrayList::create()); | ||
} | ||
} |