mirror of
https://github.com/silverstripe/silverstripe-versionfeed
synced 2024-10-22 09:05:31 +00:00
Merge pull request #4 from chillu/pulls/travis
Page specific cache key, unit and functional tests
This commit is contained in:
commit
aabb774d20
28
.travis.yml
Normal file
28
.travis.yml
Normal file
@ -0,0 +1,28 @@
|
||||
# See https://github.com/silverstripe-labs/silverstripe-travis-support for setup details
|
||||
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.3
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- DB=MYSQL CORE_RELEASE=3.1
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 5.3
|
||||
env: DB=PGSQL CORE_RELEASE=3.1
|
||||
- php: 5.4
|
||||
env: DB=MYSQL CORE_RELEASE=master
|
||||
- php: 5.5
|
||||
env: DB=MYSQL CORE_RELEASE=master
|
||||
|
||||
before_script:
|
||||
- phpenv rehash
|
||||
- git clone git://github.com/silverstripe-labs/silverstripe-travis-support.git ~/travis-support
|
||||
- php ~/travis-support/travis_setup.php --source `pwd` --target ~/builds/ss
|
||||
- cd ~/builds/ss
|
||||
|
||||
script:
|
||||
- phpunit versionfeed/tests/
|
@ -1,5 +1,7 @@
|
||||
# Version Feed
|
||||
|
||||
[](http://travis-ci.org/silverstripe-labs/silverstripe-versionfeed)
|
||||
|
||||
## Overview
|
||||
|
||||
The module creates an RSS feed on each page with their change history, as well as one for the entire site.
|
||||
|
@ -32,7 +32,7 @@ class VersionFeed_Controller extends Extension {
|
||||
// Cache the diffs to remove DOS possibility.
|
||||
$cache = SS_Cache::factory('VersionFeed_Controller');
|
||||
$cache->setOption('automatic_serialization', true);
|
||||
$key = 'changes' . $this->owner->Version;
|
||||
$key = implode('_', array('changes', $this->owner->ID, $this->owner->Version));
|
||||
$entries = $cache->load($key);
|
||||
if(!$entries || isset($_GET['flush'])) {
|
||||
$entries = $this->owner->getDiffedChanges();
|
||||
@ -85,6 +85,8 @@ class VersionFeed_Controller extends Extension {
|
||||
$cache->save($changeList, $key);
|
||||
}
|
||||
|
||||
} else {
|
||||
$changeList = new ArrayList();
|
||||
}
|
||||
|
||||
// Produce output
|
||||
|
25
templates/Page_allchanges_rss.ss
Normal file
25
templates/Page_allchanges_rss.ss
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0"?>
|
||||
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>$Title</title>
|
||||
<link>$Link</link>
|
||||
<atom:link href="$Link" rel="self" type="application/rss+xml"></atom:link>
|
||||
|
||||
<% loop Entries %>
|
||||
<item>
|
||||
<title>$Title.XML</title>
|
||||
<link>$GeneratedLink</link>
|
||||
<description>
|
||||
<% if DiffTitle %>
|
||||
$DiffTitle.XML
|
||||
<% end_if %>
|
||||
<% if DiffContent %>
|
||||
$DiffContent.AbsoluteLinks.XML
|
||||
<% end_if %>
|
||||
</description>
|
||||
<pubDate>$LastEdited.Rfc822</pubDate>
|
||||
<guid>$GeneratedLink</guid>
|
||||
</item>
|
||||
<% end_loop %>
|
||||
</channel>
|
||||
</rss>
|
25
templates/Page_changes_rss.ss
Normal file
25
templates/Page_changes_rss.ss
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0"?>
|
||||
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<title>$Title</title>
|
||||
<link>$Link</link>
|
||||
<atom:link href="$Link" rel="self" type="application/rss+xml"></atom:link>
|
||||
|
||||
<% loop Entries %>
|
||||
<item>
|
||||
<title>$Title.XML</title>
|
||||
<link>$GeneratedLink</link>
|
||||
<description>
|
||||
<% if DiffTitle %>
|
||||
$DiffTitle.XML
|
||||
<% end_if %>
|
||||
<% if DiffContent %>
|
||||
$DiffContent.AbsoluteLinks.XML
|
||||
<% end_if %>
|
||||
</description>
|
||||
<pubDate>$LastEdited.Rfc822</pubDate>
|
||||
<guid>$GeneratedLink</guid>
|
||||
</item>
|
||||
<% end_loop %>
|
||||
</channel>
|
||||
</rss>
|
97
tests/VersionFeedFunctionalTest.php
Normal file
97
tests/VersionFeedFunctionalTest.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
class VersionFeedFunctionalTest extends FunctionalTest {
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'Page' => array('VersionFeed'),
|
||||
'Page_Controller' => array('VersionFeed_Controller'),
|
||||
);
|
||||
|
||||
public function testPublicHistory() {
|
||||
$page = $this->createPageWithChanges(array('PublicHistory' => false));
|
||||
|
||||
$response = $this->get($page->RelativeLink('changes'));
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
|
||||
$response = $this->get($page->RelativeLink('allchanges'));
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$this->assertFalse((bool)$xml->channel->item);
|
||||
|
||||
$page = $this->createPageWithChanges(array('PublicHistory' => true));
|
||||
|
||||
$response = $this->get($page->RelativeLink('changes'));
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$this->assertTrue((bool)$xml->channel->item);
|
||||
|
||||
$response = $this->get($page->RelativeLink('allchanges'));
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$xml = simplexml_load_string($response->getBody());
|
||||
$this->assertTrue((bool)$xml->channel->item);
|
||||
}
|
||||
|
||||
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'));
|
||||
// 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'));
|
||||
// TODO Unclear if this should contain the original version
|
||||
$this->assertNotContains('Changed: Page1', $titles);
|
||||
$this->assertContains('Changed: Page2', $titles);
|
||||
}
|
||||
|
||||
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'));
|
||||
$this->assertContains('Page1', $titles);
|
||||
$this->assertContains('Page2', $titles);
|
||||
}
|
||||
|
||||
protected function createPageWithChanges($seed = null) {
|
||||
$page = new Page();
|
||||
|
||||
$seed = array_merge(array(
|
||||
'Title' => 'My Title',
|
||||
'Content' => 'My Content'
|
||||
), $seed);
|
||||
$page->update($seed);
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$page->update(array(
|
||||
'Title' => 'Changed: ' . $seed['Title'],
|
||||
'Content' => 'Changed: ' . $seed['Content'],
|
||||
));
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$page->update(array(
|
||||
'Title' => 'Changed again: ' . $seed['Title'],
|
||||
'Content' => 'Changed again: ' . $seed['Content'],
|
||||
));
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$page->update(array(
|
||||
'Title' => 'Unpublished: ' . $seed['Title'],
|
||||
'Content' => 'Unpublished: ' . $seed['Content'],
|
||||
));
|
||||
$page->write();
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
}
|
48
tests/VersionFeedTest.php
Normal file
48
tests/VersionFeedTest.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
class VersionFeedTest extends SapphireTest {
|
||||
|
||||
protected $usesDatabase = true;
|
||||
|
||||
protected $requiredExtensions = array(
|
||||
'SiteTree' => array('VersionFeed'),
|
||||
'ContentController' => array('VersionFeed_Controller'),
|
||||
);
|
||||
|
||||
protected $illegalExtensions = array(
|
||||
'SiteTree' => array('Translatable')
|
||||
);
|
||||
|
||||
public function testDiffedChangesExcludesRestrictedItems() {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
public function testDiffedChangesIncludesFullHistory() {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
public function testDiffedChangesTitle() {
|
||||
$page = new Page(array('Title' => 'My Title'));
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$page->Title = 'My Changed Title';
|
||||
$page->write();
|
||||
$page->publish('Stage', 'Live');
|
||||
|
||||
$page->Title = 'My Unpublished Changed Title';
|
||||
$page->write();
|
||||
|
||||
$this->assertContains(
|
||||
_t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Changed Title',
|
||||
array_map('strip_tags', $page->getDiffedChanges()->column('DiffTitle')),
|
||||
'Detects published title changes'
|
||||
);
|
||||
|
||||
$this->assertNotContains(
|
||||
_t('RSSHistory.TITLECHANGED', 'Title has changed:') . 'My Unpublished Changed Title',
|
||||
array_map('strip_tags', $page->getDiffedChanges()->column('DiffTitle')),
|
||||
'Ignores unpublished title changes'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user