[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> cache_use.test.php (source)

   1  <?php
   2  
   3  use dokuwiki\Cache\CacheRenderer;
   4  
   5  /**
   6   * Class cache_use_test
   7   *
   8   * Tests if caching can actually be used
   9   *
  10   * @todo tests marked as flaky until Ticket #694 has been fixed
  11   */
  12  class cache_use_test extends DokuWikiTest {
  13      /** @var CacheRenderer $cache */
  14      private $cache;
  15  
  16      function setUp() {
  17          global $ID, $conf;
  18          parent::setUp();
  19  
  20          $ID = 'cached';
  21          $file = wikiFN($ID);
  22          $conf['cachetime'] = 0;  // ensure the value is not -1, which disables caching
  23  
  24          saveWikiText($ID, 'Content', 'Created');
  25  
  26          $this->cache = new CacheRenderer($ID, $file, 'xhtml');
  27          $this->cache->storeCache('Test');
  28  
  29          // set the modification times explicitly (overcome Issue #694)
  30          $time = time();
  31          touch($file, $time-1);
  32          touch($this->cache->cache, $time);
  33      }
  34  
  35      /**
  36       * In all the following tests the cache should not be usable
  37       * as such, they are meaningless if test_use didn't pass.
  38       *
  39       * @group flaky
  40       */
  41      function test_purge() {
  42          /* @var Input $INPUT */
  43          global $INPUT;
  44          $INPUT->set('purge',1);
  45  
  46          $this->assertFalse($this->cache->useCache());
  47          $this->assertNotEmpty($this->cache->depends['purge']);
  48      }
  49  
  50      /**
  51       * @group flaky
  52       */
  53      function test_filedependency() {
  54          // give the dependent src file the same mtime as the cache
  55          touch($this->cache->file, filemtime($this->cache->cache));
  56          $this->assertFalse($this->cache->useCache());
  57      }
  58  
  59      /**
  60       * @group flaky
  61       */
  62      function test_age() {
  63          // need to age both our source file & the cache
  64          $age = 10;
  65          $time = time() - $age - 1;  // older than age
  66  
  67          touch($this->cache->file, $time - 1);
  68          touch($this->cache->cache, $time);
  69  
  70          $this->assertFalse($this->cache->useCache(array('age' => $age)));
  71      }
  72  
  73      /**
  74       * @group flaky
  75       */
  76      function test_confnocaching() {
  77          global $conf;
  78          $conf['cachetime'] = -1;   // disables renderer caching
  79  
  80          $this->assertFalse($this->cache->useCache());
  81          $this->assertNotEmpty($this->cache->isNoCache());
  82      }
  83  }