/** * Create a template from a string instead of a .ss file * * @param string $content The template content * @param bool|void $cacheTemplate Whether or not to cache the template from string * @return SSViewer */ public static function fromString($content, $cacheTemplate = null) { $viewer = new SSViewer_FromString($content); if ($cacheTemplate !== null) { $viewer->setCacheTemplate($cacheTemplate); } return $viewer; }
/** * Tests if caching for SSViewer_FromString is working */ public function testFromStringCaching() { $content = 'Test content'; $cacheFile = TEMP_FOLDER . '/.cache.' . sha1($content); if (file_exists($cacheFile)) { unlink($cacheFile); } // Test global behaviors $this->render($content, null, null); $this->assertFalse(file_exists($cacheFile), 'Cache file was created when caching was off'); SSViewer_FromString::config()->update('cache_template', true); $this->render($content, null, null); $this->assertTrue(file_exists($cacheFile), 'Cache file wasn\'t created when it was meant to'); unlink($cacheFile); // Test instance behaviors $this->render($content, null, false); $this->assertFalse(file_exists($cacheFile), 'Cache file was created when caching was off'); $this->render($content, null, true); $this->assertTrue(file_exists($cacheFile), 'Cache file wasn\'t created when it was meant to'); unlink($cacheFile); }