Merge pull request #524 from creative-commoners/pulls/3.2/tweaks

Minor tweaks, syntax, namespace imports, docblocks, test improvements
This commit is contained in:
Dylan Wagstaff 2018-04-09 12:06:34 +12:00 committed by GitHub
commit 2d62251858
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 84 additions and 111 deletions

View File

@ -9,13 +9,13 @@ env:
matrix: matrix:
include: include:
- php: 5.6 - php: 5.6
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.0.x-dev PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0 - php: 7.0
env: DB=PGSQL PHPUNIT_TEST=1 env: DB=PGSQL INSTALLER_VERSION=4.1.x-dev PHPUNIT_TEST=1
- php: 7.1 - php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.2.x-dev PHPUNIT_COVERAGE_TEST=1
- php: 7.2 - php: 7.2
env: DB=MYSQL PHPUNIT_TEST=1 env: DB=MYSQL INSTALLER_VERSION=4.x-dev PHPUNIT_TEST=1
before_script: before_script:
# Init PHP # Init PHP
@ -25,7 +25,7 @@ before_script:
# Install composer dependencies # Install composer dependencies
- composer validate - composer validate
- composer require --no-update silverstripe/installer:4.0.x-dev 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.0.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

View File

@ -4,8 +4,10 @@ namespace SilverStripe\Blog\Admin;
use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField; use SilverStripe\Blog\Forms\GridField\GridFieldAddByDBField;
use SilverStripe\Blog\Model\CategorisationObject; use SilverStripe\Blog\Model\CategorisationObject;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor; use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns; use SilverStripe\Forms\GridField\GridFieldDataColumns;
use SilverStripe\ORM\SS_List;
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
{ {
@ -20,7 +22,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
{ {
parent::__construct($itemsPerPage); parent::__construct($itemsPerPage);
$this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton'); $this->removeComponentsByType(GridFieldAddNewButton::class);
$this->addComponent( $this->addComponent(
GridFieldAddByDBField::create('buttons-before-left') GridFieldAddByDBField::create('buttons-before-left')
@ -33,7 +35,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
/** /**
* @var GridFieldDataColumns $columns * @var GridFieldDataColumns $columns
*/ */
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns = $this->getComponentByType(GridFieldDataColumns::class);
$columns->setFieldFormatting( $columns->setFieldFormatting(
[ [
@ -54,7 +56,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
/** /**
* @var GridFieldDataColumns $columns * @var GridFieldDataColumns $columns
*/ */
$columns = $this->getComponentByType('SilverStripe\\Forms\\GridField\\GridFieldDataColumns'); $columns = $this->getComponentByType(GridFieldDataColumns::class);
$columns->setDisplayFields( $columns->setDisplayFields(
[ [

View File

@ -3,6 +3,7 @@
namespace SilverStripe\Blog\Forms\GridField; namespace SilverStripe\Blog\Forms\GridField;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\HTTPResponse;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField;
@ -11,6 +12,8 @@ use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\Forms\GridField\GridField_HTMLProvider; use SilverStripe\Forms\GridField\GridField_HTMLProvider;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements; use SilverStripe\View\Requirements;
@ -69,7 +72,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* @param $arguments mixed * @param $arguments mixed
* @param $data array * @param $data array
* *
* @return null|SS_HTTPResponse * @return null|HTTPResponse
* *
* @throws UnexpectedValueException * @throws UnexpectedValueException
*/ */
@ -154,7 +157,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @param $gridField GridField * @param $gridField GridField
* *
* @return string * @return string[]
*/ */
public function getHTMLFragments($gridField) public function getHTMLFragments($gridField)
{ {
@ -170,7 +173,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$obj = singleton($dataClass); $obj = singleton($dataClass);
if (!$obj->canCreate()) { if (!$obj->canCreate()) {
return ''; return [];
} }
$dbField = $this->getDataObjectField(); $dbField = $this->getDataObjectField();

View File

@ -8,12 +8,16 @@ use SilverStripe\Blog\Forms\GridField\GridFieldConfigBlogPost;
use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\CMS\Controllers\RootURLController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldConfig;
use SilverStripe\Forms\ListboxField; use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\UnsavedRelationList; use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Security\Group; use SilverStripe\Security\Group;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
@ -443,11 +447,11 @@ class Blog extends Page implements PermissionProvider
$list = Member::get(); $list = Member::get();
$this->extend('updateCandidateUsers', $list); $this->extend('updateCandidateUsers', $list);
return $list; return $list;
} else {
return Permission::get_members_by_permission(
$this->config()->get('grant_user_permission')
);
} }
return Permission::get_members_by_permission(
$this->config()->get('grant_user_permission')
);
} }
/** /**

View File

@ -108,7 +108,7 @@ class BlogFilter extends Lumberjack
$tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField); $tab = Tab::create('ChildPages', $this->getLumberjackTitle(), $gridField);
$fields->insertBefore($tab, 'Main'); $fields->insertBefore('Main', $tab);
} }
} }
} }

View File

@ -8,6 +8,8 @@ use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet; use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\View\Parsers\URLSegmentFilter; use SilverStripe\View\Parsers\URLSegmentFilter;

View File

@ -8,12 +8,15 @@ use SilverStripe\Assets\Image;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField; use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
use SilverStripe\Forms\ListboxField; use SilverStripe\Forms\ListboxField;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField; use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBHTMLText;
use SilverStripe\ORM\SS_List;
use SilverStripe\ORM\UnsavedRelationList; use SilverStripe\ORM\UnsavedRelationList;
use SilverStripe\Security\Group; use SilverStripe\Security\Group;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
@ -224,7 +227,7 @@ class BlogPost extends Page
/** /**
* @var FieldList $fields * @var FieldList $fields
*/ */
$fields->insertAfter($uploadField, 'Content'); $fields->insertAfter('Content', $uploadField);
$summary = HtmlEditorField::create('Summary', false); $summary = HtmlEditorField::create('Summary', false);
$summary->setRows(5); $summary->setRows(5);
@ -243,7 +246,7 @@ class BlogPost extends Page
$summaryHolder->setHeadingLevel(4); $summaryHolder->setHeadingLevel(4);
$summaryHolder->addExtraClass('custom-summary'); $summaryHolder->addExtraClass('custom-summary');
$fields->insertAfter($summaryHolder, 'FeaturedImage'); $fields->insertAfter('FeaturedImage', $summaryHolder);
$urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment = $fields->dataFieldByName('URLSegment');
$urlSegment->setURLPrefix($this->Parent()->RelativeLink()); $urlSegment->setURLPrefix($this->Parent()->RelativeLink());
@ -605,7 +608,7 @@ class BlogPost extends Page
*/ */
public function Excerpt($wordsToDisplay = 30) public function Excerpt($wordsToDisplay = 30)
{ {
/** @var HTMLText $content */ /** @var DBHTMLText $content */
$content = $this->dbObject('Content'); $content = $this->dbObject('Content');
return $content->Summary($wordsToDisplay); return $content->Summary($wordsToDisplay);

View File

@ -23,7 +23,8 @@ class BlogPostFilter extends DataExtension
/** /**
* Augment queries so that we don't fetch unpublished articles. * Augment queries so that we don't fetch unpublished articles.
* *
* @param SQLQuery $query * @param SQLSelect $query
* @param DataQuery $query
*/ */
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
{ {

View File

@ -5,11 +5,13 @@ namespace SilverStripe\Blog\Widgets;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\ORM\FieldType\DBDate; use SilverStripe\ORM\FieldType\DBDate;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\FieldType\DBEnum;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
@ -76,7 +78,7 @@ class BlogArchiveWidget extends Widget
{ {
$this->beforeUpdateCMSFields(function ($fields) { $this->beforeUpdateCMSFields(function ($fields) {
/** /**
* @var Enum $archiveType * @var DBEnum $archiveType
*/ */
$archiveType = $this->dbObject('ArchiveType'); $archiveType = $this->dbObject('ArchiveType');

View File

@ -2,10 +2,6 @@
namespace SilverStripe\Blog\Widgets; namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
@ -14,6 +10,10 @@ use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\Widgets\Model\Widget; use SilverStripe\Widgets\Model\Widget;
if (!class_exists(Widget::class)) {
return;
}
/** /**
* @method Blog Blog() * @method Blog Blog()
*/ */

View File

@ -2,16 +2,17 @@
namespace SilverStripe\Blog\Widgets; namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList;
use SilverStripe\Widgets\Model\Widget; use SilverStripe\Widgets\Model\Widget;
if (!class_exists(Widget::class)) {
return;
}
/** /**
* @method Blog Blog() * @method Blog Blog()
* *
@ -72,7 +73,7 @@ class BlogRecentPostsWidget extends Widget
} }
/** /**
* @return array * @return array|DataList
*/ */
public function getPosts() public function getPosts()
{ {

View File

@ -2,10 +2,6 @@
namespace SilverStripe\Blog\Widgets; namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
@ -14,6 +10,10 @@ use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\Widgets\Model\Widget; use SilverStripe\Widgets\Model\Widget;
if (!class_exists(Widget::class)) {
return;
}
/** /**
* @method Blog Blog() * @method Blog Blog()
*/ */

View File

@ -2,17 +2,18 @@
namespace SilverStripe\Blog\Widgets; namespace SilverStripe\Blog\Widgets;
if (!class_exists('\\SilverStripe\\Widgets\\Model\\Widget')) {
return;
}
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\NumericField; use SilverStripe\Forms\NumericField;
use SilverStripe\ORM\DataList;
use SilverStripe\Widgets\Model\Widget; use SilverStripe\Widgets\Model\Widget;
if (!class_exists(Widget::class)) {
return;
}
/** /**
* @method Blog Blog() * @method Blog Blog()
*/ */

View File

@ -5,7 +5,7 @@
<% include SilverStripe\\Blog\\MemberDetails %> <% include SilverStripe\\Blog\\MemberDetails %>
<% if $PaginatedList.Exists %> <% if $PaginatedList.Exists %>
<h2>Posts by $CurrentProfile.FirstName $CurrentProfile.Surname for $Title:</h2> <h2><%t SilverStripe\\Blog\\Model\\Blog.PostsByUser 'Posts by {firstname} {surname} for {title}' firstname=$CurrentProfile.FirstName surname=$CurrentProfile.Surname title=$Title %></h2>
<% loop $PaginatedList %> <% loop $PaginatedList %>
<% include SilverStripe\\Blog\\PostSummary %> <% include SilverStripe\\Blog\\PostSummary %>
<% end_loop %> <% end_loop %>

View File

@ -5,7 +5,6 @@ namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security; use SilverStripe\Security\Security;
/** /**

View File

@ -3,24 +3,22 @@
namespace SilverStripe\Blog\Tests; namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\CommentNotifications\Extensions\CommentNotifier;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
class BlogPostNotificationsTest extends SapphireTest class BlogPostNotificationsTest extends SapphireTest
{ {
/**
* {@inheritDoc}
* @var string
*/
protected static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
public function testUpdateNotificationRecipients() public function testUpdateNotificationRecipients()
{ {
if (!class_exists('CommentNotifier')) { if (!class_exists(CommentNotifier::class)) {
$this->markTestSkipped('Comments Notification module is not installed'); $this->markTestSkipped('Comments Notification module is not installed');
} }
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
$comment = new \SilverStripe\Comments\Model\Comment(); $comment = new Comment();
$comment->Comment = 'This is a comment'; $comment->Comment = 'This is a comment';
$comment->write(); $comment->write();
$recipients = $blogPost->notificationRecipients( $recipients = $blogPost->notificationRecipients(
@ -41,11 +39,11 @@ class BlogPostNotificationsTest extends SapphireTest
public function testUpdateNotificationSubject() public function testUpdateNotificationSubject()
{ {
if (!class_exists('CommentNotifier')) { if (!class_exists(CommentNotifier::class)) {
$this->markTestSkipped('Comments Notification module is not installed'); $this->markTestSkipped('Comments Notification module is not installed');
} }
$blogPost = $this->objFromFixture(BlogPost::class, 'PostC'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostC');
$comment = new \SilverStripe\Comments\Model\Comment(); $comment = new Comment();
$comment->Comment = 'This is a comment'; $comment->Comment = 'This is a comment';
$comment->write(); $comment->write();
$recipients = $blogPost->notificationRecipients( $recipients = $blogPost->notificationRecipients(

View File

@ -11,16 +11,9 @@ use SilverStripe\Versioned\Versioned;
class BlogPostTest extends SapphireTest class BlogPostTest extends SapphireTest
{ {
/**
* {@inheritDoc}
* @var string
*/
protected static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** protected function tearDown()
* {@inheritdoc}
*/
public function tearDown()
{ {
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();
parent::tearDown(); parent::tearDown();

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Blog\Tests; namespace SilverStripe\Blog\Tests;
use PHPUnit_Framework_TestCase;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Blog\Model\BlogTag;
@ -17,26 +18,16 @@ use SilverStripe\Security\Security;
*/ */
class BlogTagTest extends FunctionalTest class BlogTagTest extends FunctionalTest
{ {
/**
* {@inheritDoc}
* @var string
*/
protected static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** protected function setUp()
* {@inheritdoc}
*/
public function setUp()
{ {
parent::setUp(); parent::setUp();
DBDatetime::set_mock_now('2013-10-10 20:00:00'); DBDatetime::set_mock_now('2013-10-10 20:00:00');
} }
/** protected function tearDown()
* {@inheritdoc}
*/
public function tearDown()
{ {
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();

View File

@ -7,6 +7,7 @@ use SilverStripe\Blog\Widgets\BlogTagsCloudWidget;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Widgets\Model\Widget;
class BlogTagsCloudWidgetTest extends SapphireTest class BlogTagsCloudWidgetTest extends SapphireTest
{ {
@ -17,7 +18,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest
public function testGetCMSFields() public function testGetCMSFields()
{ {
if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) { if (!class_exists(Widget::class)) {
$this->markTestSkipped('Widgets module not installed'); $this->markTestSkipped('Widgets module not installed');
} }
@ -34,7 +35,7 @@ class BlogTagsCloudWidgetTest extends SapphireTest
public function testGetTags() public function testGetTags()
{ {
if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) { if (!class_exists(Widget::class)) {
$this->markTestSkipped('Widgets module not installed'); $this->markTestSkipped('Widgets module not installed');
} }
$widget = new BlogTagsCloudWidget(); $widget = new BlogTagsCloudWidget();

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Blog\Tests; namespace SilverStripe\Blog\Tests;
use PHPUnit_Framework_TestCase;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogController; use SilverStripe\Blog\Model\BlogController;
use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogPost;
@ -9,62 +10,43 @@ use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest; use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\DataModel;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\SS_List; use SilverStripe\ORM\SS_List;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
/** /**
* @mixin PHPUnit_Framework_TestCase * @mixin PHPUnit_Framework_TestCase
*/ */
class BlogTest extends SapphireTest class BlogTest extends SapphireTest
{ {
/**
* @var string
*/
protected static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** protected function setUp()
* {@inheritdoc}
*/
public function setUp()
{ {
parent::setUp(); parent::setUp();
Config::nest();
DBDatetime::set_mock_now('2013-10-10 20:00:00'); DBDatetime::set_mock_now('2013-10-10 20:00:00');
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture(Blog::class, 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog->publishRecursive();
$blog->publish('Stage', 'Live');
} }
/** protected function tearDown()
* {@inheritdoc}
*/
public function tearDown()
{ {
DBDatetime::clear_mock_now(); DBDatetime::clear_mock_now();
Config::unnest();
parent::tearDown(); parent::tearDown();
} }
public function testGetExcludedSiteTreeClassNames() public function testGetExcludedSiteTreeClassNames()
{ {
$member = Security::getCurrentUser(); $this->logOut();
if ($member) {
Security::setCurrentUser(null);
}
/** /**
* @var Blog $blog * @var Blog $blog
@ -84,11 +66,7 @@ class BlogTest extends SapphireTest
public function testGetArchivedBlogPosts() public function testGetArchivedBlogPosts()
{ {
$member = Security::getCurrentUser(); $this->logOut();
if ($member) {
Security::setCurrentUser(null);
}
/** /**
* @var Blog $blog * @var Blog $blog
@ -349,23 +327,17 @@ class BlogTest extends SapphireTest
); );
} }
/**
* @expectedException \SilverStripe\Control\HTTPResponse_Exception
* @expectedExceptionCode 404
*/
public function testDisabledProfiles() public function testDisabledProfiles()
{ {
Config::modify()->set(BlogController::class, 'disable_profiles', true); Config::modify()->set(BlogController::class, 'disable_profiles', true);
try { $controller = BlogController::create();
$controller = BlogController::create(); $controller->setRequest(Controller::curr()->getRequest());
$controller->setRequest(Controller::curr()->getRequest()); $controller->profile();
$controller->profile();
$this->fail('The "profile" action should throw a HTTPResponse_Exception when disable_profiles is enabled');
} catch (HTTPResponse_Exception $e) {
$this->assertEquals(
404,
$e->getResponse()->getStatusCode(),
'The response status code should be 404 Not Found'
);
}
} }
/** /**