[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\ChangeLog\MediaChangeLog;
   4  use dokuwiki\ChangeLog\PageChangeLog;
   5  
   6  /**
   7   * Tests for requesting revisioninfo of a revision of a page with getRevisionInfo()
   8   *
   9   * This class uses the files:
  10   * - data/pages/mailinglist.txt
  11   * - data/meta/mailinglist.changes
  12   */
  13  class changelog_getlastrevisionat_test extends DokuWikiTest {
  14  
  15      private $pageid = 'mailinglist';
  16  
  17      function setup() {
  18          parent::setup();
  19          global $cache_revinfo;
  20          $cache =& $cache_revinfo;
  21          if(isset($cache['nonexist'])) {
  22              unset($cache['nonexist']);
  23          }
  24          if(isset($cache['mailinglist'])) {
  25              unset($cache['mailinglist']);
  26          }
  27      }
  28  
  29  
  30      /**
  31       * no nonexist.changes meta file available
  32       */
  33      function test_changemetadatanotexists() {
  34          $rev = 1362525899;
  35          $id = 'nonexist';
  36          $revsexpected = false;
  37  
  38          $pagelog = new PageChangeLog($id, $chunk_size = 8192);
  39          $revs = $pagelog->getLastRevisionAt($rev);
  40          $this->assertEquals($revsexpected, $revs);
  41      }
  42  
  43      /**
  44       * start at exact current revision of mailinglist page
  45       *
  46       */
  47      function test_startatexactcurrentrev() {
  48          $rev = 1385051947;
  49          $revsexpected = '';
  50  
  51          //set a known timestamp
  52          touch(wikiFN($this->pageid), $rev);
  53  
  54          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  55          $revs = $pagelog->getLastRevisionAt($rev);
  56          $this->assertEquals($revsexpected, $revs);
  57  
  58      }
  59  
  60      /**
  61       * test a future revision
  62       *
  63       */
  64      function test_futurerev() {
  65          $rev = 1385051947;
  66          $revsexpected = '';
  67  
  68          //set a known timestamp
  69          touch(wikiFN($this->pageid), $rev);
  70  
  71          $rev +=1;
  72  
  73          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  74          $revs = $pagelog->getLastRevisionAt($rev);
  75          $this->assertEquals($revsexpected, $revs);
  76  
  77      }
  78  
  79      /**
  80       * start at exact last revision of mailinglist page
  81       *
  82       */
  83      function test_exactlastrev() {
  84          $rev = 1360110636;
  85          $revsexpected = 1360110636;
  86  
  87          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  88          $revs = $pagelog->getLastRevisionAt($rev);
  89          $this->assertEquals($revsexpected, $revs);
  90      }
  91  
  92  
  93      /**
  94       * Request not existing revision
  95       *
  96       */
  97      function test_olderrev() {
  98          $rev = 1;
  99          $revexpected = false;
 100  
 101          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 102          $revfound = $pagelog->getLastRevisionAt($rev);
 103          $this->assertEquals($revexpected, $revfound);
 104      }
 105  
 106      /**
 107       * Start at non existing revision somewhere between existing revisions
 108       */
 109      function test_notexistingrev() {
 110          $rev = 1362525890;
 111          $revexpected = 1362525359;
 112  
 113          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 114          $revfound = $pagelog->getLastRevisionAt($rev);
 115          $this->assertEquals($revexpected, $revfound);
 116      }
 117  
 118      /**
 119       * request nonexisting page
 120       *
 121       */
 122      function test_notexistingpage() {
 123          $rev = 1385051947;
 124          $currentexpected = false;
 125  
 126          $pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192);
 127          $current = $pagelog->getLastRevisionAt($rev);
 128          $this->assertEquals($currentexpected, $current);
 129      }
 130  
 131      /**
 132       * test get correct revision on deleted media
 133       *
 134       */
 135      function test_deletedimage() {
 136          global $conf;
 137          global $AUTH_ACL;
 138  
 139          //we need to have a user with AUTH_DELETE rights
 140          //save settings
 141          $oldSuperUser = $conf['superuser'];
 142          $oldUseacl = $conf['useacl'];
 143          $oldRemoteUser = $_SERVER['REMOTE_USER'];
 144  
 145          $conf['superuser'] = 'admin';
 146          $conf['useacl']    = 1;
 147          $_SERVER['REMOTE_USER'] = 'admin';
 148  
 149          $image = 'wiki:imageat.png';
 150  
 151          $ret = copy(mediaFn('wiki:kind_zu_katze.png'),mediaFn($image));
 152  
 153          $revexpected = @filemtime(mediaFn($image));
 154          $rev = $revexpected + 10;
 155  
 156          $this->waitForTick(true);
 157  
 158          $ret = media_delete($image, 0);
 159  
 160          $medialog = new MediaChangeLog($image);
 161          $current = $medialog->getLastRevisionAt($rev);
 162          // as we wait for a tick, we should get something greater than the timestamp
 163          $this->assertGreaterThan($revexpected, $current);
 164          // however, it should be less than the current time or equal to it
 165          $this->assertLessThanOrEqual(time(), $current);
 166  
 167          //restore settings
 168          $_SERVER['REMOTE_USER'] = $oldRemoteUser;
 169          $conf['superuser'] = $oldSuperUser;
 170          $conf['useacl'] = $oldUseacl;
 171      }
 172  }