mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 11:05:31 +02:00
Edit updated things until the tests pass
This commit is contained in:
parent
17699f2b8a
commit
229463547d
@ -1,21 +1,25 @@
|
|||||||
---
|
---
|
||||||
Name: versionedfeedconfig
|
Name: versionedfeedconfig
|
||||||
---
|
---
|
||||||
Injector:
|
SilverStripe\Core\Injector\Injector:
|
||||||
RateLimitFilter: \VersionFeed\Filters\RateLimitFilter
|
RateLimitFilter: SilverStripe\VersionFeed\Filters\RateLimitFilter
|
||||||
ContentFilter:
|
ContentFilter:
|
||||||
class: \VersionFeed\Filters\CachedContentFilter
|
class: SilverStripe\VersionFeed\Filters\CachedContentFilter
|
||||||
constructor:
|
constructor:
|
||||||
- %$RateLimitFilter
|
- %$RateLimitFilter
|
||||||
SiteTree:
|
Psr\SimpleCache\CacheInterface.VersionFeedController:
|
||||||
|
factory: SilverStripe\Core\Cache\CacheFactory
|
||||||
|
constructor:
|
||||||
|
namespace: 'VersionFeedController'
|
||||||
|
SilverStripe\CMS\Model\SiteTree:
|
||||||
extensions:
|
extensions:
|
||||||
- VersionFeed
|
- SilverStripe\VersionFeed\VersionFeed
|
||||||
SiteConfig:
|
SilverStripe\SiteConfig\SiteConfig:
|
||||||
extensions:
|
extensions:
|
||||||
- VersionFeedSiteConfig
|
- SilverStripe\VersionFeed\VersionFeedSiteConfig
|
||||||
ContentController:
|
SilverStripe\CMS\Controllers\ContentController:
|
||||||
extensions:
|
extensions:
|
||||||
- VersionFeed_Controller
|
- SilverStripe\VersionFeed\VersionFeedController
|
||||||
VersionFeed_Controller:
|
SilverStripe\VersionFeed\VersionFeedController:
|
||||||
dependencies:
|
dependencies:
|
||||||
ContentFilter: %$ContentFilter
|
ContentFilter: %$ContentFilter
|
||||||
|
@ -42,7 +42,7 @@ Two filters are applied on top of one another:
|
|||||||
server. This filter will only be applied if the `CachedContentFilter` does not have any cached record
|
server. This filter will only be applied if the `CachedContentFilter` does not have any cached record
|
||||||
for a request.
|
for a request.
|
||||||
|
|
||||||
Either one of these can be replaced, added to, or removed, by adjusting the `VersionFeed_Controller.dependencies`
|
Either one of these can be replaced, added to, or removed, by adjusting the `SilverStripe\VersionFeed\VersionFeedController.dependencies`
|
||||||
config to point to a replacement (or no) filter.
|
config to point to a replacement (or no) filter.
|
||||||
|
|
||||||
For smaller servers where it's reasonable to apply a strict approach to rate limiting the default
|
For smaller servers where it's reasonable to apply a strict approach to rate limiting the default
|
||||||
|
@ -34,7 +34,7 @@ class CachedContentFilter extends ContentFilter {
|
|||||||
// Fallback to generate result
|
// Fallback to generate result
|
||||||
$result = parent::getContent($key, $callback);
|
$result = parent::getContent($key, $callback);
|
||||||
$lifetime = Config::inst()->get(ContentFilter::class, 'cache_lifetime') ?: null;
|
$lifetime = Config::inst()->get(ContentFilter::class, 'cache_lifetime') ?: null;
|
||||||
$cache->set($result, $key, $lifetime);
|
$cache->set($key, $result, $lifetime);
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
namespace SilverStripe\VersionFeed\Filters;
|
namespace SilverStripe\VersionFeed\Filters;
|
||||||
|
|
||||||
use SS_Cache;
|
|
||||||
|
|
||||||
use SilverStripe\VersionFeed\VersionFeedController;
|
use SilverStripe\VersionFeed\VersionFeedController;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Configurable;
|
||||||
use Psr\SimpleCache\CacheInterface;
|
use Psr\SimpleCache\CacheInterface;
|
||||||
use SilverStripe\Core\Injector\Injector;
|
use SilverStripe\Core\Injector\Injector;
|
||||||
|
|
||||||
@ -17,6 +15,8 @@ use SilverStripe\Core\Injector\Injector;
|
|||||||
*/
|
*/
|
||||||
abstract class ContentFilter {
|
abstract class ContentFilter {
|
||||||
|
|
||||||
|
use configurable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nested content filter
|
* Nested content filter
|
||||||
*
|
*
|
||||||
@ -43,7 +43,7 @@ abstract class ContentFilter {
|
|||||||
*/
|
*/
|
||||||
protected function getCache() {
|
protected function getCache() {
|
||||||
return Injector::inst()->get(
|
return Injector::inst()->get(
|
||||||
CacheInterface::class . '.' . VersionFeedController::class
|
CacheInterface::class . '.VersionFeedController'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ class RateLimitFilter extends ContentFilter {
|
|||||||
$key = self::CACHE_PREFIX;
|
$key = self::CACHE_PREFIX;
|
||||||
|
|
||||||
// Add global identifier
|
// Add global identifier
|
||||||
if(Config::inst()->get(get_class(), 'lock_bypage')) {
|
if($this->config()->get('lock_bypage')) {
|
||||||
$key .= '_' . md5($itemkey);
|
$key .= '_' . md5($itemkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add user-specific identifier
|
// Add user-specific identifier
|
||||||
if(Config::inst()->get(get_class(), 'lock_byuserip') && Controller::has_curr()) {
|
if($this->config()->get('lock_byuserip') && Controller::has_curr()) {
|
||||||
$ip = Controller::curr()->getRequest()->getIP();
|
$ip = Controller::curr()->getRequest()->getIP();
|
||||||
$key .= '_' . md5($ip);
|
$key .= '_' . md5($ip);
|
||||||
}
|
}
|
||||||
@ -86,7 +86,7 @@ class RateLimitFilter extends ContentFilter {
|
|||||||
|
|
||||||
public function getContent($key, $callback) {
|
public function getContent($key, $callback) {
|
||||||
// Bypass rate limiting if flushing, or timeout isn't set
|
// Bypass rate limiting if flushing, or timeout isn't set
|
||||||
$timeout = Config::inst()->get(get_class(), 'lock_timeout');
|
$timeout = $this->config()->get('lock_timeout');
|
||||||
if(isset($_GET['flush']) || !$timeout) {
|
if(isset($_GET['flush']) || !$timeout) {
|
||||||
return parent::getContent($key, $callback);
|
return parent::getContent($key, $callback);
|
||||||
}
|
}
|
||||||
@ -106,18 +106,18 @@ class RateLimitFilter extends ContentFilter {
|
|||||||
$lifetime = Config::inst()->get(ContentFilter::class, 'cache_lifetime') ?: null;
|
$lifetime = Config::inst()->get(ContentFilter::class, 'cache_lifetime') ?: null;
|
||||||
|
|
||||||
// Apply rate limit
|
// Apply rate limit
|
||||||
$cache->set(time() + $timeout, $limitKey, $lifetime);
|
$cache->set($limitKey, time() + $timeout, $lifetime);
|
||||||
|
|
||||||
// Generate results
|
// Generate results
|
||||||
$result = parent::getContent($key, $callback);
|
$result = parent::getContent($key, $callback);
|
||||||
|
|
||||||
// Reset rate limit with optional cooldown
|
// Reset rate limit with optional cooldown
|
||||||
if($cooldown = Config::inst()->get(get_class(), 'lock_cooldown')) {
|
if($cooldown = $this->config()->get('lock_cooldown')) {
|
||||||
// Set cooldown on successful query execution
|
// Set cooldown on successful query execution
|
||||||
$cache->set(time() + $cooldown, $limitKey, $lifetime);
|
$cache->set($limitKey, time() + $cooldown, $lifetime);
|
||||||
} else {
|
} else {
|
||||||
// Without cooldown simply disable lock
|
// Without cooldown simply disable lock
|
||||||
$cache->remove($limitKey);
|
$cache->delete($limitKey);
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,8 @@
|
|||||||
|
|
||||||
namespace SilverStripe\VersionFeed;
|
namespace SilverStripe\VersionFeed;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\FieldType\DBField;
|
||||||
|
use SilverStripe\View\Parsers\Diff;
|
||||||
use Diff;
|
|
||||||
use HTMLText;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Core\Config\Config;
|
use SilverStripe\Core\Config\Config;
|
||||||
@ -21,8 +13,6 @@ use SilverStripe\Forms\LiteralField;
|
|||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
use SilverStripe\CMS\Model\SiteTreeExtension;
|
use SilverStripe\CMS\Model\SiteTreeExtension;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VersionFeed extends SiteTreeExtension {
|
class VersionFeed extends SiteTreeExtension {
|
||||||
|
|
||||||
private static $db = array(
|
private static $db = array(
|
||||||
@ -103,7 +93,7 @@ class VersionFeed extends SiteTreeExtension {
|
|||||||
if ($version->Title != $previous->Title) {
|
if ($version->Title != $previous->Title) {
|
||||||
$diffTitle = Diff::compareHTML($version->Title, $previous->Title);
|
$diffTitle = Diff::compareHTML($version->Title, $previous->Title);
|
||||||
|
|
||||||
$version->DiffTitle = new HTMLText();
|
$version->DiffTitle = DBField::create_field('HTMLText', null);
|
||||||
$version->DiffTitle->setValue(
|
$version->DiffTitle->setValue(
|
||||||
sprintf(
|
sprintf(
|
||||||
'<div><em>%s</em> ' . $diffTitle . '</div>',
|
'<div><em>%s</em> ' . $diffTitle . '</div>',
|
||||||
@ -116,7 +106,7 @@ class VersionFeed extends SiteTreeExtension {
|
|||||||
if ($version->Content != $previous->Content) {
|
if ($version->Content != $previous->Content) {
|
||||||
$diffContent = Diff::compareHTML($version->Content, $previous->Content);
|
$diffContent = Diff::compareHTML($version->Content, $previous->Content);
|
||||||
|
|
||||||
$version->DiffContent = new HTMLText();
|
$version->DiffContent = DBField::create_field('HTMLText', null);
|
||||||
$version->DiffContent->setValue('<div>'.$diffContent.'</div>');
|
$version->DiffContent->setValue('<div>'.$diffContent.'</div>');
|
||||||
$changed = true;
|
$changed = true;
|
||||||
}
|
}
|
||||||
@ -140,7 +130,7 @@ class VersionFeed extends SiteTreeExtension {
|
|||||||
// a diff on the initial version we will just get that version, verbatim.
|
// a diff on the initial version we will just get that version, verbatim.
|
||||||
if ($previous && $versions->count()<$qLimit) {
|
if ($previous && $versions->count()<$qLimit) {
|
||||||
$first = clone($previous);
|
$first = clone($previous);
|
||||||
$first->DiffContent = new HTMLText();
|
$first->DiffContent = DBField::create_field('HTMLText', null);
|
||||||
$first->DiffContent->setValue('<div>' . $first->Content . '</div>');
|
$first->DiffContent->setValue('<div>' . $first->Content . '</div>');
|
||||||
// Copy the link so it can be cached.
|
// Copy the link so it can be cached.
|
||||||
$first->GeneratedLink = $first->AbsoluteLink();
|
$first->GeneratedLink = $first->AbsoluteLink();
|
||||||
|
@ -16,7 +16,7 @@ use SilverStripe\View\Requirements;
|
|||||||
use SilverStripe\Core\Extension;
|
use SilverStripe\Core\Extension;
|
||||||
use SilverStripe\VersionFeed\Filters\ContentFilter;
|
use SilverStripe\VersionFeed\Filters\ContentFilter;
|
||||||
|
|
||||||
class VersionFeed_Controller extends Extension {
|
class VersionFeedController extends Extension {
|
||||||
|
|
||||||
private static $allowed_actions = array(
|
private static $allowed_actions = array(
|
||||||
'changes',
|
'changes',
|
||||||
|
@ -14,45 +14,50 @@ use SilverStripe\CMS\Model\SiteTree;
|
|||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\Versioned\Versioned;
|
||||||
use SilverStripe\SiteConfig\SiteConfig;
|
use SilverStripe\SiteConfig\SiteConfig;
|
||||||
use SilverStripe\Dev\FunctionalTest;
|
use SilverStripe\Dev\FunctionalTest;
|
||||||
|
use SilverStripe\Control\Director;
|
||||||
|
use Psr\SimpleCache\CacheInterface;
|
||||||
|
|
||||||
|
|
||||||
class VersionFeedFunctionalTest extends FunctionalTest {
|
class VersionFeedFunctionalTest extends FunctionalTest {
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
protected $required_extensions = array(
|
protected $baseURI = 'http://www.fakesite.test';
|
||||||
|
|
||||||
|
protected static $required_extensions = array(
|
||||||
'Page' => array(VersionFeed::class),
|
'Page' => array(VersionFeed::class),
|
||||||
'Page_Controller' => array(VersionFeedController::class),
|
'PageController' => array(VersionFeedController::class),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $userIP;
|
protected $userIP;
|
||||||
|
|
||||||
public function setUp() {
|
protected function setUp() {
|
||||||
|
Director::config()->set('alternate_base_url', $this->baseURI);
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$cache = Injector::inst()->get(
|
$cache = Injector::inst()->get(
|
||||||
CacheInterface::class . '.' . VersionFeedController::class
|
CacheInterface::class . '.VersionFeedController'
|
||||||
);
|
);
|
||||||
$cache->clear();
|
$cache->clear();
|
||||||
|
|
||||||
$this->userIP = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : null;
|
$this->userIP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
|
||||||
|
|
||||||
Config::nest();
|
|
||||||
// Enable history by default
|
// Enable history by default
|
||||||
Config::inst()->update(VersionFeed::class, 'changes_enabled', true);
|
Config::modify()->set(VersionFeed::class, 'changes_enabled', true);
|
||||||
Config::inst()->update(VersionFeed::class, 'allchanges_enabled', true);
|
Config::modify()->set(VersionFeed::class, 'allchanges_enabled', true);
|
||||||
|
|
||||||
// Disable caching and locking by default
|
// Disable caching and locking by default
|
||||||
Config::inst()->update(CachedContentFilter::class, 'cache_enabled', false);
|
Config::modify()->set(CachedContentFilter::class, 'cache_enabled', false);
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_timeout', 0);
|
Config::modify()->set(RateLimitFilter::class, 'lock_timeout', 0);
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_bypage', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_bypage', false);
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_byuserip', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_byuserip', false);
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_cooldown', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_cooldown', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown() {
|
public function tearDown() {
|
||||||
Config::unnest();
|
Director::config()->set('alternate_base_url', null);
|
||||||
|
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = $this->userIP;
|
$_SERVER['REMOTE_ADDR'] = $this->userIP;
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
@ -83,18 +88,18 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
|
|
||||||
public function testRateLimiting() {
|
public function testRateLimiting() {
|
||||||
// Re-enable locking just for this test
|
// Re-enable locking just for this test
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_timeout', 20);
|
Config::modify()->set(RateLimitFilter::class, 'lock_timeout', 20);
|
||||||
Config::inst()->update(CachedContentFilter::class, 'cache_enabled', true);
|
Config::modify()->set(CachedContentFilter::class, 'cache_enabled', true);
|
||||||
|
|
||||||
$page1 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page1'));
|
$page1 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page1'));
|
||||||
$page2 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page2'));
|
$page2 = $this->createPageWithChanges(array('PublicHistory' => true, 'Title' => 'Page2'));
|
||||||
|
|
||||||
// Artifically set cache lock
|
// Artifically set cache lock
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_byuserip', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_byuserip', false);
|
||||||
$cache = Injector::inst()->get(
|
$cache = Injector::inst()->get(
|
||||||
CacheInterface::class . '.' . VersionFeedController::class
|
CacheInterface::class . '.VersionFeedController'
|
||||||
);
|
);
|
||||||
$cache->set(time() + 10, \VersionFeed\Filters\RateLimitFilter::CACHE_PREFIX);
|
$cache->set(RateLimitFilter::CACHE_PREFIX, time() + 10);
|
||||||
|
|
||||||
// Test normal hit
|
// Test normal hit
|
||||||
$response = $this->get($page1->RelativeLink('changes'));
|
$response = $this->get($page1->RelativeLink('changes'));
|
||||||
@ -105,39 +110,39 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
||||||
|
|
||||||
// Test page specific lock
|
// Test page specific lock
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_bypage', true);
|
Config::modify()->set(RateLimitFilter::class, 'lock_bypage', true);
|
||||||
$key = implode('_', array(
|
$key = implode('_', array(
|
||||||
'changes',
|
'changes',
|
||||||
$page1->ID,
|
$page1->ID,
|
||||||
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Live', $page1->ID, false)
|
Versioned::get_versionnumber_by_stage(SiteTree::class, 'Live', $page1->ID, false)
|
||||||
));
|
));
|
||||||
$key = \VersionFeed\Filters\RateLimitFilter::CACHE_PREFIX . '_' . md5($key);
|
$key = RateLimitFilter::CACHE_PREFIX . '_' . md5($key);
|
||||||
$cache->set(time() + 10, $key);
|
$cache->set($key, time() + 10);
|
||||||
$response = $this->get($page1->RelativeLink('changes'));
|
$response = $this->get($page1->RelativeLink('changes'));
|
||||||
$this->assertEquals(429, $response->getStatusCode());
|
$this->assertEquals(429, $response->getStatusCode());
|
||||||
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
||||||
$response = $this->get($page2->RelativeLink('changes'));
|
$response = $this->get($page2->RelativeLink('changes'));
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_bypage', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_bypage', false);
|
||||||
|
|
||||||
// Test rate limit hit by IP
|
// Test rate limit hit by IP
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_byuserip', true);
|
Config::modify()->set(RateLimitFilter::class, 'lock_byuserip', true);
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '127.0.0.1';
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
$cache->set(time() + 10, \VersionFeed\Filters\RateLimitFilter::CACHE_PREFIX . '_' . md5('127.0.0.1'));
|
$cache->set(RateLimitFilter::CACHE_PREFIX . '_' . md5('127.0.0.1'), time() + 10);
|
||||||
$response = $this->get($page1->RelativeLink('changes'));
|
$response = $this->get($page1->RelativeLink('changes'));
|
||||||
$this->assertEquals(429, $response->getStatusCode());
|
$this->assertEquals(429, $response->getStatusCode());
|
||||||
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
$this->assertGreaterThan(0, $response->getHeader('Retry-After'));
|
||||||
|
|
||||||
// Test rate limit doesn't hit other IP
|
// Test rate limit doesn't hit other IP
|
||||||
$_SERVER['HTTP_CLIENT_IP'] = '127.0.0.20';
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.20';
|
||||||
$cache->set(time() + 10, \VersionFeed\Filters\RateLimitFilter::CACHE_PREFIX . '_' . md5('127.0.0.1'));
|
$cache->set(RateLimitFilter::CACHE_PREFIX . '_' . md5('127.0.0.1'), time() + 10);
|
||||||
$response = $this->get($page1->RelativeLink('changes'));
|
$response = $this->get($page1->RelativeLink('changes'));
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
|
||||||
// Restore setting
|
// Restore setting
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_byuserip', false);
|
Config::modify()->set(RateLimitFilter::class, 'lock_byuserip', false);
|
||||||
Config::inst()->update(RateLimitFilter::class, 'lock_timeout', 0);
|
Config::modify()->set(RateLimitFilter::class, 'lock_timeout', 0);
|
||||||
Config::inst()->update(CachedContentFilter::class, 'cache_enabled', false);
|
Config::modify()->set(CachedContentFilter::class, 'cache_enabled', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testContainsChangesForPageOnly() {
|
public function testContainsChangesForPageOnly() {
|
||||||
@ -215,7 +220,7 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
|
|
||||||
// Test requests to 'changes' action
|
// Test requests to 'changes' action
|
||||||
foreach(array(true, false) as $publicHistory_Config) {
|
foreach(array(true, false) as $publicHistory_Config) {
|
||||||
Config::inst()->update(VersionFeed::class, 'changes_enabled', $publicHistory_Config);
|
Config::modify()->set(VersionFeed::class, 'changes_enabled', $publicHistory_Config);
|
||||||
$expectedResponse = $publicHistory_Page && $publicHistory_Config ? 200 : 404;
|
$expectedResponse = $publicHistory_Page && $publicHistory_Config ? 200 : 404;
|
||||||
$response = $this->get($page->RelativeLink('changes'));
|
$response = $this->get($page->RelativeLink('changes'));
|
||||||
$this->assertEquals($expectedResponse, $response->getStatusCode());
|
$this->assertEquals($expectedResponse, $response->getStatusCode());
|
||||||
@ -224,7 +229,7 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
|||||||
// Test requests to 'allchanges' action on each page
|
// Test requests to 'allchanges' action on each page
|
||||||
foreach(array(true, false) as $allChanges_Config) {
|
foreach(array(true, false) as $allChanges_Config) {
|
||||||
foreach(array(true, false) as $allChanges_SiteConfig) {
|
foreach(array(true, false) as $allChanges_SiteConfig) {
|
||||||
Config::inst()->update(VersionFeed::class, 'allchanges_enabled', $allChanges_Config);
|
Config::modify()->set(VersionFeed::class, 'allchanges_enabled', $allChanges_Config);
|
||||||
$siteConfig = SiteConfig::current_site_config();
|
$siteConfig = SiteConfig::current_site_config();
|
||||||
$siteConfig->AllChangesEnabled = $allChanges_SiteConfig;
|
$siteConfig->AllChangesEnabled = $allChanges_SiteConfig;
|
||||||
$siteConfig->write();
|
$siteConfig->write();
|
||||||
|
@ -7,20 +7,22 @@ use Page;
|
|||||||
use SilverStripe\VersionFeed\VersionFeed;
|
use SilverStripe\VersionFeed\VersionFeed;
|
||||||
use SilverStripe\VersionFeed\VersionFeedController;
|
use SilverStripe\VersionFeed\VersionFeedController;
|
||||||
use SilverStripe\Dev\SapphireTest;
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\CMS\Model\SiteTree;
|
||||||
|
use SilverStripe\CMS\Controllers\ContentController;
|
||||||
|
|
||||||
|
|
||||||
class VersionFeedTest extends SapphireTest {
|
class VersionFeedTest extends SapphireTest {
|
||||||
|
|
||||||
protected $usesDatabase = true;
|
protected $usesDatabase = true;
|
||||||
|
|
||||||
protected $required_extensions = array(
|
protected static $required_extensions = [
|
||||||
'SiteTree' => array(VersionFeed::class),
|
SiteTree::class => [VersionFeed::class],
|
||||||
'ContentController' => array(VersionFeedController::class),
|
ContentController::class => [VersionFeedController::class],
|
||||||
);
|
];
|
||||||
|
|
||||||
protected $illegalExtensions = array(
|
protected $illegalExtensions = [
|
||||||
'SiteTree' => array('Translatable')
|
'SiteTree' => ['Translatable']
|
||||||
);
|
];
|
||||||
|
|
||||||
public function testDiffedChangesExcludesRestrictedItems() {
|
public function testDiffedChangesExcludesRestrictedItems() {
|
||||||
$this->markTestIncomplete();
|
$this->markTestIncomplete();
|
||||||
@ -31,7 +33,7 @@ class VersionFeedTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testDiffedChangesTitle() {
|
public function testDiffedChangesTitle() {
|
||||||
$page = new Page(array('Title' => 'My Title'));
|
$page = new Page(['Title' => 'My Title']);
|
||||||
$page->write();
|
$page->write();
|
||||||
$page->publish('Stage', 'Live');
|
$page->publish('Stage', 'Live');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user