1*2bde879aSAndreas Gohr<?php 2*2bde879aSAndreas Gohr 3*2bde879aSAndreas Gohrnamespace dokuwiki\test\Ui; 4*2bde879aSAndreas Gohr 5*2bde879aSAndreas Gohruse dokuwiki\Ui\PageDiff; 6*2bde879aSAndreas Gohr 7*2bde879aSAndreas Gohr/** 8*2bde879aSAndreas Gohr * Tests for the page diff view dokuwiki\Ui\PageDiff. 9*2bde879aSAndreas Gohr */ 10*2bde879aSAndreas Gohrclass PageDiffTest extends \DokuWikiTest 11*2bde879aSAndreas Gohr{ 12*2bde879aSAndreas Gohr /** 13*2bde879aSAndreas Gohr * Determine which two revisions PageDiff would compare for a ?do=diff request 14*2bde879aSAndreas Gohr * that carries no rev or rev2 parameters. 15*2bde879aSAndreas Gohr * 16*2bde879aSAndreas Gohr * Clears any leftover request parameters, then runs PageDiff's internal request 17*2bde879aSAndreas Gohr * handler, which derives the default comparison pair from the changelog. Returns 18*2bde879aSAndreas Gohr * the timestamps it selected for the older and newer side of the diff. 19*2bde879aSAndreas Gohr * 20*2bde879aSAndreas Gohr * @param string $page page id to diff 21*2bde879aSAndreas Gohr * @return array the older (rev1) and newer (rev2) revision timestamps or false 22*2bde879aSAndreas Gohr */ 23*2bde879aSAndreas Gohr private function resolveDefaultDiff($page) 24*2bde879aSAndreas Gohr { 25*2bde879aSAndreas Gohr global $INPUT, $INFO; 26*2bde879aSAndreas Gohr // make sure no rev parameters leak in from a previous request 27*2bde879aSAndreas Gohr $INPUT->remove('rev'); 28*2bde879aSAndreas Gohr $INPUT->remove('rev2'); 29*2bde879aSAndreas Gohr $INFO['id'] = $page; 30*2bde879aSAndreas Gohr 31*2bde879aSAndreas Gohr $diff = new PageDiff($page); 32*2bde879aSAndreas Gohr $this->callInaccessibleMethod($diff, 'handle', []); 33*2bde879aSAndreas Gohr return [ 34*2bde879aSAndreas Gohr $this->getInaccessibleProperty($diff, 'rev1'), 35*2bde879aSAndreas Gohr $this->getInaccessibleProperty($diff, 'rev2'), 36*2bde879aSAndreas Gohr ]; 37*2bde879aSAndreas Gohr } 38*2bde879aSAndreas Gohr 39*2bde879aSAndreas Gohr /** 40*2bde879aSAndreas Gohr * Without rev parameters, the diff of an existing page compares the previous 41*2bde879aSAndreas Gohr * revision with the current one. 42*2bde879aSAndreas Gohr */ 43*2bde879aSAndreas Gohr public function testExistingPageComparesPreviousToCurrent() 44*2bde879aSAndreas Gohr { 45*2bde879aSAndreas Gohr $page = 'pagediff_existing'; 46*2bde879aSAndreas Gohr // the page file's mtime after each save is that revision's timestamp 47*2bde879aSAndreas Gohr saveWikiText($page, 'first content', 'create', false); 48*2bde879aSAndreas Gohr clearstatcache(); 49*2bde879aSAndreas Gohr $previous = filemtime(wikiFN($page)); 50*2bde879aSAndreas Gohr $this->waitForTick(true); 51*2bde879aSAndreas Gohr saveWikiText($page, 'second content', 'edit', false); 52*2bde879aSAndreas Gohr clearstatcache(); 53*2bde879aSAndreas Gohr $current = filemtime(wikiFN($page)); 54*2bde879aSAndreas Gohr 55*2bde879aSAndreas Gohr [$rev1, $rev2] = $this->resolveDefaultDiff($page); 56*2bde879aSAndreas Gohr 57*2bde879aSAndreas Gohr $this->assertEquals($previous, $rev1, 'older side should be the previous revision'); 58*2bde879aSAndreas Gohr $this->assertEquals($current, $rev2, 'newer side should be the current revision'); 59*2bde879aSAndreas Gohr } 60*2bde879aSAndreas Gohr 61*2bde879aSAndreas Gohr /** 62*2bde879aSAndreas Gohr * Regression test for issue #4635: opening the default diff of a page deleted 63*2bde879aSAndreas Gohr * through DokuWiki compares the last edit with the deletion, instead of comparing 64*2bde879aSAndreas Gohr * the deletion entry with itself. 65*2bde879aSAndreas Gohr */ 66*2bde879aSAndreas Gohr public function testNormalDeletionComparesPreviousToDeletion() 67*2bde879aSAndreas Gohr { 68*2bde879aSAndreas Gohr $page = 'pagediff_deleted'; 69*2bde879aSAndreas Gohr saveWikiText($page, 'some content', 'create', false); 70*2bde879aSAndreas Gohr clearstatcache(); 71*2bde879aSAndreas Gohr $contentRev = filemtime(wikiFN($page)); // last revision that still had content 72*2bde879aSAndreas Gohr $this->waitForTick(true); 73*2bde879aSAndreas Gohr 74*2bde879aSAndreas Gohr saveWikiText($page, '', 'delete', false); 75*2bde879aSAndreas Gohr clearstatcache(); 76*2bde879aSAndreas Gohr $this->assertFileDoesNotExist(wikiFN($page)); 77*2bde879aSAndreas Gohr 78*2bde879aSAndreas Gohr [$rev1, $rev2] = $this->resolveDefaultDiff($page); 79*2bde879aSAndreas Gohr 80*2bde879aSAndreas Gohr $this->assertEquals($contentRev, $rev1, 'older side should be the content revision before deletion'); 81*2bde879aSAndreas Gohr $this->assertGreaterThan( 82*2bde879aSAndreas Gohr $rev1, 83*2bde879aSAndreas Gohr $rev2, 84*2bde879aSAndreas Gohr 'newer side must be the later deletion, not the same revision compared with itself' 85*2bde879aSAndreas Gohr ); 86*2bde879aSAndreas Gohr } 87*2bde879aSAndreas Gohr 88*2bde879aSAndreas Gohr /** 89*2bde879aSAndreas Gohr * Regression test for issue #4635: opening the default diff of an externally 90*2bde879aSAndreas Gohr * deleted page compares the last edit with the persisted deletion, instead of 91*2bde879aSAndreas Gohr * comparing the deletion entry with itself. 92*2bde879aSAndreas Gohr */ 93*2bde879aSAndreas Gohr public function testExternalDeletionComparesPreviousToDeletion() 94*2bde879aSAndreas Gohr { 95*2bde879aSAndreas Gohr $page = 'pagediff_extdeleted'; 96*2bde879aSAndreas Gohr saveWikiText($page, 'some content', 'create', false); 97*2bde879aSAndreas Gohr clearstatcache(); 98*2bde879aSAndreas Gohr $contentRev = filemtime(wikiFN($page)); // last revision that still had content 99*2bde879aSAndreas Gohr 100*2bde879aSAndreas Gohr // delete the page file externally, bypassing DokuWiki; resolving the diff is 101*2bde879aSAndreas Gohr // what triggers detection and persistence of the synthesized deletion entry, 102*2bde879aSAndreas Gohr // which is dated lastRev+1 at the earliest, so no tick is needed here 103*2bde879aSAndreas Gohr unlink(wikiFN($page)); 104*2bde879aSAndreas Gohr clearstatcache(); 105*2bde879aSAndreas Gohr 106*2bde879aSAndreas Gohr [$rev1, $rev2] = $this->resolveDefaultDiff($page); 107*2bde879aSAndreas Gohr 108*2bde879aSAndreas Gohr $this->assertEquals($contentRev, $rev1, 'older side should be the content revision before external deletion'); 109*2bde879aSAndreas Gohr $this->assertGreaterThan( 110*2bde879aSAndreas Gohr $rev1, 111*2bde879aSAndreas Gohr $rev2, 112*2bde879aSAndreas Gohr 'newer side must be the later deletion, not the same revision compared with itself' 113*2bde879aSAndreas Gohr ); 114*2bde879aSAndreas Gohr } 115*2bde879aSAndreas Gohr 116*2bde879aSAndreas Gohr /** 117*2bde879aSAndreas Gohr * Regression test for issue #4635: the rendered diff of a deleted page shows the 118*2bde879aSAndreas Gohr * removed content rather than an empty diff. 119*2bde879aSAndreas Gohr */ 120*2bde879aSAndreas Gohr public function testDeletionDiffRendersRemovedContent() 121*2bde879aSAndreas Gohr { 122*2bde879aSAndreas Gohr global $INPUT, $INFO; 123*2bde879aSAndreas Gohr 124*2bde879aSAndreas Gohr $page = 'pagediff_removedcontent'; 125*2bde879aSAndreas Gohr saveWikiText($page, 'zqxdistinctivebody', 'create', false); 126*2bde879aSAndreas Gohr $this->waitForTick(true); 127*2bde879aSAndreas Gohr saveWikiText($page, '', 'delete', false); 128*2bde879aSAndreas Gohr clearstatcache(); 129*2bde879aSAndreas Gohr 130*2bde879aSAndreas Gohr $INPUT->remove('rev'); 131*2bde879aSAndreas Gohr $INPUT->remove('rev2'); 132*2bde879aSAndreas Gohr $INFO['id'] = $page; 133*2bde879aSAndreas Gohr 134*2bde879aSAndreas Gohr $diff = new PageDiff($page); 135*2bde879aSAndreas Gohr ob_start(); 136*2bde879aSAndreas Gohr $diff->show(); 137*2bde879aSAndreas Gohr $html = ob_get_clean(); 138*2bde879aSAndreas Gohr 139*2bde879aSAndreas Gohr $this->assertStringContainsString( 140*2bde879aSAndreas Gohr 'zqxdistinctivebody', 141*2bde879aSAndreas Gohr $html, 142*2bde879aSAndreas Gohr 'the diff should display the removed content, not an empty diff' 143*2bde879aSAndreas Gohr ); 144*2bde879aSAndreas Gohr } 145*2bde879aSAndreas Gohr} 146