[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> changelog_getRevisionsAround.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_getrevisionsaround_test extends DokuWikiTest {
  13  
  14      /**
  15       * list of revisions in mailinglist.changes
  16       */
  17      private $revsexpected = array(
  18          1374261194, //current page
  19          1371579614, 1368622240,
  20          1368622195, 1368622152,
  21          1368612599, 1368612506,
  22          1368609772, 1368575634,
  23          1363436892, 1362527164,
  24          1362527046, 1362526861,
  25          1362526767, 1362526167,
  26          1362526119, 1362526039,
  27          1362525926, 1362525899,
  28          1362525359, 1362525145,
  29          1362524799, 1361901536,
  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          $rev1 = 1362526767;
  51          $rev2 = 1362527164;
  52          $max = 50;
  53          $id = 'nonexist';
  54          $revsexpected = array(array(), array());
  55  
  56          $pagelog = new PageChangeLog($id, $chunk_size = 8192);
  57          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
  58          $this->assertEquals($revsexpected, $revs);
  59      }
  60  
  61      /**
  62       * Surrounding revisions of rev1 and rev2 overlaps
  63       */
  64      function test_request_overlapping() {
  65          $rev1 = 1362526767;
  66          $rev2 = 1362527164;
  67          $max = 10;
  68          $revsexpected = array(
  69              array_slice($this->revsexpected, 8, 11),
  70              array_slice($this->revsexpected, 5, 11)
  71          );
  72  
  73          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  74          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
  75          $this->assertEquals($revsexpected, $revs);
  76  
  77          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
  78          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
  79          $this->assertEquals($revsexpected, $revs);
  80  
  81          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
  82          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
  83          $this->assertEquals($revsexpected, $revs);
  84      }
  85  
  86      /**
  87       * Surrounding revisions of rev1 and rev2 don't overlap.
  88       */
  89      function test_request_non_overlapping() {
  90          $rev1 = 1362525899;
  91          $rev2 = 1368612599;
  92          $max = 10;
  93          $revsexpected = array(
  94              array_slice($this->revsexpected, 13, 11),
  95              array_slice($this->revsexpected, 0, 11)
  96          );
  97  
  98          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  99          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 100          $this->assertEquals($revsexpected, $revs);
 101  
 102          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 103          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 104          $this->assertEquals($revsexpected, $revs);
 105  
 106          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 107          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 108          $this->assertEquals($revsexpected, $revs);
 109      }
 110  
 111      /**
 112       * rev1 and rev2 are at start and end of the changelog.
 113       * Should return still a number of revisions equal to max
 114       */
 115      function test_request_first_last() {
 116          $rev1 = 1360110636;
 117          $rev2 = 1374261194;
 118          $max = 10;
 119          $revsexpected = array(
 120              array_slice($this->revsexpected, 13, 11),
 121              array_slice($this->revsexpected, 0, 11)
 122          );
 123  
 124          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 125          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 126          $this->assertEquals($revsexpected, $revs);
 127  
 128          //todo: number of revisions on the left side is not (yet) completed until max number
 129          $revsexpected = array(
 130              array_slice($this->revsexpected, 18, 6),
 131              array_slice($this->revsexpected, 0, 11)
 132          );
 133          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 134          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 135          $this->assertEquals($revsexpected, $revs);
 136  
 137          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 138          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 139          $this->assertEquals($revsexpected, $revs);
 140      }
 141  
 142  
 143      /**
 144       * Number of requested revisions is larger than available revisions,
 145       * so returns whole log
 146       */
 147      function test_request_wholelog() {
 148          $rev1 = 1362525899;
 149          $rev2 = 1368612599;
 150          $max = 50;
 151          $revsexpected = array($this->revsexpected, $this->revsexpected);
 152  
 153          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 154          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 155          $this->assertEquals($revsexpected, $revs);
 156  
 157          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 158          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 159          $this->assertEquals($revsexpected, $revs);
 160  
 161          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 162          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 163          $this->assertEquals($revsexpected, $revs);
 164      }
 165  
 166      /**
 167       * When rev1 > rev2, their order is changed
 168       */
 169      function test_request_wrong_order_revs() {
 170          $rev1 = 1362527164;
 171          $rev2 = 1362526767;
 172          $max = 10;
 173          $revsexpected = array(
 174              array_slice($this->revsexpected, 8, 11),
 175              array_slice($this->revsexpected, 5, 11)
 176          );
 177  
 178          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 179          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 180          $this->assertEquals($revsexpected, $revs);
 181  
 182          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 183          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 184          $this->assertEquals($revsexpected, $revs);
 185  
 186          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 187          $revs = $pagelog->getRevisionsAround($rev1, $rev2, $max);
 188          $this->assertEquals($revsexpected, $revs);
 189      }
 190  
 191  }