1*023953f0SAndreas Gohr<?php 2*023953f0SAndreas Gohr 3*023953f0SAndreas Gohrclass common_saveWikiText_test extends DokuWikiTest { 4*023953f0SAndreas Gohr 5*023953f0SAndreas Gohr /** 6*023953f0SAndreas Gohr * Execute a whole bunch of saves on the same page and check the results 7*023953f0SAndreas Gohr */ 8*023953f0SAndreas Gohr function test_savesequence() { 9*023953f0SAndreas Gohr global $REV; 10*023953f0SAndreas Gohr 11*023953f0SAndreas Gohr $page = 'page'; 12*023953f0SAndreas Gohr $file = wikiFN($page); 13*023953f0SAndreas Gohr 14*023953f0SAndreas Gohr // create the page 15*023953f0SAndreas Gohr $this->assertFileNotExists($file); 16*023953f0SAndreas Gohr saveWikiText($page, 'teststring', 'first save', false); 17*023953f0SAndreas Gohr $this->assertFileExists($file); 18*023953f0SAndreas Gohr $lastmod = filemtime($file); 19*023953f0SAndreas Gohr 20*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 21*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 22*023953f0SAndreas Gohr $this->assertEquals(1, count($revisions)); 23*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 24*023953f0SAndreas Gohr $this->assertEquals('first save', $revinfo['sum']); 25*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_CREATE, $revinfo['type']); 26*023953f0SAndreas Gohr 27*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 28*023953f0SAndreas Gohr 29*023953f0SAndreas Gohr // save with same content should be ignored 30*023953f0SAndreas Gohr saveWikiText($page, 'teststring', 'second save', false); 31*023953f0SAndreas Gohr clearstatcache(false, $file); 32*023953f0SAndreas Gohr $this->assertEquals($lastmod, filemtime($file)); 33*023953f0SAndreas Gohr 34*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 35*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 36*023953f0SAndreas Gohr $this->assertEquals(1, count($revisions)); 37*023953f0SAndreas Gohr 38*023953f0SAndreas Gohr // update the page with new text 39*023953f0SAndreas Gohr saveWikiText($page, 'teststring2', 'third save', false); 40*023953f0SAndreas Gohr clearstatcache(false, $file); 41*023953f0SAndreas Gohr $newmod = filemtime($file); 42*023953f0SAndreas Gohr $this->assertNotEquals($lastmod, $newmod); 43*023953f0SAndreas Gohr $lastmod = $newmod; 44*023953f0SAndreas Gohr 45*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 46*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 47*023953f0SAndreas Gohr $this->assertEquals(2, count($revisions)); 48*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 49*023953f0SAndreas Gohr $this->assertEquals('third save', $revinfo['sum']); 50*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']); 51*023953f0SAndreas Gohr 52*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 53*023953f0SAndreas Gohr 54*023953f0SAndreas Gohr // add a minor edit (unauthenticated) 55*023953f0SAndreas Gohr saveWikiText($page, 'teststring3', 'fourth save', true); 56*023953f0SAndreas Gohr clearstatcache(false, $file); 57*023953f0SAndreas Gohr $newmod = filemtime($file); 58*023953f0SAndreas Gohr $this->assertNotEquals($lastmod, $newmod); 59*023953f0SAndreas Gohr $lastmod = $newmod; 60*023953f0SAndreas Gohr 61*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 62*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 63*023953f0SAndreas Gohr $this->assertEquals(3, count($revisions)); 64*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 65*023953f0SAndreas Gohr $this->assertEquals('fourth save', $revinfo['sum']); 66*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']); 67*023953f0SAndreas Gohr 68*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 69*023953f0SAndreas Gohr 70*023953f0SAndreas Gohr // add a minor edit (authenticated) 71*023953f0SAndreas Gohr $_SERVER['REMOTE_USER'] = 'user'; 72*023953f0SAndreas Gohr saveWikiText($page, 'teststring4', 'fifth save', true); 73*023953f0SAndreas Gohr clearstatcache(false, $file); 74*023953f0SAndreas Gohr $newmod = filemtime($file); 75*023953f0SAndreas Gohr $this->assertNotEquals($lastmod, $newmod); 76*023953f0SAndreas Gohr $lastmod = $newmod; 77*023953f0SAndreas Gohr 78*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 79*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 80*023953f0SAndreas Gohr $this->assertEquals(4, count($revisions)); 81*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 82*023953f0SAndreas Gohr $this->assertEquals('fifth save', $revinfo['sum']); 83*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_MINOR_EDIT, $revinfo['type']); 84*023953f0SAndreas Gohr 85*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 86*023953f0SAndreas Gohr 87*023953f0SAndreas Gohr // delete 88*023953f0SAndreas Gohr saveWikiText($page, '', 'sixth save', false); 89*023953f0SAndreas Gohr clearstatcache(false, $file); 90*023953f0SAndreas Gohr $this->assertFileNotExists($file); 91*023953f0SAndreas Gohr 92*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 93*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 94*023953f0SAndreas Gohr $this->assertEquals(5, count($revisions)); 95*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 96*023953f0SAndreas Gohr $this->assertEquals('sixth save', $revinfo['sum']); 97*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_DELETE, $revinfo['type']); 98*023953f0SAndreas Gohr 99*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 100*023953f0SAndreas Gohr 101*023953f0SAndreas Gohr // restore 102*023953f0SAndreas Gohr $REV = $lastmod; 103*023953f0SAndreas Gohr saveWikiText($page, 'teststring4', 'seventh save', true); 104*023953f0SAndreas Gohr clearstatcache(false, $file); 105*023953f0SAndreas Gohr $this->assertFileExists($file); 106*023953f0SAndreas Gohr $newmod = filemtime($file); 107*023953f0SAndreas Gohr $this->assertNotEquals($lastmod, $newmod); 108*023953f0SAndreas Gohr $lastmod = $newmod; 109*023953f0SAndreas Gohr 110*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 111*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 112*023953f0SAndreas Gohr $this->assertEquals(6, count($revisions)); 113*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 114*023953f0SAndreas Gohr $this->assertEquals('seventh save', $revinfo['sum']); 115*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_REVERT, $revinfo['type']); 116*023953f0SAndreas Gohr $this->assertEquals($REV, $revinfo['extra']); 117*023953f0SAndreas Gohr $REV = ''; 118*023953f0SAndreas Gohr 119*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 120*023953f0SAndreas Gohr 121*023953f0SAndreas Gohr // create external edit 122*023953f0SAndreas Gohr file_put_contents($file, 'teststring5'); 123*023953f0SAndreas Gohr 124*023953f0SAndreas Gohr sleep(1); // wait for new revision ID 125*023953f0SAndreas Gohr 126*023953f0SAndreas Gohr // save on top of external edit 127*023953f0SAndreas Gohr saveWikiText($page, 'teststring6', 'eigth save', false); 128*023953f0SAndreas Gohr clearstatcache(false, $file); 129*023953f0SAndreas Gohr $newmod = filemtime($file); 130*023953f0SAndreas Gohr $this->assertNotEquals($lastmod, $newmod); 131*023953f0SAndreas Gohr $lastmod = $newmod; 132*023953f0SAndreas Gohr 133*023953f0SAndreas Gohr $pagelog = new PageChangeLog($page); 134*023953f0SAndreas Gohr $revisions = $pagelog->getRevisions(-1, 200); 135*023953f0SAndreas Gohr $this->assertEquals(8, count($revisions)); // two more revisions now! 136*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[0]); 137*023953f0SAndreas Gohr $this->assertEquals('eigth save', $revinfo['sum']); 138*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']); 139*023953f0SAndreas Gohr 140*023953f0SAndreas Gohr $revinfo = $pagelog->getRevisionInfo($revisions[1]); 141*023953f0SAndreas Gohr $this->assertEquals('external edit', $revinfo['sum']); 142*023953f0SAndreas Gohr $this->assertEquals(DOKU_CHANGE_TYPE_EDIT, $revinfo['type']); 143*023953f0SAndreas Gohr 144*023953f0SAndreas Gohr } 145*023953f0SAndreas Gohr} 146