MINOR Fixed RSSFeedTest which should put test configuration code into setUp() and tearDown() methods. If the test fails halfway through, these will get called to clean up the state

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@113430 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sean Harvey 2010-11-04 03:34:17 +00:00 committed by Sam Minnee
parent 1050c7ee4e
commit 9bae66760a

View File

@ -5,17 +5,14 @@
*/ */
class RSSFeedTest extends SapphireTest { class RSSFeedTest extends SapphireTest {
protected static $original_host;
function testRSSFeed() { function testRSSFeed() {
$list = new DataObjectSet(); $list = new DataObjectSet();
$list->push(new RSSFeedTest_ItemA()); $list->push(new RSSFeedTest_ItemA());
$list->push(new RSSFeedTest_ItemB()); $list->push(new RSSFeedTest_ItemB());
$list->push(new RSSFeedTest_ItemC()); $list->push(new RSSFeedTest_ItemC());
$origServer = $_SERVER;
$_SERVER['HTTP_HOST'] = 'www.example.org';
Director::setBaseURL('/');
$rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description"); $rssFeed = new RSSFeed($list, "http://www.example.com", "Test RSS Feed", "Test RSS Feed Description");
$content = $rssFeed->feedContent(); $content = $rssFeed->feedContent();
@ -44,9 +41,19 @@ class RSSFeedTest extends SapphireTest {
$this->assertContains('<description>ItemA AltContent</description>', $content); $this->assertContains('<description>ItemA AltContent</description>', $content);
$this->assertContains('<description>ItemB AltContent</description>', $content); $this->assertContains('<description>ItemB AltContent</description>', $content);
$this->assertContains('<description>ItemC AltContent</description>', $content); $this->assertContains('<description>ItemC AltContent</description>', $content);
}
public function setUp() {
parent::setUp();
Director::setBaseURL('/');
if(!self::$original_host) self::$original_host = $_SERVER['HTTP_HOST'];
$_SERVER['HTTP_HOST'] = 'www.example.org';
}
public function tearDown() {
parent::tearDown();
Director::setBaseURL(null); Director::setBaseURL(null);
$_SERVER = $origServer; $_SERVER['HTTP_HOST'] = self::$original_host;
} }
} }