[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\ChangeLog\PageChangeLog;
   4  
   5  /**
   6   * Tests for requesting revisions of a page with getRevisions()
   7   *
   8   * This class uses the files:
   9   * - data/pages/mailinglist.txt
  10   * - data/meta/mailinglist.changes
  11   */
  12  class changelog_getrevisions_test extends DokuWikiTest {
  13  
  14      /**
  15       * $first counts inclusive zero, after the current page
  16       */
  17      private $revsexpected = array(
  18          1374261194, //current page
  19          1371579614, 1368622240, // revisions, corresponds to respectively $first = 0 and 1
  20          1368622195, 1368622152,
  21          1368612599, 1368612506,
  22          1368609772, 1368575634,
  23          1363436892, 1362527164,
  24          1362527046, 1362526861, //10 and 11
  25          1362526767, 1362526167,
  26          1362526119, 1362526039,
  27          1362525926, 1362525899,
  28          1362525359, 1362525145,
  29          1362524799, 1361901536, //20 and 21
  30          1360110636
  31      );
  32      private $pageid = 'mailinglist';
  33  
  34      function setup() : void {
  35          parent::setup();
  36          global $cache_revinfo;
  37          $cache =& $cache_revinfo;
  38          unset($cache['nonexist']);
  39          unset($cache['mailinglist']);
  40          // fix filemtime of page source
  41          touch(wikiFN($this->pageid), $this->revsexpected[0]);
  42      }
  43  
  44      /**
  45       * no nonexist.changes meta file available
  46       */
  47      function test_changemetadatanotexists() {
  48          $first = 0;
  49          $num = 1;
  50          $id = 'nonexist';
  51          $revsexpected = array();
  52  
  53          $pagelog = new PageChangeLog($id, $chunk_size = 8192);
  54          $revs = $pagelog->getRevisions($first, $num);
  55          $this->assertEquals($revsexpected, $revs);
  56      }
  57  
  58      /**
  59       * request first recentest revision
  60       * (so skips first line which belongs to the current existing page)
  61       */
  62      function test_requestlastrev() {
  63          $first = 0;
  64          $num = 1;
  65          $revsexpected = array($this->revsexpected[1]);
  66  
  67          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  68          $revs = $pagelog->getRevisions($first, $num);
  69          $this->assertEquals($revsexpected, $revs);
  70  
  71          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
  72          $revs = $pagelog->getRevisions($first, $num);
  73          $this->assertEquals($revsexpected, $revs);
  74  
  75          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
  76          $revs = $pagelog->getRevisions($first, $num);
  77          $this->assertEquals($revsexpected, $revs);
  78      }
  79  
  80      /**
  81       * request first recentest revision
  82       * (so skips first line which belongs to the current existing page)
  83       */
  84      function test_requestonebutlastrev() {
  85          $first = 1;
  86          $num = 1;
  87          $revsexpected = array($this->revsexpected[2]);
  88  
  89          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  90          $revs = $pagelog->getRevisions($first, $num);
  91          $this->assertEquals($revsexpected, $revs);
  92  
  93          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
  94          $revs = $pagelog->getRevisions($first, $num);
  95          $this->assertEquals($revsexpected, $revs);
  96  
  97          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
  98          $revs = $pagelog->getRevisions($first, $num);
  99          $this->assertEquals($revsexpected, $revs);
 100      }
 101  
 102      /**
 103       * request first recentest revision
 104       * (so skips first line of current existing page)
 105       */
 106      function test_requestrevswithoffset() {
 107          $first = 10;
 108          $num = 5;
 109          $revsexpected = array_slice($this->revsexpected, $first + 1, $num);
 110  
 111          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 112          $revs = $pagelog->getRevisions($first, $num);
 113          $this->assertEquals($revsexpected, $revs);
 114  
 115          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 116          $revs = $pagelog->getRevisions($first, $num);
 117          $this->assertEquals($revsexpected, $revs);
 118  
 119          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 120          $revs = $pagelog->getRevisions($first, $num);
 121          $this->assertEquals($revsexpected, $revs);
 122      }
 123  
 124      /**
 125       * first = -1 requests recentest logline, without skipping
 126       */
 127      function test_requestrecentestlogline() {
 128          $first = -1;
 129          $num = 1;
 130          $revsexpected = array($this->revsexpected[0]);
 131  
 132          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 133          $revs = $pagelog->getRevisions($first, $num);
 134          $this->assertEquals($revsexpected, $revs);
 135  
 136          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 137          $revs = $pagelog->getRevisions($first, $num);
 138          $this->assertEquals($revsexpected, $revs);
 139      }
 140  
 141      /**
 142       * chunck size = 0 skips chuncked loading
 143       */
 144      function test_wholefile() {
 145          $first = 0;
 146          $num = 1000;
 147          $revsexpected = array_slice($this->revsexpected, 1);
 148  
 149          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 0);
 150          $revs = $pagelog->getRevisions($first, $num);
 151          $this->assertEquals($revsexpected, $revs);
 152      }
 153  
 154      /**
 155       * Negative range returns no result
 156       */
 157      function test_negativenum() {
 158          $first = 0;
 159          $num = -10;
 160          $revsexpected = array();
 161  
 162          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 163          $revs = $pagelog->getRevisions($first, $num);
 164          $this->assertEquals($revsexpected, $revs);
 165  
 166          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 167          $revs = $pagelog->getRevisions($first, $num);
 168          $this->assertEquals($revsexpected, $revs);
 169      }
 170  
 171      /**
 172       * Negative range returns no result
 173       */
 174      function test_negativennumoffset() {
 175          $first = 2;
 176          $num = -10;
 177          $revsexpected = array();
 178  
 179          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 180          $revs = $pagelog->getRevisions($first, $num);
 181          $this->assertEquals($revsexpected, $revs);
 182  
 183          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 184          $revs = $pagelog->getRevisions($first, $num);
 185          $this->assertEquals($revsexpected, $revs);
 186      }
 187  
 188      /**
 189       * zero range returns no result
 190       */
 191      function test_zeronum() {
 192          $first = 5;
 193          $num = 0;
 194          $revsexpected = array();
 195  
 196          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 197          $revs = $pagelog->getRevisions($first, $num);
 198          $this->assertEquals($revsexpected, $revs);
 199  
 200          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 201          $revs = $pagelog->getRevisions($first, $num);
 202          $this->assertEquals($revsexpected, $revs);
 203      }
 204  
 205      /**
 206       * get oldest revisions
 207       */
 208      function test_requestlargeoffset() {
 209          $first = 22;
 210          $num = 50;
 211          $revsexpected = array_slice($this->revsexpected, $first + 1);
 212  
 213          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 214          $revs = $pagelog->getRevisions($first, $num);
 215          $this->assertEquals($revsexpected, $revs);
 216      }
 217  
 218      /**
 219       * request with too large offset and range
 220       */
 221      function test_requesttoolargenumberrevs() {
 222          $first = 50;
 223          $num = 50;
 224          $revsexpected = array();
 225  
 226          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 227          $revs = $pagelog->getRevisions($first, $num);
 228          $this->assertEquals($revsexpected, $revs);
 229      }
 230  
 231  }