f7ff53c3f3ecba017fea1ce2d9e4d9f9e7d3d2b9
[yaffs-website] / vendor / twig / twig / test / Twig / Tests / FileCachingTest.php
1 <?php
2
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 require_once dirname(__FILE__).'/FilesystemHelper.php';
13
14 class Twig_Tests_FileCachingTest extends PHPUnit_Framework_TestCase
15 {
16     private $env;
17     private $tmpDir;
18
19     protected function setUp()
20     {
21         $this->tmpDir = sys_get_temp_dir().'/TwigTests';
22         if (!file_exists($this->tmpDir)) {
23             @mkdir($this->tmpDir, 0777, true);
24         }
25
26         if (!is_writable($this->tmpDir)) {
27             $this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir));
28         }
29
30         $this->env = new Twig_Environment(new Twig_Loader_Array(array('index' => 'index', 'index2' => 'index2')), array('cache' => $this->tmpDir));
31     }
32
33     protected function tearDown()
34     {
35         Twig_Tests_FilesystemHelper::removeDir($this->tmpDir);
36     }
37
38     /**
39      * @group legacy
40      */
41     public function testWritingCacheFiles()
42     {
43         $name = 'index';
44         $this->env->loadTemplate($name);
45         $cacheFileName = $this->env->getCacheFilename($name);
46
47         $this->assertFileExists($cacheFileName, 'Cache file does not exist.');
48     }
49
50     /**
51      * @group legacy
52      */
53     public function testClearingCacheFiles()
54     {
55         $name = 'index2';
56         $this->env->loadTemplate($name);
57         $cacheFileName = $this->env->getCacheFilename($name);
58
59         $this->assertFileExists($cacheFileName, 'Cache file does not exist.');
60         $this->env->clearCacheFiles();
61         $this->assertFileNotExists($cacheFileName, 'Cache file was not cleared.');
62     }
63 }