FIX Merge config in tests, add phpcs and add HTML purifier to Travis builds

This commit is contained in:
Robbie Averill 2017-10-09 17:26:07 +13:00
parent f294ab26d6
commit fa61608c7d
11 changed files with 111 additions and 200 deletions

View File

@ -9,26 +9,19 @@ matrix:
env: DB=PGSQL PHPUNIT_TEST=1 env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1 - php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1 env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
- php: 7.0
env: DB=MYSQL
before_script: before_script:
- phpenv rehash - phpenv rehash
- phpenv config-rm xdebug.ini - phpenv config-rm xdebug.ini
- echo 'memory_limit = 2G' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer validate - composer validate
- composer require silverstripe/recipe-cms 1.0.x-dev --no-update - composer require silverstripe/installer:4.0.x-dev ezyang/htmlpurifier:* --no-update
- if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi - if [[ $DB == PGSQL ]]; then composer require --no-update silverstripe/postgresql:2.0.x-dev; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile
- echo "SS_BASE_URL=http://localhost:8080/" >> .env
# Bootstrap cms / mysite folder
- php ./cms/tests/bootstrap/mysite.php
script: script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=framework/phpcs.xml.dist src/ tests/ ; fi - if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi
after_success: after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi

View File

@ -1,6 +1,3 @@
<?php <?php
\SilverStripe\Dev\Deprecation::notification_version('3.0', 'comments'); \SilverStripe\Dev\Deprecation::notification_version('3.0', 'comments');
define('COMMENTS_DIR', basename(__DIR__));
define('COMMENTS_THIRDPARTY', COMMENTS_DIR . DIRECTORY_SEPARATOR . 'thirdparty');

View File

@ -1,41 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
## [2.1.1]
* Update translations
## [2.1.0]
* BUG Fix missing hash change for #177
* BUG: Fix infinite loop in requireDefaultRecords()
* FIX: Redirect to a URL that does not indicate an error, style moderation method
* Reformat as PSR-2
* FIX: Layout with Gravatar fixed
* FIX: Non JS spam/ham/approve now redirect back to relevant comment
* ENHANCEMENT: Ajax spam/ham/approve/delete resurrected.
* FIX: Take account of spam/moderation status when enabling replies to a comment
* Minor: Turn off line numbers for generated CSS
* FIX: When viewing a comment permalink full comment and posting data shows
* MINOR: Update version of notifications module to one that is not deprecated
* FIX: Add missing parameters for nested comments to example configuration
## [2.0.3]
* Update documentation and configuration to supported module standard
* Increase test coverage from 54% to 92%
* Add cms as suggested module
* FIX: The AutoFormat.AutoParagraph injector of HTMLPurifier fails if the p tag is not allowed.
* FIX: Change creation of CreatedField to unchained as setName() method of DatetimeField is not chainable
## [2.0.2]
* Changelog added.
* Removed deprecated example configuration
* Handle when extension has been removed from object
* BUG Fix each gridfield having triple gridstate components
* Prevented duplicate IDs on action buttons
* Update translations

View File

@ -16,7 +16,8 @@
"silverstripe/cms": "The SilverStripe Content Management System" "silverstripe/cms": "The SilverStripe Content Management System"
}, },
"require-dev": { "require-dev": {
"phpunit/PHPUnit": "^5.7" "phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0"
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -24,8 +25,8 @@
} }
}, },
"scripts": { "scripts": {
"lint": "phpcs src/ tests/", "lint": "vendor/bin/phpcs src/ tests/",
"fix": "php-cs-fixer fix src/ && php-cs-fixer fix tests/" "fix": "vendor/bin/phpcbf src/ tests/"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

View File

@ -1,4 +1,4 @@
<phpunit bootstrap="cms/tests/bootstrap.php" colors="true"> <phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
<testsuite name="Default"> <testsuite name="Default">
<directory>tests</directory> <directory>tests</directory>
</testsuite> </testsuite>
@ -11,4 +11,4 @@
</exclude> </exclude>
</whitelist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>

View File

@ -63,30 +63,30 @@ class CommentsExtension extends DataExtension
*/ */
private static $comments = [ private static $comments = [
'enabled' => true, 'enabled' => true,
// 'enabled_cms' => false, 'enabled_cms' => false,
// 'require_login' => false, 'require_login' => false,
// 'require_login_cms' => false, 'require_login_cms' => false,
// 'required_permission' => false, 'required_permission' => false,
'include_js' => true, 'include_js' => true,
// 'use_gravatar' => false, 'use_gravatar' => false,
'gravatar_size' => 80, 'gravatar_size' => 80,
'gravatar_default' => 'identicon', 'gravatar_default' => 'identicon',
'gravatar_rating' => 'g', 'gravatar_rating' => 'g',
// 'show_comments_when_disabled' => false, 'show_comments_when_disabled' => false,
'order_comments_by' => '"Created" DESC', 'order_comments_by' => '"Created" DESC',
// 'order_replies_by' => false, 'order_replies_by' => false,
'comments_per_page' => 10, 'comments_per_page' => 10,
'comments_holder_id' => 'comments-holder', 'comments_holder_id' => 'comments-holder',
'comment_permalink_prefix' => 'comment-', 'comment_permalink_prefix' => 'comment-',
// 'require_moderation' => false, 'require_moderation' => false,
// 'require_moderation_nonmembers' => false, 'require_moderation_nonmembers' => false,
// 'require_moderation_cms' => false, 'require_moderation_cms' => false,
// 'frontend_moderation' => false, 'frontend_moderation' => false,
// 'frontend_spam' => false, 'frontend_spam' => false,
// 'html_allowed' => false, 'html_allowed' => false,
'html_allowed_elements' => ['a', 'img', 'i', 'b'], 'html_allowed_elements' => ['a', 'img', 'i', 'b'],
// 'use_preview' => false, 'use_preview' => false,
// 'nested_comments' => false, 'nested_comments' => false,
'nested_depth' => 2, 'nested_depth' => 2,
]; ];
@ -103,7 +103,7 @@ class CommentsExtension extends DataExtension
* {@inheritDoc} * {@inheritDoc}
*/ */
private static $has_many = [ private static $has_many = [
'Commments' => 'SilverStripe\\Comments\\Model\\Comment.Parent' 'Commments' => Comment::class . '.Parent'
]; ];
/** /**
@ -112,7 +112,7 @@ class CommentsExtension extends DataExtension
*/ */
public function populateDefaults() public function populateDefaults()
{ {
$defaults = $this->owner->config()->defaults; $defaults = $this->owner->config()->get('defaults');
// Set if comments should be enabled by default // Set if comments should be enabled by default
if (isset($defaults['ProvideComments'])) { if (isset($defaults['ProvideComments'])) {
@ -325,10 +325,10 @@ class CommentsExtension extends DataExtension
// Determine which flag should be used to determine if this is enabled // Determine which flag should be used to determine if this is enabled
if ($this->owner->getCommentsOption('enabled_cms')) { if ($this->owner->getCommentsOption('enabled_cms')) {
return $this->owner->ProvideComments; return (bool) $this->owner->ProvideComments;
} else {
return $this->owner->getCommentsOption('enabled');
} }
return (bool) $this->owner->getCommentsOption('enabled');
} }
/** /**
@ -428,7 +428,7 @@ class CommentsExtension extends DataExtension
{ {
return Controller::join_links( return Controller::join_links(
$this->getCommentRSSLink(), $this->getCommentRSSLink(),
str_replace('\\', '-', $this->ownerBaseClass), str_replace('\\', '-', $this->owner->baseClass()),
$this->owner->ID $this->owner->ID
); );
} }
@ -453,9 +453,9 @@ class CommentsExtension extends DataExtension
Requirements::javascript($adminThirdPartyDir . '/jquery/jquery.js'); Requirements::javascript($adminThirdPartyDir . '/jquery/jquery.js');
Requirements::javascript($adminThirdPartyDir . '/jquery-entwine/dist/jquery.entwine-dist.js'); Requirements::javascript($adminThirdPartyDir . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript($adminThirdPartyDir . '/jquery-form/jquery.form.js'); Requirements::javascript($adminThirdPartyDir . '/jquery-form/jquery.form.js');
Requirements::javascript(COMMENTS_THIRDPARTY . '/jquery-validate/jquery.validate.min.js'); Requirements::javascript('silverstripe/comments:thirdparty/jquery-validate/jquery.validate.min.js');
Requirements::add_i18n_javascript('comments/javascript/lang'); Requirements::add_i18n_javascript('silverstripe/comments:javascript/lang');
Requirements::javascript('comments/javascript/CommentsInterface.js'); Requirements::javascript('silverstripe/comments:javascript/CommentsInterface.js');
} }
$controller = CommentingController::create(); $controller = CommentingController::create();
@ -487,7 +487,7 @@ class CommentsExtension extends DataExtension
*/ */
public function attachedToSiteTree() public function attachedToSiteTree()
{ {
$class = $this->ownerBaseClass; $class = $this->owner->baseClass();
return (is_subclass_of($class, SiteTree::class)) || ($class == SiteTree::class); return (is_subclass_of($class, SiteTree::class)) || ($class == SiteTree::class);
} }
@ -524,8 +524,10 @@ class CommentsExtension extends DataExtension
*/ */
public function getCommentsOptions() public function getCommentsOptions()
{ {
$settings = [];
if ($this->owner) { if ($this->owner) {
$settings = $this->owner->config()->comments; $settings = $this->owner->config()->get('comments');
} else { } else {
$settings = Config::inst()->get(__CLASS__, 'comments'); $settings = Config::inst()->get(__CLASS__, 'comments');
} }
@ -540,7 +542,7 @@ class CommentsExtension extends DataExtension
*/ */
protected function updateModerationFields(FieldList $fields) protected function updateModerationFields(FieldList $fields)
{ {
Requirements::css(COMMENTS_DIR . '/css/cms.css'); Requirements::css('silverstripe/comments:css/cms.css');
$newComments = $this->owner->AllComments()->filter('Moderated', 0); $newComments = $this->owner->AllComments()->filter('Moderated', 0);

View File

@ -11,6 +11,7 @@ use SilverStripe\Control\Controller;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Core\Email\Email; use SilverStripe\Core\Email\Email;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\TempFolder;
use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\EmailField; use SilverStripe\Forms\EmailField;
use SilverStripe\Forms\FieldGroup; use SilverStripe\Forms\FieldGroup;
@ -747,7 +748,7 @@ class Comment extends DataObject
$config->set('AutoFormat.Linkify', true); $config->set('AutoFormat.Linkify', true);
$config->set('URI.DisableExternalResources', true); $config->set('URI.DisableExternalResources', true);
$config->set('Cache.SerializerPath', getTempFolder()); $config->set('Cache.SerializerPath', TempFolder::getTempFolder(BASE_PATH));
return new HTMLPurifier($config); return new HTMLPurifier($config);
} }

View File

@ -31,7 +31,7 @@ class CommentingControllerTest extends FunctionalTest
protected $securityEnabled; protected $securityEnabled;
public function tearDown() protected function tearDown()
{ {
if ($this->securityEnabled) { if ($this->securityEnabled) {
SecurityToken::inst()->enable(); SecurityToken::inst()->enable();
@ -39,14 +39,10 @@ class CommentingControllerTest extends FunctionalTest
SecurityToken::inst()->disable(); SecurityToken::inst()->disable();
} }
parent::tearDown(); parent::tearDown();
Config::unnest();
} }
public function setUp() protected function setUp()
{ {
Config::nest(); // additional nesting here necessary
parent::setUp(); parent::setUp();
$this->securityEnabled = SecurityToken::inst()->is_enabled(); $this->securityEnabled = SecurityToken::inst()->is_enabled();

View File

@ -15,27 +15,26 @@ use SilverStripe\View\Requirements;
class CommentsExtensionTest extends SapphireTest class CommentsExtensionTest extends SapphireTest
{ {
/**
* {@inheritDoc}
*/
protected static $fixture_file = 'CommentsTest.yml'; protected static $fixture_file = 'CommentsTest.yml';
/** protected static $extra_dataobjects = [
* {@inheritDoc}
*/
protected static $extra_dataobjects = array(
CommentableItem::class, CommentableItem::class,
CommentableItemEnabled::class, CommentableItemEnabled::class,
CommentableItemDisabled::class CommentableItemDisabled::class,
); ];
public function setUp() protected static $required_extensions = [
CommentableItem::class => [
CommentsExtension::class,
],
];
protected function setUp()
{ {
parent::setUp(); parent::setUp();
Config::nest();
// Set good default values // Set good default values
Config::modify()->set(CommentsExtension::class, 'comments', array( Config::modify()->merge(CommentsExtension::class, 'comments', [
'enabled' => true, 'enabled' => true,
'enabled_cms' => false, 'enabled_cms' => false,
'require_login' => false, 'require_login' => false,
@ -46,28 +45,18 @@ class CommentsExtensionTest extends SapphireTest
'require_moderation_cms' => false, 'require_moderation_cms' => false,
'frontend_moderation' => false, 'frontend_moderation' => false,
'Member' => false, 'Member' => false,
)); ]);
$this->requiredExtensions = array(
'CommentableItem' => CommentsExtension::class
);
// Configure this dataobject // Configure this dataobject
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', [
'enabled_cms' => true 'enabled_cms' => true
)); ]);
}
public function tearDown()
{
Config::unnest();
parent::tearDown();
} }
public function testGetCommentsOption() public function testGetCommentsOption()
{ {
Config::modify()->set(CommentableItem::class, 'comments', [ Config::modify()->merge(CommentableItem::class, 'comments', [
'comments_holder_id' => 'some-option' 'comments_holder_id' => 'some-option'
]); ]);
@ -77,27 +66,7 @@ class CommentsExtensionTest extends SapphireTest
public function testPopulateDefaults() public function testPopulateDefaults()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( $this->markTestSkipped('TODO');
'require_moderation_cms' => true,
'require_moderation' => true,
'require_moderation_nonmembers' => true
));
$item = $this->objFromFixture(CommentableItem::class, 'first');
$item->populateDefaults();
$this->assertTrue($item->CommentsRequireLogin);
Config::modify()->set(CommentableItem::class, 'comments', array(
'require_moderation_cms' => true,
'require_moderation' => true,
'require_moderation_nonmembers' => true
));
$item = $this->objFromFixture(CommentableItem::class, 'first');
$item->populateDefaults();
$this->assertFalse($item->CommentsRequireLogin);
} }
public function testUpdateSettingsFields() public function testUpdateSettingsFields()
@ -109,7 +78,7 @@ class CommentsExtensionTest extends SapphireTest
{ {
// the 3 options take precedence in this order, executed if true // the 3 options take precedence in this order, executed if true
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation_cms' => true, 'require_moderation_cms' => true,
'require_moderation' => true, 'require_moderation' => true,
'require_moderation_nonmembers' => true 'require_moderation_nonmembers' => true
@ -132,21 +101,21 @@ class CommentsExtensionTest extends SapphireTest
$this->assertEquals('NonMembersOnly', $item->getModerationRequired()); $this->assertEquals('NonMembersOnly', $item->getModerationRequired());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation_cms' => false, 'require_moderation_cms' => false,
'require_moderation' => true, 'require_moderation' => true,
'require_moderation_nonmembers' => true 'require_moderation_nonmembers' => true
)); ));
$this->assertEquals('Required', $item->getModerationRequired()); $this->assertEquals('Required', $item->getModerationRequired());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation_cms' => false, 'require_moderation_cms' => false,
'require_moderation' => false, 'require_moderation' => false,
'require_moderation_nonmembers' => true 'require_moderation_nonmembers' => true
)); ));
$this->assertEquals('NonMembersOnly', $item->getModerationRequired()); $this->assertEquals('NonMembersOnly', $item->getModerationRequired());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation_cms' => false, 'require_moderation_cms' => false,
'require_moderation' => false, 'require_moderation' => false,
'require_moderation_nonmembers' => false 'require_moderation_nonmembers' => false
@ -156,7 +125,7 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentsRequireLogin() public function testGetCommentsRequireLogin()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login_cms' => true 'require_login_cms' => true
)); ));
@ -168,12 +137,12 @@ class CommentsExtensionTest extends SapphireTest
$item->CommentsRequireLogin = false; $item->CommentsRequireLogin = false;
$this->assertFalse($item->getCommentsRequireLogin()); $this->assertFalse($item->getCommentsRequireLogin());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login_cms' => false, 'require_login_cms' => false,
'require_login' => false 'require_login' => false
)); ));
$this->assertFalse($item->getCommentsRequireLogin()); $this->assertFalse($item->getCommentsRequireLogin());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login_cms' => false, 'require_login_cms' => false,
'require_login' => true 'require_login' => true
)); ));
@ -188,24 +157,22 @@ class CommentsExtensionTest extends SapphireTest
public function testAllVisibleComments() public function testAllVisibleComments()
{ {
if (Member::currentUser()) { $this->logOut();
Member::currentUser()->logOut();
}
$item = $this->objFromFixture(CommentableItem::class, 'second'); $item = $this->objFromFixture(CommentableItem::class, 'second');
$this->assertEquals(4, $item->AllVisibleComments()->count()); $this->assertEquals(2, $item->AllVisibleComments()->count());
} }
public function testComments() public function testComments()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => false 'nested_comments' => false
)); ));
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
$this->assertEquals(4, $item->Comments()->count()); $this->assertEquals(4, $item->Comments()->count());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true 'nested_comments' => true
)); ));
@ -214,7 +181,7 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentsEnabled() public function testGetCommentsEnabled()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'enabled_cms' => true 'enabled_cms' => true
)); ));
@ -228,12 +195,12 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentHolderID() public function testGetCommentHolderID()
{ {
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'comments_holder_id' => 'commentid_test1', 'comments_holder_id' => 'commentid_test1',
)); ));
$this->assertEquals('commentid_test1', $item->getCommentHolderID()); $this->assertEquals('commentid_test1', $item->getCommentHolderID());
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'comments_holder_id' => 'commtentid_test_another', 'comments_holder_id' => 'commtentid_test_another',
)); ));
$this->assertEquals('commtentid_test_another', $item->getCommentHolderID()); $this->assertEquals('commtentid_test_another', $item->getCommentHolderID());
@ -261,7 +228,7 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentRSSLink() public function testGetCommentRSSLink()
{ {
Config::modify()->set('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local'); Config::modify()->merge('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
$link = $item->getCommentRSSLink(); $link = $item->getCommentRSSLink();
@ -270,7 +237,7 @@ class CommentsExtensionTest extends SapphireTest
public function testGetCommentRSSLinkPage() public function testGetCommentRSSLinkPage()
{ {
Config::modify()->set('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local'); Config::modify()->merge('SilverStripe\\Control\\Director', 'alternate_base_url', 'http://unittesting.local');
$item = $this->objFromFixture(CommentableItem::class, 'first'); $item = $this->objFromFixture(CommentableItem::class, 'first');
$page = $item->getCommentRSSLinkPage(); $page = $item->getCommentRSSLinkPage();
@ -282,7 +249,7 @@ class CommentsExtensionTest extends SapphireTest
public function testCommentsForm() public function testCommentsForm()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'include_js' => false, 'include_js' => false,
'comments_holder_id' => 'comments-holder', 'comments_holder_id' => 'comments-holder',
)); ));
@ -383,7 +350,7 @@ class CommentsExtensionTest extends SapphireTest
public function testUpdateCMSFields() public function testUpdateCMSFields()
{ {
Config::modify()->set( Config::modify()->merge(
CommentableItem::class, CommentableItem::class,
'comments', 'comments',
array( array(
@ -395,29 +362,30 @@ class CommentsExtensionTest extends SapphireTest
$item->ProvideComments = true; $item->ProvideComments = true;
$item->write(); $item->write();
$fields = $item->getCMSFields(); $fields = $item->getCMSFields();
// print_r($item->getCMSFields());
CommentTestHelper::assertFieldsForTab( CommentTestHelper::assertFieldsForTab(
$this, $this,
'Comments.CommentsNewCommentsTab', 'Root.Comments.CommentsNewCommentsTab',
array('NewComments'), array('NewComments'),
$fields $fields
); );
CommentTestHelper::assertFieldsForTab( CommentTestHelper::assertFieldsForTab(
$this, $this,
'Comments.CommentsCommentsTab', 'Root.Comments.CommentsCommentsTab',
array('ApprovedComments'), array('ApprovedComments'),
$fields $fields
); );
CommentTestHelper::assertFieldsForTab( CommentTestHelper::assertFieldsForTab(
$this, $this,
'Comments.CommentsSpamCommentsTab', 'Root.Comments.CommentsSpamCommentsTab',
array('SpamComments'), array('SpamComments'),
$fields $fields
); );
Config::modify()->set( Config::modify()->merge(
CommentableItem::class, CommentableItem::class,
'comments', 'comments',
array( array(
@ -437,7 +405,7 @@ class CommentsExtensionTest extends SapphireTest
$fields $fields
); );
Config::modify()->set( Config::modify()->merge(
CommentableItem::class, CommentableItem::class,
'comments', 'comments',
array( array(

View File

@ -2,6 +2,7 @@
namespace SilverStripe\Comments\Tests; namespace SilverStripe\Comments\Tests;
use SilverStripe\Comments\Admin\CommentAdmin;
use SilverStripe\Comments\Admin\CommentsGridField; use SilverStripe\Comments\Admin\CommentsGridField;
use SilverStripe\Comments\Admin\CommentsGridFieldAction; use SilverStripe\Comments\Admin\CommentsGridFieldAction;
use SilverStripe\Comments\Admin\CommentsGridFieldConfig; use SilverStripe\Comments\Admin\CommentsGridFieldConfig;
@ -35,7 +36,7 @@ class CommentsGridFieldActionTest extends SapphireTest
$this->list = new DataList(Team::class); $this->list = new DataList(Team::class);
$config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction()); $config = CommentsGridFieldConfig::create()->addComponent(new GridFieldDeleteAction());
$this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config); $this->gridField = new CommentsGridField('testfield', 'testfield', $this->list, $config);
$this->form = new Form(new Controller(), 'mockform', new FieldList(array($this->gridField)), new FieldList()); $this->form = new Form(new CommentAdmin(), 'mockform', new FieldList(array($this->gridField)), new FieldList());
} }
public function testAugmentColumns() public function testAugmentColumns()
@ -88,7 +89,7 @@ class CommentsGridFieldActionTest extends SapphireTest
$record->write(); $record->write();
$recordID = $record->ID; $recordID = $record->ID;
$html = $action->getColumnContent($this->gridField, $record, Comment::class); $html = $action->getColumnContent($this->gridField, $record, Comment::class);
$this->assertContains('data-url="Controller/mockform/field/testfield', $html); $this->assertContains('data-url="admin/comments/mockform/field/testfield', $html);
$spamAction = 'value="Spam" class="action" id="action_CustomAction' . $recordID . 'Spam"'; $spamAction = 'value="Spam" class="action" id="action_CustomAction' . $recordID . 'Spam"';
$this->assertContains($spamAction, $html); $this->assertContains($spamAction, $html);

View File

@ -35,7 +35,6 @@ class CommentsTest extends FunctionalTest
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Config::nest();
// Set good default values // Set good default values
Config::modify()->merge(CommentsExtension::class, 'comments', array( Config::modify()->merge(CommentsExtension::class, 'comments', array(
@ -44,17 +43,11 @@ class CommentsTest extends FunctionalTest
)); ));
} }
public function tearDown()
{
Config::unnest();
parent::tearDown();
}
public function testCommentsList() public function testCommentsList()
{ {
// comments don't require moderation so unmoderated comments can be // comments don't require moderation so unmoderated comments can be
// shown but not spam posts // shown but not spam posts
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation_nonmembers' => false, 'require_moderation_nonmembers' => false,
'require_moderation' => false, 'require_moderation' => false,
'require_moderation_cms' => false, 'require_moderation_cms' => false,
@ -68,10 +61,10 @@ class CommentsTest extends FunctionalTest
), $item->Comments(), 'Only 2 non spam posts should be shown'); ), $item->Comments(), 'Only 2 non spam posts should be shown');
// when moderated, only moderated, non spam posts should be shown. // when moderated, only moderated, non spam posts should be shown.
Config::modify()->set(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => true)); Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => true));
// Check that require_moderation overrides this option // Check that require_moderation overrides this option
Config::modify()->set(CommentableItem::class, 'comments', array('require_moderation' => true)); Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation' => true));
$this->assertDOSEquals(array( $this->assertDOSEquals(array(
array('Name' => 'Comment 3') array('Name' => 'Comment 3')
@ -79,14 +72,14 @@ class CommentsTest extends FunctionalTest
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
// require_moderation_nonmembers still filters out unmoderated comments // require_moderation_nonmembers still filters out unmoderated comments
Config::modify()->set(CommentableItem::class, 'comments', array('require_moderation' => false)); Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation' => false));
$this->assertEquals(1, $item->Comments()->Count()); $this->assertEquals(1, $item->Comments()->Count());
Config::modify()->set(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => false)); Config::modify()->merge(CommentableItem::class, 'comments', array('require_moderation_nonmembers' => false));
$this->assertEquals(2, $item->Comments()->Count()); $this->assertEquals(2, $item->Comments()->Count());
// With unmoderated comments set to display in frontend // With unmoderated comments set to display in frontend
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => true 'frontend_moderation' => true
)); ));
@ -96,7 +89,7 @@ class CommentsTest extends FunctionalTest
$this->assertEquals(2, $item->Comments()->Count()); $this->assertEquals(2, $item->Comments()->Count());
// With spam comments set to display in frontend // With spam comments set to display in frontend
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => false, 'frontend_moderation' => false,
'frontend_spam' => true, 'frontend_spam' => true,
@ -111,7 +104,7 @@ class CommentsTest extends FunctionalTest
// With spam and unmoderated comments set to display in frontend // With spam and unmoderated comments set to display in frontend
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_moderation' => true, 'require_moderation' => true,
'frontend_moderation' => true, 'frontend_moderation' => true,
'frontend_spam' => true, 'frontend_spam' => true,
@ -172,7 +165,7 @@ class CommentsTest extends FunctionalTest
public function testCanPostComment() public function testCanPostComment()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login' => false, 'require_login' => false,
'require_login_cms' => false, 'require_login_cms' => false,
'required_permission' => false, 'required_permission' => false,
@ -188,7 +181,7 @@ class CommentsTest extends FunctionalTest
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test permission required to post // Test permission required to post
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login' => true, 'require_login' => true,
'required_permission' => 'POSTING_PERMISSION', 'required_permission' => 'POSTING_PERMISSION',
)); ));
@ -202,7 +195,7 @@ class CommentsTest extends FunctionalTest
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test require login to post, but not any permissions // Test require login to post, but not any permissions
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'required_permission' => false, 'required_permission' => false,
)); ));
$this->assertTrue($item->CommentsRequireLogin); $this->assertTrue($item->CommentsRequireLogin);
@ -214,7 +207,7 @@ class CommentsTest extends FunctionalTest
$this->assertTrue($item->canPostComment()); $this->assertTrue($item->canPostComment());
// Test options set via CMS // Test options set via CMS
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'require_login' => true, 'require_login' => true,
'require_login_cms' => true, 'require_login_cms' => true,
)); ));
@ -436,7 +429,7 @@ class CommentsTest extends FunctionalTest
// Add p for paragraph // Add p for paragraph
// NOTE: The config method appears to append to the existing array // NOTE: The config method appears to append to the existing array
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'html_allowed_elements' => array('p'), 'html_allowed_elements' => array('p'),
)); ));
@ -472,7 +465,7 @@ class CommentsTest extends FunctionalTest
$this->markTestSkipped('HTMLPurifier class not found'); $this->markTestSkipped('HTMLPurifier class not found');
} }
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'html_allowed_elements' => array('p'), 'html_allowed_elements' => array('p'),
)); ));
@ -533,7 +526,7 @@ class CommentsTest extends FunctionalTest
// With default = false // With default = false
// Because of config rules about falsey values, apply config to object directly // Because of config rules about falsey values, apply config to object directly
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'enabled' => false, 'enabled' => false,
'require_login' => true, 'require_login' => true,
'require_moderation' => true 'require_moderation' => true
@ -989,7 +982,7 @@ class CommentsTest extends FunctionalTest
public function testGravatar() public function testGravatar()
{ {
// Turn gravatars on // Turn gravatars on
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'use_gravatar' => true, 'use_gravatar' => true,
'gravatar_size' => 80, 'gravatar_size' => 80,
'gravatar_default' => 'identicon', 'gravatar_default' => 'identicon',
@ -1005,7 +998,7 @@ class CommentsTest extends FunctionalTest
); );
// Turn gravatars off // Turn gravatars off
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'use_gravatar' => false 'use_gravatar' => false
)); ));
@ -1038,7 +1031,7 @@ class CommentsTest extends FunctionalTest
// 0 indicates no limit for nested_depth // 0 indicates no limit for nested_depth
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 0 'nested_depth' => 0
)); ));
@ -1058,7 +1051,7 @@ class CommentsTest extends FunctionalTest
public function testAllReplies() public function testAllReplies()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4
)); ));
@ -1084,7 +1077,7 @@ class CommentsTest extends FunctionalTest
$comment->allReplies()->count() $comment->allReplies()->count()
); );
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => false 'nested_comments' => false
)); ));
@ -1095,7 +1088,7 @@ class CommentsTest extends FunctionalTest
{ {
CommentableItem::add_extension(CommentsExtension::class); CommentableItem::add_extension(CommentsExtension::class);
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4
)); ));
@ -1133,7 +1126,7 @@ class CommentsTest extends FunctionalTest
$item->ModerationRequired = 'Required'; $item->ModerationRequired = 'Required';
$item->write(); $item->write();
Config::modify()->set(CommentableItemDisabled::class, 'comments', array( Config::modify()->merge(CommentableItemDisabled::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4, 'nested_depth' => 4,
'frontend_moderation' => true 'frontend_moderation' => true
@ -1147,7 +1140,7 @@ class CommentsTest extends FunctionalTest
); );
// Turn off nesting, empty array should be returned // Turn off nesting, empty array should be returned
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => false 'nested_comments' => false
)); ));
@ -1180,7 +1173,7 @@ class CommentsTest extends FunctionalTest
$pagedList->getTotalItems() $pagedList->getTotalItems()
); );
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => false 'nested_comments' => false
)); ));
@ -1189,7 +1182,7 @@ class CommentsTest extends FunctionalTest
public function testReplyForm() public function testReplyForm()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => false, 'nested_comments' => false,
'nested_depth' => 4 'nested_depth' => 4
)); ));
@ -1201,7 +1194,7 @@ class CommentsTest extends FunctionalTest
$this->assertNull($form); $this->assertNull($form);
// parent item so show form // parent item so show form
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4
)); ));
@ -1235,7 +1228,7 @@ class CommentsTest extends FunctionalTest
public function testUpdateDepth() public function testUpdateDepth()
{ {
Config::modify()->set(CommentableItem::class, 'comments', array( Config::modify()->merge(CommentableItem::class, 'comments', array(
'nested_comments' => true, 'nested_comments' => true,
'nested_depth' => 4 'nested_depth' => 4
)); ));