mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Better tests for SSViewer::flush & Flushable
This commit is contained in:
parent
f86b0bbca0
commit
97170dd42d
26
tests/control/FlushRequestFilterTest.php
Normal file
26
tests/control/FlushRequestFilterTest.php
Normal 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;
|
||||
}
|
||||
|
||||
}
|
@ -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');
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user