Merge pull request #331 from helpfulrobot/convert-to-psr-2

Converted to PSR-2
This commit is contained in:
Damian Mooyman 2015-11-23 10:46:41 +13:00
commit 0a8ee233a6
34 changed files with 4276 additions and 4078 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor { class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
{
/** /**
* @param int $itemsPerPage * @param int $itemsPerPage
* @param array|SS_List $mergeRecords * @param array|SS_List $mergeRecords
@ -8,7 +9,8 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
* @param string $parentMethod * @param string $parentMethod
* @param string $childMethod * @param string $childMethod
*/ */
public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod) { public function __construct($itemsPerPage = 15, $mergeRecords, $parentType, $parentMethod, $childMethod)
{
parent::__construct($itemsPerPage); parent::__construct($itemsPerPage);
$this->removeComponentsByType('GridFieldAddNewButton'); $this->removeComponentsByType('GridFieldAddNewButton');
@ -38,7 +40,8 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor {
/** /**
* Reorders GridField columns so that Actions is last. * Reorders GridField columns so that Actions is last.
*/ */
protected function changeColumnOrder() { protected function changeColumnOrder()
{
/** /**
* @var GridFieldDataColumns $columns * @var GridFieldDataColumns $columns
*/ */

View File

@ -1,6 +1,7 @@
<?php <?php
class GridFieldFormAction extends GridField_FormAction { class GridFieldFormAction extends GridField_FormAction
{
/** /**
* @var array * @var array
*/ */
@ -9,14 +10,16 @@ class GridFieldFormAction extends GridField_FormAction {
/** /**
* @param array $attributes * @param array $attributes
*/ */
public function setExtraAttributes(array $attributes) { public function setExtraAttributes(array $attributes)
{
$this->extraAttributes = $attributes; $this->extraAttributes = $attributes;
} }
/** /**
* @return array * @return array
*/ */
public function getAttributes() { public function getAttributes()
{
$attributes = parent::getAttributes(); $attributes = parent::getAttributes();
return array_merge( return array_merge(

View File

@ -1,6 +1,7 @@
<?php <?php
class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider { class GridFieldMergeAction implements GridField_ColumnProvider, GridField_ActionProvider
{
/** /**
* List of records to show in the MergeAction column. * List of records to show in the MergeAction column.
* *
@ -35,7 +36,8 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
* @param string $parentMethod * @param string $parentMethod
* @param string $childMethod * @param string $childMethod
*/ */
public function __construct($records = array(), $parentType, $parentMethod, $childMethod) { public function __construct($records = array(), $parentType, $parentMethod, $childMethod)
{
$this->records = $records; $this->records = $records;
$this->parentType = $parentType; $this->parentType = $parentType;
$this->parentMethod = $parentMethod; $this->parentMethod = $parentMethod;
@ -45,7 +47,8 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function augmentColumns($gridField, &$columns) { public function augmentColumns($gridField, &$columns)
{
if (!in_array('MergeAction', $columns)) { if (!in_array('MergeAction', $columns)) {
$columns[] = 'MergeAction'; $columns[] = 'MergeAction';
} }
@ -56,14 +59,16 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnsHandled($gridField) { public function getColumnsHandled($gridField)
{
return array('MergeAction'); return array('MergeAction');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnContent($gridField, $record, $columnName) { public function getColumnContent($gridField, $record, $columnName)
{
if ($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) { if ($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) {
$dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map()); $dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map());
$dropdown->setAttribute('id', 'Target_'.$record->ID); $dropdown->setAttribute('id', 'Target_'.$record->ID);
@ -93,28 +98,32 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnAttributes($gridField, $record, $columnName) { public function getColumnAttributes($gridField, $record, $columnName)
{
return array('class' => 'MergeAction'); return array('class' => 'MergeAction');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnMetadata($gridField, $columnName) { public function getColumnMetadata($gridField, $columnName)
{
return array('title' => 'Move posts to'); return array('title' => 'Move posts to');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getActions($gridField) { public function getActions($gridField)
{
return array('merge'); return array('merge');
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function handleAction(GridField $gridField, $actionName, $arguments, $data) { public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName === 'merge') { if ($actionName === 'merge') {
$controller = Controller::curr(); $controller = Controller::curr();

View File

@ -8,7 +8,8 @@
* @property string $PublishDate * @property string $PublishDate
* @property string $Tags * @property string $Tags
*/ */
class BlogEntry extends BlogPost implements MigratableObject { class BlogEntry extends BlogPost implements MigratableObject
{
/** /**
* @var string * @var string
*/ */
@ -26,23 +27,23 @@ class BlogEntry extends BlogPost implements MigratableObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
return false; return false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
//Migrate comma separated tags into BlogTag objects. //Migrate comma separated tags into BlogTag objects.
foreach ($this->TagNames() as $tag) { foreach ($this->TagNames() as $tag) {
$existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID)); $existingTag = BlogTag::get()->filter(array('Title' => $tag, 'BlogID' => $this->ParentID));
if ($existingTag->count()) { if ($existingTag->count()) {
//if tag already exists we will simply add it to this post. //if tag already exists we will simply add it to this post.
$tagObject = $existingTag->First(); $tagObject = $existingTag->First();
} else { } else {
//if the tag is now we create it and add it to this post. //if the tag is now we create it and add it to this post.
@ -50,8 +51,6 @@ class BlogEntry extends BlogPost implements MigratableObject {
$tagObject->Title = $tag; $tagObject->Title = $tag;
$tagObject->BlogID = $this->ParentID; $tagObject->BlogID = $this->ParentID;
$tagObject->write(); $tagObject->write();
} }
if ($tagObject) { if ($tagObject) {
@ -90,23 +89,25 @@ class BlogEntry extends BlogPost implements MigratableObject {
* *
* @return array * @return array
*/ */
public function TagNames() { public function TagNames()
{
$tags = preg_split('/\s*,\s*/', trim($this->Tags)); $tags = preg_split('/\s*,\s*/', trim($this->Tags));
$results = array(); $results = array();
foreach ($tags as $tag) { foreach ($tags as $tag) {
if($tag) $results[mb_strtolower($tag)] = $tag; if ($tag) {
$results[mb_strtolower($tag)] = $tag;
}
} }
return $results; return $results;
} }
} }
/** /**
* @deprecated since version 2.0 * @deprecated since version 2.0
*/ */
class BlogEntry_Controller extends BlogPost_Controller { class BlogEntry_Controller extends BlogPost_Controller
{
} }

View File

@ -3,7 +3,8 @@
/** /**
* @deprecated since version 2.0 * @deprecated since version 2.0
*/ */
class BlogHolder extends BlogTree implements MigratableObject { class BlogHolder extends BlogTree implements MigratableObject
{
/** /**
* @var string * @var string
*/ */
@ -27,24 +28,27 @@ class BlogHolder extends BlogTree implements MigratableObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
return false; return false;
} }
//Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error. //Overload these to stop the Uncaught Exception: Object->__call(): the method 'parent' does not exist on 'BlogHolder' error.
public function validURLSegment() { public function validURLSegment()
{
return true; return true;
} }
public function syncLinkTracking() { public function syncLinkTracking()
{
return null; return null;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
$published = $this->IsPublished(); $published = $this->IsPublished();
if ($this->ClassName === 'BlogHolder') { if ($this->ClassName === 'BlogHolder') {
@ -68,6 +72,6 @@ class BlogHolder extends BlogTree implements MigratableObject {
/** /**
* @deprecated since version 2.0 * @deprecated since version 2.0
*/ */
class BlogHolder_Controller extends BlogTree_Controller { class BlogHolder_Controller extends BlogTree_Controller
{
} }

View File

@ -3,7 +3,8 @@
/** /**
* @deprecated since version 2.0 * @deprecated since version 2.0
*/ */
class BlogTree extends Page implements MigratableObject { class BlogTree extends Page implements MigratableObject
{
/** /**
* @var string * @var string
*/ */
@ -20,14 +21,16 @@ class BlogTree extends Page implements MigratableObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
return false; return false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
$published = $this->IsPublished(); $published = $this->IsPublished();
if ($this->ClassName === 'BlogTree') { if ($this->ClassName === 'BlogTree') {
$this->ClassName = 'Page'; $this->ClassName = 'Page';
@ -48,6 +51,6 @@ class BlogTree extends Page implements MigratableObject {
/** /**
* @deprecated since version 2.0 * @deprecated since version 2.0
*/ */
class BlogTree_Controller extends Page_Controller { class BlogTree_Controller extends Page_Controller
{
} }

View File

@ -1,6 +1,7 @@
<?php <?php
class BlogMigrationTask extends MigrationTask { class BlogMigrationTask extends MigrationTask
{
/** /**
* Should this task be invoked automatically via dev/build? * Should this task be invoked automatically via dev/build?
* *
@ -13,22 +14,22 @@ class BlogMigrationTask extends MigrationTask {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
$classes = ClassInfo::implementorsOf('MigratableObject'); $classes = ClassInfo::implementorsOf('MigratableObject');
$this->message('Migrating legacy blog records'); $this->message('Migrating legacy blog records');
foreach ($classes as $class) { foreach ($classes as $class) {
$this->upClass($class); $this->upClass($class);
} }
} }
/** /**
* @param string $text * @param string $text
*/ */
protected function message($text) { protected function message($text)
{
if (Controller::curr() instanceof DatabaseAdmin) { if (Controller::curr() instanceof DatabaseAdmin) {
DB::alteration_message($text, 'obsolete'); DB::alteration_message($text, 'obsolete');
} else { } else {
@ -42,7 +43,8 @@ class BlogMigrationTask extends MigrationTask {
* @param string $class * @param string $class
* @param null|string $stage * @param null|string $stage
*/ */
protected function upClass($class) { protected function upClass($class)
{
if (!class_exists($class)) { if (!class_exists($class)) {
return; return;
} }
@ -83,7 +85,8 @@ class BlogMigrationTask extends MigrationTask {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function down() { public function down()
{
$this->message('BlogMigrationTask::down() not implemented'); $this->message('BlogMigrationTask::down() not implemented');
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
interface MigratableObject { interface MigratableObject
{
/** /**
* Migrate the object up to the current version. * Migrate the object up to the current version.
*/ */

View File

@ -10,7 +10,8 @@ if(!class_exists('Widget')) {
* @property string $DisplayMode * @property string $DisplayMode
* @property string $ArchiveType * @property string $ArchiveType
*/ */
class ArchiveWidget extends BlogArchiveWidget implements MigratableObject { class ArchiveWidget extends BlogArchiveWidget implements MigratableObject
{
/** /**
* @var array * @var array
*/ */
@ -28,14 +29,16 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
return false; return false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
if ($this->DisplayMode) { if ($this->DisplayMode) {
$this->ArchiveType = 'Monthly'; $this->ArchiveType = 'Monthly';
@ -47,6 +50,5 @@ class ArchiveWidget extends BlogArchiveWidget implements MigratableObject {
$this->ClassName = 'BlogArchiveWidget'; $this->ClassName = 'BlogArchiveWidget';
$this->write(); $this->write();
return "Migrated " . $this->ArchiveType . " archive widget"; return "Migrated " . $this->ArchiveType . " archive widget";
} }
} }

View File

@ -9,7 +9,8 @@ if(!class_exists('Widget')) {
* *
* @package blog * @package blog
*/ */
class TagCloudWidget extends BlogTagsWidget implements MigratableObject { class TagCloudWidget extends BlogTagsWidget implements MigratableObject
{
/** /**
* @var array * @var array
*/ */
@ -29,14 +30,16 @@ class TagCloudWidget extends BlogTagsWidget implements MigratableObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
return false; return false;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function up() { public function up()
{
$this->ClassName = 'BlogTagsWidget'; $this->ClassName = 'BlogTagsWidget';
$this->write(); $this->write();
return "Migrated " . $this->Title . " widget"; return "Migrated " . $this->Title . " widget";

View File

@ -3,13 +3,15 @@
/** /**
* Adds Blog specific behaviour to Comment. * Adds Blog specific behaviour to Comment.
*/ */
class BlogCommentExtension extends DataExtension { class BlogCommentExtension extends DataExtension
{
/** /**
* Extra CSS classes for styling different comment types. * Extra CSS classes for styling different comment types.
* *
* @return string * @return string
*/ */
public function getExtraClass() { public function getExtraClass()
{
$blogPost = $this->owner->getParent(); $blogPost = $this->owner->getParent();
if ($blogPost instanceof BlogPost) { if ($blogPost instanceof BlogPost) {

View File

@ -7,11 +7,13 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogFilter extends Lumberjack { class BlogFilter extends Lumberjack
{
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function stageChildren($showAll = false) { public function stageChildren($showAll = false)
{
$staged = parent::stageChildren($showAll); $staged = parent::stageChildren($showAll);
if (!$this->shouldFilter() && $this->subclassForBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) { if (!$this->shouldFilter() && $this->subclassForBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
@ -36,14 +38,16 @@ class BlogFilter extends Lumberjack {
/** /**
* @return bool * @return bool
*/ */
protected function subclassForBlog() { protected function subclassForBlog()
{
return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog')); return in_array(get_class($this->owner), ClassInfo::subClassesFor('Blog'));
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function liveChildren($showAll = false, $onlyDeletedFromStage = false) { public function liveChildren($showAll = false, $onlyDeletedFromStage = false)
{
$staged = parent::liveChildren($showAll, $onlyDeletedFromStage); $staged = parent::liveChildren($showAll, $onlyDeletedFromStage);
if (!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) { if (!$this->shouldFilter() && $this->isBlog() && !Permission::check('VIEW_DRAFT_CONTENT')) {
@ -60,14 +64,16 @@ class BlogFilter extends Lumberjack {
/** /**
* @return bool * @return bool
*/ */
protected function isBlog() { protected function isBlog()
{
return $this->owner instanceof Blog; return $this->owner instanceof Blog;
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function updateCMSFields(FieldList $fields) { public function updateCMSFields(FieldList $fields)
{
$excluded = $this->owner->getExcludedSiteTreeClassNames(); $excluded = $this->owner->getExcludedSiteTreeClassNames();
if (!empty($excluded)) { if (!empty($excluded)) {
@ -94,13 +100,15 @@ class BlogFilter extends Lumberjack {
/** /**
* Enables children of non-editable pages to be edited. * Enables children of non-editable pages to be edited.
*/ */
class BlogFilter_GridField extends GridField { class BlogFilter_GridField extends GridField
{
/** /**
* @param FormTransformation $transformation * @param FormTransformation $transformation
* *
* @return $this * @return $this
*/ */
public function transform(FormTransformation $transformation) { public function transform(FormTransformation $transformation)
{
return $this; return $this;
} }
} }

View File

@ -6,7 +6,8 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogMemberExtension extends DataExtension { class BlogMemberExtension extends DataExtension
{
/** /**
* @var array * @var array
*/ */
@ -32,7 +33,8 @@ class BlogMemberExtension extends DataExtension {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function onBeforeWrite() { public function onBeforeWrite()
{
$count = 1; $count = 1;
$this->owner->URLSegment = $this->generateURLSegment(); $this->owner->URLSegment = $this->generateURLSegment();
@ -48,7 +50,8 @@ class BlogMemberExtension extends DataExtension {
* *
* @return string * @return string
*/ */
public function generateURLSegment() { public function generateURLSegment()
{
$filter = URLSegmentFilter::create(); $filter = URLSegmentFilter::create();
$name = $this->owner->FirstName . ' ' . $this->owner->Surname; $name = $this->owner->FirstName . ' ' . $this->owner->Surname;
$urlSegment = $filter->filter($name); $urlSegment = $filter->filter($name);
@ -66,7 +69,8 @@ class BlogMemberExtension extends DataExtension {
* *
* @return bool * @return bool
*/ */
public function validURLSegment() { public function validURLSegment()
{
$conflict = Member::get()->filter('URLSegment', $this->owner->URLSegment); $conflict = Member::get()->filter('URLSegment', $this->owner->URLSegment);
if ($this->owner->ID) { if ($this->owner->ID) {
@ -80,7 +84,8 @@ class BlogMemberExtension extends DataExtension {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function updateCMSFields(FieldList $fields) { public function updateCMSFields(FieldList $fields)
{
$fields->removeByName('URLSegment'); $fields->removeByName('URLSegment');
// Remove the automatically-generated posts tab. // Remove the automatically-generated posts tab.

View File

@ -7,13 +7,15 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogPostFilter extends DataExtension { 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 SQLQuery $query
*/ */
public function augmentSQL(SQLQuery &$query) { public function augmentSQL(SQLQuery &$query)
{
$stage = Versioned::current_stage(); $stage = Versioned::current_stage();
if (Controller::curr() instanceof LeftAndMain) { if (Controller::curr() instanceof LeftAndMain) {
@ -36,7 +38,8 @@ class BlogPostFilter extends DataExtension {
* @param mixed $dataQuery * @param mixed $dataQuery
* @param mixed $parent * @param mixed $parent
*/ */
public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent) { public function augmentLoadLazyFields(SQLQuery &$query, &$dataQuery, $parent)
{
$dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"'); $dataQuery->innerJoin('BlogPost', '"SiteTree"."ID" = "BlogPost"."ID"');
} }
} }

View File

@ -5,14 +5,16 @@
* *
* Extends {@see BlogPost} with extensions to {@see CommentNotifiable}. * Extends {@see BlogPost} with extensions to {@see CommentNotifiable}.
*/ */
class BlogPostNotifications extends DataExtension { class BlogPostNotifications extends DataExtension
{
/** /**
* Notify all authors of notifications. * Notify all authors of notifications.
* *
* @param SS_List $list * @param SS_List $list
* @param mixed $comment * @param mixed $comment
*/ */
public function updateNotificationRecipients(&$list, &$comment) { public function updateNotificationRecipients(&$list, &$comment)
{
$list = $this->owner->Authors(); $list = $this->owner->Authors();
} }
@ -23,7 +25,8 @@ class BlogPostNotifications extends DataExtension {
* @param Comment $comment * @param Comment $comment
* @param Member|string $recipient * @param Member|string $recipient
*/ */
public function updateNotificationSubject(&$subject, &$comment, &$recipient) { public function updateNotificationSubject(&$subject, &$comment, &$recipient)
{
$subject = sprintf('A new comment has been posted on ', $this->owner->Title); $subject = sprintf('A new comment has been posted on ', $this->owner->Title);
} }
} }

View File

@ -6,7 +6,8 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class URLSegmentExtension extends DataExtension { class URLSegmentExtension extends DataExtension
{
/** /**
* @var array * @var array
*/ */
@ -17,7 +18,8 @@ class URLSegmentExtension extends DataExtension {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function onBeforeWrite() { public function onBeforeWrite()
{
$this->owner->generateURLSegment(); $this->owner->generateURLSegment();
} }
@ -28,7 +30,8 @@ class URLSegmentExtension extends DataExtension {
* *
* @return string * @return string
*/ */
public function generateURLSegment($increment = null) { public function generateURLSegment($increment = null)
{
$filter = new URLSegmentFilter(); $filter = new URLSegmentFilter();
$this->owner->URLSegment = $filter->filter($this->owner->Title); $this->owner->URLSegment = $filter->filter($this->owner->Title);

View File

@ -1,10 +1,12 @@
<?php <?php
class BlogAdminSidebar extends FieldGroup { class BlogAdminSidebar extends FieldGroup
{
/** /**
* @return bool * @return bool
*/ */
public function isOpen() { public function isOpen()
{
$sidebar = Cookie::get('blog-admin-sidebar'); $sidebar = Cookie::get('blog-admin-sidebar');
if ($sidebar == 1 || is_null($sidebar)) { if ($sidebar == 1 || is_null($sidebar)) {

View File

@ -6,7 +6,8 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLProvider { class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLProvider
{
/** /**
* HTML Fragment to render the field. * HTML Fragment to render the field.
* *
@ -28,7 +29,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* @param string $targetFragment * @param string $targetFragment
* @param string $dataObjectField * @param string $dataObjectField
*/ */
public function __construct($targetFragment = 'before', $dataObjectField = 'Title') { public function __construct($targetFragment = 'before', $dataObjectField = 'Title')
{
$this->targetFragment = $targetFragment; $this->targetFragment = $targetFragment;
$this->dataObjectField = (string) $dataObjectField; $this->dataObjectField = (string) $dataObjectField;
} }
@ -40,7 +42,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @return array * @return array
*/ */
public function getActions($gridField) { public function getActions($gridField)
{
return array( return array(
'add', 'add',
); );
@ -58,7 +61,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @throws UnexpectedValueException * @throws UnexpectedValueException
*/ */
public function handleAction(GridField $gridField, $actionName, $arguments, $data) { public function handleAction(GridField $gridField, $actionName, $arguments, $data)
{
if ($actionName == 'add') { if ($actionName == 'add') {
$dbField = $this->getDataObjectField(); $dbField = $this->getDataObjectField();
@ -119,7 +123,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @return string * @return string
*/ */
public function getDataObjectField() { public function getDataObjectField()
{
return $this->dataObjectField; return $this->dataObjectField;
} }
@ -128,7 +133,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @param $field string * @param $field string
*/ */
public function setDataObjectField($field) { public function setDataObjectField($field)
{
$this->dataObjectField = (string) $field; $this->dataObjectField = (string) $field;
} }
@ -139,7 +145,8 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
* *
* @return string * @return string
*/ */
public function getHTMLFragments($gridField) { public function getHTMLFragments($gridField)
{
/** /**
* @var DataList $dataList * @var DataList $dataList
*/ */

View File

@ -7,11 +7,13 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class GridFieldBlogPostState extends GridFieldSiteTreeState { class GridFieldBlogPostState extends GridFieldSiteTreeState
{
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnContent($gridField, $record, $columnName) { public function getColumnContent($gridField, $record, $columnName)
{
if ($columnName == 'State') { if ($columnName == 'State') {
Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::css(BLOGGER_DIR . '/css/cms.css');
if ($record instanceof BlogPost) { if ($record instanceof BlogPost) {
@ -70,7 +72,8 @@ class GridFieldBlogPostState extends GridFieldSiteTreeState {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumnAttributes($gridField, $record, $columnName) { public function getColumnAttributes($gridField, $record, $columnName)
{
if ($columnName == 'State') { if ($columnName == 'State') {
if ($record instanceof BlogPost) { if ($record instanceof BlogPost) {
$published = $record->isPublished(); $published = $record->isPublished();

View File

@ -6,11 +6,13 @@
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack { class GridFieldConfig_BlogPost extends GridFieldConfig_Lumberjack
{
/** /**
* @param null|int $itemsPerPage * @param null|int $itemsPerPage
*/ */
public function __construct($itemsPerPage = null) { public function __construct($itemsPerPage = null)
{
parent::__construct($itemsPerPage); parent::__construct($itemsPerPage);
$this->removeComponentsByType('GridFieldSiteTreeState'); $this->removeComponentsByType('GridFieldSiteTreeState');

View File

@ -12,7 +12,8 @@
* @method ManyManyList Writers() List of writers * @method ManyManyList Writers() List of writers
* @method ManyManyList Contributors() List of contributors * @method ManyManyList Contributors() List of contributors
*/ */
class Blog extends Page implements PermissionProvider { class Blog extends Page implements PermissionProvider
{
/** /**
* Permission for user management. * Permission for user management.
* *
@ -103,7 +104,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
@ -145,7 +147,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canEdit($member = null) { public function canEdit($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if ($this->isEditor($member)) { if ($this->isEditor($member)) {
@ -160,7 +163,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return null|Member * @return null|Member
*/ */
protected function getMember($member = null) { protected function getMember($member = null)
{
if (!$member) { if (!$member) {
$member = Member::currentUser(); $member = Member::currentUser();
} }
@ -179,7 +183,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return bool * @return bool
*/ */
public function isEditor($member) { public function isEditor($member)
{
$isEditor = $this->isMemberOf($member, $this->Editors()); $isEditor = $this->isMemberOf($member, $this->Editors());
$this->extend('updateIsEditor', $isEditor, $member); $this->extend('updateIsEditor', $isEditor, $member);
@ -194,7 +199,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return bool * @return bool
*/ */
protected function isMemberOf($member, $relation) { protected function isMemberOf($member, $relation)
{
if (!$member || !$member->exists()) { if (!$member || !$member->exists()) {
return false; return false;
} }
@ -217,7 +223,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return null|string * @return null|string
*/ */
public function RoleOf($member) { public function RoleOf($member)
{
if (is_numeric($member)) { if (is_numeric($member)) {
$member = DataObject::get_by_id('Member', $member); $member = DataObject::get_by_id('Member', $member);
} }
@ -248,7 +255,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return bool * @return bool
*/ */
public function isWriter($member) { public function isWriter($member)
{
$isWriter = $this->isMemberOf($member, $this->Writers()); $isWriter = $this->isMemberOf($member, $this->Writers());
$this->extend('updateIsWriter', $isWriter, $member); $this->extend('updateIsWriter', $isWriter, $member);
@ -262,7 +270,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return bool * @return bool
*/ */
public function isContributor($member) { public function isContributor($member)
{
$isContributor = $this->isMemberOf($member, $this->Contributors()); $isContributor = $this->isMemberOf($member, $this->Contributors());
$this->extend('updateIsContributor', $isContributor, $member); $this->extend('updateIsContributor', $isContributor, $member);
@ -272,7 +281,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canAddChildren($member = null) { public function canAddChildren($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if ($this->isEditor($member) || $this->isWriter($member) || $this->isContributor($member)) { if ($this->isEditor($member) || $this->isWriter($member) || $this->isContributor($member)) {
@ -285,7 +295,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSettingsFields() { public function getSettingsFields()
{
$fields = parent::getSettingsFields(); $fields = parent::getSettingsFields();
$fields->addFieldToTab('Root.Settings', $fields->addFieldToTab('Root.Settings',
@ -358,7 +369,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return SS_List * @return SS_List
*/ */
protected function getCandidateUsers() { protected function getCandidateUsers()
{
if ($this->config()->grant_user_access) { if ($this->config()->grant_user_access) {
$list = Member::get(); $list = Member::get();
$this->extend('updateCandidateUsers', $list); $this->extend('updateCandidateUsers', $list);
@ -377,7 +389,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return bool * @return bool
*/ */
public function canEditEditors($member = null) { public function canEditEditors($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$extended = $this->extendedCan('canEditEditors', $member); $extended = $this->extendedCan('canEditEditors', $member);
@ -396,7 +409,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return boolean * @return boolean
*/ */
public function canEditWriters($member = null) { public function canEditWriters($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$extended = $this->extendedCan('canEditWriters', $member); $extended = $this->extendedCan('canEditWriters', $member);
@ -419,7 +433,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return boolean * @return boolean
*/ */
public function canEditContributors($member = null) { public function canEditContributors($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$extended = $this->extendedCan('canEditContributors', $member); $extended = $this->extendedCan('canEditContributors', $member);
@ -444,7 +459,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return DataList * @return DataList
*/ */
public function getArchivedBlogPosts($year, $month = null, $day = null) { public function getArchivedBlogPosts($year, $month = null, $day = null)
{
$query = $this->getBlogPosts()->dataQuery(); $query = $this->getBlogPosts()->dataQuery();
$stage = $query->getQueryParam('Versioned.stage'); $stage = $query->getQueryParam('Versioned.stage');
@ -473,7 +489,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return DataList of BlogPost objects * @return DataList of BlogPost objects
*/ */
public function getBlogPosts() { public function getBlogPosts()
{
$blogPosts = BlogPost::get()->filter('ParentID', $this->ID); $blogPosts = BlogPost::get()->filter('ParentID', $this->ID);
$this->extend('updateGetBlogPosts', $blogPosts); $this->extend('updateGetBlogPosts', $blogPosts);
@ -488,7 +505,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return string * @return string
*/ */
public function ProfileLink($urlSegment) { public function ProfileLink($urlSegment)
{
return Controller::join_links($this->Link(), 'profile', $urlSegment); return Controller::join_links($this->Link(), 'profile', $urlSegment);
} }
@ -497,7 +515,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return string * @return string
*/ */
public function getLumberjackTitle() { public function getLumberjackTitle()
{
return _t('Blog.LumberjackTitle', 'Blog Posts'); return _t('Blog.LumberjackTitle', 'Blog Posts');
} }
@ -506,14 +525,16 @@ class Blog extends Page implements PermissionProvider {
* *
* @return GridFieldConfig * @return GridFieldConfig
*/ */
public function getLumberjackGridFieldConfig() { public function getLumberjackGridFieldConfig()
{
return GridFieldConfig_BlogPost::create(); return GridFieldConfig_BlogPost::create();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function providePermissions() { public function providePermissions()
{
return array( return array(
Blog::MANAGE_USERS => array( Blog::MANAGE_USERS => array(
'name' => _t( 'name' => _t(
@ -533,7 +554,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function onBeforeWrite() { protected function onBeforeWrite()
{
parent::onBeforeWrite(); parent::onBeforeWrite();
$this->assignGroup(); $this->assignGroup();
} }
@ -541,7 +563,8 @@ class Blog extends Page implements PermissionProvider {
/** /**
* Assign users as necessary to the blog group. * Assign users as necessary to the blog group.
*/ */
protected function assignGroup() { protected function assignGroup()
{
if (!$this->config()->grant_user_access) { if (!$this->config()->grant_user_access) {
return; return;
} }
@ -565,7 +588,8 @@ class Blog extends Page implements PermissionProvider {
* *
* @return Group * @return Group
*/ */
protected function getUserGroup() { protected function getUserGroup()
{
$code = $this->config()->grant_user_group; $code = $this->config()->grant_user_group;
$group = Group::get()->filter('Code', $code)->first(); $group = Group::get()->filter('Code', $code)->first();
@ -593,7 +617,8 @@ class Blog extends Page implements PermissionProvider {
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class Blog_Controller extends Page_Controller { class Blog_Controller extends Page_Controller
{
/** /**
* @var array * @var array
*/ */
@ -633,7 +658,8 @@ class Blog_Controller extends Page_Controller {
/** /**
* @return string * @return string
*/ */
public function index() { public function index()
{
/** /**
* @var Blog $dataRecord * @var Blog $dataRecord
*/ */
@ -649,7 +675,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return SS_HTTPResponse * @return SS_HTTPResponse
*/ */
public function profile() { public function profile()
{
$profile = $this->getCurrentProfile(); $profile = $this->getCurrentProfile();
if (!$profile) { if (!$profile) {
@ -666,7 +693,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|Member * @return null|Member
*/ */
public function getCurrentProfile() { public function getCurrentProfile()
{
$urlSegment = $this->request->param('URLSegment'); $urlSegment = $this->request->param('URLSegment');
if ($urlSegment) { if ($urlSegment) {
@ -683,7 +711,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|DataList * @return null|DataList
*/ */
public function getCurrentProfilePosts() { public function getCurrentProfilePosts()
{
$profile = $this->getCurrentProfile(); $profile = $this->getCurrentProfile();
if ($profile) { if ($profile) {
@ -698,7 +727,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|SS_HTTPResponse * @return null|SS_HTTPResponse
*/ */
public function archive() { public function archive()
{
/** /**
* @var Blog $dataRecord * @var Blog $dataRecord
*/ */
@ -732,10 +762,9 @@ class Blog_Controller extends Page_Controller {
* *
* @return int * @return int
*/ */
public function getArchiveYear() { public function getArchiveYear()
{
if ($this->request->param('Year')) { if ($this->request->param('Year')) {
if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) { if (preg_match('/^[0-9]{4}$/', $year = $this->request->param('Year'))) {
return (int) $year; return (int) $year;
} }
@ -751,7 +780,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|int * @return null|int
*/ */
public function getArchiveMonth() { public function getArchiveMonth()
{
$month = $this->request->param('Month'); $month = $this->request->param('Month');
if (preg_match('/^[0-9]{1,2}$/', $month)) { if (preg_match('/^[0-9]{1,2}$/', $month)) {
@ -770,7 +800,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|int * @return null|int
*/ */
public function getArchiveDay() { public function getArchiveDay()
{
$day = $this->request->param('Day'); $day = $this->request->param('Day');
if (preg_match('/^[0-9]{1,2}$/', $day)) { if (preg_match('/^[0-9]{1,2}$/', $day)) {
@ -787,7 +818,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|SS_HTTPResponse * @return null|SS_HTTPResponse
*/ */
public function tag() { public function tag()
{
$tag = $this->getCurrentTag(); $tag = $this->getCurrentTag();
if ($tag) { if ($tag) {
@ -805,7 +837,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|BlogTag * @return null|BlogTag
*/ */
public function getCurrentTag() { public function getCurrentTag()
{
/** /**
* @var Blog $dataRecord * @var Blog $dataRecord
*/ */
@ -824,7 +857,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|SS_HTTPResponse * @return null|SS_HTTPResponse
*/ */
public function category() { public function category()
{
$category = $this->getCurrentCategory(); $category = $this->getCurrentCategory();
if ($category) { if ($category) {
@ -843,7 +877,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|BlogCategory * @return null|BlogCategory
*/ */
public function getCurrentCategory() { public function getCurrentCategory()
{
/** /**
* @var Blog $dataRecord * @var Blog $dataRecord
*/ */
@ -862,7 +897,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return string * @return string
*/ */
public function getMetaTitle() { public function getMetaTitle()
{
$title = $this->data()->getTitle(); $title = $this->data()->getTitle();
$filter = $this->getFilterDescription(); $filter = $this->getFilterDescription();
@ -880,7 +916,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return string * @return string
*/ */
public function getFilterDescription() { public function getFilterDescription()
{
$items = array(); $items = array();
$list = $this->PaginatedList(); $list = $this->PaginatedList();
@ -965,7 +1002,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return PaginatedList * @return PaginatedList
*/ */
public function PaginatedList() { public function PaginatedList()
{
$allPosts = $this->blogPosts ?: new ArrayList(); $allPosts = $this->blogPosts ?: new ArrayList();
$posts = new PaginatedList($allPosts); $posts = new PaginatedList($allPosts);
@ -992,7 +1030,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return string * @return string
*/ */
public function rss() { public function rss()
{
/** /**
* @var Blog $dataRecord * @var Blog $dataRecord
*/ */
@ -1012,7 +1051,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return null|Date * @return null|Date
*/ */
public function getArchiveDate() { public function getArchiveDate()
{
$year = $this->getArchiveYear(); $year = $this->getArchiveYear();
$month = $this->getArchiveMonth(); $month = $this->getArchiveMonth();
$day = $this->getArchiveDay(); $day = $this->getArchiveDay();
@ -1039,7 +1079,8 @@ class Blog_Controller extends Page_Controller {
* *
* @return string * @return string
*/ */
public function getRSSLink() { public function getRSSLink()
{
return $this->Link('rss'); return $this->Link('rss');
} }
} }

View File

@ -11,7 +11,8 @@
* @property string $URLSegment * @property string $URLSegment
* @property int $BlogID * @property int $BlogID
*/ */
class BlogCategory extends DataObject implements CategorisationObject { class BlogCategory extends DataObject implements CategorisationObject
{
/** /**
* @var array * @var array
*/ */
@ -43,7 +44,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
/** /**
* @return DataList * @return DataList
*/ */
public function BlogPosts() { public function BlogPosts()
{
$blogPosts = parent::BlogPosts(); $blogPosts = parent::BlogPosts();
$this->extend("updateGetBlogPosts", $blogPosts); $this->extend("updateGetBlogPosts", $blogPosts);
@ -54,7 +56,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$fields = new FieldList( $fields = new FieldList(
TextField::create('Title', _t('BlogCategory.Title', 'Title')) TextField::create('Title', _t('BlogCategory.Title', 'Title'))
); );
@ -69,7 +72,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
* *
* @return string * @return string
*/ */
public function getLink() { public function getLink()
{
return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment); return Controller::join_links($this->Blog()->Link(), 'category', $this->URLSegment);
} }
@ -80,7 +84,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canView($member = null) { public function canView($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -97,7 +102,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -116,7 +122,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canDelete($member = null) { public function canDelete($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -133,7 +140,8 @@ class BlogCategory extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canEdit($member = null) { public function canEdit($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {

View File

@ -15,8 +15,8 @@
* @property string $AuthorNames * @property string $AuthorNames
* @property int $ParentID * @property int $ParentID
*/ */
class BlogPost extends Page { class BlogPost extends Page
{
/** /**
* Same as above, but for list of users that can be * Same as above, but for list of users that can be
* given credit in the author field for blog posts * given credit in the author field for blog posts
@ -122,7 +122,8 @@ class BlogPost extends Page {
* *
* @return null|string * @return null|string
*/ */
public function RoleOf($member = null) { public function RoleOf($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if (!$member) { if (!$member) {
@ -149,7 +150,8 @@ class BlogPost extends Page {
* *
* @return bool * @return bool
*/ */
public function isAuthor($member = null) { public function isAuthor($member = null)
{
if (!$member || !$member->exists()) { if (!$member || !$member->exists()) {
return false; return false;
} }
@ -166,7 +168,8 @@ class BlogPost extends Page {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
Requirements::css(BLOGGER_DIR . '/css/cms.css'); Requirements::css(BLOGGER_DIR . '/css/cms.css');
Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); Requirements::javascript(BLOGGER_DIR . '/js/cms.js');
@ -289,7 +292,8 @@ class BlogPost extends Page {
* *
* @return SS_List * @return SS_List
*/ */
public function getCandidateAuthors() { public function getCandidateAuthors()
{
if ($this->config()->restrict_authors_to_group) { if ($this->config()->restrict_authors_to_group) {
return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members(); return Group::get()->filter('Code', $this->config()->restrict_authors_to_group)->first()->Members();
} else { } else {
@ -306,7 +310,8 @@ class BlogPost extends Page {
* *
* @return bool * @return bool
*/ */
public function canEditAuthors($member = null) { public function canEditAuthors($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$extended = $this->extendedCan('canEditAuthors', $member); $extended = $this->extendedCan('canEditAuthors', $member);
@ -335,7 +340,8 @@ class BlogPost extends Page {
* *
* @return null|Member * @return null|Member
*/ */
protected function getMember($member = null) { protected function getMember($member = null)
{
if (!$member) { if (!$member) {
$member = Member::currentUser(); $member = Member::currentUser();
} }
@ -354,7 +360,8 @@ class BlogPost extends Page {
* *
* @return bool * @return bool
*/ */
public function canCreateCategories($member = null) { public function canCreateCategories($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$parent = $this->Parent(); $parent = $this->Parent();
@ -377,7 +384,8 @@ class BlogPost extends Page {
* *
* @return bool * @return bool
*/ */
public function canCreateTags($member = null) { public function canCreateTags($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
$parent = $this->Parent(); $parent = $this->Parent();
@ -402,7 +410,8 @@ class BlogPost extends Page {
* *
* Update the PublishDate to now if the BlogPost would otherwise be published without a date. * Update the PublishDate to now if the BlogPost would otherwise be published without a date.
*/ */
public function onBeforePublish() { public function onBeforePublish()
{
/** /**
* @var SS_Datetime $publishDate * @var SS_Datetime $publishDate
*/ */
@ -419,7 +428,8 @@ class BlogPost extends Page {
* *
* Sets blog relationship on all categories and tags assigned to this post. * Sets blog relationship on all categories and tags assigned to this post.
*/ */
public function onAfterWrite() { public function onAfterWrite()
{
parent::onAfterWrite(); parent::onAfterWrite();
foreach ($this->Categories() as $category) { foreach ($this->Categories() as $category) {
@ -442,7 +452,8 @@ class BlogPost extends Page {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canView($member = null) { public function canView($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if (!parent::canView($member)) { if (!parent::canView($member)) {
@ -466,7 +477,8 @@ class BlogPost extends Page {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canPublish($member = null) { public function canPublish($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if (Permission::checkMember($member, 'ADMIN')) { if (Permission::checkMember($member, 'ADMIN')) {
@ -501,7 +513,8 @@ class BlogPost extends Page {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function canEdit($member = null) { public function canEdit($member = null)
{
$member = $this->getMember($member); $member = $this->getMember($member);
if (parent::canEdit($member)) { if (parent::canEdit($member)) {
@ -532,7 +545,8 @@ class BlogPost extends Page {
* *
* @return string * @return string
*/ */
public function Excerpt($wordsToDisplay = 30) { public function Excerpt($wordsToDisplay = 30)
{
/** /**
* @var Text $content * @var Text $content
*/ */
@ -548,7 +562,8 @@ class BlogPost extends Page {
* *
* @return string * @return string
*/ */
public function getMonthlyArchiveLink($type = 'day') { public function getMonthlyArchiveLink($type = 'day')
{
/** /**
* @var SS_Datetime $date * @var SS_Datetime $date
*/ */
@ -575,7 +590,8 @@ class BlogPost extends Page {
* *
* @return string * @return string
*/ */
public function getYearlyArchiveLink() { public function getYearlyArchiveLink()
{
/** /**
* @var SS_Datetime $date * @var SS_Datetime $date
*/ */
@ -589,7 +605,8 @@ class BlogPost extends Page {
* *
* @return ArrayList * @return ArrayList
*/ */
public function getCredits() { public function getCredits()
{
$list = new ArrayList(); $list = new ArrayList();
$list->merge($this->getDynamicCredits()); $list->merge($this->getDynamicCredits());
@ -603,7 +620,8 @@ class BlogPost extends Page {
* *
* @return ArrayList * @return ArrayList
*/ */
protected function getDynamicCredits() { protected function getDynamicCredits()
{
// Find best page to host user profiles // Find best page to host user profiles
$parent = $this->Parent(); $parent = $this->Parent();
if (! ($parent instanceof Blog)) { if (! ($parent instanceof Blog)) {
@ -634,7 +652,8 @@ class BlogPost extends Page {
* *
* @return ArrayList * @return ArrayList
*/ */
protected function getStaticCredits() { protected function getStaticCredits()
{
$items = new ArrayList(); $items = new ArrayList();
$authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames)); $authors = array_filter(preg_split('/\s*,\s*/', $this->AuthorNames));
@ -657,7 +676,8 @@ class BlogPost extends Page {
* *
* @return array * @return array
*/ */
public function fieldLabels($includeRelations = true) { public function fieldLabels($includeRelations = true)
{
$labels = parent::fieldLabels($includeRelations); $labels = parent::fieldLabels($includeRelations);
$labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title'); $labels['Title'] = _t('BlogPost.PageTitleLabel', 'Post Title');
@ -668,7 +688,8 @@ class BlogPost extends Page {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function onBeforeWrite() { protected function onBeforeWrite()
{
parent::onBeforeWrite(); parent::onBeforeWrite();
if (!$this->exists() && ($member = Member::currentUser())) { if (!$this->exists() && ($member = Member::currentUser())) {
@ -681,6 +702,6 @@ class BlogPost extends Page {
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogPost_Controller extends Page_Controller { class BlogPost_Controller extends Page_Controller
{
} }

View File

@ -12,7 +12,8 @@
* @property string $URLSegment * @property string $URLSegment
* @property int $BlogID * @property int $BlogID
*/ */
class BlogTag extends DataObject implements CategorisationObject { class BlogTag extends DataObject implements CategorisationObject
{
/** /**
* @var array * @var array
*/ */
@ -44,7 +45,8 @@ class BlogTag extends DataObject implements CategorisationObject {
/** /**
* @return DataList * @return DataList
*/ */
public function BlogPosts() { public function BlogPosts()
{
$blogPosts = parent::BlogPosts(); $blogPosts = parent::BlogPosts();
$this->extend("updateGetBlogPosts", $blogPosts); $this->extend("updateGetBlogPosts", $blogPosts);
@ -55,7 +57,8 @@ class BlogTag extends DataObject implements CategorisationObject {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$fields = new FieldList( $fields = new FieldList(
TextField::create('Title', _t('BlogTag.Title', 'Title')) TextField::create('Title', _t('BlogTag.Title', 'Title'))
); );
@ -70,7 +73,8 @@ class BlogTag extends DataObject implements CategorisationObject {
* *
* @return string * @return string
*/ */
public function getLink() { public function getLink()
{
return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment); return Controller::join_links($this->Blog()->Link(), 'tag', $this->URLSegment);
} }
@ -81,7 +85,8 @@ class BlogTag extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canView($member = null) { public function canView($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -98,7 +103,8 @@ class BlogTag extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canCreate($member = null) { public function canCreate($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -117,7 +123,8 @@ class BlogTag extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canDelete($member = null) { public function canDelete($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {
@ -134,7 +141,8 @@ class BlogTag extends DataObject implements CategorisationObject {
* *
* @return bool * @return bool
*/ */
public function canEdit($member = null) { public function canEdit($member = null)
{
$extended = $this->extendedCan(__FUNCTION__, $member); $extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) { if ($extended !== null) {

View File

@ -3,6 +3,6 @@
/** /**
* @method ManyManyList BlogPosts * @method ManyManyList BlogPosts
*/ */
interface CategorisationObject { interface CategorisationObject
{
} }

View File

@ -10,7 +10,8 @@ if(!class_exists('Widget')) {
* @property string $ArchiveType * @property string $ArchiveType
* @property int $NumberToDisplay * @property int $NumberToDisplay
*/ */
class BlogArchiveWidget extends Widget { class BlogArchiveWidget extends Widget
{
/** /**
* @var string * @var string
*/ */
@ -51,7 +52,8 @@ class BlogArchiveWidget extends Widget {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$self =& $this; $self =& $this;
$this->beforeUpdateCMSFields(function ($fields) use ($self) { $this->beforeUpdateCMSFields(function ($fields) use ($self) {
@ -84,7 +86,8 @@ class BlogArchiveWidget extends Widget {
* *
* @return DataList * @return DataList
*/ */
public function getArchive() { public function getArchive()
{
$query = $this->Blog()->getBlogPosts()->dataQuery(); $query = $this->Blog()->getBlogPosts()->dataQuery();
if ($this->ArchiveType == 'Yearly') { if ($this->ArchiveType == 'Yearly') {
@ -130,6 +133,6 @@ class BlogArchiveWidget extends Widget {
} }
} }
class BlogArchiveWidget_Controller extends Widget_Controller { class BlogArchiveWidget_Controller extends Widget_Controller
{
} }

View File

@ -7,7 +7,8 @@ if(!class_exists("Widget")) {
/** /**
* @method Blog Blog() * @method Blog Blog()
*/ */
class BlogCategoriesWidget extends Widget { class BlogCategoriesWidget extends Widget
{
/** /**
* @var string * @var string
*/ */
@ -42,7 +43,8 @@ class BlogCategoriesWidget extends Widget {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$this->beforeUpdateCMSFields(function (FieldList $fields) { $this->beforeUpdateCMSFields(function (FieldList $fields) {
$fields[] = DropdownField::create( $fields[] = DropdownField::create(
'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map() 'BlogID', _t('BlogCategoriesWidget.Blog', 'Blog'), Blog::get()->map()
@ -71,7 +73,8 @@ class BlogCategoriesWidget extends Widget {
/** /**
* @return DataList * @return DataList
*/ */
public function getCategories() { public function getCategories()
{
$blog = $this->Blog(); $blog = $this->Blog();
if (!$blog) { if (!$blog) {
@ -92,6 +95,6 @@ class BlogCategoriesWidget extends Widget {
} }
} }
class BlogCategoriesWidget_Controller extends Widget_Controller { class BlogCategoriesWidget_Controller extends Widget_Controller
{
} }

View File

@ -9,7 +9,8 @@ if(!class_exists("Widget")) {
* *
* @property int $NumberOfPosts * @property int $NumberOfPosts
*/ */
class BlogRecentPostsWidget extends Widget { class BlogRecentPostsWidget extends Widget
{
/** /**
* @var string * @var string
*/ */
@ -42,7 +43,8 @@ class BlogRecentPostsWidget extends Widget {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$this->beforeUpdateCMSFields(function ($fields) { $this->beforeUpdateCMSFields(function ($fields) {
/** /**
* @var FieldList $fields * @var FieldList $fields
@ -59,7 +61,8 @@ class BlogRecentPostsWidget extends Widget {
/** /**
* @return array * @return array
*/ */
public function getPosts() { public function getPosts()
{
$blog = $this->Blog(); $blog = $this->Blog();
if ($blog) { if ($blog) {
@ -72,6 +75,6 @@ class BlogRecentPostsWidget extends Widget {
} }
} }
class BlogRecentPostsWidget_Controller extends Widget_Controller { class BlogRecentPostsWidget_Controller extends Widget_Controller
{
} }

View File

@ -7,7 +7,8 @@ if(!class_exists("Widget")) {
/** /**
* @method Blog Blog() * @method Blog Blog()
*/ */
class BlogTagsWidget extends Widget { class BlogTagsWidget extends Widget
{
/** /**
* @var string * @var string
*/ */
@ -42,7 +43,8 @@ class BlogTagsWidget extends Widget {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCMSFields() { public function getCMSFields()
{
$this->beforeUpdateCMSFields(function (Fieldlist $fields) { $this->beforeUpdateCMSFields(function (Fieldlist $fields) {
$fields[] = DropdownField::create( $fields[] = DropdownField::create(
'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map() 'BlogID', _t('BlogTagsWidget.Blog', 'Blog'), Blog::get()->map()
@ -71,7 +73,8 @@ class BlogTagsWidget extends Widget {
/** /**
* @return DataList * @return DataList
*/ */
public function getTags() { public function getTags()
{
$blog = $this->Blog(); $blog = $this->Blog();
if (!$blog) { if (!$blog) {
@ -92,6 +95,6 @@ class BlogTagsWidget extends Widget {
} }
} }
class BlogTagsWidget_Controller extends Widget_Controller { class BlogTagsWidget_Controller extends Widget_Controller
{
} }

View File

@ -3,16 +3,18 @@
/** /**
* @mixin PHPUnit_Framework_TestCase * @mixin PHPUnit_Framework_TestCase
*/ */
class BlogCategoryTest extends FunctionalTest { class BlogCategoryTest extends FunctionalTest
{
/** /**
* @var string * @var string
*/ */
static $fixture_file = 'blog.yml'; public static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp() { public function setUp()
{
parent::setUp(); parent::setUp();
SS_Datetime::set_mock_now('2013-10-10 20:00:00'); SS_Datetime::set_mock_now('2013-10-10 20:00:00');
@ -21,7 +23,8 @@ class BlogCategoryTest extends FunctionalTest {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function tearDown() { public function tearDown()
{
SS_Datetime::clear_mock_now(); SS_Datetime::clear_mock_now();
parent::tearDown(); parent::tearDown();
@ -31,7 +34,8 @@ class BlogCategoryTest extends FunctionalTest {
* Tests that any blog posts returned from $category->BlogPosts() many_many are published, * Tests that any blog posts returned from $category->BlogPosts() many_many are published,
* both by normal 'save & publish' functionality and by publish date. * both by normal 'save & publish' functionality and by publish date.
*/ */
public function testBlogPosts() { public function testBlogPosts()
{
$member = Member::currentUser(); $member = Member::currentUser();
if ($member) { if ($member) {
@ -48,7 +52,8 @@ class BlogCategoryTest extends FunctionalTest {
$this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count'); $this->assertEquals(1, $category->BlogPosts()->count(), 'Category blog post count');
} }
public function testCanView() { public function testCanView()
{
$this->useDraftSite(); $this->useDraftSite();
$this->objFromFixture('Member', 'Admin'); $this->objFromFixture('Member', 'Admin');
@ -62,7 +67,8 @@ class BlogCategoryTest extends FunctionalTest {
/** /**
* The first blog can be viewed by anybody. * The first blog can be viewed by anybody.
*/ */
public function testCanEdit() { public function testCanEdit()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');
@ -84,7 +90,8 @@ class BlogCategoryTest extends FunctionalTest {
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
} }
public function testCanCreate() { public function testCanCreate()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');
@ -96,7 +103,8 @@ class BlogCategoryTest extends FunctionalTest {
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); $this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
} }
public function testCanDelete() { public function testCanDelete()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');

View File

@ -3,25 +3,29 @@
/** /**
* @mixin PHPUnit_Framework_TestCase * @mixin PHPUnit_Framework_TestCase
*/ */
class BlogPostFilterTest extends SapphireTest { class BlogPostFilterTest extends SapphireTest
{
/** /**
* @var string * @var string
*/ */
static $fixture_file = 'blog.yml'; public static $fixture_file = 'blog.yml';
public function setUp() { public function setUp()
{
parent::setUp(); parent::setUp();
SS_Datetime::set_mock_now('2013-10-10 20:00:00'); SS_Datetime::set_mock_now('2013-10-10 20:00:00');
} }
public function tearDown() { public function tearDown()
{
SS_Datetime::clear_mock_now(); SS_Datetime::clear_mock_now();
parent::tearDown(); parent::tearDown();
} }
public function testFilter() { public function testFilter()
{
$member = Member::currentUser(); $member = Member::currentUser();
if ($member) { if ($member) {

View File

@ -1,23 +1,25 @@
<?php <?php
class BlogPostTest extends SapphireTest { class BlogPostTest extends SapphireTest
{
/** /**
* @var string * @var string
*/ */
static $fixture_file = 'blog.yml'; public static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp() { public function setUp()
{
parent::setUp(); parent::setUp();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function tearDown() { public function tearDown()
{
SS_Datetime::clear_mock_now(); SS_Datetime::clear_mock_now();
parent::tearDown(); parent::tearDown();
} }
@ -25,14 +27,16 @@ class BlogPostTest extends SapphireTest {
/** /**
* @dataProvider canViewProvider * @dataProvider canViewProvider
*/ */
public function testCanView($date, $user, $page, $canView) { public function testCanView($date, $user, $page, $canView)
{
$userRecord = $this->objFromFixture('Member', $user); $userRecord = $this->objFromFixture('Member', $user);
$pageRecord = $this->objFromFixture('BlogPost', $page); $pageRecord = $this->objFromFixture('BlogPost', $page);
SS_Datetime::set_mock_now($date); SS_Datetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord)); $this->assertEquals($canView, $pageRecord->canView($userRecord));
} }
public function canViewProvider() { public function canViewProvider()
{
$someFutureDate = '2013-10-10 20:00:00'; $someFutureDate = '2013-10-10 20:00:00';
$somePastDate = '2009-10-10 20:00:00'; $somePastDate = '2009-10-10 20:00:00';
return array( return array(
@ -64,7 +68,8 @@ class BlogPostTest extends SapphireTest {
); );
} }
public function testCandidateAuthors() { public function testCandidateAuthors()
{
$blogpost = $this->objFromFixture('BlogPost', 'PostC'); $blogpost = $this->objFromFixture('BlogPost', 'PostC');
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
@ -73,7 +78,5 @@ class BlogPostTest extends SapphireTest {
Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'BlogUsers'); Config::inst()->update('BlogPost', 'restrict_authors_to_group', 'BlogUsers');
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); $this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
} }
} }

View File

@ -3,16 +3,18 @@
/** /**
* @mixin PHPUnit_Framework_TestCase * @mixin PHPUnit_Framework_TestCase
*/ */
class BlogTagTest extends FunctionalTest { class BlogTagTest extends FunctionalTest
{
/** /**
* @var string * @var string
*/ */
static $fixture_file = 'blog.yml'; public static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp() { public function setUp()
{
parent::setUp(); parent::setUp();
SS_Datetime::set_mock_now('2013-10-10 20:00:00'); SS_Datetime::set_mock_now('2013-10-10 20:00:00');
@ -21,7 +23,8 @@ class BlogTagTest extends FunctionalTest {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function tearDown() { public function tearDown()
{
SS_Datetime::clear_mock_now(); SS_Datetime::clear_mock_now();
parent::tearDown(); parent::tearDown();
@ -31,7 +34,8 @@ class BlogTagTest extends FunctionalTest {
* Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by * Tests that any blog posts returned from $tag->BlogPosts() many_many are published, both by
* normal 'save & publish' functionality and by publish date. * normal 'save & publish' functionality and by publish date.
*/ */
public function testBlogPosts() { public function testBlogPosts()
{
$member = Member::currentUser(); $member = Member::currentUser();
if ($member) { if ($member) {
@ -51,7 +55,8 @@ class BlogTagTest extends FunctionalTest {
/** /**
* The first blog can be viewed by anybody. * The first blog can be viewed by anybody.
*/ */
public function testCanView() { public function testCanView()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');
@ -68,7 +73,8 @@ class BlogTagTest extends FunctionalTest {
$this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.'); $this->assertFalse($tag->canView($editor), 'Editor should not be able to view tag.');
} }
public function testCanEdit() { public function testCanEdit()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');
@ -90,7 +96,8 @@ class BlogTagTest extends FunctionalTest {
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
} }
public function testCanCreate() { public function testCanCreate()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');
@ -102,7 +109,8 @@ class BlogTagTest extends FunctionalTest {
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); $this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
} }
public function testCanDelete() { public function testCanDelete()
{
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('Member', 'Admin'); $admin = $this->objFromFixture('Member', 'Admin');

View File

@ -3,16 +3,18 @@
/** /**
* @mixin PHPUnit_Framework_TestCase * @mixin PHPUnit_Framework_TestCase
*/ */
class BlogTest extends SapphireTest { class BlogTest extends SapphireTest
{
/** /**
* @var string * @var string
*/ */
static $fixture_file = 'blog.yml'; public static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function setUp() { public function setUp()
{
parent::setUp(); parent::setUp();
Config::nest(); Config::nest();
@ -29,14 +31,16 @@ class BlogTest extends SapphireTest {
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function tearDown() { public function tearDown()
{
SS_Datetime::clear_mock_now(); SS_Datetime::clear_mock_now();
Config::unnest(); Config::unnest();
parent::tearDown(); parent::tearDown();
} }
public function testGetExcludedSiteTreeClassNames() { public function testGetExcludedSiteTreeClassNames()
{
$member = Member::currentUser(); $member = Member::currentUser();
if ($member) { if ($member) {
@ -59,7 +63,8 @@ class BlogTest extends SapphireTest {
$this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.'); $this->assertContains('BlogPost', $classes, 'BlogPost class should be hidden.');
} }
public function testGetArchivedBlogPosts() { public function testGetArchivedBlogPosts()
{
$member = Member::currentUser(); $member = Member::currentUser();
if ($member) { if ($member) {
@ -86,7 +91,8 @@ class BlogTest extends SapphireTest {
$this->assertEquals(1, $archive->count(), 'Incorrect daily archive count.'); $this->assertEquals(1, $archive->count(), 'Incorrect daily archive count.');
} }
public function testArchiveLinks() { public function testArchiveLinks()
{
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
@ -122,13 +128,13 @@ class BlogTest extends SapphireTest {
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '99'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '99');
$this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404'); $this->assertEquals(404, $this->getStatusOf($link), 'HTTP Status should be 404');
} }
/* /*
* Test archive year * Test archive year
*/ */
public function testArchiveYear(){ public function testArchiveYear()
{
$blog = $this->objFromFixture('Blog', 'FirstBlog'); $blog = $this->objFromFixture('Blog', 'FirstBlog');
$controller = new Blog_Controller($blog); $controller = new Blog_Controller($blog);
$this->requestURL($controller, 'first-post/archive/'); $this->requestURL($controller, 'first-post/archive/');
@ -140,11 +146,13 @@ class BlogTest extends SapphireTest {
* *
* @return int * @return int
*/ */
protected function getStatusOf($link) { protected function getStatusOf($link)
{
return Director::test($link)->getStatusCode(); return Director::test($link)->getStatusCode();
} }
public function testRoles() { public function testRoles()
{
/** /**
* @var Blog $firstBlog * @var Blog $firstBlog
*/ */
@ -264,7 +272,8 @@ class BlogTest extends SapphireTest {
$this->assertFalse($postC->canPublish($visitor)); $this->assertFalse($postC->canPublish($visitor));
} }
public function testFilteredCategories() { public function testFilteredCategories()
{
$blog = $this->objFromFixture('Blog', 'FirstBlog'); $blog = $this->objFromFixture('Blog', 'FirstBlog');
$controller = new Blog_Controller($blog); $controller = new Blog_Controller($blog);
@ -310,7 +319,8 @@ class BlogTest extends SapphireTest {
* @param ContentController $controller * @param ContentController $controller
* @param string $url * @param string $url
*/ */
protected function requestURL(ContentController $controller, $url) { protected function requestURL(ContentController $controller, $url)
{
$request = new SS_HTTPRequest('get', $url); $request = new SS_HTTPRequest('get', $url);
$request->match('$URLSegment//$Action/$ID/$OtherID'); $request->match('$URLSegment//$Action/$ID/$OtherID');
$request->shift(); $request->shift();
@ -324,9 +334,14 @@ class BlogTest extends SapphireTest {
* @param array|SS_List $left * @param array|SS_List $left
* @param array|SS_List $right * @param array|SS_List $right
*/ */
protected function assertIDsEquals($left, $right) { protected function assertIDsEquals($left, $right)
if($left instanceof SS_List) $left = $left->column('ID'); {
if($right instanceof SS_List) $right = $right->column('ID'); if ($left instanceof SS_List) {
$left = $left->column('ID');
}
if ($right instanceof SS_List) {
$right = $right->column('ID');
}
asort($left); asort($left);
asort($right); asort($right);
$this->assertEquals(array_values($left), array_values($right)); $this->assertEquals(array_values($left), array_values($right));