From c698632aae850759c5afa2f89f388c3c7d5da14d Mon Sep 17 00:00:00 2001
From: Robbie Averill
Date: Mon, 16 Jan 2017 18:10:05 +1300
Subject: [PATCH 1/6] SS4 compat: Update composer and YAML config, rename
classes, update readme
---
.travis.yml | 19 ++++---
README.md | 2 +-
_config/comments.yml | 2 +-
_config/routes.yml | 8 +--
composer.json | 51 +++++++++----------
{code/admin => src/Admin}/CommentAdmin.php | 0
.../admin => src/Admin}/CommentsGridField.php | 0
.../Admin}/CommentsGridFieldAction.php | 0
.../Admin}/CommentsGridFieldBulkAction.php | 0
.../Admin}/CommentsGridFieldConfig.php | 0
{code => src}/Commenting.php | 0
.../Controllers}/CommentingController.php | 0
.../Extensions}/CommentsExtension.php | 0
{code/model => src/Model}/Comment.php | 0
{code/model => src/Model}/CommentList.php | 0
15 files changed, 40 insertions(+), 42 deletions(-)
rename {code/admin => src/Admin}/CommentAdmin.php (100%)
rename {code/admin => src/Admin}/CommentsGridField.php (100%)
rename {code/admin => src/Admin}/CommentsGridFieldAction.php (100%)
rename {code/admin => src/Admin}/CommentsGridFieldBulkAction.php (100%)
rename {code/admin => src/Admin}/CommentsGridFieldConfig.php (100%)
rename {code => src}/Commenting.php (100%)
rename {code/controllers => src/Controllers}/CommentingController.php (100%)
rename {code/extensions => src/Extensions}/CommentsExtension.php (100%)
rename {code/model => src/Model}/Comment.php (100%)
rename {code/model => src/Model}/CommentList.php (100%)
diff --git a/.travis.yml b/.travis.yml
index bbdf9f8..2587d8a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,18 +8,17 @@ addons:
- tidy
php:
- - 5.3
- - 5.4
- 5.5
- 5.6
- 7.0
+ - 7.1
before_install:
- pip install --user codecov
env:
global:
- - DB=MYSQL CORE_RELEASE=3.1
+ - DB=MYSQL CORE_RELEASE=4
- MODULE_PATH=comments
# Set to 1 in the matrix to enable code coverage
@@ -29,15 +28,15 @@ matrix:
include:
- php: 5.6
#CommentsListTest breaks with this env: DB=MYSQL CORE_RELEASE=3.2 COVERAGE=1
- env: DB=SQLITE CORE_RELEASE=3.2 COVERAGE=1
+ env: DB=SQLITE CORE_RELEASE=4 COVERAGE=1
- php: 5.6
- env: DB=MYSQL CORE_RELEASE=3
- - php: 5.6
- env: DB=MYSQL CORE_RELEASE=3.1
- - php: 5.6
- env: DB=PGSQL CORE_RELEASE=3.2
- allow_failures:
+ env: DB=MYSQL CORE_RELEASE=4
- php: 7.0
+ env: DB=MYSQL CORE_RELEASE=4
+ - php: 7.1
+ env: DB=MYSQL CORE_RELEASE=4
+ - php: 5.6
+ env: DB=PGSQL CORE_RELEASE=4
before_script:
- phpenv rehash
diff --git a/README.md b/README.md
index 5c70491..815e672 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ inside the docs folder.
## Requirements
- * SilverStripe 3.1
+ * SilverStripe ^4.0
## Installation
diff --git a/_config/comments.yml b/_config/comments.yml
index cd0abb2..8a09bf0 100644
--- a/_config/comments.yml
+++ b/_config/comments.yml
@@ -4,6 +4,6 @@ Name: commentssitetree
only:
moduleexists: 'cms'
---
-SiteTree:
+SilverStripe\CMS\Model\SiteTree:
comments:
enabled_cms: true
diff --git a/_config/routes.yml b/_config/routes.yml
index 959e233..210a7cd 100644
--- a/_config/routes.yml
+++ b/_config/routes.yml
@@ -2,9 +2,9 @@
Name: commentroutes
After: framework/routes#coreroutes
---
-Director:
+SilverStripe\Control\Director:
rules:
# handle old 2.4 style urls
- 'CommentingController//$Action/$ID/$OtherID': 'CommentingController'
- 'PageComments/$Action/$ID/$OtherID': 'CommentingController'
- 'PageComments_Controller/$Action/$ID/$OtherID': 'CommentingController'
+ 'CommentingController//$Action/$ID/$OtherID': 'SilverStripe\Comments\Controllers\CommentingController'
+ 'PageComments/$Action/$ID/$OtherID': 'SilverStripe\Comments\Controllers\CommentingController'
+ 'PageComments_Controller/$Action/$ID/$OtherID': 'SilverStripe\Comments\Controllers\CommentingController'
diff --git a/composer.json b/composer.json
index d114ce4..d889cd8 100644
--- a/composer.json
+++ b/composer.json
@@ -1,28 +1,27 @@
{
- "name": "silverstripe/comments",
- "description": "This module provides commenting functionality for Pages and other DataObjects on your SilverStripe site.",
- "type": "silverstripe-module",
- "keywords": ["silverstripe", "comments"],
- "authors": [{
- "name": "Will Rossiter",
- "email": "will@fullscreen.io"
- }],
- "require": {
- "assertchris/hash-compat": "~1.0",
- "silverstripe/framework": "~3.1",
- "colymba/gridfield-bulk-editing-tools": "~2.1"
- },
- "suggest": {
- "ezyang/htmlpurifier": "Standards compliant HTML filter written in PHP",
- "silverstripe/cms": "The SilverStripe Content Management System"
- },
- "require-dev": {
- "phpunit/PHPUnit": "~3.7@stable"
- },
- "extra": {
- "branch-alias": {
- "dev-master": "2.1.x-dev"
- }
- },
- "license": "BSD-3-Clause"
+ "name": "silverstripe/comments",
+ "description": "This module provides commenting functionality for Pages and other DataObjects on your SilverStripe site.",
+ "type": "silverstripe-module",
+ "keywords": ["silverstripe", "comments"],
+ "authors": [{
+ "name": "Will Rossiter",
+ "email": "will@fullscreen.io"
+ }],
+ "require": {
+ "silverstripe/framework": "^4.0@dev",
+ "colymba/gridfield-bulk-editing-tools": "~2.1"
+ },
+ "suggest": {
+ "ezyang/htmlpurifier": "Standards compliant HTML filter written in PHP",
+ "silverstripe/cms": "The SilverStripe Content Management System"
+ },
+ "require-dev": {
+ "phpunit/PHPUnit": "~4.8"
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-master": "3.x-dev"
+ }
+ },
+ "license": "BSD-3-Clause"
}
diff --git a/code/admin/CommentAdmin.php b/src/Admin/CommentAdmin.php
similarity index 100%
rename from code/admin/CommentAdmin.php
rename to src/Admin/CommentAdmin.php
diff --git a/code/admin/CommentsGridField.php b/src/Admin/CommentsGridField.php
similarity index 100%
rename from code/admin/CommentsGridField.php
rename to src/Admin/CommentsGridField.php
diff --git a/code/admin/CommentsGridFieldAction.php b/src/Admin/CommentsGridFieldAction.php
similarity index 100%
rename from code/admin/CommentsGridFieldAction.php
rename to src/Admin/CommentsGridFieldAction.php
diff --git a/code/admin/CommentsGridFieldBulkAction.php b/src/Admin/CommentsGridFieldBulkAction.php
similarity index 100%
rename from code/admin/CommentsGridFieldBulkAction.php
rename to src/Admin/CommentsGridFieldBulkAction.php
diff --git a/code/admin/CommentsGridFieldConfig.php b/src/Admin/CommentsGridFieldConfig.php
similarity index 100%
rename from code/admin/CommentsGridFieldConfig.php
rename to src/Admin/CommentsGridFieldConfig.php
diff --git a/code/Commenting.php b/src/Commenting.php
similarity index 100%
rename from code/Commenting.php
rename to src/Commenting.php
diff --git a/code/controllers/CommentingController.php b/src/Controllers/CommentingController.php
similarity index 100%
rename from code/controllers/CommentingController.php
rename to src/Controllers/CommentingController.php
diff --git a/code/extensions/CommentsExtension.php b/src/Extensions/CommentsExtension.php
similarity index 100%
rename from code/extensions/CommentsExtension.php
rename to src/Extensions/CommentsExtension.php
diff --git a/code/model/Comment.php b/src/Model/Comment.php
similarity index 100%
rename from code/model/Comment.php
rename to src/Model/Comment.php
diff --git a/code/model/CommentList.php b/src/Model/CommentList.php
similarity index 100%
rename from code/model/CommentList.php
rename to src/Model/CommentList.php
From ab3f35257b8a85a2d9cba5d4a463a3e16af0d008 Mon Sep 17 00:00:00 2001
From: Robbie Averill
Date: Tue, 17 Jan 2017 08:57:37 +1300
Subject: [PATCH 2/6] SS4 compatibility updates - ORM, Form, Controller changes
* Remove CommentList and replace with a polymorphic has_one relationship
* Tweaks for unit tests. Add tests for encode/decodeClassName.
---
.travis.yml | 2 +-
.upgrade.yml | 28 ++
_config.php | 2 +-
_config/routes.yml | 7 +-
composer.json | 7 +-
docs/en/Configuration.md | 66 +--
docs/en/Installing.md | 4 +-
src/Admin/CommentAdmin.php | 12 +
src/Admin/CommentsGridField.php | 5 +
src/Admin/CommentsGridFieldAction.php | 15 +-
src/Admin/CommentsGridFieldBulkAction.php | 64 +--
.../CommentsGridFieldBulkAction/Handler.php | 78 ++++
src/Admin/CommentsGridFieldConfig.php | 25 +-
src/Commenting.php | 36 +-
src/Controllers/CommentingController.php | 214 ++++++----
src/Extensions/CommentsExtension.php | 56 ++-
src/Model/Comment.php | 283 ++++++------
src/Model/Comment/SecurityToken.php | 120 ++++++
src/Model/CommentList.php | 98 -----
src/Tasks/MigrateCommentParentsTask.php | 47 ++
templates/CommentReplies.ss | 23 -
templates/CommentsInterface.ss | 2 +-
templates/Includes/CommentReplies.ss | 25 ++
.../CommentsInterface_pendingcomment.ss | 0
.../CommentsInterface_singlecomment.ss | 2 +-
tests/CommentAdminTest.php | 13 +-
tests/CommentListTest.php | 145 -------
tests/CommentTestHelper.php | 21 +-
tests/CommentingControllerTest.php | 200 +++++----
tests/CommentingTest.php | 94 ++--
tests/CommentsExtensionTest.php | 180 +++++---
tests/CommentsGridFieldActionTest.php | 46 +-
tests/CommentsGridFieldBulkActionTest.php | 4 +
tests/CommentsGridFieldConfigTest.php | 8 +-
tests/CommentsGridFieldTest.php | 13 +-
tests/CommentsTest.php | 401 ++++++++----------
tests/CommentsTest.yml | 104 +++--
tests/Stubs/CommentableItem.php | 62 +++
tests/Stubs/CommentableItemController.php | 19 +
tests/Stubs/CommentableItemDisabled.php | 14 +
tests/Stubs/CommentableItemEnabled.php | 14 +
41 files changed, 1418 insertions(+), 1141 deletions(-)
create mode 100644 .upgrade.yml
create mode 100644 src/Admin/CommentsGridFieldBulkAction/Handler.php
create mode 100644 src/Model/Comment/SecurityToken.php
delete mode 100644 src/Model/CommentList.php
create mode 100644 src/Tasks/MigrateCommentParentsTask.php
delete mode 100644 templates/CommentReplies.ss
create mode 100644 templates/Includes/CommentReplies.ss
rename templates/{ => Includes}/CommentsInterface_pendingcomment.ss (100%)
rename templates/{ => Includes}/CommentsInterface_singlecomment.ss (97%)
delete mode 100644 tests/CommentListTest.php
create mode 100644 tests/Stubs/CommentableItem.php
create mode 100644 tests/Stubs/CommentableItemController.php
create mode 100644 tests/Stubs/CommentableItemDisabled.php
create mode 100644 tests/Stubs/CommentableItemEnabled.php
diff --git a/.travis.yml b/.travis.yml
index 2587d8a..00b0a82 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -43,7 +43,7 @@ before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
# Install suggested modules in order to maximize test coverage
- - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "ezyang/htmlpurifier:4.*,silverstripe/cms:~3.1"
+ - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "silverstripe/cms:^4.0@dev"
- cd ~/builds/ss
script:
diff --git a/.upgrade.yml b/.upgrade.yml
new file mode 100644
index 0000000..42fd6b0
--- /dev/null
+++ b/.upgrade.yml
@@ -0,0 +1,28 @@
+mappings:
+ Commenting: SilverStripe\Comments\Commenting
+ CommentAdmin: SilverStripe\Comments\Admin\CommentAdmin
+ CommentsGridField: SilverStripe\Comments\Admin\CommentsGridField
+ CommentsGridFieldAction: SilverStripe\Comments\Admin\CommentsGridFieldAction
+ CommentsGridFieldBulkAction: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction
+ CommentsGridFieldBulkAction_Handlers: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction_Handlers
+ CommentsGridFieldConfig: SilverStripe\Comments\Admin\CommentsGridFieldConfig
+ CommentingController: SilverStripe\Comments\Controllers\CommentingController
+ CommentsExtension: SilverStripe\Comments\Extensions\CommentsExtension
+ Comment: SilverStripe\Comments\Model\Comment
+ Comment_SecurityToken: SilverStripe\Comments\Model\Comment_SecurityToken
+ CommentList: SilverStripe\Comments\Model\CommentList
+ CommentAdminTest: SilverStripe\Comments\Tests\CommentAdminTest
+ CommentingControllerTest: SilverStripe\Comments\Tests\CommentingControllerTest
+ CommentingTest: SilverStripe\Comments\Tests\CommentingTest
+ CommentListTest: SilverStripe\Comments\Tests\CommentListTest
+ CommentsExtensionTest: SilverStripe\Comments\Tests\CommentsExtensionTest
+ CommentsGridFieldActionTest: SilverStripe\Comments\Tests\CommentsGridFieldActionTest
+ CommentsGridFieldBulkActionTest: SilverStripe\Comments\Tests\CommentsGridFieldBulkActionTest
+ CommentsGridFieldConfigTest: SilverStripe\Comments\Tests\CommentsGridFieldConfigTest
+ CommentsGridFieldTest: SilverStripe\Comments\Tests\CommentsGridFieldTest
+ CommentsTest: SilverStripe\Comments\Tests\CommentsTest
+ CommentableItem: SilverStripe\Comments\Tests\CommentableItem
+ CommentableItemEnabled: SilverStripe\Comments\Tests\CommentableItemEnabled
+ CommentableItemDisabled: SilverStripe\Comments\Tests\CommentableItemDisabled
+ CommentableItem_Controller: SilverStripe\Comments\Tests\CommentableItem_Controller
+ CommentTestHelper: SilverStripe\Comments\Tests\CommentTestHelper
diff --git a/_config.php b/_config.php
index 3fbfa6d..48f849c 100644
--- a/_config.php
+++ b/_config.php
@@ -1,6 +1,6 @@
getCommentsOption('require_login');
+$loginRequired = singleton('SilverStripe\\CMS\\Model\\SiteTree')->getCommentsOption('require_login');
```
-
+
## HTML Comments
-Comments can be configured to contain a restricted set of HTML tags through the
-`html_allowed` and `html_allowed_elements` settings. Raw HTML is hardly user
-friendly, but combined with a rich-text editor of your own choosing it can
+Comments can be configured to contain a restricted set of HTML tags through the
+`html_allowed` and `html_allowed_elements` settings. Raw HTML is hardly user
+friendly, but combined with a rich-text editor of your own choosing it can
allow rich comment formatting.
In order to use this feature, you need to install the
-[HTMLPurifier](http://htmlpurifier.org/) library. The easiest way to do this is
+[HTMLPurifier](http://htmlpurifier.org/) library. The easiest way to do this is
through [Composer](http://getcomposer.org).
- {
- "require": {"ezyang/htmlpurifier": "4.*"}
- }
+```json
+ {
+ "require": {"ezyang/htmlpurifier": "^4.8"}
+ }
+```
-**Important**: Rendering user-provided HTML on your website always risks
-exposing your users to cross-site scripting (XSS) attacks, if the HTML isn't
+**Important**: Rendering user-provided HTML on your website always risks
+exposing your users to cross-site scripting (XSS) attacks, if the HTML isn't
properly sanitized. Don't allow tags like `my comment
';
$comment1->write();
$this->assertEquals(
@@ -454,7 +478,7 @@ class CommentsTest extends FunctionalTest
// With HTML allowed
$comment2 = new Comment();
$comment2->AllowHtml = true;
- $comment2->BaseClass = 'CommentableItem';
+ $comment2->ParentClass = CommentableItem::class;
$comment2->Comment = 'my comment
';
$comment2->write();
$this->assertEquals(
@@ -466,11 +490,11 @@ class CommentsTest extends FunctionalTest
public function testDefaultTemplateRendersHtmlWithAllowHtml()
{
- if (!class_exists('HTMLPurifier')) {
+ if (!class_exists('\\HTMLPurifier')) {
$this->markTestSkipped('HTMLPurifier class not found');
}
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'html_allowed_elements' => array('p'),
));
@@ -482,7 +506,7 @@ class CommentsTest extends FunctionalTest
$comment->Comment = 'my comment
';
$comment->AllowHtml = false;
$comment->ParentID = $item->ID;
- $comment->BaseClass = 'CommentableItem';
+ $comment->BaseClass = CommentableItem::class;
$comment->write();
$html = $item->customise(array('CommentsEnabled' => true))->renderWith('CommentsInterface');
@@ -507,7 +531,7 @@ class CommentsTest extends FunctionalTest
public function testDefaultEnabled()
{
// Ensure values are set via cms (not via config)
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'enabled_cms' => true,
'require_moderation_cms' => true,
'require_login_cms' => true
@@ -532,13 +556,13 @@ class CommentsTest extends FunctionalTest
// With default = false
// Because of config rules about falsey values, apply config to object directly
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'enabled' => false,
'require_login' => true,
'require_moderation' => true
));
$obj = new CommentableItem();
- $this->assertFalse((bool)$obj->getCommentsOption('enabled'), "Default setting is disabled");
+ $this->assertFalse((bool)$obj->getCommentsOption('enabled'), 'Default setting is disabled');
$this->assertFalse((bool)$obj->ProvideComments);
$this->assertEquals('Required', $obj->ModerationRequired);
$this->assertTrue((bool)$obj->CommentsRequireLogin);
@@ -559,7 +583,7 @@ class CommentsTest extends FunctionalTest
*/
public function testOnBeforeDelete()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$child = new Comment();
$child->Name = 'Fred Bloggs';
@@ -574,8 +598,8 @@ class CommentsTest extends FunctionalTest
$comment->delete();
// assert that the new child been deleted
- $this->assertFalse(DataObject::get_by_id('Comment', $commentID));
- $this->assertFalse(DataObject::get_by_id('Comment', $childCommentID));
+ $this->assertFalse(DataObject::get_by_id(Comment::class, $commentID));
+ $this->assertFalse(DataObject::get_by_id(Comment::class, $childCommentID));
}
public function testRequireDefaultRecords()
@@ -585,41 +609,42 @@ class CommentsTest extends FunctionalTest
public function testLink()
{
- $comment = $this->objFromFixture('Comment', 'thirdComD');
- $this->assertEquals('CommentableItem_Controller#comment-'.$comment->ID,
- $comment->Link());
+ $comment = $this->objFromFixture(Comment::class, 'thirdComD');
+ $this->assertEquals(
+ 'CommentableItemController#comment-' . $comment->ID,
+ $comment->Link()
+ );
$this->assertEquals($comment->ID, $comment->ID);
// An orphan comment has no link
$comment->ParentID = 0;
+ $comment->ParentClass = null;
$comment->write();
$this->assertEquals('', $comment->Link());
}
public function testPermalink()
{
- $comment = $this->objFromFixture('Comment', 'thirdComD');
+ $comment = $this->objFromFixture(Comment::class, 'thirdComD');
$this->assertEquals('comment-' . $comment->ID, $comment->Permalink());
}
- /*
- Test field labels in 2 languages
+ /**
+ * Test field labels in 2 languages
*/
public function testFieldLabels()
{
$locale = i18n::get_locale();
i18n::set_locale('fr');
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$labels = $comment->FieldLabels();
$expected = array(
'Name' => 'Nom de l\'Auteur',
'Comment' => 'Commentaire',
'Email' => 'Email',
'URL' => 'URL',
- 'BaseClass' => 'Base Class',
'Moderated' => 'Modéré?',
'IsSpam' => 'Spam?',
- 'ParentID' => 'Parent ID',
'AllowHtml' => 'Allow Html',
'SecretToken' => 'Secret Token',
'Depth' => 'Depth',
@@ -627,7 +652,8 @@ class CommentsTest extends FunctionalTest
'ParentComment' => 'Parent Comment',
'ChildComments' => 'Child Comments',
'ParentTitle' => 'Parent',
- 'Created' => 'Date de publication'
+ 'Created' => 'Date de publication',
+ 'Parent' => 'Parent'
);
i18n::set_locale($locale);
$this->assertEquals($expected, $labels);
@@ -637,10 +663,8 @@ class CommentsTest extends FunctionalTest
'Comment' => 'Comment',
'Email' => 'Email',
'URL' => 'URL',
- 'BaseClass' => 'Base Class',
'Moderated' => 'Moderated?',
'IsSpam' => 'Spam?',
- 'ParentID' => 'Parent ID',
'AllowHtml' => 'Allow Html',
'SecretToken' => 'Secret Token',
'Depth' => 'Depth',
@@ -648,8 +672,8 @@ class CommentsTest extends FunctionalTest
'ParentComment' => 'Parent Comment',
'ChildComments' => 'Child Comments',
'ParentTitle' => 'Parent',
- 'Created' => 'Date posted'
-
+ 'Created' => 'Date posted',
+ 'Parent' => 'Parent'
);
$this->assertEquals($expected, $labels);
}
@@ -661,29 +685,31 @@ class CommentsTest extends FunctionalTest
public function testGetParent()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
- $item = $this->objFromFixture('CommentableItem', 'first');
- $parent = $comment->getParent();
- $this->assertEquals($item, $parent);
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
+ $item = $this->objFromFixture(CommentableItem::class, 'first');
+ $parent = $comment->Parent();
+ $this->assertSame($item->getClassName(), $parent->getClassName());
+ $this->assertSame($item->ID, $parent->ID);
}
public function testGetParentTitle()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$title = $comment->getParentTitle();
$this->assertEquals('First', $title);
// Title from a comment with no parent is blank
$comment->ParentID = 0;
+ $comment->ParentClass = null;
$comment->write();
$this->assertEquals('', $comment->getParentTitle());
}
public function testGetParentClassName()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$className = $comment->getParentClassName();
- $this->assertEquals('CommentableItem', $className);
+ $this->assertEquals(CommentableItem::class, $className);
}
public function testCastingHelper()
@@ -708,7 +734,7 @@ class CommentsTest extends FunctionalTest
public function testCanCreate()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
// admin can create - this is always false
$this->logInAs('commentadmin');
@@ -721,7 +747,7 @@ class CommentsTest extends FunctionalTest
public function testCanView()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
// admin can view
$this->logInAs('commentadmin');
@@ -738,7 +764,7 @@ class CommentsTest extends FunctionalTest
public function testCanEdit()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
// admin can edit
$this->logInAs('commentadmin');
@@ -755,7 +781,7 @@ class CommentsTest extends FunctionalTest
public function testCanDelete()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
// admin can delete
$this->logInAs('commentadmin');
@@ -774,7 +800,7 @@ class CommentsTest extends FunctionalTest
{
$this->logInAs('visitor');
$current = Member::currentUser();
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$method = $this->getMethod('getMember');
// null case
@@ -792,7 +818,7 @@ class CommentsTest extends FunctionalTest
public function testGetAuthorName()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
'FA',
$comment->getAuthorName()
@@ -804,7 +830,7 @@ class CommentsTest extends FunctionalTest
$comment->getAuthorName()
);
- $author = $this->objFromFixture('Member', 'visitor');
+ $author = $this->objFromFixture(Member::class, 'visitor');
$comment->AuthorID = $author->ID;
$comment->write();
$this->assertEquals(
@@ -821,44 +847,44 @@ class CommentsTest extends FunctionalTest
public function testLinks()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->logInAs('commentadmin');
$method = $this->getMethod('ActionLink');
// test with starts of strings and tokens and salts change each time
$this->assertStringStartsWith(
- '/CommentingController/theaction/'.$comment->ID,
+ '/comments/theaction/' . $comment->ID,
$method->invokeArgs($comment, array('theaction'))
);
$this->assertStringStartsWith(
- '/CommentingController/delete/'.$comment->ID,
+ '/comments/delete/' . $comment->ID,
$comment->DeleteLink()
);
$this->assertStringStartsWith(
- '/CommentingController/spam/'.$comment->ID,
+ '/comments/spam/' . $comment->ID,
$comment->SpamLink()
);
$comment->markSpam();
$this->assertStringStartsWith(
- '/CommentingController/ham/'.$comment->ID,
+ '/comments/ham/' . $comment->ID,
$comment->HamLink()
);
//markApproved
$comment->markUnapproved();
$this->assertStringStartsWith(
- '/CommentingController/approve/'.$comment->ID,
+ '/comments/approve/' . $comment->ID,
$comment->ApproveLink()
);
}
public function testMarkSpam()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$comment->markSpam();
$this->assertTrue($comment->Moderated);
$this->assertTrue($comment->IsSpam);
@@ -866,7 +892,7 @@ class CommentsTest extends FunctionalTest
public function testMarkApproved()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$comment->markApproved();
$this->assertTrue($comment->Moderated);
$this->assertFalse($comment->IsSpam);
@@ -874,14 +900,14 @@ class CommentsTest extends FunctionalTest
public function testMarkUnapproved()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$comment->markApproved();
$this->assertTrue($comment->Moderated);
}
public function testSpamClass()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals('notspam', $comment->spamClass());
$comment->Moderated = false;
$this->assertEquals('unmoderated', $comment->spamClass());
@@ -891,7 +917,7 @@ class CommentsTest extends FunctionalTest
public function testGetTitle()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
'Comment by FA on First',
$comment->getTitle()
@@ -900,7 +926,7 @@ class CommentsTest extends FunctionalTest
public function testGetCMSFields()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$fields = $comment->getCMSFields();
$names = array();
foreach ($fields as $field) {
@@ -912,7 +938,7 @@ class CommentsTest extends FunctionalTest
'Comment',
'Email',
'URL',
- null #FIXME this is suspicious
+ 'Options'
);
$this->assertEquals($expected, $names);
}
@@ -920,7 +946,7 @@ class CommentsTest extends FunctionalTest
public function testGetCMSFieldsCommentHasAuthor()
{
$member = Member::get()->filter('FirstName', 'visitor')->first();
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$comment->AuthorID = $member->ID;
$comment->write();
@@ -936,14 +962,14 @@ class CommentsTest extends FunctionalTest
'Comment',
'Email',
'URL',
- null #FIXME this is suspicious
+ 'Options'
);
$this->assertEquals($expected, $names);
}
public function testGetCMSFieldsWithParentComment()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$child = new Comment();
$child->Name = 'John Smith';
@@ -962,7 +988,7 @@ class CommentsTest extends FunctionalTest
'Comment',
'Email',
'URL',
- null, #FIXME this is suspicious
+ 'Options',
'ParentComment_Title',
'ParentComment_Created',
'ParentComment_AuthorName',
@@ -971,10 +997,9 @@ class CommentsTest extends FunctionalTest
$this->assertEquals($expected, $names);
}
-
public function testPurifyHtml()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$dirtyHTML = 'my comment
';
$this->assertEquals(
@@ -986,22 +1011,22 @@ class CommentsTest extends FunctionalTest
public function testGravatar()
{
// Turn gravatars on
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'use_gravatar' => true
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
- 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s'.
- '=80&d=identicon&r=g',
+ 'http://www.gravatar.com/avatar/d41d8cd98f00b204e9800998ecf8427e?s'
+ . '=80&d=identicon&r=g',
$comment->gravatar()
);
// Turn gravatars off
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'use_gravatar' => false
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
'',
@@ -1011,13 +1036,13 @@ class CommentsTest extends FunctionalTest
public function testGetRepliesEnabled()
{
- $comment = $this->objFromFixture('Comment', 'firstComA');
- Config::inst()->update('CommentableItem', 'comments', array(
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => false
));
$this->assertFalse($comment->getRepliesEnabled());
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4
));
@@ -1028,7 +1053,7 @@ class CommentsTest extends FunctionalTest
// 0 indicates no limit for nested_depth
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 0
));
@@ -1046,11 +1071,11 @@ class CommentsTest extends FunctionalTest
public function testAllReplies()
{
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
3,
$comment->allReplies()->count()
@@ -1069,7 +1094,7 @@ class CommentsTest extends FunctionalTest
$comment->allReplies()->count()
);
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => false
));
@@ -1078,13 +1103,13 @@ class CommentsTest extends FunctionalTest
public function testReplies()
{
- CommentableItem::add_extension('CommentsExtension');
+ CommentableItem::add_extension(CommentsExtension::class);
$this->logInWithPermission('ADMIN');
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$this->assertEquals(
3,
$comment->Replies()->count()
@@ -1114,17 +1139,17 @@ class CommentsTest extends FunctionalTest
// Test moderation required on the front end
- $item = $this->objFromFixture('CommentableItem', 'first');
+ $item = $this->objFromFixture(CommentableItem::class, 'first');
$item->ModerationRequired = 'Required';
$item->write();
- Config::inst()->update('CommentableItemDisabled', 'comments', array(
+ Config::inst()->update(CommentableItemDisabled::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4,
'frontend_moderation' => true
));
- $comment = DataObject::get_by_id('Comment', $comment->ID);
+ $comment = DataObject::get_by_id(Comment::class, $comment->ID);
$this->assertEquals(
2,
@@ -1132,7 +1157,7 @@ class CommentsTest extends FunctionalTest
);
// Turn off nesting, empty array should be returned
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => false
));
@@ -1141,18 +1166,18 @@ class CommentsTest extends FunctionalTest
$comment->Replies()->count()
);
- CommentableItem::remove_extension('CommentsExtension');
+ CommentableItem::remove_extension(CommentsExtension::class);
}
public function testPagedReplies()
{
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4,
'comments_per_page' => 2 #Force 2nd page for 3 items
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$pagedList = $comment->pagedReplies();
$this->assertEquals(
2,
@@ -1164,7 +1189,7 @@ class CommentsTest extends FunctionalTest
);
//TODO - 2nd page requires controller
//
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => false
));
@@ -1173,19 +1198,19 @@ class CommentsTest extends FunctionalTest
public function testReplyForm()
{
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => false,
'nested_depth' => 4
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
// No nesting, no reply form
$form = $comment->replyForm();
$this->assertNull($form);
// parent item so show form
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4
));
@@ -1198,11 +1223,11 @@ class CommentsTest extends FunctionalTest
$this->assertEquals(
array(
- null, #FIXME suspicious
+ 'NameEmailURLComment', // The CompositeField name?
'ParentID',
+ 'ParentClassName',
'ReturnURL',
- 'ParentCommentID',
- 'BaseClass'
+ 'ParentCommentID'
),
$names
);
@@ -1210,6 +1235,7 @@ class CommentsTest extends FunctionalTest
// no parent, no reply form
$comment->ParentID = 0;
+ $comment->ParentClass = null;
$comment->write();
$form = $comment->replyForm();
$this->assertNull($form);
@@ -1217,12 +1243,12 @@ class CommentsTest extends FunctionalTest
public function testUpdateDepth()
{
- Config::inst()->update('CommentableItem', 'comments', array(
+ Config::inst()->update(CommentableItem::class, 'comments', array(
'nested_comments' => true,
'nested_depth' => 4
));
- $comment = $this->objFromFixture('Comment', 'firstComA');
+ $comment = $this->objFromFixture(Comment::class, 'firstComA');
$children = $comment->allReplies()->toArray();
// Make the second child a child of the first
// Make the third child a child of the second
@@ -1262,98 +1288,11 @@ class CommentsTest extends FunctionalTest
$this->markTestSkipped('TODO');
}
-
protected static function getMethod($name)
{
- $class = new ReflectionClass('Comment');
+ $class = new ReflectionClass(Comment::class);
$method = $class->getMethod($name);
$method->setAccessible(true);
return $method;
}
}
-
-
-/**
- * @package comments
- * @subpackage tests
- */
-class CommentableItem extends DataObject implements TestOnly
-{
-
- private static $db = array(
- 'Title' => 'Varchar'
- );
-
- private static $extensions = array(
- 'CommentsExtension'
- );
-
- public function RelativeLink()
- {
- return "CommentableItem_Controller";
- }
-
- public function canView($member = null)
- {
- return true;
- }
-
- // This is needed for canModerateComments
- public function canEdit($member = null)
- {
- if ($member instanceof Member) {
- $memberID = $member->ID;
- } elseif (is_numeric($member)) {
- $memberID = $member;
- } else {
- $memberID = Member::currentUserID();
- }
-
- if ($memberID && Permission::checkMember($memberID, array("ADMIN", "CMS_ACCESS_CommentAdmin"))) {
- return true;
- }
- return false;
- }
-
- public function Link()
- {
- return $this->RelativeLink();
- }
-
- public function AbsoluteLink()
- {
- return Director::absoluteURL($this->RelativeLink());
- }
-}
-
-class CommentableItemEnabled extends CommentableItem
-{
- private static $defaults = array(
- 'ProvideComments' => true,
- 'ModerationRequired' => 'Required',
- 'CommentsRequireLogin' => true
- );
-}
-
-
-class CommentableItemDisabled extends CommentableItem
-{
- private static $defaults = array(
- 'ProvideComments' => false,
- 'ModerationRequired' => 'None',
- 'CommentsRequireLogin' => false
- );
-}
-
-/**
- * @package comments
- * @subpackage tests
- */
-class CommentableItem_Controller extends Controller implements TestOnly
-{
-
- public function index()
- {
- return CommentableItem::get()->first()->CommentsForm();
- }
-}
diff --git a/tests/CommentsTest.yml b/tests/CommentsTest.yml
index 7f5ee3e..a25a3c9 100644
--- a/tests/CommentsTest.yml
+++ b/tests/CommentsTest.yml
@@ -1,4 +1,4 @@
-Member:
+SilverStripe\Security\Member:
commentadmin:
FirstName: admin
commentadmin2:
@@ -6,17 +6,17 @@ Member:
visitor:
FirstName: visitor
-Group:
+SilverStripe\Security\Group:
commentadmins:
Title: Admin
- Members: =>Member.commentadmin, =>Member.commentadmin2
+ Members: =>SilverStripe\Security\Member.commentadmin, =>SilverStripe\Security\Member.commentadmin2
-Permission:
+SilverStripe\Security\Permission:
admin:
Code: CMS_ACCESS_CommentAdmin
- Group: =>Group.commentadmins
+ Group: =>SilverStripe\Security\Group.commentadmins
-CommentableItem:
+SilverStripe\Comments\Tests\Stubs\CommentableItem:
first:
Title: First
ProvideComments: 1
@@ -35,166 +35,158 @@ CommentableItem:
ProvideComments: 1
Title: spammed
ModerationRequired: 'None'
+ moderated:
+ ProvideComments: 1
+ Title: Moderate everything
+ ModerationRequired: Required
+ CommentsRequireLogin: 0
-Comment:
+SilverStripe\Comments\Model\Comment:
firstComA:
- ParentID: =>CommentableItem.first
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.first
Name: FA
Comment: textFA
- BaseClass: CommentableItem
Moderated: 1
IsSpam:
Depth: 1
firstComAChild1:
- ParentID: =>CommentableItem.first
- ParentCommentID: =>Comment.firstComA
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.first
+ ParentComment: =>SilverStripe\Comments\Model\Comment.firstComA
Name: John Smith
Comment: Reply to firstComA 1
- BaseClass: CommentableItem
Moderated: 1
IsSpam: 0
Depth: 2
firstComAChild2:
- ParentID: =>CommentableItem.first
- ParentCommentID: =>Comment.firstComA
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.first
+ ParentComment: =>SilverStripe\Comments\Model\Comment.firstComA
Name: John Smith
Comment: Reply to firstComA 2
- BaseClass: CommentableItem
Moderated: 1
IsSpam: 0
Depth: 2
firstComAChild3:
- ParentID: =>CommentableItem.first
- ParentCommentID: =>Comment.firstComA
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.first
+ ParentComment: =>SilverStripe\Comments\Model\Comment.firstComA
Name: John Smith
Comment: Reply to firstComA 3
- BaseClass: CommentableItem
Moderated: 1
IsSpam: 0
Depth: 2
secondComA:
- ParentID: =>CommentableItem.second
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.second
Name: SA
Comment: textSA
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
secondComB:
- ParentID: =>CommentableItem.second
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.second
Name: SB
Comment: textSB
Moderated: 0
IsSpam: 0
- BaseClass: CommentableItem
secondComC:
- ParentID: =>CommentableItem.second
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.second
Name: SB
Comment: textSB
Moderated: 1
IsSpam: 1
- BaseClass: CommentableItem
thirdComA:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TA
Comment: textTA
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComB:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TB
Comment: textTB
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComC:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComD:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
- BaseClass: CommentableItem
thirdComE:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
- BaseClass: CommentableItem
thirdComF:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComG:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComH:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComI:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComJ:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
thirdComK:
- ParentID: =>CommentableItem.third
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.third
Name: TC
Comment: textTC
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
disabledCom:
- ParentID: =>CommentableItem.nocomments
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.nocomments
Name: Disabled
Moderated: 0
IsSpam: 1
- BaseClass: CommentableItem
testCommentList1:
- ParentID: =>CommentableItem.spammed
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.spammed
Name: Comment 1
Moderated: 0
IsSpam: 0
- BaseClass: CommentableItem
testCommentList2:
- ParentID: =>CommentableItem.spammed
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.spammed
Name: Comment 2
Moderated: 1
IsSpam: 1
- BaseClass: CommentableItem
testCommentList3:
- ParentID: =>CommentableItem.spammed
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.spammed
Name: Comment 3
Moderated: 1
IsSpam: 0
- BaseClass: CommentableItem
testCommentList4:
- ParentID: =>CommentableItem.spammed
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.spammed
Name: Comment 4
Moderated: 0
IsSpam: 1
- BaseClass: CommentableItem
+ testModeratedComment1:
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.moderated
+ Name: Moderated comment 1
+ Moderated: 0
+ IsSpam: 0
+ testModeratedComment2:
+ Parent: =>SilverStripe\Comments\Tests\Stubs\CommentableItem.moderated
+ Name: Moderated comment 2
+ Moderated: 0
+ IsSpam: 1
diff --git a/tests/Stubs/CommentableItem.php b/tests/Stubs/CommentableItem.php
new file mode 100644
index 0000000..79cdaac
--- /dev/null
+++ b/tests/Stubs/CommentableItem.php
@@ -0,0 +1,62 @@
+ 'Varchar'
+ );
+
+ private static $extensions = array(
+ CommentsExtension::class
+ );
+
+ public function RelativeLink()
+ {
+ return 'CommentableItemController';
+ }
+
+ public function canView($member = null)
+ {
+ return true;
+ }
+
+ // This is needed for canModerateComments
+ public function canEdit($member = null)
+ {
+ if ($member instanceof Member) {
+ $memberID = $member->ID;
+ } elseif (is_numeric($member)) {
+ $memberID = $member;
+ } else {
+ $memberID = Member::currentUserID();
+ }
+
+ if ($memberID && Permission::checkMember($memberID, array('ADMIN', 'CMS_ACCESS_CommentAdmin'))) {
+ return true;
+ }
+ return false;
+ }
+
+ public function Link()
+ {
+ return $this->RelativeLink();
+ }
+
+ public function AbsoluteLink()
+ {
+ return Director::absoluteURL($this->RelativeLink());
+ }
+}
diff --git a/tests/Stubs/CommentableItemController.php b/tests/Stubs/CommentableItemController.php
new file mode 100644
index 0000000..211e20a
--- /dev/null
+++ b/tests/Stubs/CommentableItemController.php
@@ -0,0 +1,19 @@
+first()->CommentsForm();
+ }
+}
diff --git a/tests/Stubs/CommentableItemDisabled.php b/tests/Stubs/CommentableItemDisabled.php
new file mode 100644
index 0000000..c5c4402
--- /dev/null
+++ b/tests/Stubs/CommentableItemDisabled.php
@@ -0,0 +1,14 @@
+ false,
+ 'ModerationRequired' => 'None',
+ 'CommentsRequireLogin' => false
+ );
+}
diff --git a/tests/Stubs/CommentableItemEnabled.php b/tests/Stubs/CommentableItemEnabled.php
new file mode 100644
index 0000000..5489827
--- /dev/null
+++ b/tests/Stubs/CommentableItemEnabled.php
@@ -0,0 +1,14 @@
+ true,
+ 'ModerationRequired' => 'Required',
+ 'CommentsRequireLogin' => true
+ );
+}
From 6aeab9f823fe77252432ca960e78bfd6decd726b Mon Sep 17 00:00:00 2001
From: Robbie Averill
Date: Tue, 17 Jan 2017 16:56:30 +1300
Subject: [PATCH 3/6] FIX Update upgrade mapping, add purifier back into
composer and travis build
---
.travis.yml | 2 +-
.upgrade.yml | 13 ++++++-------
composer.json | 1 +
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 00b0a82..86bfbb6 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -43,7 +43,7 @@ before_script:
- composer self-update || true
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
# Install suggested modules in order to maximize test coverage
- - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "silverstripe/cms:^4.0@dev"
+ - php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss --require "ezyang/htmlpurifier:4.*,silverstripe/cms:^4.0@dev"
- cd ~/builds/ss
script:
diff --git a/.upgrade.yml b/.upgrade.yml
index 42fd6b0..948f795 100644
--- a/.upgrade.yml
+++ b/.upgrade.yml
@@ -4,13 +4,12 @@ mappings:
CommentsGridField: SilverStripe\Comments\Admin\CommentsGridField
CommentsGridFieldAction: SilverStripe\Comments\Admin\CommentsGridFieldAction
CommentsGridFieldBulkAction: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction
- CommentsGridFieldBulkAction_Handlers: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction_Handlers
+ CommentsGridFieldBulkAction_Handlers: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handlers
CommentsGridFieldConfig: SilverStripe\Comments\Admin\CommentsGridFieldConfig
CommentingController: SilverStripe\Comments\Controllers\CommentingController
CommentsExtension: SilverStripe\Comments\Extensions\CommentsExtension
Comment: SilverStripe\Comments\Model\Comment
- Comment_SecurityToken: SilverStripe\Comments\Model\Comment_SecurityToken
- CommentList: SilverStripe\Comments\Model\CommentList
+ Comment_SecurityToken: SilverStripe\Comments\Model\Comment\SecurityToken
CommentAdminTest: SilverStripe\Comments\Tests\CommentAdminTest
CommentingControllerTest: SilverStripe\Comments\Tests\CommentingControllerTest
CommentingTest: SilverStripe\Comments\Tests\CommentingTest
@@ -21,8 +20,8 @@ mappings:
CommentsGridFieldConfigTest: SilverStripe\Comments\Tests\CommentsGridFieldConfigTest
CommentsGridFieldTest: SilverStripe\Comments\Tests\CommentsGridFieldTest
CommentsTest: SilverStripe\Comments\Tests\CommentsTest
- CommentableItem: SilverStripe\Comments\Tests\CommentableItem
- CommentableItemEnabled: SilverStripe\Comments\Tests\CommentableItemEnabled
- CommentableItemDisabled: SilverStripe\Comments\Tests\CommentableItemDisabled
- CommentableItem_Controller: SilverStripe\Comments\Tests\CommentableItem_Controller
+ CommentableItem: SilverStripe\Comments\Tests\Stubs\CommentableItem
+ CommentableItemEnabled: SilverStripe\Comments\Tests\Stubs\CommentableItemEnabled
+ CommentableItemDisabled: SilverStripe\Comments\Tests\Stubs\CommentableItemDisabled
+ CommentableItem_Controller: SilverStripe\Comments\Tests\Stubs\CommentableItemController
CommentTestHelper: SilverStripe\Comments\Tests\CommentTestHelper
diff --git a/composer.json b/composer.json
index 62c31bf..4afc8b5 100644
--- a/composer.json
+++ b/composer.json
@@ -12,6 +12,7 @@
"colymba/gridfield-bulk-editing-tools": "~2.1"
},
"suggest": {
+ "ezyang/htmlpurifier": "Standards compliant HTML filter written in PHP",
"silverstripe/cms": "The SilverStripe Content Management System"
},
"require-dev": {
From 7a92b0915de670a36185afc0fe8fb5babdcf1b92 Mon Sep 17 00:00:00 2001
From: Robbie Averill
Date: Tue, 17 Jan 2017 17:33:39 +1300
Subject: [PATCH 4/6] Remove deprecated@2.0. Update Migrate task to check table
name. Minor tweaks to class names. Use Director::absoluteURL.
---
.travis.yml | 12 +-
.upgrade.yml | 2 -
_config.php | 2 +-
_config/routes.yml | 4 -
src/Admin/CommentsGridFieldBulkAction.php | 13 --
.../CommentsGridFieldBulkAction/Handler.php | 10 +-
src/Admin/CommentsGridFieldConfig.php | 9 +-
src/Commenting.php | 170 ---------------
src/Extensions/CommentsExtension.php | 53 +----
src/Tasks/MigrateCommentParentsTask.php | 19 +-
tests/CommentingTest.php | 200 ------------------
tests/CommentsExtensionTest.php | 36 +---
tests/CommentsTest.php | 8 +-
13 files changed, 30 insertions(+), 508 deletions(-)
delete mode 100644 src/Admin/CommentsGridFieldBulkAction.php
delete mode 100644 src/Commenting.php
delete mode 100644 tests/CommentingTest.php
diff --git a/.travis.yml b/.travis.yml
index 86bfbb6..3aeb37e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,7 +18,7 @@ before_install:
env:
global:
- - DB=MYSQL CORE_RELEASE=4
+ - DB=MYSQL CORE_RELEASE=master
- MODULE_PATH=comments
# Set to 1 in the matrix to enable code coverage
@@ -28,15 +28,15 @@ matrix:
include:
- php: 5.6
#CommentsListTest breaks with this env: DB=MYSQL CORE_RELEASE=3.2 COVERAGE=1
- env: DB=SQLITE CORE_RELEASE=4 COVERAGE=1
+ env: DB=SQLITE CORE_RELEASE=master COVERAGE=1
- php: 5.6
- env: DB=MYSQL CORE_RELEASE=4
+ env: DB=MYSQL CORE_RELEASE=master
- php: 7.0
- env: DB=MYSQL CORE_RELEASE=4
+ env: DB=MYSQL CORE_RELEASE=master
- php: 7.1
- env: DB=MYSQL CORE_RELEASE=4
+ env: DB=MYSQL CORE_RELEASE=master
- php: 5.6
- env: DB=PGSQL CORE_RELEASE=4
+ env: DB=PGSQL CORE_RELEASE=master
before_script:
- phpenv rehash
diff --git a/.upgrade.yml b/.upgrade.yml
index 948f795..b426b9b 100644
--- a/.upgrade.yml
+++ b/.upgrade.yml
@@ -1,9 +1,7 @@
mappings:
- Commenting: SilverStripe\Comments\Commenting
CommentAdmin: SilverStripe\Comments\Admin\CommentAdmin
CommentsGridField: SilverStripe\Comments\Admin\CommentsGridField
CommentsGridFieldAction: SilverStripe\Comments\Admin\CommentsGridFieldAction
- CommentsGridFieldBulkAction: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction
CommentsGridFieldBulkAction_Handlers: SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handlers
CommentsGridFieldConfig: SilverStripe\Comments\Admin\CommentsGridFieldConfig
CommentingController: SilverStripe\Comments\Controllers\CommentingController
diff --git a/_config.php b/_config.php
index 48f849c..83966ab 100644
--- a/_config.php
+++ b/_config.php
@@ -1,6 +1,6 @@
'spam',
'approve' => 'approve',
diff --git a/src/Admin/CommentsGridFieldConfig.php b/src/Admin/CommentsGridFieldConfig.php
index c739925..18ff3eb 100644
--- a/src/Admin/CommentsGridFieldConfig.php
+++ b/src/Admin/CommentsGridFieldConfig.php
@@ -3,14 +3,11 @@
namespace SilverStripe\Comments\Admin;
use Colymba\BulkManager\GridFieldBulkManager;
-use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handlers;
+use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
-/**
- * @package comments
- */
class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
{
public function __construct($itemsPerPage = 25)
@@ -39,7 +36,7 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
$manager->addBulkAction(
'spam',
_t('CommentsGridFieldConfig.SPAM', 'Spam'),
- Handlers::class,
+ Handler::class,
array(
'isAjax' => true,
'icon' => 'cross',
@@ -50,7 +47,7 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
$manager->addBulkAction(
'approve',
_t('CommentsGridFieldConfig.APPROVE', 'Approve'),
- Handlers::class,
+ Handler::class,
array(
'isAjax' => true,
'icon' => 'cross',
diff --git a/src/Commenting.php b/src/Commenting.php
deleted file mode 100644
index 5d3f80e..0000000
--- a/src/Commenting.php
+++ /dev/null
@@ -1,170 +0,0 @@
-update($class, 'extensions', array(CommentsExtension::class));
-
- // Check if settings must be customised
- if ($settings === false) {
- return;
- }
- if (!is_array($settings)) {
- throw new InvalidArgumentException('$settings needs to be an array or null');
- }
- Config::inst()->update($class, 'comments', $settings);
- }
-
- /**
- * Removes commenting from a {@link DataObject}. Does not remove existing comments
- * but does remove the extension.
- *
- * @deprecated since version 2.0
- *
- * @param string $class Class to remove {@link CommentsExtension} from
- */
- public static function remove($class)
- {
- Deprecation::notice('2.0', 'Using Commenting::remove is deprecated. Please use the config API instead');
- $class::remove_extension(CommentsExtension::class);
- }
-
- /**
- * Returns whether a given class name has commenting enabled
- *
- * @deprecated since version 2.0
- *
- * @return bool
- */
- public static function has_commenting($class)
- {
- Deprecation::notice('2.0', 'Using Commenting::has_commenting is deprecated. Please use the config API instead');
- return $class::has_extension(CommentsExtension::class);
- }
-
- /**
- * Sets a value for a class of a given config setting. Passing 'all' as the class
- * sets it for everything
- *
- * @deprecated since version 2.0
- *
- * @param string $class Class to set the value on. Passing 'all' will set it to all
- * active mappings
- * @param string $key setting to change
- * @param mixed $value value of the setting
- */
- public static function set_config_value($class, $key, $value = false)
- {
- Deprecation::notice('2.0', 'Commenting::set_config_value is deprecated. Use the config api instead');
- if ($class === 'all') {
- $class = CommentsExtension::class;
- }
- Config::inst()->update($class, 'comments', array($key => $value));
- }
-
- /**
- * Returns a given config value for a commenting class
- *
- * @deprecated since version 2.0
- *
- * @param string $class
- * @param string $key config value to return
- *
- * @throws Exception
- * @return mixed
- */
- public static function get_config_value($class, $key)
- {
- Deprecation::notice(
- '2.0',
- 'Using Commenting::get_config_value is deprecated. Please use $parent->getCommentsOption() or '
- . 'CommentingController::getOption() instead'
- );
-
- // Get settings
- if (!$class) {
- $class = CommentsExtension::class;
- } elseif (!$class::has_extension(CommentsExtension::class)) {
- throw new InvalidArgumentException("$class does not have commenting enabled");
- }
- return singleton($class)->getCommentsOption($key);
- }
-
- /**
- * Determines whether a config value on the commenting extension
- * matches a given value.
- *
- * @deprecated since version 2.0
- *
- * @param string $class
- * @param string $key
- * @param string $value Expected value
- * @return boolean
- */
- public static function config_value_equals($class, $key, $value)
- {
- $check = self::get_config_value($class, $key);
- if ($check && ($check == $value)) {
- return true;
- }
- }
-
- /**
- * Return whether a user can post on a given commenting instance
- *
- * @deprecated since version 2.0
- *
- * @param string $class
- * @return boolean true
- */
- public static function can_member_post($class)
- {
- Deprecation::notice('2.0', 'Use $instance->canPostComment() directly instead');
- $member = Member::currentUser();
-
- // Check permission
- $permission = self::get_config_value($class, 'required_permission');
- if ($permission && !Permission::check($permission)) {
- return false;
- }
-
- // Check login required
- $requireLogin = self::get_config_value($class, 'require_login');
- return !$requireLogin || $member;
- }
-}
diff --git a/src/Extensions/CommentsExtension.php b/src/Extensions/CommentsExtension.php
index 3edf887..827a754 100644
--- a/src/Extensions/CommentsExtension.php
+++ b/src/Extensions/CommentsExtension.php
@@ -309,20 +309,6 @@ class CommentsExtension extends DataExtension
return $list;
}
- /**
- * Check if comments are configured for this page even if they are currently disabled.
- * Do not include the comments on pages which don't have id's such as security pages
- *
- * @deprecated since version 2.0
- *
- * @return boolean
- */
- public function getCommentsConfigured()
- {
- Deprecation::notice('2.0', 'getCommentsConfigured is deprecated. Use getCommentsEnabled instead');
- return true; // by virtue of all classes with this extension being 'configured'
- }
-
/**
* Determine if comments are enabled for this instance
*
@@ -353,15 +339,6 @@ class CommentsExtension extends DataExtension
return $this->owner->getCommentsOption('comments_holder_id');
}
- /**
- * @deprecated since version 2.0
- */
- public function getPostingRequiresPermission()
- {
- Deprecation::notice('2.0', 'Use getPostingRequiredPermission instead');
- return $this->getPostingRequiredPermission();
- }
-
/**
* Permission codes required in order to post (or empty if none required)
*
@@ -372,12 +349,6 @@ class CommentsExtension extends DataExtension
return $this->owner->getCommentsOption('required_permission');
}
- public function canPost()
- {
- Deprecation::notice('2.0', 'Use canPostComment instead');
- return $this->canPostComment();
- }
-
/**
* Determine if a user can post comments on this item
*
@@ -431,12 +402,6 @@ class CommentsExtension extends DataExtension
return $this->owner->canEdit($member);
}
- public function getRssLink()
- {
- Deprecation::notice('2.0', 'Use getCommentRSSLink instead');
- return $this->getCommentRSSLink();
- }
-
/**
* Gets the RSS link to all comments
*
@@ -444,13 +409,7 @@ class CommentsExtension extends DataExtension
*/
public function getCommentRSSLink()
{
- return Controller::join_links(Director::baseURL(), 'comments/rss');
- }
-
- public function getRssLinkPage()
- {
- Deprecation::notice('2.0', 'Use getCommentRSSLinkPage instead');
- return $this->getCommentRSSLinkPage();
+ return Director::absoluteURL('comments/rss');
}
/**
@@ -524,16 +483,6 @@ class CommentsExtension extends DataExtension
return (is_subclass_of($class, SiteTree::class)) || ($class == SiteTree::class);
}
- /**
- * @deprecated 1.0 Please use {@link CommentsExtension->CommentsForm()}
- */
- public function PageComments()
- {
- // This method is very commonly used, don't throw a warning just yet
- Deprecation::notice('1.0', '$PageComments is deprecated. Please use $CommentsForm');
- return $this->CommentsForm();
- }
-
/**
* Get the commenting option for this object
*
diff --git a/src/Tasks/MigrateCommentParentsTask.php b/src/Tasks/MigrateCommentParentsTask.php
index 98fbf28..aa18aba 100644
--- a/src/Tasks/MigrateCommentParentsTask.php
+++ b/src/Tasks/MigrateCommentParentsTask.php
@@ -2,6 +2,7 @@
namespace SilverStripe\Comments\Tasks;
+use SilverStripe\Comments\Model\Comment;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\BuildTask;
use SilverStripe\ORM\DB;
@@ -13,26 +14,24 @@ use SilverStripe\ORM\DB;
*/
class MigrateCommentParentsTask extends BuildTask
{
- /**
- * {@inheritDoc}
- */
private static $segment = 'MigrateCommentParentsTask';
- /**
- * {@inheritDoc}
- */
protected $title = 'Migrate Comment Parent classes from 3.x';
- /**
- * {@inheritDoc}
- */
protected $description = 'Migrates all 3.x Comment BaseClass fields to the new ParentClass fields in 4.0';
/**
- * {@inheritDoc}
+ * @param HTTPRequest $request
*/
public function run($request)
{
+ // Check if anything needs to be done
+ $tableName = Comment::getSchema()->tableName(Comment::class);
+ if (!DB::get_schema()->hasField($tableName, 'BaseClass')) {
+ DB::alteration_message('"BaseClass" does not exist on "' . $tableName . '", nothing to upgrade.', 'notice');
+ return;
+ }
+
// Set the class names to fully qualified class names first
$remapping = Config::inst()->get('SilverStripe\\ORM\\DatabaseAdmin', 'classname_value_remapping');
$updateQuery = "UPDATE \"Comment\" SET \"BaseClass\" = ? WHERE \"BaseClass\" = ?";
diff --git a/tests/CommentingTest.php b/tests/CommentingTest.php
deleted file mode 100644
index a773132..0000000
--- a/tests/CommentingTest.php
+++ /dev/null
@@ -1,200 +0,0 @@
-assertEquals($expected, $e->getMessage());
- }
- }
- }
-
- public function testSetConfigValue()
- {
- // public static function set_config_value($class, $key, $value = false) {
- Commenting::set_config_value(
- CommentableItem::class,
- 'comments_holder_id',
- 'commentable_item'
- );
-
- $config = Config::inst()->get(
- CommentableItem::class,
- 'comments'
- );
- $actual = $config['comments_holder_id'];
-
- $this->assertEquals(
- 'commentable_item',
- $actual
- );
- Commenting::set_config_value(
- 'all',
- 'comments_holder_id',
- 'all_items_actually_commentsextension'
- );
-
- $config = Config::inst()->get(
- CommentsExtension::class,
- 'comments'
- );
- $actual = $config['comments_holder_id'];
- $this->assertEquals(
- 'all_items_actually_commentsextension',
- $actual
- );
- }
-
- public function testGetConfigValue()
- {
- Config::inst()->update(
- CommentableItem::class,
- 'comments',
- array(
- 'comments_holder_id' => 'commentable_item'
- )
- );
- $this->assertEquals(
- 'commentable_item',
- Commenting::get_config_value(CommentableItem::class, 'comments_holder_id')
- );
-
- Config::inst()->update(
- CommentsExtension::class,
- 'comments',
- array(
- 'comments_holder_id' => 'comments_extension'
- )
- );
- // if class is null, method uses the CommentsExtension property
- $this->assertEquals(
- 'comments_extension',
- Commenting::get_config_value(null, 'comments_holder_id')
- );
-
- $this->setExpectedException(
- 'InvalidArgumentException',
- 'Member does not have commenting enabled'
- );
- Commenting::get_config_value(Member::class, 'comments_holder_id');
- }
-
- public function testConfigValueEquals()
- {
- Config::inst()->update(
- CommentableItem::class,
- 'comments',
- array(
- 'comments_holder_id' => 'some_value'
- )
- );
-
- $this->assertTrue(
- Commenting::config_value_equals(
- CommentableItem::class,
- 'comments_holder_id',
- 'some_value'
- )
- );
-
- $this->assertNull(
- Commenting::config_value_equals(
- CommentableItem::class,
- 'comments_holder_id',
- 'not_some_value'
- )
- );
- }
-
- public function testAdd()
- {
- Commenting::add(Member::class, array('comments_holder_id' => 'test_add_value'));
-
- $config = Config::inst()->get(
- Member::class,
- 'comments'
- );
- $actual = $config['comments_holder_id'];
- $this->assertEquals(
- 'test_add_value',
- $actual
- );
-
- Commenting::add(Member::class);
-
- $config = Config::inst()->get(
- Member::class,
- 'comments'
- );
- $actual = $config['comments_holder_id'];
- // no settings updated
- $this->assertEquals(
- 'test_add_value',
- $actual
- );
-
- $this->setExpectedException('InvalidArgumentException', "\$settings needs to be an array or null");
- Commenting::add(Member::class, 'illegal format, not an array');
- }
-
- public function testCanMemberPost()
- {
- // logout
- if ($member = Member::currentUser()) {
- $member->logOut();
- }
-
- Config::inst()->update(
- CommentableItem::class,
- 'comments',
- array(
- 'require_login' => false
- )
- );
- $this->assertTrue(Commenting::can_member_post(CommentableItem::class));
-
- Config::inst()->update(
- CommentableItem::class,
- 'comments',
- array(
- 'require_login' => true
- )
- );
- $this->assertFalse(Commenting::can_member_post(CommentableItem::class));
-
- $this->logInWithPermission('CMS_ACCESS_CommentAdmin');
- $this->assertTrue(Commenting::can_member_post(CommentableItem::class));
-
- Config::inst()->update(
- CommentableItem::class,
- 'comments',
- array(
- 'require_login' => false
- )
- );
-
- $this->assertTrue(Commenting::can_member_post(CommentableItem::class));
- }
-}
diff --git a/tests/CommentsExtensionTest.php b/tests/CommentsExtensionTest.php
index e950aa3..bee4b55 100644
--- a/tests/CommentsExtensionTest.php
+++ b/tests/CommentsExtensionTest.php
@@ -2,7 +2,6 @@
namespace SilverStripe\Comments\Tests;
-use PHPUnit_Framework_Error_Deprecated;
use SilverStripe\Comments\Extensions\CommentsExtension;
use SilverStripe\Comments\Model\Comment;
use SilverStripe\Comments\Tests\CommentTestHelper;
@@ -199,18 +198,21 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentRSSLink()
{
+ Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
+
$item = $this->objFromFixture(CommentableItem::class, 'first');
$link = $item->getCommentRSSLink();
- $this->assertEquals('/comments/rss', $link);
+ $this->assertEquals('http://unittesting.local/comments/rss', $link);
}
-
public function testGetCommentRSSLinkPage()
{
+ Config::inst()->update('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
+
$item = $this->objFromFixture(CommentableItem::class, 'first');
$page = $item->getCommentRSSLinkPage();
$this->assertEquals(
- '/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID,
+ 'http://unittesting.local/comments/rss/SilverStripe-Comments-Tests-Stubs-CommentableItem/' . $item->ID,
$page
);
}
@@ -447,30 +449,4 @@ class CommentsExtensionTest extends SapphireTest
$fields
);
}
-
- public function testDeprecatedMethods()
- {
- $item = $this->objFromFixture(CommentableItem::class, 'first');
- $methodNames = array(
- 'getRssLinkPage',
- 'getRssLink',
- 'PageComments',
- 'getPostingRequiresPermission',
- 'canPost',
- 'getCommentsConfigured'
- );
-
- foreach ($methodNames as $methodName) {
- try {
- $item->$methodName();
- $this->fail('Method ' . $methodName .' should be depracated');
- } catch (PHPUnit_Framework_Error_Deprecated $e) {
- $expected = 'SilverStripe\\Comments\\Extensions\\CommentsExtension->' . $methodName . ' is '
- . 'deprecated.';
- $this->assertStringStartsWith($expected, $e->getMessage());
- }
- }
-
- // ooh, $this->setExpectedException('ExpectedException', 'Expected Message');
- }
}
diff --git a/tests/CommentsTest.php b/tests/CommentsTest.php
index 4dbb8f3..9be355a 100644
--- a/tests/CommentsTest.php
+++ b/tests/CommentsTest.php
@@ -24,14 +24,10 @@ use SilverStripe\Security\Permission;
*/
class CommentsTest extends FunctionalTest
{
- /**
- * {@inheritDoc}
- */
+
public static $fixture_file = 'comments/tests/CommentsTest.yml';
- /**
- * {@inheritDoc}
- */
+
protected $extraDataObjects = array(
CommentableItem::class,
CommentableItemEnabled::class,
From 279d47f43c52cadc222b9286c92e6cbe2d3afd05 Mon Sep 17 00:00:00 2001
From: Andrew Aitken-Fincham
Date: Thu, 19 Jan 2017 13:23:00 +0000
Subject: [PATCH 5/6] FIX namespacing for BulkManager
This namespace changes once BulkManager gets updated to ss4.
---
src/Admin/CommentsGridFieldConfig.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/Admin/CommentsGridFieldConfig.php b/src/Admin/CommentsGridFieldConfig.php
index 18ff3eb..1661468 100644
--- a/src/Admin/CommentsGridFieldConfig.php
+++ b/src/Admin/CommentsGridFieldConfig.php
@@ -2,7 +2,7 @@
namespace SilverStripe\Comments\Admin;
-use Colymba\BulkManager\GridFieldBulkManager;
+use Colymba\BulkManager\BulkManager;
use SilverStripe\Comments\Admin\CommentsGridFieldBulkAction\Handler;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
@@ -31,7 +31,7 @@ class CommentsGridFieldConfig extends GridFieldConfig_RecordEditor
));
// Add bulk option
- $manager = new GridFieldBulkManager();
+ $manager = new BulkManager();
$manager->addBulkAction(
'spam',
From 978879e01c927ae1c12212fde35d53613a2204dd Mon Sep 17 00:00:00 2001
From: Damian Mooyman
Date: Wed, 25 Jan 2017 17:51:21 +1300
Subject: [PATCH 6/6] Fix incorrect namespace
---
src/Admin/CommentsGridFieldBulkAction/Handler.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/Admin/CommentsGridFieldBulkAction/Handler.php b/src/Admin/CommentsGridFieldBulkAction/Handler.php
index ee7c3eb..407872e 100644
--- a/src/Admin/CommentsGridFieldBulkAction/Handler.php
+++ b/src/Admin/CommentsGridFieldBulkAction/Handler.php
@@ -2,7 +2,7 @@
namespace SilverStripe\Comments\Admin\CommentsGridFieldBulkAction;
-use Colymba\BulkManager\GridFieldBulkActionHandler;
+use Colymba\BulkManager\BulkAction\Handler as GridFieldBulkActionHandler;
use SilverStripe\Core\Convert;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse;