[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\ChangeLog\PageChangeLog;
   4  
   5  /**
   6   * Tests for requesting revisioninfo of a revision of a page with getRevisionInfo()
   7   *
   8   * This class uses the files:
   9   * - data/pages/mailinglist.txt
  10   * - data/meta/mailinglist.changes
  11   */
  12  class changelog_getrelativerevision_test extends DokuWikiTest {
  13  
  14      private $logline = "1362525899    127.0.0.1    E    mailinglist    pubcie    [Data entry]     \n";
  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       * no nonexist.changes meta file available
  31       */
  32      function test_changemetadatanotexists() {
  33          $rev = 1362525899;
  34          $dir = 1;
  35          $id = 'nonexist';
  36          $revsexpected = false;
  37  
  38          $pagelog = new PageChangeLog($id, $chunk_size = 8192);
  39          $revs = $pagelog->getRelativeRevision($rev, $dir);
  40          $this->assertEquals($revsexpected, $revs);
  41      }
  42  
  43      /**
  44       * no nonexist.changes meta file available
  45       */
  46      function test_nodirection() {
  47          $rev = 1362525899;
  48          $dir = 0;
  49          $revsexpected = false;
  50  
  51          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  52          $revs = $pagelog->getRelativeRevision($rev, $dir);
  53          $this->assertEquals($revsexpected, $revs);
  54      }
  55  
  56      /**
  57       * start at exact current revision of mailinglist page
  58       *
  59       */
  60      function test_startatexactcurrentrev() {
  61          $rev = 1385051947;
  62          $dir = 1;
  63          $revsexpectedpos = false;
  64          $revsexpectedneg = 1374261194;
  65  
  66          //set a known timestamp
  67          touch(wikiFN($this->pageid), $rev);
  68  
  69          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  70          $revs = $pagelog->getRelativeRevision($rev, $dir);
  71          $this->assertEquals($revsexpectedpos, $revs);
  72  
  73          $revs = $pagelog->getRelativeRevision($rev, -$dir);
  74          $this->assertEquals($revsexpectedneg, $revs);
  75      }
  76  
  77      /**
  78       * start at exact last revision of mailinglist page
  79       *
  80       */
  81      function test_startatexactlastrev() {
  82          $rev = 1360110636;
  83          $dir = 1;
  84          $revsexpectedpos = 1361901536;
  85          $revsexpectedneg = false;
  86  
  87          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
  88          $revs = $pagelog->getRelativeRevision($rev, $dir);
  89          $this->assertEquals($revsexpectedpos, $revs);
  90  
  91          $revs = $pagelog->getRelativeRevision($rev, -$dir);
  92          $this->assertEquals($revsexpectedneg, $revs);
  93      }
  94  
  95      /**
  96       * start at exact one before last revision of mailinglist page
  97       *
  98       */
  99      function test_requestlastrevisions() {
 100          $rev = 1361901536;
 101          $dir = -1;
 102          $revsexpectedlast = 1360110636;
 103          $revsexpectedbeforelast = false;
 104  
 105          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 106          $revs = $pagelog->getRelativeRevision($rev, $dir);
 107          $this->assertEquals($revsexpectedlast, $revs);
 108  
 109          $revs = $pagelog->getRelativeRevision($rev, 2 * $dir);
 110          $this->assertEquals($revsexpectedbeforelast, $revs);
 111      }
 112  
 113      /**
 114       * request existing rev and check cache
 115       */
 116      function test_requestrev_checkcache() {
 117          $rev = 1362525359;
 118          $dir = 1;
 119          $revexpected = 1362525899;
 120          $infoexpected = parseChangelogLine($this->logline);
 121  
 122          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 123          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 124          $this->assertEquals($revexpected, $revfound);
 125  
 126          //checked info returned from cache
 127          $info = $pagelog->getRevisionInfo($revfound);
 128          $this->assertEquals($infoexpected, $info);
 129      }
 130  
 131      /**
 132       * request existing rev
 133       */
 134      function test_requestnextrev() {
 135          $rev = 1362525899;
 136  
 137          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 138  
 139          $dir = 1;
 140          $revexpected = 1362525926;
 141          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 142          $this->assertEquals($revexpected, $revfound);
 143  
 144          $dir = 2;
 145          $revexpected = 1362526039;
 146          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 147          $this->assertEquals($revexpected, $revfound);
 148  
 149          $dir = -1;
 150          $revexpected = 1362525359;
 151          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 152          $this->assertEquals($revexpected, $revfound);
 153  
 154          $dir = -2;
 155          $revexpected = 1362525145;
 156          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 157          $this->assertEquals($revexpected, $revfound);
 158      }
 159  
 160      /**
 161       * request existing rev with chucked reading
 162       */
 163      function test_requestnextrev_chuncked() {
 164          $rev = 1362525899;
 165  
 166          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 167  
 168          $dir = 1;
 169          $revexpected = 1362525926;
 170          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 171          $this->assertEquals($revexpected, $revfound);
 172  
 173          $dir = 2;
 174          $revexpected = 1362526039;
 175          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 176          $this->assertEquals($revexpected, $revfound);
 177  
 178          $dir = -1;
 179          $revexpected = 1362525359;
 180          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 181          $this->assertEquals($revexpected, $revfound);
 182  
 183          $dir = -2;
 184          $revexpected = 1362525145;
 185          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 186          $this->assertEquals($revexpected, $revfound);
 187      }
 188  
 189  
 190      /**
 191       * request existing rev with chucked reading, chunk size smaller than line length
 192       */
 193      function test_requestnextrev_chunkshorterthanlines() {
 194          $rev = 1362525899;
 195  
 196          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 20);
 197  
 198          $dir = 1;
 199          $revexpected = 1362525926;
 200          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 201          $this->assertEquals($revexpected, $revfound);
 202  
 203          $dir = 2;
 204          $revexpected = 1362526039;
 205          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 206          $this->assertEquals($revexpected, $revfound);
 207  
 208          $dir = -1;
 209          $revexpected = 1362525359;
 210          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 211          $this->assertEquals($revexpected, $revfound);
 212  
 213          $dir = -2;
 214          $revexpected = 1362525145;
 215          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 216          $this->assertEquals($revexpected, $revfound);
 217      }
 218  
 219      /**
 220       * request existing rev
 221       */
 222      function test_requestnextfifthrev() {
 223          $rev = 1362525899;
 224          $dir = 5;
 225          $revexpected = 1362526767;
 226  
 227          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 228          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 229          $this->assertEquals($revexpected, $revfound);
 230      }
 231  
 232      /**
 233       * request existing rev with chucked reading
 234       */
 235      function test_requestnextfifthrev_chuncked() {
 236          $rev = 1362525899;
 237          $dir = 5;
 238          $revexpected = 1362526767;
 239  
 240          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 241          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 242          $this->assertEquals($revexpected, $revfound);
 243      }
 244  
 245      /**
 246       * request existing rev
 247       */
 248      function test_requestprevrev() {
 249          $rev = 1362525899;
 250          $dir1 = -1;
 251          $dir5 = -5;
 252          $revexpected1 = 1362525359;
 253          $revexpected5 = 1360110636;
 254  
 255          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 256          $revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
 257          $this->assertEquals($revexpected1, $revfound1);
 258  
 259          $revfound5 = $pagelog->getRelativeRevision($rev, $dir5);
 260          $this->assertEquals($revexpected5, $revfound5);
 261      }
 262  
 263      /**
 264       * request existing rev with chucked reading
 265       */
 266      function test_requestprevrev_chuncked() {
 267          $rev = 1362525899;
 268          $dir1 = -1;
 269          $dir5 = -5;
 270          $revexpected1 = 1362525359;
 271          $revexpected5 = 1360110636;
 272  
 273          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 274          $revfound1 = $pagelog->getRelativeRevision($rev, $dir1);
 275          $this->assertEquals($revexpected1, $revfound1);
 276  
 277          $revfound5 = $pagelog->getRelativeRevision($rev, $dir5);
 278          $this->assertEquals($revexpected5, $revfound5);
 279      }
 280  
 281      /**
 282       * request after recentest version in changelog
 283       */
 284      function test_requestrecentestlogline_next() {
 285          $rev = 1374261194;
 286          $dir = 1;
 287          $revexpected = false;
 288  
 289          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 290          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 291          $this->assertEquals($revexpected, $revfound);
 292      }
 293  
 294      /**
 295       * request after recentest version in changelog, with chuncked reading
 296       */
 297      function test_requestrecentestlogline_next_chuncked() {
 298          $rev = 1374261194;
 299          $dir = 1;
 300          $revexpected = false;
 301  
 302          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 303          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 304          $this->assertEquals($revexpected, $revfound);
 305      }
 306  
 307      /**
 308       * request before current version
 309       */
 310      function test_requestrecentestlogline_prev() {
 311          $rev = 1374261194;
 312          $dir = -1;
 313          $revexpected = 1371579614;
 314  
 315          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 316          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 317          $this->assertEquals($revexpected, $revfound);
 318      }
 319  
 320      /**
 321       * request before current version, with chuncked reading
 322       */
 323      function test_requestrecentestlogline_prev_chuncked() {
 324          $rev = 1374261194;
 325          $dir = -1;
 326          $revexpected = 1371579614;
 327  
 328          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 512);
 329          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 330          $this->assertEquals($revexpected, $revfound);
 331      }
 332  
 333      /**
 334       * Request negative revision
 335       * looks in positive direction, so it catches the oldest revision
 336       */
 337      function test_negativerev_posdir() {
 338          $rev = -10;
 339          $dir = 1;
 340          $revexpected = 1360110636;
 341  
 342          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 343          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 344          $this->assertEquals($revexpected, $revfound);
 345      }
 346  
 347      /**
 348       * Request negative revision
 349       * looks in negative direction, but there is nothing
 350       */
 351      function test_negativerev_negdir() {
 352          $rev = -10;
 353          $dir = -1;
 354          $revexpected = false;
 355  
 356          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 357          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 358          $this->assertEquals($revexpected, $revfound);
 359      }
 360  
 361      /**
 362       * Start at non existing revision somewhere between existing revisions
 363       */
 364      function test_startatnotexistingrev_next() {
 365          $rev = 1362525890;
 366          $dir = 1;
 367          $revexpected = 1362525899;
 368  
 369          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 370          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 371          $this->assertEquals($revexpected, $revfound);
 372      }
 373  
 374      /**
 375       * Start at non existing revision somewhere between existing revisions
 376       */
 377      function test_startatnotexistingrev_prev() {
 378          $rev = 1362525890;
 379          $dir = -1;
 380          $revexpected = 1362525359;
 381  
 382          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 383          $revfound = $pagelog->getRelativeRevision($rev, $dir);
 384          $this->assertEquals($revexpected, $revfound);
 385      }
 386  
 387      function test_iscurrentpagerevision() {
 388          $rev = 1385051947;
 389          $currentexpected = true;
 390  
 391          //set a known timestamp
 392          touch(wikiFN($this->pageid), $rev);
 393  
 394          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 395          $current = $pagelog->isCurrentRevision($rev);
 396          $this->assertEquals($currentexpected, $current);
 397      }
 398  
 399      function test_isnotcurrentpagerevision() {
 400          $rev = 1385051947;
 401          $not_current_rev = $rev - 1;
 402          $currentexpected = false;
 403  
 404          //set a known timestamp
 405          touch(wikiFN($this->pageid), $rev);
 406  
 407          $pagelog = new PageChangeLog($this->pageid, $chunk_size = 8192);
 408          $current = $pagelog->isCurrentRevision($not_current_rev);
 409          $this->assertEquals($currentexpected, $current);
 410      }
 411  
 412      function test_notexistingcurrentpage() {
 413          $rev = 1385051947;
 414          $currentexpected = false;
 415  
 416          $pagelog = new PageChangeLog('nonexistingpage', $chunk_size = 8192);
 417          $current = $pagelog->isCurrentRevision($rev);
 418          $this->assertEquals($currentexpected, $current);
 419      }
 420  }