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": {
"psr-4": {
"SilverStripe\\Blog\\": "src/"
"SilverStripe\\Blog\\": "src/",
"SilverStripe\\Blog\\Tests\\": "tests/"
}
},
"license": "BSD-2-Clause",

View File

@ -2,8 +2,8 @@
namespace SilverStripe\Blog\Forms;
use SilverStripe\Forms\FieldGroup;
use SilverStripe\Control\Cookie;
use SilverStripe\Forms\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($addAction);
return array(
$this->targetFragment => $forTemplate->renderWith(
'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField'
)
);
return array($this->targetFragment => $forTemplate->renderWith(self::class));
}
}

View File

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

View File

@ -2,7 +2,9 @@
namespace SilverStripe\Blog\Model;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Blog\Model\BlogObject;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Blog\Model\CategorisationObject;
use SilverStripe\ORM\DataObject;
@ -49,14 +51,14 @@ class BlogCategory extends DataObject implements CategorisationObject
* @var array
*/
private static $has_one = array(
'Blog' => 'SilverStripe\\Blog\\Model\\Blog',
'Blog' => Blog::class,
);
/**
* @var 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;
use SilverStripe\Assets\Image;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\Tab;
@ -31,14 +33,14 @@ class BlogMemberExtension extends DataExtension
* @var array
*/
private static $has_one = array(
'BlogProfileImage' => 'SilverStripe\\Assets\\Image'
'BlogProfileImage' => Image::class
);
/**
* @var 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()
{
parent::onBeforeWrite();
if (empty($this->URLSegment)) {
if ($this->exists() || empty($this->URLSegment)) {
return $this->generateURLSegment();
}
}
@ -181,6 +181,12 @@ trait BlogObject
$increment = (int) $increment;
$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);
if ($increment > 0) {

View File

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

View File

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

View File

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

View File

@ -1,5 +1,8 @@
<?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\Blog;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member;
@ -13,7 +16,7 @@ class BlogPostFilterTest extends SapphireTest
/**
* @var string
*/
public static $fixture_file = 'blog.yml';
protected static $fixture_file = 'blog.yml';
public function setUp()
{
@ -44,7 +47,7 @@ class BlogPostFilterTest extends SapphireTest
/**
* @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');

View File

@ -1,5 +1,7 @@
<?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Dev\SapphireTest;
@ -9,7 +11,7 @@ class BlogPostNotificationsTest extends SapphireTest
* {@inheritDoc}
* @var string
*/
public static $fixture_file = 'blog.yml';
protected static $fixture_file = 'blog.yml';
public function testUpdateNotificationRecipients()
{
@ -43,7 +45,7 @@ class BlogPostNotificationsTest extends SapphireTest
$this->markTestSkipped('Comments Notification module is not installed');
}
$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->write();
$recipients = $blogPost->notificationRecipients(

View File

@ -1,8 +1,12 @@
<?php
namespace SilverStripe\Blog\Tests;
use SilverStripe\Blog\Model\BlogPost;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\ORM\FieldType\DBDatetime;
use SilverStripe\Security\Member;
class BlogPostTest extends SapphireTest
{
@ -10,15 +14,7 @@ class BlogPostTest extends SapphireTest
* {@inheritDoc}
* @var string
*/
public static $fixture_file = 'blog.yml';
/**
* {@inheritdoc}
*/
public function setUp()
{
parent::setUp();
}
protected static $fixture_file = 'blog.yml';
/**
* {@inheritdoc}
@ -34,8 +30,8 @@ class BlogPostTest extends SapphireTest
*/
public function testCanView($date, $user, $page, $canView)
{
$userRecord = $this->objFromFixture('SilverStripe\\Security\\Member', $user);
$pageRecord = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', $page);
$userRecord = $this->objFromFixture(Member::class, $user);
$pageRecord = $this->objFromFixture(BlogPost::class, $page);
DBDatetime::set_mock_now($date);
$this->assertEquals($canView, $pageRecord->canView($userRecord));
}
@ -78,12 +74,12 @@ class BlogPostTest extends SapphireTest
public function testCandidateAuthors()
{
$blogpost = $this->objFromFixture('SilverStripe\\Blog\\Model\\BlogPost', 'PostC');
$blogpost = $this->objFromFixture(BlogPost::class, 'PostC');
$this->assertEquals(7, $blogpost->getCandidateAuthors()->count());
//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());
@ -94,12 +90,12 @@ class BlogPostTest extends SapphireTest
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));
$visitor = $this->objFromFixture('SilverStripe\\Security\\Member', 'Visitor');
$visitor = $this->objFromFixture(Member::class, 'Visitor');
$this->assertFalse($blogPost->canView($visitor));
}
@ -109,10 +105,10 @@ class BlogPostTest extends SapphireTest
*/
public function testGetDate()
{
$blogPost = $this->objFromFixture('BlogPost', 'NullPublishDate');
$blogPost = $this->objFromFixture(BlogPost::class, 'NullPublishDate');
$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());
}
}

View File

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

View File

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

View File

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