Better tests for SSViewer::flush & Flushable

This commit is contained in:
Loz Calver 2014-10-13 09:10:57 +01:00
parent f86b0bbca0
commit 97170dd42d
2 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,26 @@
<?php
class FlushRequestFilterTest extends FunctionalTest {
/**
* Assert that classes that implement flushable are called
*/
public function testImplementorsAreCalled() {
$this->assertFalse(FlushRequestFilterTest_Flushable::$flushed);
$this->get('?flush=1');
$this->assertTrue(FlushRequestFilterTest_Flushable::$flushed);
}
}
class FlushRequestFilterTest_Flushable implements Flushable, TestOnly {
public static $flushed = false;
public static function flush() {
self::$flushed = true;
}
}

View File

@ -128,11 +128,18 @@ class SSViewerCacheBlockTest extends SapphireTest {
* Test that the cacheblocks invalidate when a flush occurs.
*/
public function testBlocksInvalidateOnFlush() {
Director::test('/');
// Enable caching
$this->_reset(true);
// This property must be false, or the flush won't occur. This can be affected by other tests
// if they trigger a flush via Flushable
$reflectionProp = new ReflectionProperty('SSViewer', 'cacheblock_cache_flushed');
$reflectionProp->setAccessible(true);
$reflectionProp->setValue(false);
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 1)), '1');
Director::test('/?flush=1');
SSViewer::flush_cacheblock_cache();
$this->assertEquals($this->_runtemplate('<% cached %>$Foo<% end_cached %>', array('Foo' => 2)), '2');
}