FIX Update class imports, fix broken test, add missing multibyte logic back, fix condition for generating URLSegment (also missing)

This commit is contained in:
Robbie Averill 2017-01-26 21:28:42 +13:00
parent ea121e40da
commit c004bad7b8
16 changed files with 151 additions and 118 deletions

View File

@ -22,7 +22,8 @@
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"SilverStripe\\Blog\\": "src/" "SilverStripe\\Blog\\": "src/",
"SilverStripe\\Blog\\Tests\\": "tests/"
} }
}, },
"license": "BSD-2-Clause", "license": "BSD-2-Clause",

View File

@ -2,8 +2,8 @@
namespace SilverStripe\Blog\Forms; namespace SilverStripe\Blog\Forms;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Control\Cookie; use SilverStripe\Control\Cookie;
use SilverStripe\Forms\FieldGroup;
class BlogAdminSidebar extends FieldGroup class BlogAdminSidebar extends FieldGroup
{ {

View File

@ -209,10 +209,6 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$forTemplate->Fields->push($textField); $forTemplate->Fields->push($textField);
$forTemplate->Fields->push($addAction); $forTemplate->Fields->push($addAction);
return array( return array($this->targetFragment => $forTemplate->renderWith(self::class));
$this->targetFragment => $forTemplate->renderWith(
'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField'
)
);
} }
} }

View File

@ -6,6 +6,10 @@ use Page;
use PageController; use PageController;
use SilverStripe\Blog\Admin\GridFieldCategorisationConfig; use SilverStripe\Blog\Admin\GridFieldCategorisationConfig;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\Blog\Model\BlogCategory;
use SilverStripe\Blog\Model\BlogFilter;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\CMS\Controllers\RootURLController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\Control\RSS\RSSFeed;
@ -92,31 +96,31 @@ class Blog extends Page implements PermissionProvider
* @var array * @var array
*/ */
private static $has_many = array( private static $has_many = array(
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags' => BlogTag::class,
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories' => BlogCategory::class,
); );
/** /**
* @var array * @var array
*/ */
private static $many_many = array( private static $many_many = array(
'Editors' => 'SilverStripe\\Security\\Member', 'Editors' => Member::class,
'Writers' => 'SilverStripe\\Security\\Member', 'Writers' => Member::class,
'Contributors' => 'SilverStripe\\Security\\Member', 'Contributors' => Member::class,
); );
/** /**
* @var array * @var array
*/ */
private static $allowed_children = array( private static $allowed_children = array(
'SilverStripe\\Blog\\Model\\BlogPost', BlogPost::class,
); );
/** /**
* @var array * @var array
*/ */
private static $extensions = array( private static $extensions = array(
'SilverStripe\\Blog\\Model\\BlogFilter', BlogFilter::class,
); );
/** /**

View File

@ -2,7 +2,9 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogObject; use SilverStripe\Blog\Model\BlogObject;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\CategorisationObject; use SilverStripe\Blog\Model\CategorisationObject;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
@ -49,14 +51,14 @@ class BlogCategory extends DataObject implements CategorisationObject
* @var array * @var array
*/ */
private static $has_one = array( private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog', 'Blog' => Blog::class,
); );
/** /**
* @var array * @var array
*/ */
private static $belongs_many_many = array( private static $belongs_many_many = array(
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost', 'BlogPosts' => BlogPost::class,
); );
/** /**

View File

@ -2,7 +2,9 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use SilverStripe\Assets\Image;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField; use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\Tab; use SilverStripe\Forms\Tab;
@ -31,14 +33,14 @@ class BlogMemberExtension extends DataExtension
* @var array * @var array
*/ */
private static $has_one = array( private static $has_one = array(
'BlogProfileImage' => 'SilverStripe\\Assets\\Image' 'BlogProfileImage' => Image::class
); );
/** /**
* @var array * @var array
*/ */
private static $belongs_many_many = array( private static $belongs_many_many = array(
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' 'BlogPosts' => BlogPost::class
); );
/** /**

View File

@ -164,7 +164,7 @@ trait BlogObject
protected function onBeforeWrite() protected function onBeforeWrite()
{ {
parent::onBeforeWrite(); parent::onBeforeWrite();
if (empty($this->URLSegment)) { if ($this->exists() || empty($this->URLSegment)) {
return $this->generateURLSegment(); return $this->generateURLSegment();
} }
} }
@ -181,6 +181,12 @@ trait BlogObject
$increment = (int) $increment; $increment = (int) $increment;
$filter = URLSegmentFilter::create(); $filter = URLSegmentFilter::create();
// Setting this to on. Because of the UI flow, it would be quite a lot of work
// to support turning this off. (ie. the add by title flow would not work).
// If this becomes a problem we can approach it then.
// @see https://github.com/silverstripe/silverstripe-blog/issues/376
$filter->setAllowMultibyte(true);
$this->URLSegment = $filter->filter($this->Title); $this->URLSegment = $filter->filter($this->Title);
if ($increment > 0) { if ($increment > 0) {

View File

@ -3,7 +3,11 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use Page; use Page;
use SilverStripe\Assets\Image;
use SilverStripe\Blog\Forms\BlogAdminSidebar; use SilverStripe\Blog\Forms\BlogAdminSidebar;
use SilverStripe\Blog\Model\BlogCategory;
use SilverStripe\Blog\Model\BlogPostFilter;
use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Forms\DatetimeField; use SilverStripe\Forms\DatetimeField;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
@ -65,15 +69,15 @@ class BlogPost extends Page
* @var array * @var array
*/ */
private static $has_one = array( private static $has_one = array(
'FeaturedImage' => 'SilverStripe\\Assets\\Image' 'FeaturedImage' => Image::class
); );
/** /**
* @var array * @var array
*/ */
private static $many_many = array( private static $many_many = array(
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories' => BlogCategory::class,
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags' => BlogTag::class,
'Authors' => Member::class 'Authors' => Member::class
); );
@ -90,7 +94,7 @@ class BlogPost extends Page
* @var array * @var array
*/ */
private static $extensions = array( private static $extensions = array(
'SilverStripe\\Blog\\Model\\BlogPostFilter' BlogPostFilter::class
); );
/** /**

View File

@ -3,7 +3,9 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogObject; use SilverStripe\Blog\Model\BlogObject;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\CategorisationObject; use SilverStripe\Blog\Model\CategorisationObject;
/** /**
@ -49,14 +51,14 @@ class BlogTag extends DataObject implements CategorisationObject
* @var array * @var array
*/ */
private static $has_one = array( private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog' 'Blog' => Blog::class
); );
/** /**
* @var array * @var array
*/ */
private static $belongs_many_many = array( private static $belongs_many_many = array(
'BlogPosts' => 'SilverStripe\\Blog\\Model\\BlogPost' 'BlogPosts' => BlogPost::class
); );
/** /**

View File

@ -1,8 +1,12 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogCategory; use SilverStripe\Blog\Model\BlogCategory;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationException; use SilverStripe\ORM\ValidationException;
@ -16,7 +20,7 @@ class BlogCategoryTest extends FunctionalTest
/** /**
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -50,12 +54,12 @@ class BlogCategoryTest extends FunctionalTest
$member->logout(); $member->logout();
} }
$this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
/** /**
* @var BlogCategory $category * @var BlogCategory $category
*/ */
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count'); $this->assertEquals(5, $category->BlogPosts()->count(), 'Category blog post count');
} }
@ -65,7 +69,7 @@ class BlogCategoryTest extends FunctionalTest
*/ */
public function testAllowMultibyteUrlSegment() public function testAllowMultibyteUrlSegment()
{ {
$blog = $this->objFromFixture('Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$cat = new BlogCategory(); $cat = new BlogCategory();
$cat->BlogID = $blog->ID; $cat->BlogID = $blog->ID;
$cat->Title = 'تست'; $cat->Title = 'تست';
@ -80,10 +84,10 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertFalse($category->canView($editor), 'Editor should not be able to view category.'); $this->assertFalse($category->canView($editor), 'Editor should not be able to view category.');
} }
@ -95,20 +99,20 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should be able to edit category.');
$this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.'); $this->assertFalse($category->canEdit($editor), 'Editor should not be able to edit category.');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory');
$this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.'); $this->assertTrue($category->canEdit($admin), 'Admin should always be able to edit category.');
$this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.'); $this->assertTrue($category->canEdit($editor), 'Editor should be able to edit category.');
@ -118,10 +122,10 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = singleton('SilverStripe\\Blog\\Model\\BlogCategory'); $category = singleton(BlogCategory::class);
$this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.'); $this->assertTrue($category->canCreate($admin), 'Admin should be able to create category.');
$this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.'); $this->assertTrue($category->canCreate($editor), 'Editor should be able to create category.');
@ -131,19 +135,19 @@ class BlogCategoryTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'FirstCategory'); $category = $this->objFromFixture(BlogCategory::class, 'FirstCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to category category.');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'SecondCategory'); $category = $this->objFromFixture(BlogCategory::class, 'SecondCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should be able to delete category.');
$this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.'); $this->assertFalse($category->canDelete($editor), 'Editor should not be able to delete category.');
$category = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogCategory', 'ThirdCategory'); $category = $this->objFromFixture(BlogCategory::class, 'ThirdCategory');
$this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.'); $this->assertTrue($category->canDelete($admin), 'Admin should always be able to delete category.');
$this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.'); $this->assertTrue($category->canDelete($editor), 'Editor should be able to delete category.');
} }

View File

@ -1,5 +1,8 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
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\Member;
@ -13,7 +16,7 @@ class BlogPostFilterTest extends SapphireTest
/** /**
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
public function setUp() public function setUp()
{ {
@ -44,7 +47,7 @@ class BlogPostFilterTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts'); $this->assertEquals(3, $blog->AllChildren()->Count(), 'Filtered blog posts');

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost; use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
@ -9,7 +11,7 @@ class BlogPostNotificationsTest extends SapphireTest
* {@inheritDoc} * {@inheritDoc}
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
public function testUpdateNotificationRecipients() public function testUpdateNotificationRecipients()
{ {
@ -43,7 +45,7 @@ class BlogPostNotificationsTest extends SapphireTest
$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 use SilverStripe\Comments\Model\Comment(); $comment = new SilverStripe\Comments\Model\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

@ -1,8 +1,12 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member;
class BlogPostTest extends SapphireTest class BlogPostTest extends SapphireTest
{ {
@ -10,15 +14,7 @@ class BlogPostTest extends SapphireTest
* {@inheritDoc} * {@inheritDoc}
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -34,8 +30,8 @@ class BlogPostTest extends SapphireTest
*/ */
public function testCanView($date, $user, $page, $canView) public function testCanView($date, $user, $page, $canView)
{ {
$userRecord = $this->objFromFixture('SilverStripe\\Security\\Member', $user); $userRecord = $this->objFromFixture(Member::class, $user);
$pageRecord = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', $page); $pageRecord = $this->objFromFixture(BlogPost::class, $page);
DBDatetime::set_mock_now($date); DBDatetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord)); $this->assertEquals($canView, $pageRecord->canView($userRecord));
} }
@ -78,12 +74,12 @@ class BlogPostTest extends SapphireTest
public function testCandidateAuthors() public function testCandidateAuthors()
{ {
$blogpost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); $blogpost = $this->objFromFixture(BlogPost::class, 'PostC');
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count()); $this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
//Set the group to draw Members from //Set the group to draw Members from
Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'restrict_authors_to_group', 'blogusers'); Config::inst()->update(BlogPost::class, 'restrict_authors_to_group', 'blogusers');
$this->assertEquals(3, $blogpost->getCandidateAuthors()->count()); $this->assertEquals(3, $blogpost->getCandidateAuthors()->count());
@ -94,12 +90,12 @@ class BlogPostTest extends SapphireTest
public function testCanViewFuturePost() public function testCanViewFuturePost()
{ {
$blogPost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'NullPublishDate'); $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); $editor = $this->objFromFixture(Member::class, 'BlogEditor');
$this->assertTrue($blogPost->canView($editor)); $this->assertTrue($blogPost->canView($editor));
$visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); $visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertFalse($blogPost->canView($visitor)); $this->assertFalse($blogPost->canView($visitor));
} }
@ -109,10 +105,10 @@ class BlogPostTest extends SapphireTest
*/ */
public function testGetDate() public function testGetDate()
{ {
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate'); $blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$this->assertNull($blogPost->getDate()); $this->assertNull($blogPost->getDate());
$blogPost = $this->objFromFixture('BlogPost', 'PostA'); $blogPost = $this->objFromFixture(BlogPost::class, 'PostA');
$this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate()); $this->assertEquals('2012-01-09 15:00:00', $blogPost->getDate());
} }
} }

View File

@ -1,7 +1,11 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog; use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\BlogTag; use SilverStripe\Blog\Model\BlogTag;
use SilverStripe\Control\Controller;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\ORM\ValidationException; use SilverStripe\ORM\ValidationException;
@ -16,7 +20,7 @@ class BlogTagTest extends FunctionalTest
* {@inheritDoc} * {@inheritDoc}
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -50,12 +54,12 @@ class BlogTagTest extends FunctionalTest
$member->logout(); $member->logout();
} }
$this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); $this->objFromFixture(BlogPost::class, 'FirstBlogPost');
/** /**
* @var BlogTag $tag * @var BlogTag $tag
*/ */
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count'); $this->assertEquals(1, $tag->BlogPosts()->count(), 'Tag blog post count');
} }
@ -65,7 +69,7 @@ class BlogTagTest extends FunctionalTest
*/ */
public function testAllowMultibyteUrlSegment() public function testAllowMultibyteUrlSegment()
{ {
$blog = $this->objFromFixture('Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$tag = new BlogTag(); $tag = new BlogTag();
$tag->BlogID = $blog->ID; $tag->BlogID = $blog->ID;
$tag->Title = 'تست'; $tag->Title = 'تست';
@ -83,15 +87,15 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
$this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.'); $this->assertTrue($tag->canView($editor), 'Editor should be able to view tag.');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.'); $this->assertTrue($tag->canView($admin), 'Admin should be able to view tag.');
$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.');
@ -101,20 +105,20 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.'); $this->assertTrue($tag->canEdit($admin), 'Admin should be able to edit tag.');
$this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.'); $this->assertFalse($tag->canEdit($editor), 'Editor should not be able to edit tag.');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag');
$this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.'); $this->assertTrue($tag->canEdit($admin), 'Admin should always be able to edit tags.');
$this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.'); $this->assertTrue($tag->canEdit($editor), 'Editor should be able to edit tag.');
@ -124,10 +128,10 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = singleton('SilverStripe\\Blog\\Model\\BlogTag'); $tag = singleton(BlogTag::class);
$this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.'); $this->assertTrue($tag->canCreate($admin), 'Admin should be able to create tag.');
$this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.'); $this->assertTrue($tag->canCreate($editor), 'Editor should be able to create tag.');
@ -137,20 +141,20 @@ class BlogTagTest extends FunctionalTest
{ {
$this->useDraftSite(); $this->useDraftSite();
$admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'Admin'); $admin = $this->objFromFixture(Member::class, 'Admin');
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Editor'); $editor = $this->objFromFixture(Member::class, 'Editor');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'FirstTag'); $tag = $this->objFromFixture(BlogTag::class, 'FirstTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'SecondTag'); $tag = $this->objFromFixture(BlogTag::class, 'SecondTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.'); $this->assertTrue($tag->canDelete($admin), 'Admin should be able to delete tag.');
$this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.'); $this->assertFalse($tag->canDelete($editor), 'Editor should not be able to delete tag.');
$tag = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogTag', 'ThirdTag'); $tag = $this->objFromFixture(BlogTag::class, 'ThirdTag');
$this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.'); $this->assertTrue($tag->canDelete($admin), 'Admin should always be able to delete tags.');
$this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.'); $this->assertTrue($tag->canDelete($editor), 'Editor should be able to delete tag.');

View File

@ -1,6 +1,9 @@
<?php <?php
use SilverStripe\Blog\Model\Blog\BlogTagsCloudWidget; namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog;
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;
@ -10,11 +13,11 @@ class BlogTagsCloudWidgetTest extends SapphireTest
/** /**
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
public function testGetCMSFields() public function testGetCMSFields()
{ {
if (!class_exists('Widget')) { if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) {
$this->markTestSkipped('Widgets module not installed'); $this->markTestSkipped('Widgets module not installed');
} }
@ -31,11 +34,11 @@ class BlogTagsCloudWidgetTest extends SapphireTest
public function testGetTags() public function testGetTags()
{ {
if (!class_exists('Widget')) { if (!class_exists('SilverStripe\\Widgets\\Model\\Widget')) {
$this->markTestSkipped('Widgets module not installed'); $this->markTestSkipped('Widgets module not installed');
} }
$widget = new BlogTagsCloudWidget(); $widget = new BlogTagsCloudWidget();
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); $blog = $this->objFromFixture(Blog::class, 'FourthBlog');
$widget->BlogID = $blog->ID; $widget->BlogID = $blog->ID;
$widget->write(); $widget->write();
$tags = $widget->getTags()->toArray(); $tags = $widget->getTags()->toArray();

View File

@ -1,6 +1,10 @@
<?php <?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogController; use SilverStripe\Blog\Model\BlogController;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -20,7 +24,7 @@ class BlogTest extends SapphireTest
/** /**
* @var string * @var string
*/ */
public static $fixture_file = 'blog.yml'; protected static $fixture_file = 'blog.yml';
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -35,7 +39,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$blog->publish('Stage', 'Live'); $blog->publish('Stage', 'Live');
} }
@ -62,17 +66,17 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', true); Config::inst()->update(BlogPost::class, 'show_in_sitetree', true);
$classes = $blog->getExcludedSiteTreeClassNames(); $classes = $blog->getExcludedSiteTreeClassNames();
$this->assertNotContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); $this->assertNotContains(BlogPost::class, $classes, 'BlogPost class should be hidden.');
Config::inst()->update('SilverStripe\\Blog\\Model\\BlogPost', 'show_in_sitetree', false); Config::inst()->update(BlogPost::class, 'show_in_sitetree', false);
$classes = $blog->getExcludedSiteTreeClassNames(); $classes = $blog->getExcludedSiteTreeClassNames();
$this->assertContains('SilverStripe\\Blog\\Model\\BlogPost', $classes, 'BlogPost class should be hidden.'); $this->assertContains(BlogPost::class, $classes, 'BlogPost class should be hidden.');
} }
public function testGetArchivedBlogPosts() public function testGetArchivedBlogPosts()
@ -86,7 +90,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$archive = $blog->getArchivedBlogPosts(2013); $archive = $blog->getArchivedBlogPosts(2013);
@ -108,7 +112,7 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $blog * @var Blog $blog
*/ */
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$link = Controller::join_links($blog->Link('archive'), '2013', '10', '01'); $link = Controller::join_links($blog->Link('archive'), '2013', '10', '01');
@ -147,7 +151,7 @@ class BlogTest extends SapphireTest
*/ */
public function testArchiveYear() public function testArchiveYear()
{ {
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog); $controller = new BlogController($blog);
$this->requestURL($controller, 'first-post/archive/'); $this->requestURL($controller, 'first-post/archive/');
$this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013'); $this->assertEquals(2013, $controller->getArchiveYear(), 'getArchiveYear should return 2013');
@ -168,47 +172,47 @@ class BlogTest extends SapphireTest
/** /**
* @var Blog $firstBlog * @var Blog $firstBlog
*/ */
$firstBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $firstBlog = $this->objFromFixture(Blog::class, 'FirstBlog');
/** /**
* @var Blog $fourthBlog * @var Blog $fourthBlog
*/ */
$fourthBlog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FourthBlog'); $fourthBlog = $this->objFromFixture(Blog::class, 'FourthBlog');
/** /**
* @var BlogPost $postA * @var BlogPost $postA
*/ */
$postA = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostA'); $postA = $this->objFromFixture(BlogPost::class, 'PostA');
/** /**
* @var BlogPost $postB * @var BlogPost $postB
*/ */
$postB = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostB'); $postB = $this->objFromFixture(BlogPost::class, 'PostB');
/** /**
* @var BlogPost $postC * @var BlogPost $postC
*/ */
$postC = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC'); $postC = $this->objFromFixture(BlogPost::class, 'PostC');
/** /**
* @var Member $editor * @var Member $editor
*/ */
$editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'BlogEditor'); $editor = $this->objFromFixture(Member::class, 'BlogEditor');
/** /**
* @var Member $writer * @var Member $writer
*/ */
$writer = $this->objFromFixture('SilverStripe\\Security\\Member', 'Writer'); $writer = $this->objFromFixture(Member::class, 'Writer');
/** /**
* @var Member $contributor * @var Member $contributor
*/ */
$contributor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Contributor'); $contributor = $this->objFromFixture(Member::class, 'Contributor');
/** /**
* @var Member $visitor * @var Member $visitor
*/ */
$visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor'); $visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertEquals('Editor', $fourthBlog->RoleOf($editor)); $this->assertEquals('Editor', $fourthBlog->RoleOf($editor));
$this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor)); $this->assertEquals('Contributor', $fourthBlog->RoleOf($contributor));
@ -286,7 +290,7 @@ class BlogTest extends SapphireTest
public function testFilteredCategories() public function testFilteredCategories()
{ {
$blog = $this->objFromFixture('SilverStripe\\Blog\\Model\\Blog', 'FirstBlog'); $blog = $this->objFromFixture(Blog::class, 'FirstBlog');
$controller = new BlogController($blog); $controller = new BlogController($blog);
// Root url // Root url
@ -305,10 +309,10 @@ class BlogTest extends SapphireTest
); );
// Posts // Posts
$firstPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstBlogPost'); $firstPostID = $this->idFromFixture(BlogPost::class, 'FirstBlogPost');
$secondPostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondBlogPost'); $secondPostID = $this->idFromFixture(BlogPost::class, 'SecondBlogPost');
$firstFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'FirstFutureBlogPost'); $firstFuturePostID = $this->idFromFixture(BlogPost::class, 'FirstFutureBlogPost');
$secondFuturePostID = $this->idFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'SecondFutureBlogPost'); $secondFuturePostID = $this->idFromFixture(BlogPost::class, 'SecondFutureBlogPost');
// Request first tag // Request first tag
$this->requestURL($controller, 'first-post/tag/first-tag'); $this->requestURL($controller, 'first-post/tag/first-tag');
@ -336,7 +340,7 @@ class BlogTest extends SapphireTest
$request = new HTTPRequest('get', $url); $request = new HTTPRequest('get', $url);
$request->match('$URLSegment//$Action/$ID/$OtherID'); $request->match('$URLSegment//$Action/$ID/$OtherID');
$request->shift(); $request->shift();
$controller->init(); $controller->doInit();
$controller->handleRequest($request, new DataModel()); $controller->handleRequest($request, new DataModel());
} }