1*fe9d054bSAndreas Gohr<?php 2*fe9d054bSAndreas Gohr 3*fe9d054bSAndreas Gohrnamespace dokuwiki\test\Feed; 4*fe9d054bSAndreas Gohr 5*fe9d054bSAndreas Gohruse dokuwiki\Feed\FeedPageProcessor; 6*fe9d054bSAndreas Gohruse DOMWrap\Document; 7*fe9d054bSAndreas Gohr 8*fe9d054bSAndreas Gohrclass FeedPageProcessorTest extends \DokuWikiTest 9*fe9d054bSAndreas Gohr{ 10*fe9d054bSAndreas Gohr 11*fe9d054bSAndreas Gohr public function provideData() 12*fe9d054bSAndreas Gohr { 13*fe9d054bSAndreas Gohr // an Item returned by FeedCreator::fetchItemsFromRecentChanges() 14*fe9d054bSAndreas Gohr yield ([ 15*fe9d054bSAndreas Gohr [ 16*fe9d054bSAndreas Gohr 'date' => 1705501370, 17*fe9d054bSAndreas Gohr 'ip' => '::1', 18*fe9d054bSAndreas Gohr 'type' => 'E', 19*fe9d054bSAndreas Gohr 'id' => 'wiki:dokuwiki', 20*fe9d054bSAndreas Gohr 'user' => 'testuser', 21*fe9d054bSAndreas Gohr 'sum' => 'test editing', 22*fe9d054bSAndreas Gohr 'extra' => '', 23*fe9d054bSAndreas Gohr 'sizechange' => 41, 24*fe9d054bSAndreas Gohr 'perms' => 8, 25*fe9d054bSAndreas Gohr 'mode' => 'page', 26*fe9d054bSAndreas Gohr ], 27*fe9d054bSAndreas Gohr 1705501370, // fixed revision 28*fe9d054bSAndreas Gohr ['testuser@undisclosed.example.com', 'Arthur Dent'], // proper author 29*fe9d054bSAndreas Gohr 'test editing', // summary 30*fe9d054bSAndreas Gohr ]); 31*fe9d054bSAndreas Gohr 32*fe9d054bSAndreas Gohr // an Item returned by FeedCreator::fetchItemsFromNamespace() 33*fe9d054bSAndreas Gohr clearstatcache(); 34*fe9d054bSAndreas Gohr yield ([ 35*fe9d054bSAndreas Gohr [ 36*fe9d054bSAndreas Gohr 'id' => 'wiki:dokuwiki', 37*fe9d054bSAndreas Gohr 'ns' => 'wiki', 38*fe9d054bSAndreas Gohr 'perm' => 8, 39*fe9d054bSAndreas Gohr 'type' => 'f', 40*fe9d054bSAndreas Gohr 'level' => 1, 41*fe9d054bSAndreas Gohr 'open' => true, 42*fe9d054bSAndreas Gohr ], 43*fe9d054bSAndreas Gohr filemtime(wikiFN('wiki:dokuwiki')), // current revision 44*fe9d054bSAndreas Gohr ['anonymous@undisclosed.example.com', 'Anonymous'], // unknown author 45*fe9d054bSAndreas Gohr '', // no summary 46*fe9d054bSAndreas Gohr ]); 47*fe9d054bSAndreas Gohr 48*fe9d054bSAndreas Gohr // an Item returned by FeedCreator::fetchItemsFromSearch() 49*fe9d054bSAndreas Gohr clearstatcache(); 50*fe9d054bSAndreas Gohr yield ([ 51*fe9d054bSAndreas Gohr [ 52*fe9d054bSAndreas Gohr 'id' => 'wiki:dokuwiki', 53*fe9d054bSAndreas Gohr ], 54*fe9d054bSAndreas Gohr filemtime(wikiFN('wiki:dokuwiki')), // current revision 55*fe9d054bSAndreas Gohr ['anonymous@undisclosed.example.com', 'Anonymous'], // unknown author 56*fe9d054bSAndreas Gohr '', // no summary 57*fe9d054bSAndreas Gohr ]); 58*fe9d054bSAndreas Gohr } 59*fe9d054bSAndreas Gohr 60*fe9d054bSAndreas Gohr 61*fe9d054bSAndreas Gohr /** 62*fe9d054bSAndreas Gohr * @dataProvider provideData 63*fe9d054bSAndreas Gohr */ 64*fe9d054bSAndreas Gohr public function testProcessing($data, $expectedMtime, $expectedAuthor, $expectedSummary) 65*fe9d054bSAndreas Gohr { 66*fe9d054bSAndreas Gohr global $conf; 67*fe9d054bSAndreas Gohr $conf['useacl'] = 1; 68*fe9d054bSAndreas Gohr $conf['showuseras'] = 'username'; 69*fe9d054bSAndreas Gohr $conf['useheading'] = 1; 70*fe9d054bSAndreas Gohr 71*fe9d054bSAndreas Gohr $proc = new FeedPageProcessor($data); 72*fe9d054bSAndreas Gohr 73*fe9d054bSAndreas Gohr $this->assertEquals('wiki:dokuwiki', $proc->getId()); 74*fe9d054bSAndreas Gohr $this->assertEquals('DokuWiki', $proc->getTitle()); 75*fe9d054bSAndreas Gohr $this->assertEquals($expectedAuthor, $proc->getAuthor()); 76*fe9d054bSAndreas Gohr $this->assertEquals($expectedMtime, $proc->getRev()); 77*fe9d054bSAndreas Gohr $this->assertEquals(null, $proc->getPrev()); 78*fe9d054bSAndreas Gohr $this->assertTrue($proc->isExisting()); 79*fe9d054bSAndreas Gohr $this->assertEquals(['wiki'], $proc->getCategory()); 80*fe9d054bSAndreas Gohr $this->assertStringContainsString('standards compliant', $proc->getAbstract()); 81*fe9d054bSAndreas Gohr $this->assertEquals($expectedSummary, $proc->getSummary()); 82*fe9d054bSAndreas Gohr 83*fe9d054bSAndreas Gohr $this->assertEquals( 84*fe9d054bSAndreas Gohr "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime", 85*fe9d054bSAndreas Gohr $proc->getURL('page') 86*fe9d054bSAndreas Gohr ); 87*fe9d054bSAndreas Gohr $this->assertEquals( 88*fe9d054bSAndreas Gohr "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime&do=revisions", 89*fe9d054bSAndreas Gohr $proc->getURL('rev') 90*fe9d054bSAndreas Gohr ); 91*fe9d054bSAndreas Gohr $this->assertEquals( 92*fe9d054bSAndreas Gohr 'http://wiki.example.com/doku.php?id=wiki:dokuwiki', 93*fe9d054bSAndreas Gohr $proc->getURL('current') 94*fe9d054bSAndreas Gohr ); 95*fe9d054bSAndreas Gohr $this->assertEquals( 96*fe9d054bSAndreas Gohr "http://wiki.example.com/doku.php?id=wiki:dokuwiki&rev=$expectedMtime&do=diff", 97*fe9d054bSAndreas Gohr $proc->getURL('diff') 98*fe9d054bSAndreas Gohr ); 99*fe9d054bSAndreas Gohr 100*fe9d054bSAndreas Gohr $diff = explode("\n", $proc->getBody('diff')); 101*fe9d054bSAndreas Gohr $this->assertEquals('<pre>', $diff[0]); 102*fe9d054bSAndreas Gohr $this->assertStringStartsWith('@@', $diff[1]); 103*fe9d054bSAndreas Gohr 104*fe9d054bSAndreas Gohr $doc = new Document(); 105*fe9d054bSAndreas Gohr $doc->html($proc->getBody('htmldiff')); 106*fe9d054bSAndreas Gohr $th = $doc->find('table th'); 107*fe9d054bSAndreas Gohr $this->assertGreaterThanOrEqual(2, $th->count()); 108*fe9d054bSAndreas Gohr 109*fe9d054bSAndreas Gohr $doc = new Document(); 110*fe9d054bSAndreas Gohr $doc->html($proc->getBody('html')); 111*fe9d054bSAndreas Gohr $home = $doc->find('a[href^="https://www.dokuwiki.org/manual"]'); 112*fe9d054bSAndreas Gohr $this->assertGreaterThanOrEqual(1, $home->count()); 113*fe9d054bSAndreas Gohr 114*fe9d054bSAndreas Gohr $this->assertStringContainsString('standards compliant', $proc->getBody('abstract')); 115*fe9d054bSAndreas Gohr } 116*fe9d054bSAndreas Gohr 117*fe9d054bSAndreas Gohr} 118