mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 11:05:31 +02:00
FIX: Minor functional alterations and CI improvements
FIX: PSR-2 codebase. Formatting via phpcbf FIX: rendering bug in allchanges FIX: update .gitattributes to not export codecov's config file FIX: Update SiteTree_versions to the ss4 equivalent SiteTree_Versions
This commit is contained in:
parent
17cf3d7487
commit
67e112fd12
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -4,3 +4,4 @@
|
||||
/.gitignore export-ignore
|
||||
/.travis.yml export-ignore
|
||||
/.scrutinizer.yml export-ignore
|
||||
/codecov.yml export-ignore
|
||||
|
@ -22,7 +22,6 @@ before_script:
|
||||
|
||||
# Install composer dependencies
|
||||
- composer validate
|
||||
- composer require --no-update silverstripe/recipe-core:1.0.x-dev
|
||||
- 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
|
||||
|
||||
|
@ -12,7 +12,9 @@
|
||||
],
|
||||
"require":
|
||||
{
|
||||
"silverstripe/recipe-cms": "^1"
|
||||
"silverstripe/cms": "^4",
|
||||
"silverstripe/versioned": "^1",
|
||||
"silverstripe/siteconfig": "^4"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^5.7",
|
||||
|
@ -1,4 +1,4 @@
|
||||
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
|
||||
<phpunit bootstrap="vendor/silverstripe/cms/tests/bootstrap.php" colors="true">
|
||||
<testsuite name="Default">
|
||||
<directory>tests/</directory>
|
||||
</testsuite>
|
||||
|
@ -2,16 +2,13 @@
|
||||
|
||||
namespace SilverStripe\VersionFeed\Filters;
|
||||
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Caches results of a callback
|
||||
*/
|
||||
class CachedContentFilter extends ContentFilter {
|
||||
class CachedContentFilter extends ContentFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* Enable caching
|
||||
@ -21,7 +18,8 @@ class CachedContentFilter extends ContentFilter {
|
||||
*/
|
||||
private static $cache_enabled = true;
|
||||
|
||||
public function getContent($key, $callback) {
|
||||
public function getContent($key, $callback)
|
||||
{
|
||||
$cache = $this->getCache();
|
||||
|
||||
// Return cached value if available
|
||||
@ -29,7 +27,9 @@ class CachedContentFilter extends ContentFilter {
|
||||
$result = (isset($_GET['flush']) || !$cacheEnabled)
|
||||
? null
|
||||
: $cache->get($key);
|
||||
if($result) return $result;
|
||||
if ($result) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Fallback to generate result
|
||||
$result = parent::getContent($key, $callback);
|
||||
|
@ -7,13 +7,12 @@ use SilverStripe\Core\Config\Configurable;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Conditionally executes a given callback, attempting to return the desired results
|
||||
* of its execution.
|
||||
*/
|
||||
abstract class ContentFilter {
|
||||
abstract class ContentFilter
|
||||
{
|
||||
|
||||
use Configurable;
|
||||
|
||||
@ -32,7 +31,8 @@ abstract class ContentFilter {
|
||||
*/
|
||||
private static $cache_lifetime = 300;
|
||||
|
||||
public function __construct($nestedContentFilter = null) {
|
||||
public function __construct($nestedContentFilter = null)
|
||||
{
|
||||
$this->nestedContentFilter = $nestedContentFilter;
|
||||
}
|
||||
|
||||
@ -41,7 +41,8 @@ abstract class ContentFilter {
|
||||
*
|
||||
* @return Zend_Cache_Frontend
|
||||
*/
|
||||
protected function getCache() {
|
||||
protected function getCache()
|
||||
{
|
||||
return Injector::inst()->get(
|
||||
CacheInterface::class . '.VersionFeedController'
|
||||
);
|
||||
@ -54,8 +55,9 @@ abstract class ContentFilter {
|
||||
* @param callable $callback Callback for evaluating the content
|
||||
* @return mixed Result of $callback()
|
||||
*/
|
||||
public function getContent($key, $callback) {
|
||||
if($this->nestedContentFilter) {
|
||||
public function getContent($key, $callback)
|
||||
{
|
||||
if ($this->nestedContentFilter) {
|
||||
return $this->nestedContentFilter->getContent($key, $callback);
|
||||
} else {
|
||||
return call_user_func($callback);
|
||||
|
@ -2,20 +2,15 @@
|
||||
|
||||
namespace SilverStripe\VersionFeed\Filters;
|
||||
|
||||
|
||||
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\HTTPResponse_Exception;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Provides rate limiting of execution of a callback
|
||||
*/
|
||||
class RateLimitFilter extends ContentFilter {
|
||||
class RateLimitFilter extends ContentFilter
|
||||
{
|
||||
|
||||
/**
|
||||
* Time duration (in second) to allow for generation of cached results. Requests to
|
||||
@ -66,16 +61,17 @@ class RateLimitFilter extends ContentFilter {
|
||||
* @param string $itemkey Input key
|
||||
* @return string Result key
|
||||
*/
|
||||
protected function getCacheKey($itemkey) {
|
||||
protected function getCacheKey($itemkey)
|
||||
{
|
||||
$key = self::CACHE_PREFIX;
|
||||
|
||||
// Add global identifier
|
||||
if($this->config()->get('lock_bypage')) {
|
||||
if ($this->config()->get('lock_bypage')) {
|
||||
$key .= '_' . md5($itemkey);
|
||||
}
|
||||
|
||||
// Add user-specific identifier
|
||||
if($this->config()->get('lock_byuserip') && Controller::has_curr()) {
|
||||
if ($this->config()->get('lock_byuserip') && Controller::has_curr()) {
|
||||
$ip = Controller::curr()->getRequest()->getIP();
|
||||
$key .= '_' . md5($ip);
|
||||
}
|
||||
@ -84,18 +80,19 @@ class RateLimitFilter extends ContentFilter {
|
||||
}
|
||||
|
||||
|
||||
public function getContent($key, $callback) {
|
||||
public function getContent($key, $callback)
|
||||
{
|
||||
// Bypass rate limiting if flushing, or timeout isn't set
|
||||
$timeout = $this->config()->get('lock_timeout');
|
||||
if(isset($_GET['flush']) || !$timeout) {
|
||||
if (isset($_GET['flush']) || !$timeout) {
|
||||
return parent::getContent($key, $callback);
|
||||
}
|
||||
|
||||
// Generate result with rate limiting enabled
|
||||
$limitKey = $this->getCacheKey($key);
|
||||
$cache = $this->getCache();
|
||||
if($lockedUntil = $cache->get($limitKey)) {
|
||||
if(time() < $lockedUntil) {
|
||||
if ($lockedUntil = $cache->get($limitKey)) {
|
||||
if (time() < $lockedUntil) {
|
||||
// Politely inform visitor of limit
|
||||
$response = new HTTPResponse_Exception('Too Many Requests.', 429);
|
||||
$response->getResponse()->addHeader('Retry-After', 1 + $lockedUntil - time());
|
||||
@ -112,7 +109,7 @@ class RateLimitFilter extends ContentFilter {
|
||||
$result = parent::getContent($key, $callback);
|
||||
|
||||
// Reset rate limit with optional cooldown
|
||||
if($cooldown = $this->config()->get('lock_cooldown')) {
|
||||
if ($cooldown = $this->config()->get('lock_cooldown')) {
|
||||
// Set cooldown on successful query execution
|
||||
$cache->set($limitKey, time() + $cooldown, $lifetime);
|
||||
} else {
|
||||
|
@ -13,7 +13,8 @@ use SilverStripe\Forms\LiteralField;
|
||||
use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\CMS\Model\SiteTreeExtension;
|
||||
|
||||
class VersionFeed extends SiteTreeExtension {
|
||||
class VersionFeed extends SiteTreeExtension
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'PublicHistory' => 'Boolean(true)'
|
||||
@ -23,7 +24,8 @@ class VersionFeed extends SiteTreeExtension {
|
||||
'PublicHistory' => true
|
||||
);
|
||||
|
||||
public function updateFieldLabels(&$labels) {
|
||||
public function updateFieldLabels(&$labels)
|
||||
{
|
||||
$labels['PublicHistory'] = _t('RSSHistory.LABEL', 'Make history public');
|
||||
}
|
||||
|
||||
@ -67,10 +69,11 @@ class VersionFeed extends SiteTreeExtension {
|
||||
*
|
||||
* @returns ArrayList List of cleaned records.
|
||||
*/
|
||||
public function getDiffList($highestVersion = null, $limit = 100) {
|
||||
public function getDiffList($highestVersion = null, $limit = 100)
|
||||
{
|
||||
// This can leak secured content if it was protected via inherited setting.
|
||||
// For now the users will need to be aware about this shortcoming.
|
||||
$offset = $highestVersion ? "AND \"SiteTree_versions\".\"Version\"<='".(int)$highestVersion."'" : '';
|
||||
$offset = $highestVersion ? "AND \"SiteTree_Versions\".\"Version\"<='".(int)$highestVersion."'" : '';
|
||||
// Get just enough elements for diffing. We need one more than desired to have something to compare to.
|
||||
$qLimit = (int)$limit + 1;
|
||||
$versions = $this->owner->allVersions(
|
||||
@ -88,7 +91,6 @@ class VersionFeed extends SiteTreeExtension {
|
||||
|
||||
// Check if we have something to compare with.
|
||||
if (isset($previous)) {
|
||||
|
||||
// Produce the diff fields for use in the template.
|
||||
if ($version->Title != $previous->Title) {
|
||||
$diffTitle = Diff::compareHTML($version->Title, $previous->Title);
|
||||
@ -146,7 +148,8 @@ class VersionFeed extends SiteTreeExtension {
|
||||
*
|
||||
* @returns DataObject Object with relevant fields diffed.
|
||||
*/
|
||||
public function getDiff() {
|
||||
public function getDiff()
|
||||
{
|
||||
$changes = $this->getDiffList($this->owner->Version, 1);
|
||||
if ($changes && $changes->Count()) {
|
||||
return $changes->First();
|
||||
@ -166,20 +169,24 @@ class VersionFeed extends SiteTreeExtension {
|
||||
*
|
||||
* @returns ArrayList List of cleaned records.
|
||||
*/
|
||||
public function getDiffedChanges($highestVersion = null, $fullHistory = true, $limit = 100) {
|
||||
public function getDiffedChanges($highestVersion = null, $fullHistory = true, $limit = 100)
|
||||
{
|
||||
return $this->getDiffList(
|
||||
$highestVersion,
|
||||
$fullHistory ? $limit : 1
|
||||
);
|
||||
}
|
||||
|
||||
public function updateSettingsFields(FieldList $fields) {
|
||||
if(!Config::inst()->get(get_class(), 'changes_enabled')) return;
|
||||
public function updateSettingsFields(FieldList $fields)
|
||||
{
|
||||
if (!Config::inst()->get(get_class(), 'changes_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add public history field.
|
||||
$fields->addFieldToTab('Root.Settings', $publicHistory = new FieldGroup(
|
||||
new CheckboxField('PublicHistory', $this->owner->fieldLabel('PublicHistory')
|
||||
)));
|
||||
new CheckboxField('PublicHistory', $this->owner->fieldLabel('PublicHistory'))
|
||||
));
|
||||
|
||||
$warning = _t(
|
||||
'VersionFeed.Warning',
|
||||
@ -201,17 +208,19 @@ class VersionFeed extends SiteTreeExtension {
|
||||
}
|
||||
}
|
||||
|
||||
public function getSiteRSSLink() {
|
||||
public function getSiteRSSLink()
|
||||
{
|
||||
// TODO: This link should be from the homepage, not this page.
|
||||
if(Config::inst()->get(get_class(), 'allchanges_enabled')
|
||||
if (Config::inst()->get(get_class(), 'allchanges_enabled')
|
||||
&& SiteConfig::current_site_config()->AllChangesEnabled
|
||||
) {
|
||||
return $this->owner->Link('allchanges');
|
||||
}
|
||||
}
|
||||
|
||||
public function getDefaultRSSLink() {
|
||||
if(Config::inst()->get(get_class(), 'changes_enabled') && $this->owner->PublicHistory) {
|
||||
public function getDefaultRSSLink()
|
||||
{
|
||||
if (Config::inst()->get(get_class(), 'changes_enabled') && $this->owner->PublicHistory) {
|
||||
return $this->owner->Link('changes');
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,8 @@ use SilverStripe\View\Requirements;
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\VersionFeed\Filters\ContentFilter;
|
||||
|
||||
class VersionFeedController extends Extension {
|
||||
class VersionFeedController extends Extension
|
||||
{
|
||||
|
||||
private static $allowed_actions = array(
|
||||
'changes',
|
||||
@ -35,7 +36,8 @@ class VersionFeedController extends Extension {
|
||||
*
|
||||
* @param ContentFilter $contentFilter
|
||||
*/
|
||||
public function setContentFilter(ContentFilter $contentFilter) {
|
||||
public function setContentFilter(ContentFilter $contentFilter)
|
||||
{
|
||||
$this->contentFilter = $contentFilter;
|
||||
}
|
||||
|
||||
@ -46,15 +48,17 @@ class VersionFeedController extends Extension {
|
||||
* @param callable $callback Callback for evaluating the content
|
||||
* @return mixed Result of $callback()
|
||||
*/
|
||||
protected function filterContent($key, $callback) {
|
||||
if($this->contentFilter) {
|
||||
protected function filterContent($key, $callback)
|
||||
{
|
||||
if ($this->contentFilter) {
|
||||
return $this->contentFilter->getContent($key, $callback);
|
||||
} else {
|
||||
return call_user_func($callback);
|
||||
}
|
||||
}
|
||||
|
||||
public function onAfterInit() {
|
||||
public function onAfterInit()
|
||||
{
|
||||
$this->linkToPageRSSFeed();
|
||||
$this->linkToAllSiteRSSFeed();
|
||||
}
|
||||
@ -62,9 +66,10 @@ class VersionFeedController extends Extension {
|
||||
/**
|
||||
* Get page-specific changes in a RSS feed.
|
||||
*/
|
||||
public function changes() {
|
||||
public function changes()
|
||||
{
|
||||
// Check viewability of changes
|
||||
if(!Config::inst()->get(VersionFeed::class, 'changes_enabled')
|
||||
if (!Config::inst()->get(VersionFeed::class, 'changes_enabled')
|
||||
|| !$this->owner->PublicHistory
|
||||
|| $this->owner->Version == ''
|
||||
) {
|
||||
@ -74,7 +79,7 @@ class VersionFeedController extends Extension {
|
||||
// Cache the diffs to remove DOS possibility.
|
||||
$target = $this->owner;
|
||||
$key = implode('_', array('changes', $this->owner->ID, $this->owner->Version));
|
||||
$entries = $this->filterContent($key, function() use ($target) {
|
||||
$entries = $this->filterContent($key, function () use ($target) {
|
||||
return $target->getDiffList(null, Config::inst()->get(VersionFeed::class, 'changes_limit'));
|
||||
});
|
||||
|
||||
@ -88,9 +93,10 @@ class VersionFeedController extends Extension {
|
||||
/**
|
||||
* Get all changes from the site in a RSS feed.
|
||||
*/
|
||||
public function allchanges() {
|
||||
public function allchanges()
|
||||
{
|
||||
// Check viewability of allchanges
|
||||
if(!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')
|
||||
if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')
|
||||
|| !SiteConfig::current_site_config()->AllChangesEnabled
|
||||
) {
|
||||
return $this->owner->httpError(404, 'Global history not viewable');
|
||||
@ -98,38 +104,37 @@ class VersionFeedController extends Extension {
|
||||
|
||||
$limit = (int)Config::inst()->get(VersionFeed::class, 'allchanges_limit');
|
||||
$latestChanges = DB::query('
|
||||
SELECT * FROM "SiteTree_versions"
|
||||
SELECT * FROM "SiteTree_Versions"
|
||||
WHERE "WasPublished" = \'1\'
|
||||
AND "CanViewType" IN (\'Anyone\', \'Inherit\')
|
||||
AND "ShowInSearch" = 1
|
||||
AND ("PublicHistory" IS NULL OR "PublicHistory" = \'1\')
|
||||
ORDER BY "LastEdited" DESC LIMIT ' . $limit
|
||||
);
|
||||
ORDER BY "LastEdited" DESC LIMIT ' . $limit);
|
||||
$lastChange = $latestChanges->record();
|
||||
$latestChanges->rewind();
|
||||
|
||||
if ($lastChange) {
|
||||
|
||||
// Cache the diffs to remove DOS possibility.
|
||||
$key = 'allchanges'
|
||||
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'])
|
||||
. (Member::currentUserID() ?: 'public');
|
||||
$changeList = $this->filterContent($key, function() use ($latestChanges) {
|
||||
$changeList = $this->filterContent($key, function () use ($latestChanges) {
|
||||
$changeList = new ArrayList();
|
||||
$canView = array();
|
||||
foreach ($latestChanges as $record) {
|
||||
|
||||
// Check if the page should be visible.
|
||||
// WARNING: although we are providing historical details, we check the current configuration.
|
||||
$id = $record['RecordID'];
|
||||
if(!isset($canView[$id])) {
|
||||
if (!isset($canView[$id])) {
|
||||
$page = SiteTree::get()->byID($id);
|
||||
$canView[$id] = $page && $page->canView(new Member());
|
||||
}
|
||||
if (!$canView[$id]) continue;
|
||||
if (!$canView[$id]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get the diff to the previous version.
|
||||
$version = new Versioned_Version($record);
|
||||
$version = SiteTree::create($record);
|
||||
if ($diff = $version->getDiff()) {
|
||||
$changeList->push($diff);
|
||||
}
|
||||
@ -142,7 +147,8 @@ class VersionFeedController extends Extension {
|
||||
}
|
||||
|
||||
// Produce output
|
||||
$rss = new RSSFeed($changeList, $this->owner->request->getURL(), $this->linkToAllSitesRSSFeedTitle(), '', 'Title', '', null);
|
||||
$url = $this->owner->getRequest()->getURL();
|
||||
$rss = new RSSFeed($changeList, $url, $this->linkToAllSitesRSSFeedTitle(), '', 'Title', '', null);
|
||||
$rss->setTemplate('Page_allchanges_rss');
|
||||
return $rss->outputToBrowser();
|
||||
}
|
||||
@ -150,7 +156,8 @@ class VersionFeedController extends Extension {
|
||||
/**
|
||||
* Generates and embeds the RSS header link for the page-specific version rss feed
|
||||
*/
|
||||
public function linkToPageRSSFeed() {
|
||||
public function linkToPageRSSFeed()
|
||||
{
|
||||
if (!Config::inst()->get(VersionFeed::class, 'changes_enabled') || !$this->owner->PublicHistory) {
|
||||
return;
|
||||
}
|
||||
@ -167,8 +174,9 @@ class VersionFeedController extends Extension {
|
||||
/**
|
||||
* Generates and embeds the RSS header link for the global version rss feed
|
||||
*/
|
||||
public function linkToAllSiteRSSFeed() {
|
||||
if(!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')
|
||||
public function linkToAllSiteRSSFeed()
|
||||
{
|
||||
if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')
|
||||
|| !SiteConfig::current_site_config()->AllChangesEnabled
|
||||
) {
|
||||
return;
|
||||
@ -180,10 +188,12 @@ class VersionFeedController extends Extension {
|
||||
|
||||
Requirements::insertHeadTags(
|
||||
'<link rel="alternate" type="application/rss+xml" title="' . $title .
|
||||
'" href="' . $url . '" />');
|
||||
'" href="' . $url . '" />'
|
||||
);
|
||||
}
|
||||
|
||||
public function linkToAllSitesRSSFeedTitle() {
|
||||
public function linkToAllSitesRSSFeedTitle()
|
||||
{
|
||||
return sprintf(_t('RSSHistory.SITEFEEDTITLE', 'Updates to %s'), SiteConfig::current_site_config()->Title);
|
||||
}
|
||||
}
|
||||
|
@ -2,11 +2,6 @@
|
||||
|
||||
namespace SilverStripe\VersionFeed;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\VersionFeed\VersionFeed;
|
||||
@ -14,12 +9,11 @@ use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldGroup;
|
||||
use SilverStripe\ORM\DataExtension;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allows global configuration of all changes
|
||||
*/
|
||||
class VersionFeedSiteConfig extends DataExtension {
|
||||
class VersionFeedSiteConfig extends DataExtension
|
||||
{
|
||||
|
||||
private static $db = array(
|
||||
'AllChangesEnabled' => 'Boolean(true)'
|
||||
@ -29,14 +23,19 @@ class VersionFeedSiteConfig extends DataExtension {
|
||||
'AllChangesEnabled' => true
|
||||
);
|
||||
|
||||
public function updateFieldLabels(&$labels) {
|
||||
public function updateFieldLabels(&$labels)
|
||||
{
|
||||
$labels['AllChangesEnabled'] = _t('VersionFeedSiteConfig.ALLCHANGESLABEL', 'Make global changes feed public');
|
||||
}
|
||||
|
||||
public function updateCMSFields(FieldList $fields) {
|
||||
if(!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')) return;
|
||||
public function updateCMSFields(FieldList $fields)
|
||||
{
|
||||
if (!Config::inst()->get(VersionFeed::class, 'allchanges_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$fields->addFieldToTab('Root.Access',
|
||||
$fields->addFieldToTab(
|
||||
'Root.Access',
|
||||
FieldGroup::create(new CheckboxField('AllChangesEnabled', $this->owner->fieldLabel('AllChangesEnabled')))
|
||||
->setTitle(_t('VersionFeedSiteConfig.ALLCHANGES', 'All page changes'))
|
||||
->setDescription(_t(
|
||||
|
@ -17,8 +17,8 @@ use SilverStripe\Dev\FunctionalTest;
|
||||
use SilverStripe\Control\Director;
|
||||
use Psr\SimpleCache\CacheInterface;
|
||||
|
||||
|
||||
class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
class VersionFeedFunctionalTest extends FunctionalTest
|
||||
{
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected $baseURI = 'http://www.fakesite.test';
|
||||
@ -30,7 +30,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
|
||||
protected $userIP;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp()
|
||||
{
|
||||
Director::config()->set('alternate_base_url', $this->baseURI);
|
||||
|
||||
parent::setUp();
|
||||
@ -54,7 +55,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
Config::modify()->set(RateLimitFilter::class, 'lock_cooldown', false);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public function tearDown()
|
||||
{
|
||||
Director::config()->set('alternate_base_url', null);
|
||||
|
||||
$_SERVER['REMOTE_ADDR'] = $this->userIP;
|
||||
@ -62,7 +64,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testPublicHistory() {
|
||||
public function testPublicHistory()
|
||||
{
|
||||
$page = $this->createPageWithChanges(array('PublicHistory' => false));
|
||||
|
||||
$response = $this->get($page->RelativeLink('changes'));
|
||||
@ -86,7 +89,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
$this->assertTrue((bool)$xml->channel->item);
|
||||
}
|
||||
|
||||
public function testRateLimiting() {
|
||||
public function testRateLimiting()
|
||||
{
|
||||
// Re-enable locking just for this test
|
||||
Config::modify()->set(RateLimitFilter::class, 'lock_timeout', 20);
|
||||
Config::modify()->set(CachedContentFilter::class, 'cache_enabled', true);
|
||||
@ -145,37 +149,46 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
Config::modify()->set(CachedContentFilter::class, 'cache_enabled', false);
|
||||
}
|
||||
|
||||
public function testContainsChangesForPageOnly() {
|
||||
public function testContainsChangesForPageOnly()
|
||||
{
|
||||
$page1 = $this->createPageWithChanges(array('Title' => 'Page1'));
|
||||
$page2 = $this->createPageWithChanges(array('Title' => 'Page2'));
|
||||
|
||||
$response = $this->get($page1->RelativeLink('changes'));
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$titles = array_map(function($item) {return (string)$item->title;}, $xml->xpath('//item'));
|
||||
$titles = array_map(function ($item) {
|
||||
return (string)$item->title;
|
||||
}, $xml->xpath('//item'));
|
||||
// TODO Unclear if this should contain the original version
|
||||
$this->assertContains('Changed: Page1', $titles);
|
||||
$this->assertNotContains('Changed: Page2', $titles);
|
||||
|
||||
$response = $this->get($page2->RelativeLink('changes'));
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$titles = array_map(function($item) {return (string)$item->title;}, $xml->xpath('//item'));
|
||||
$titles = array_map(function ($item) {
|
||||
return (string)$item->title;
|
||||
}, $xml->xpath('//item'));
|
||||
// TODO Unclear if this should contain the original version
|
||||
$this->assertNotContains('Changed: Page1', $titles);
|
||||
$this->assertContains('Changed: Page2', $titles);
|
||||
}
|
||||
|
||||
public function testContainsAllChangesForAllPages() {
|
||||
public function testContainsAllChangesForAllPages()
|
||||
{
|
||||
$page1 = $this->createPageWithChanges(array('Title' => 'Page1'));
|
||||
$page2 = $this->createPageWithChanges(array('Title' => 'Page2'));
|
||||
|
||||
$response = $this->get($page1->RelativeLink('allchanges'));
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$titles = array_map(function($item) {return (string)$item->title;}, $xml->xpath('//item'));
|
||||
$titles = array_map(function ($item) {
|
||||
return (string)$item->title;
|
||||
}, $xml->xpath('//item'));
|
||||
$this->assertContains('Page1', $titles);
|
||||
$this->assertContains('Page2', $titles);
|
||||
}
|
||||
|
||||
protected function createPageWithChanges($seed = null) {
|
||||
protected function createPageWithChanges($seed = null)
|
||||
{
|
||||
$page = new Page();
|
||||
|
||||
$seed = array_merge(array(
|
||||
@ -212,14 +225,15 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
/**
|
||||
* Tests response code for globally disabled feedss
|
||||
*/
|
||||
public function testFeedViewability() {
|
||||
public function testFeedViewability()
|
||||
{
|
||||
|
||||
// Nested loop through each configuration
|
||||
foreach(array(true, false) as $publicHistory_Page) {
|
||||
foreach (array(true, false) as $publicHistory_Page) {
|
||||
$page = $this->createPageWithChanges(array('PublicHistory' => $publicHistory_Page, 'Title' => 'Page'));
|
||||
|
||||
// Test requests to 'changes' action
|
||||
foreach(array(true, false) as $publicHistory_Config) {
|
||||
foreach (array(true, false) as $publicHistory_Config) {
|
||||
Config::modify()->set(VersionFeed::class, 'changes_enabled', $publicHistory_Config);
|
||||
$expectedResponse = $publicHistory_Page && $publicHistory_Config ? 200 : 404;
|
||||
$response = $this->get($page->RelativeLink('changes'));
|
||||
@ -227,8 +241,8 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
}
|
||||
|
||||
// Test requests to 'allchanges' action on each page
|
||||
foreach(array(true, false) as $allChanges_Config) {
|
||||
foreach(array(true, false) as $allChanges_SiteConfig) {
|
||||
foreach (array(true, false) as $allChanges_Config) {
|
||||
foreach (array(true, false) as $allChanges_SiteConfig) {
|
||||
Config::modify()->set(VersionFeed::class, 'allchanges_enabled', $allChanges_Config);
|
||||
$siteConfig = SiteConfig::current_site_config();
|
||||
$siteConfig->AllChangesEnabled = $allChanges_SiteConfig;
|
||||
@ -241,6 +255,4 @@ class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace SilverStripe\VersionFeed\Tests;
|
||||
|
||||
|
||||
use Page;
|
||||
use SilverStripe\VersionFeed\VersionFeed;
|
||||
use SilverStripe\VersionFeed\VersionFeedController;
|
||||
@ -10,8 +9,8 @@ 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;
|
||||
|
||||
@ -24,15 +23,18 @@ class VersionFeedTest extends SapphireTest {
|
||||
'SiteTree' => ['Translatable']
|
||||
];
|
||||
|
||||
public function testDiffedChangesExcludesRestrictedItems() {
|
||||
public function testDiffedChangesExcludesRestrictedItems()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
public function testDiffedChangesIncludesFullHistory() {
|
||||
public function testDiffedChangesIncludesFullHistory()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
public function testDiffedChangesTitle() {
|
||||
public function testDiffedChangesTitle()
|
||||
{
|
||||
$page = new Page(['Title' => 'My Title']);
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
@ -45,21 +47,20 @@ class VersionFeedTest extends SapphireTest {
|
||||
$page->write();
|
||||
|
||||
// Strip spaces from test output because they're not reliably maintained by the HTML Tidier
|
||||
$cleanDiffOutput = function($val) {
|
||||
return str_replace(' ','',strip_tags($val));
|
||||
$cleanDiffOutput = function ($val) {
|
||||
return str_replace(' ', '', strip_tags($val));
|
||||
};
|
||||
|
||||
$this->assertContains(
|
||||
str_replace(' ' ,'',_t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'),
|
||||
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title'),
|
||||
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')),
|
||||
'Detects published title changes'
|
||||
);
|
||||
|
||||
$this->assertNotContains(
|
||||
str_replace(' ' ,'',_t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'),
|
||||
str_replace(' ', '', _t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title'),
|
||||
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle')),
|
||||
'Ignores unpublished title changes'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user