mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 11:05:31 +02:00
ENH PHP 8.1 compatibility
This commit is contained in:
parent
7195e2a833
commit
600a4b2cde
@ -68,13 +68,13 @@ class RateLimitFilter extends ContentFilter
|
|||||||
|
|
||||||
// Add global identifier
|
// Add global identifier
|
||||||
if ($this->config()->get('lock_bypage')) {
|
if ($this->config()->get('lock_bypage')) {
|
||||||
$key .= '_' . md5($itemkey);
|
$key .= '_' . md5($itemkey ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add user-specific identifier
|
// 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();
|
$ip = Controller::curr()->getRequest()->getIP();
|
||||||
$key .= '_' . md5($ip);
|
$key .= '_' . md5($ip ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $key;
|
return $key;
|
||||||
|
@ -119,7 +119,7 @@ class VersionFeedController extends Extension
|
|||||||
if ($lastChange) {
|
if ($lastChange) {
|
||||||
// Cache the diffs to remove DOS possibility.
|
// Cache the diffs to remove DOS possibility.
|
||||||
$key = 'allchanges'
|
$key = 'allchanges'
|
||||||
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'])
|
. preg_replace('#[^a-zA-Z0-9_]#', '', $lastChange['LastEdited'] ?? '')
|
||||||
. (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public');
|
. (Security::getCurrentUser() ? Security::getCurrentUser()->ID : 'public');
|
||||||
$changeList = $this->filterContent($key, function () use ($latestChanges) {
|
$changeList = $this->filterContent($key, function () use ($latestChanges) {
|
||||||
$changeList = new ArrayList();
|
$changeList = new ArrayList();
|
||||||
|
@ -86,7 +86,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
|
|
||||||
$response = $this->get($page->RelativeLink('allchanges'));
|
$response = $this->get($page->RelativeLink('allchanges'));
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$this->assertFalse(
|
$this->assertFalse(
|
||||||
(bool)$xml->channel->item,
|
(bool)$xml->channel->item,
|
||||||
'With Page\'s "PublicHistory" disabled, `allchanges` action should not have an item in the channel'
|
'With Page\'s "PublicHistory" disabled, `allchanges` action should not have an item in the channel'
|
||||||
@ -99,7 +99,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
|
|
||||||
$response = $this->get($page->RelativeLink('changes'));
|
$response = $this->get($page->RelativeLink('changes'));
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
(bool)$xml->channel->item,
|
(bool)$xml->channel->item,
|
||||||
'With Page\'s "PublicHistory" enabled, `changes` action should have an item in the channel'
|
'With Page\'s "PublicHistory" enabled, `changes` action should have an item in the channel'
|
||||||
@ -107,7 +107,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
|
|
||||||
$response = $this->get($page->RelativeLink('allchanges'));
|
$response = $this->get($page->RelativeLink('allchanges'));
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
(bool)$xml->channel->item,
|
(bool)$xml->channel->item,
|
||||||
'With "PublicHistory" enabled, `allchanges` action should have an item in the channel'
|
'With "PublicHistory" enabled, `allchanges` action should have an item in the channel'
|
||||||
@ -141,7 +141,7 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
$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 = RateLimitFilter::CACHE_PREFIX . '_' . md5($key);
|
$key = RateLimitFilter::CACHE_PREFIX . '_' . md5($key ?? '');
|
||||||
$this->cache->set($key, time() + 10);
|
$this->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());
|
||||||
@ -171,19 +171,19 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);
|
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);
|
||||||
|
|
||||||
$response = $this->get($page1->RelativeLink('changes'));
|
$response = $this->get($page1->RelativeLink('changes'));
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$titles = array_map(function ($item) {
|
$titles = array_map(function ($item) {
|
||||||
return (string)$item->title;
|
return (string)$item->title;
|
||||||
}, $xml->xpath('//item'));
|
}, $xml->xpath('//item') ?? []);
|
||||||
// TODO Unclear if this should contain the original version
|
// TODO Unclear if this should contain the original version
|
||||||
$this->assertContains('Changed: Page1', $titles);
|
$this->assertContains('Changed: Page1', $titles);
|
||||||
$this->assertNotContains('Changed: Page2', $titles);
|
$this->assertNotContains('Changed: Page2', $titles);
|
||||||
|
|
||||||
$response = $this->get($page2->RelativeLink('changes'));
|
$response = $this->get($page2->RelativeLink('changes'));
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$titles = array_map(function ($item) {
|
$titles = array_map(function ($item) {
|
||||||
return (string)$item->title;
|
return (string)$item->title;
|
||||||
}, $xml->xpath('//item'));
|
}, $xml->xpath('//item') ?? []);
|
||||||
// TODO Unclear if this should contain the original version
|
// TODO Unclear if this should contain the original version
|
||||||
$this->assertNotContains('Changed: Page1', $titles);
|
$this->assertNotContains('Changed: Page1', $titles);
|
||||||
$this->assertContains('Changed: Page2', $titles);
|
$this->assertContains('Changed: Page2', $titles);
|
||||||
@ -195,10 +195,10 @@ class VersionFeedFunctionalTest extends FunctionalTest
|
|||||||
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);
|
$page2 = $this->createPageWithChanges(['Title' => 'Page2']);
|
||||||
|
|
||||||
$response = $this->get($page1->RelativeLink('allchanges'));
|
$response = $this->get($page1->RelativeLink('allchanges'));
|
||||||
$xml = simplexml_load_string($response->getBody());
|
$xml = simplexml_load_string($response->getBody() ?? '');
|
||||||
$titles = array_map(function ($item) {
|
$titles = array_map(function ($item) {
|
||||||
return str_replace('Changed: ', '', (string) $item->title);
|
return str_replace('Changed: ', '', (string) $item->title);
|
||||||
}, $xml->xpath('//item'));
|
}, $xml->xpath('//item') ?? []);
|
||||||
$this->assertContains('Page1', $titles);
|
$this->assertContains('Page1', $titles);
|
||||||
$this->assertContains('Page2', $titles);
|
$this->assertContains('Page2', $titles);
|
||||||
}
|
}
|
||||||
|
@ -44,18 +44,18 @@ class VersionFeedTest extends SapphireTest
|
|||||||
|
|
||||||
// Strip spaces from test output because they're not reliably maintained by the HTML Tidier
|
// Strip spaces from test output because they're not reliably maintained by the HTML Tidier
|
||||||
$cleanDiffOutput = function ($val) {
|
$cleanDiffOutput = function ($val) {
|
||||||
return str_replace(' ', '', strip_tags($val));
|
return str_replace(' ', '', strip_tags($val ?? ''));
|
||||||
};
|
};
|
||||||
|
|
||||||
$this->assertContains(
|
$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')),
|
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle') ?? []),
|
||||||
'Detects published title changes'
|
'Detects published title changes'
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertNotContains(
|
$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')),
|
array_map($cleanDiffOutput, $page->getDiffList()->column('DiffTitle') ?? []),
|
||||||
'Ignores unpublished title changes'
|
'Ignores unpublished title changes'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user