1*6734bb8cSAndreas Gohr<?php 2*6734bb8cSAndreas Gohr 3*6734bb8cSAndreas Gohrnamespace dokuwiki\test\Search; 4*6734bb8cSAndreas Gohr 5*6734bb8cSAndreas Gohruse dokuwiki\Search\Indexer; 6*6734bb8cSAndreas Gohruse dokuwiki\Search\MetadataSearch; 7*6734bb8cSAndreas Gohr 8*6734bb8cSAndreas Gohr/** 9*6734bb8cSAndreas Gohr * Test cases for the media usage search 10*6734bb8cSAndreas Gohr * 11*6734bb8cSAndreas Gohr * @author Michael Hamann <michael@content-space.de> 12*6734bb8cSAndreas Gohr */ 13*6734bb8cSAndreas Gohrclass MediauseTest extends \DokuWikiTest 14*6734bb8cSAndreas Gohr{ 15*6734bb8cSAndreas Gohr public function testInternalmedia() 16*6734bb8cSAndreas Gohr { 17*6734bb8cSAndreas Gohr saveWikiText('test:internalmedia_usage', '{{internalmedia.png}} {{..:internal media.png}}', 'Test initialization'); 18*6734bb8cSAndreas Gohr (new Indexer())->addPage('test:internalmedia_usage'); 19*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 20*6734bb8cSAndreas Gohr 21*6734bb8cSAndreas Gohr $this->assertEquals(array('test:internalmedia_usage'), $search->mediause('internal_media.png')); 22*6734bb8cSAndreas Gohr $this->assertEquals(array('test:internalmedia_usage'), $search->mediause('test:internalmedia.png')); 23*6734bb8cSAndreas Gohr } 24*6734bb8cSAndreas Gohr 25*6734bb8cSAndreas Gohr public function testMediaInLinks() 26*6734bb8cSAndreas Gohr { 27*6734bb8cSAndreas Gohr saveWikiText('test:medialinks', '[[doku>wiki:dokuwiki|{{wiki:logo.png}}]] [[http://www.example.com|{{example.png?200x800}}]]', 'Test init'); 28*6734bb8cSAndreas Gohr (new Indexer())->addPage('test:medialinks'); 29*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 30*6734bb8cSAndreas Gohr 31*6734bb8cSAndreas Gohr $this->assertEquals(array('test:medialinks'), $search->mediause('wiki:logo.png')); 32*6734bb8cSAndreas Gohr $this->assertEquals(array('test:medialinks'), $search->mediause('test:example.png')); 33*6734bb8cSAndreas Gohr } 34*6734bb8cSAndreas Gohr 35*6734bb8cSAndreas Gohr public function testMediaInLocalLinks() 36*6734bb8cSAndreas Gohr { 37*6734bb8cSAndreas Gohr saveWikiText('test:locallinks', '[[#test|{{wiki:logolocal.png}}]]', 'Test init'); 38*6734bb8cSAndreas Gohr (new Indexer())->addPage('test:locallinks'); 39*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 40*6734bb8cSAndreas Gohr 41*6734bb8cSAndreas Gohr $this->assertEquals(array('test:locallinks'), $search->mediause('wiki:logolocal.png')); 42*6734bb8cSAndreas Gohr } 43*6734bb8cSAndreas Gohr 44*6734bb8cSAndreas Gohr public function testMediaInFootnotes() 45*6734bb8cSAndreas Gohr { 46*6734bb8cSAndreas Gohr saveWikiText('test:media_footnotes', '(({{footnote.png?20x50}} [[foonote|{{:footlink.png}}]]))', 'Test initialization'); 47*6734bb8cSAndreas Gohr (new Indexer())->addPage('test:media_footnotes'); 48*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 49*6734bb8cSAndreas Gohr 50*6734bb8cSAndreas Gohr $this->assertEquals(array('test:media_footnotes'), $search->mediause('test:footnote.png')); 51*6734bb8cSAndreas Gohr $this->assertEquals(array('test:media_footnotes'), $search->mediause('footlink.png')); 52*6734bb8cSAndreas Gohr } 53*6734bb8cSAndreas Gohr 54*6734bb8cSAndreas Gohr public function testMediaInHiddenPages() 55*6734bb8cSAndreas Gohr { 56*6734bb8cSAndreas Gohr global $conf; 57*6734bb8cSAndreas Gohr $conf['hidepages'] = 'hidden:.*'; 58*6734bb8cSAndreas Gohr saveWikiText('hidden:medias', '[[doku>wiki:dokuwiki|{{wiki:hiddenlogo.png}}]]', 'Test initialization'); 59*6734bb8cSAndreas Gohr (new Indexer())->addPage('hidden:medias'); 60*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 61*6734bb8cSAndreas Gohr 62*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('wiki:hiddenlogo.png')); 63*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('wiki:hiddenlogo.png', false)); 64*6734bb8cSAndreas Gohr $this->assertEquals(array('hidden:medias'), $search->mediause('wiki:hiddenlogo.png', true)); 65*6734bb8cSAndreas Gohr } 66*6734bb8cSAndreas Gohr 67*6734bb8cSAndreas Gohr public function testMediaInProtectedPages() 68*6734bb8cSAndreas Gohr { 69*6734bb8cSAndreas Gohr global $conf; 70*6734bb8cSAndreas Gohr global $AUTH_ACL; 71*6734bb8cSAndreas Gohr $conf['superuser'] = 'alice'; 72*6734bb8cSAndreas Gohr $conf['useacl'] = 1; 73*6734bb8cSAndreas Gohr 74*6734bb8cSAndreas Gohr $AUTH_ACL = array( 75*6734bb8cSAndreas Gohr '* @ALL 8', 76*6734bb8cSAndreas Gohr 'secret:* @ALL 0', 77*6734bb8cSAndreas Gohr ); 78*6734bb8cSAndreas Gohr 79*6734bb8cSAndreas Gohr $_SERVER['REMOTE_USER'] = 'eve'; 80*6734bb8cSAndreas Gohr 81*6734bb8cSAndreas Gohr saveWikiText('secret:medias', '[[doku>wiki:dokuwiki|{{wiki:secretlogo.png}}]]', 'Test initialization'); 82*6734bb8cSAndreas Gohr (new Indexer())->addPage('secret:medias'); 83*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 84*6734bb8cSAndreas Gohr 85*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('wiki:secretlogo.png')); 86*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('wiki:secretlogo.png', false)); 87*6734bb8cSAndreas Gohr $this->assertEquals(array('secret:medias'), $search->mediause('wiki:secretlogo.png', true)); 88*6734bb8cSAndreas Gohr } 89*6734bb8cSAndreas Gohr 90*6734bb8cSAndreas Gohr public function testMediaInDeletedPages() 91*6734bb8cSAndreas Gohr { 92*6734bb8cSAndreas Gohr saveWikiText('test:internalmedia_usage', '{{internalmedia.png}} {{..:internal media.png}}', 'Test initialization'); 93*6734bb8cSAndreas Gohr (new Indexer())->addPage('test:internalmedia_usage'); 94*6734bb8cSAndreas Gohr saveWikiText('test:internalmedia_usage', '', 'Deleted'); 95*6734bb8cSAndreas Gohr $search = new MetadataSearch(); 96*6734bb8cSAndreas Gohr 97*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('internal_media.png')); 98*6734bb8cSAndreas Gohr $this->assertEquals(array(), $search->mediause('test:internalmedia.png')); 99*6734bb8cSAndreas Gohr } 100*6734bb8cSAndreas Gohr} 101