1*6734bb8cSAndreas Gohr<?php 2*6734bb8cSAndreas Gohr 3*6734bb8cSAndreas Gohrnamespace dokuwiki\test\Search; 4*6734bb8cSAndreas Gohr 5*6734bb8cSAndreas Gohruse dokuwiki\Search\MetadataSearch; 6*6734bb8cSAndreas Gohr 7*6734bb8cSAndreas Gohr/** 8*6734bb8cSAndreas Gohr * Tests for MetadataSearch utility methods 9*6734bb8cSAndreas Gohr */ 10*6734bb8cSAndreas Gohrclass MetadataSearchTest extends \DokuWikiTest 11*6734bb8cSAndreas Gohr{ 12*6734bb8cSAndreas Gohr /** 13*6734bb8cSAndreas Gohr * filterPages removes non-existent pages 14*6734bb8cSAndreas Gohr */ 15*6734bb8cSAndreas Gohr public function testFilterPagesRemovesNonExistent() 16*6734bb8cSAndreas Gohr { 17*6734bb8cSAndreas Gohr saveWikiText('wiki:existing', 'content', 'init'); 18*6734bb8cSAndreas Gohr 19*6734bb8cSAndreas Gohr $pages = ['wiki:existing' => true, 'wiki:nonexistent' => true]; 20*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages); 21*6734bb8cSAndreas Gohr 22*6734bb8cSAndreas Gohr $this->assertArrayHasKey('wiki:existing', $result); 23*6734bb8cSAndreas Gohr $this->assertArrayNotHasKey('wiki:nonexistent', $result); 24*6734bb8cSAndreas Gohr } 25*6734bb8cSAndreas Gohr 26*6734bb8cSAndreas Gohr /** 27*6734bb8cSAndreas Gohr * filterPages respects hidden pages setting 28*6734bb8cSAndreas Gohr */ 29*6734bb8cSAndreas Gohr public function testFilterPagesHidden() 30*6734bb8cSAndreas Gohr { 31*6734bb8cSAndreas Gohr global $conf; 32*6734bb8cSAndreas Gohr $conf['hidepages'] = 'hidden:.*'; 33*6734bb8cSAndreas Gohr 34*6734bb8cSAndreas Gohr saveWikiText('hidden:page', 'content', 'init'); 35*6734bb8cSAndreas Gohr saveWikiText('visible:page', 'content', 'init'); 36*6734bb8cSAndreas Gohr 37*6734bb8cSAndreas Gohr $pages = ['hidden:page' => true, 'visible:page' => true]; 38*6734bb8cSAndreas Gohr 39*6734bb8cSAndreas Gohr // default: hidden pages are filtered 40*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages); 41*6734bb8cSAndreas Gohr $this->assertArrayNotHasKey('hidden:page', $result); 42*6734bb8cSAndreas Gohr $this->assertArrayHasKey('visible:page', $result); 43*6734bb8cSAndreas Gohr 44*6734bb8cSAndreas Gohr // ignorePerms: hidden pages are kept 45*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, true); 46*6734bb8cSAndreas Gohr $this->assertArrayHasKey('hidden:page', $result); 47*6734bb8cSAndreas Gohr $this->assertArrayHasKey('visible:page', $result); 48*6734bb8cSAndreas Gohr } 49*6734bb8cSAndreas Gohr 50*6734bb8cSAndreas Gohr /** 51*6734bb8cSAndreas Gohr * filterPages respects ACL permissions 52*6734bb8cSAndreas Gohr */ 53*6734bb8cSAndreas Gohr public function testFilterPagesACL() 54*6734bb8cSAndreas Gohr { 55*6734bb8cSAndreas Gohr global $conf; 56*6734bb8cSAndreas Gohr global $AUTH_ACL; 57*6734bb8cSAndreas Gohr $conf['superuser'] = 'admin'; 58*6734bb8cSAndreas Gohr $conf['useacl'] = 1; 59*6734bb8cSAndreas Gohr 60*6734bb8cSAndreas Gohr $AUTH_ACL = [ 61*6734bb8cSAndreas Gohr '* @ALL 8', 62*6734bb8cSAndreas Gohr 'secret:* @ALL 0', 63*6734bb8cSAndreas Gohr ]; 64*6734bb8cSAndreas Gohr 65*6734bb8cSAndreas Gohr $_SERVER['REMOTE_USER'] = 'user'; 66*6734bb8cSAndreas Gohr 67*6734bb8cSAndreas Gohr saveWikiText('public:page', 'content', 'init'); 68*6734bb8cSAndreas Gohr saveWikiText('secret:page', 'content', 'init'); 69*6734bb8cSAndreas Gohr 70*6734bb8cSAndreas Gohr $pages = ['public:page' => true, 'secret:page' => true]; 71*6734bb8cSAndreas Gohr 72*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages); 73*6734bb8cSAndreas Gohr $this->assertArrayHasKey('public:page', $result); 74*6734bb8cSAndreas Gohr $this->assertArrayNotHasKey('secret:page', $result); 75*6734bb8cSAndreas Gohr 76*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, true); 77*6734bb8cSAndreas Gohr $this->assertArrayHasKey('public:page', $result); 78*6734bb8cSAndreas Gohr $this->assertArrayHasKey('secret:page', $result); 79*6734bb8cSAndreas Gohr } 80*6734bb8cSAndreas Gohr 81*6734bb8cSAndreas Gohr /** 82*6734bb8cSAndreas Gohr * filterPages filters by modification time 83*6734bb8cSAndreas Gohr */ 84*6734bb8cSAndreas Gohr public function testFilterPagesTime() 85*6734bb8cSAndreas Gohr { 86*6734bb8cSAndreas Gohr saveWikiText('wiki:timepage', 'content', 'init'); 87*6734bb8cSAndreas Gohr $mtime = filemtime(wikiFN('wiki:timepage')); 88*6734bb8cSAndreas Gohr 89*6734bb8cSAndreas Gohr $pages = ['wiki:timepage' => true]; 90*6734bb8cSAndreas Gohr 91*6734bb8cSAndreas Gohr // after: page mtime is before the threshold → filtered 92*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, false, $mtime + 100); 93*6734bb8cSAndreas Gohr $this->assertEmpty($result); 94*6734bb8cSAndreas Gohr 95*6734bb8cSAndreas Gohr // after: page mtime is after the threshold → kept 96*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, false, $mtime - 100); 97*6734bb8cSAndreas Gohr $this->assertArrayHasKey('wiki:timepage', $result); 98*6734bb8cSAndreas Gohr 99*6734bb8cSAndreas Gohr // before: page mtime is after the threshold → filtered 100*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, false, null, $mtime - 100); 101*6734bb8cSAndreas Gohr $this->assertEmpty($result); 102*6734bb8cSAndreas Gohr 103*6734bb8cSAndreas Gohr // before: page mtime is before the threshold → kept 104*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages, false, null, $mtime + 100); 105*6734bb8cSAndreas Gohr $this->assertArrayHasKey('wiki:timepage', $result); 106*6734bb8cSAndreas Gohr } 107*6734bb8cSAndreas Gohr 108*6734bb8cSAndreas Gohr /** 109*6734bb8cSAndreas Gohr * filterPages preserves original array values 110*6734bb8cSAndreas Gohr */ 111*6734bb8cSAndreas Gohr public function testFilterPagesPreservesValues() 112*6734bb8cSAndreas Gohr { 113*6734bb8cSAndreas Gohr saveWikiText('wiki:testpage', 'content', 'init'); 114*6734bb8cSAndreas Gohr 115*6734bb8cSAndreas Gohr $pages = ['wiki:testpage' => 'My Title']; 116*6734bb8cSAndreas Gohr $result = MetadataSearch::filterPages($pages); 117*6734bb8cSAndreas Gohr 118*6734bb8cSAndreas Gohr $this->assertEquals('My Title', $result['wiki:testpage']); 119*6734bb8cSAndreas Gohr } 120*6734bb8cSAndreas Gohr} 121