FileCachingTest.php 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. require_once dirname(__FILE__).'/TestCase.php';
  3. class Twig_Tests_FileCachingTest extends Twig_Tests_TestCase
  4. {
  5. protected $fileName;
  6. protected $env;
  7. public function setUp()
  8. {
  9. parent::setUp();
  10. $this->env = new Twig_Environment(new Twig_Loader_String(), array('cache' => $this->tmpDir));
  11. }
  12. public function tearDown()
  13. {
  14. if ($this->fileName) {
  15. unlink($this->fileName);
  16. }
  17. parent::tearDown();
  18. }
  19. public function testWritingCacheFiles()
  20. {
  21. $name = 'This is just text.';
  22. $template = $this->env->loadTemplate($name);
  23. $cacheFileName = $this->env->getCacheFilename($name);
  24. $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.');
  25. $this->fileName = $cacheFileName;
  26. }
  27. public function testClearingCacheFiles()
  28. {
  29. $name = 'I will be deleted.';
  30. $template = $this->env->loadTemplate($name);
  31. $cacheFileName = $this->env->getCacheFilename($name);
  32. $this->assertTrue(file_exists($cacheFileName), 'Cache file does not exist.');
  33. $this->env->clearCacheFiles();
  34. $this->assertFalse(file_exists($cacheFileName), 'Cache file was not cleared.');
  35. }
  36. }