public function testVersionedCache() { $origReadingMode = Versioned::get_reading_mode(); // Run without caching in stage to prove data is uncached $this->_reset(false); Versioned::set_stage(Versioned::DRAFT); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('default'); $this->assertEquals('default Stage.Stage', SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data)); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('first'); $this->assertEquals('first Stage.Stage', SSViewer::execute_string('<% cached %>$Inspect<% end_cached %>', $data)); // Run without caching in live to prove data is uncached $this->_reset(false); Versioned::set_stage(Versioned::LIVE); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('default'); $this->assertEquals('default Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('first'); $this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); // Then with caching, initially in draft, and then in live, to prove that // changing the versioned reading mode doesn't cache between modes, but it does // within them $this->_reset(true); Versioned::set_stage(Versioned::DRAFT); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('default'); $this->assertEquals('default Stage.Stage', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('first'); $this->assertEquals('default Stage.Stage', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); Versioned::set_stage(Versioned::LIVE); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('first'); $this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); $data = new SSViewerCacheBlockTest_VersionedModel(); $data->setEntropy('second'); $this->assertEquals('first Stage.Live', $this->_runtemplate('<% cached %>$Inspect<% end_cached %>', $data)); Versioned::set_reading_mode($origReadingMode); }