[ 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() {
  35          parent::setup();
  36          global $cache_revinfo;
  37          $cache =& $cache_revinfo;
  38          if(isset($cache['nonexist'])) {
  39              unset($cache['nonexist']);
  40          }
  41          if(isset($cache['mailinglist'])) {
  42              unset($cache['mailinglist']);
  43          }
  44      }
  45  
  46      /**
  47       * no nonexist.changes meta file available
  48       */
  49      function test_changemetadatanotexists() {
  50          $first = 0;
  51          $num = 1;
  52          $id = 'nonexist';
  53          $revsexpected = array();
  54  
  55          $pagelog = new PageChangeLog($id, $chunk_size = 8192);
  56          $revs = $pagelog->getRevisions($first, $num);
  57          $this->assertEquals($revsexpected, $revs);
  58      }
  59  
  60      /**
  61       * request first recentest revision
  62       * (so skips first line which belongs to the current existing page)
  63       */
  64      function test_requestlastrev() {
  65          $first = 0;
  66          $num = 1;
  67          $revsexpected = array($this->revsexpected[1]);
  68  
  69          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  70          $revs = $pagelog->getRevisions($first, $num);
  71          $this->assertEquals($revsexpected, $revs);
  72  
  73          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
  74          $revs = $pagelog->getRevisions($first, $num);
  75          $this->assertEquals($revsexpected, $revs);
  76  
  77          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
  78          $revs = $pagelog->getRevisions($first, $num);
  79          $this->assertEquals($revsexpected, $revs);
  80      }
  81  
  82      /**
  83       * request first recentest revision
  84       * (so skips first line which belongs to the current existing page)
  85       */
  86      function test_requestonebutlastrev() {
  87          $first = 1;
  88          $num = 1;
  89          $revsexpected = array($this->revsexpected[2]);
  90  
  91          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  92          $revs = $pagelog->getRevisions($first, $num);
  93          $this->assertEquals($revsexpected, $revs);
  94  
  95          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
  96          $revs = $pagelog->getRevisions($first, $num);
  97          $this->assertEquals($revsexpected, $revs);
  98  
  99          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 100          $revs = $pagelog->getRevisions($first, $num);
 101          $this->assertEquals($revsexpected, $revs);
 102      }
 103  
 104      /**
 105       * request first recentest revision
 106       * (so skips first line of current existing page)
 107       */
 108      function test_requestrevswithoffset() {
 109          $first = 10;
 110          $num = 5;
 111          $revsexpected = array_slice($this->revsexpected, $first + 1, $num);
 112  
 113          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 114          $revs = $pagelog->getRevisions($first, $num);
 115          $this->assertEquals($revsexpected, $revs);
 116  
 117          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 118          $revs = $pagelog->getRevisions($first, $num);
 119          $this->assertEquals($revsexpected, $revs);
 120  
 121          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 122          $revs = $pagelog->getRevisions($first, $num);
 123          $this->assertEquals($revsexpected, $revs);
 124      }
 125  
 126      /**
 127       * first = -1 requests recentest logline, without skipping
 128       */
 129      function test_requestrecentestlogline() {
 130          $first = -1;
 131          $num = 1;
 132          $revsexpected = array($this->revsexpected[0]);
 133  
 134          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 135          $revs = $pagelog->getRevisions($first, $num);
 136          $this->assertEquals($revsexpected, $revs);
 137  
 138          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 139          $revs = $pagelog->getRevisions($first, $num);
 140          $this->assertEquals($revsexpected, $revs);
 141      }
 142  
 143      /**
 144       * chunck size = 0 skips chuncked loading
 145       */
 146      function test_wholefile() {
 147          $first = 0;
 148          $num = 1000;
 149          $revsexpected = array_slice($this->revsexpected, 1);
 150  
 151          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 0);
 152          $revs = $pagelog->getRevisions($first, $num);
 153          $this->assertEquals($revsexpected, $revs);
 154      }
 155  
 156      /**
 157       * Negative range returns no result
 158       */
 159      function test_negativenum() {
 160          $first = 0;
 161          $num = -10;
 162          $revsexpected = array();
 163  
 164          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 165          $revs = $pagelog->getRevisions($first, $num);
 166          $this->assertEquals($revsexpected, $revs);
 167  
 168          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 169          $revs = $pagelog->getRevisions($first, $num);
 170          $this->assertEquals($revsexpected, $revs);
 171      }
 172  
 173      /**
 174       * Negative range returns no result
 175       */
 176      function test_negativennumoffset() {
 177          $first = 2;
 178          $num = -10;
 179          $revsexpected = array();
 180  
 181          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 182          $revs = $pagelog->getRevisions($first, $num);
 183          $this->assertEquals($revsexpected, $revs);
 184  
 185          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 186          $revs = $pagelog->getRevisions($first, $num);
 187          $this->assertEquals($revsexpected, $revs);
 188      }
 189  
 190      /**
 191       * zero range returns no result
 192       */
 193      function test_zeronum() {
 194          $first = 5;
 195          $num = 0;
 196          $revsexpected = array();
 197  
 198          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 199          $revs = $pagelog->getRevisions($first, $num);
 200          $this->assertEquals($revsexpected, $revs);
 201  
 202          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 203          $revs = $pagelog->getRevisions($first, $num);
 204          $this->assertEquals($revsexpected, $revs);
 205      }
 206  
 207      /**
 208       * get oldest revisions
 209       */
 210      function test_requestlargeoffset() {
 211          $first = 22;
 212          $num = 50;
 213          $revsexpected = array_slice($this->revsexpected, $first + 1);
 214  
 215          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 216          $revs = $pagelog->getRevisions($first, $num);
 217          $this->assertEquals($revsexpected, $revs);
 218      }
 219  
 220      /**
 221       * request with too large offset and range
 222       */
 223      function test_requesttoolargenumberrevs() {
 224          $first = 50;
 225          $num = 50;
 226          $revsexpected = array();
 227  
 228          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 229          $revs = $pagelog->getRevisions($first, $num);
 230          $this->assertEquals($revsexpected, $revs);
 231      }
 232  
 233  }