1<?php 2 3class common_infofunctions_test extends DokuWikiTest { 4 5 function setup(){ 6 parent::setup(); 7 8 global $USERINFO; 9 $USERINFO = array( 10 'pass' => '179ad45c6ce2cb97cf1029e212046e81', 11 'name' => 'Arthur Dent', 12 'mail' => 'arthur@example.com', 13 'grps' => array ('admin','user'), 14 ); 15 $_SERVER['REMOTE_USER'] = 'testuser'; 16 $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; 17 } 18 19 function _get_info() { 20 global $USERINFO; 21 $info = array ( 22 'isadmin' => true, 23 'ismanager' => true, 24 'userinfo' => $USERINFO, 25 'perm' => 255, 26 'namespace' => false, 27 'ismobile' => false, 28 'client' => 'testuser', 29 ); 30 31 return $info; 32 } 33 34 /** 35 * Its important to have the correct set of keys. 36 * Other functions provide the values 37 */ 38 function test_basicinfo(){ 39 // test with REMOTE_USER set and the user an admin user 40 $info = $this->_get_info(); 41 $this->assertEquals(basicinfo($ID,true),$info); 42 43 // with $httpclient parameter set to false 44 unset($info['ismobile']); 45 $this->assertEquals(basicinfo($ID,false),$info); 46 47 // with anonymous user 48 unset($_SERVER['REMOTE_USER']); 49 global $USERINFO; $USERINFO = array(); 50 51 $info = array( 52 'isadmin' => false, 53 'ismanager' => false, 54 'perm' => 8, 55 'namespace' => false, 56 'ismobile' => false, 57 'client' => '1.2.3.4', 58 ); 59 $this->assertEquals(basicinfo($ID,true),$info); 60 } 61 62 /** 63 * We're interested in the extra keys required for $INFO when its a page request 64 * and that $REV, $RANGE globals are set/cleared correctly 65 */ 66 function test_pageinfo(){ 67 global $ID,$conf; 68 $ID = 'wiki:start'; 69 70 $info = $this->_get_info(); 71 $info['id'] = 'wiki:start'; 72 $info['namespace'] = 'wiki'; 73 $info['rev'] = null; 74 $info['subscribed'] = false; 75 $info['locked'] = false; 76 $info['filepath'] = $conf['datadir'].'/wiki/start.txt'; 77 $info['exists'] = false; 78 $info['writable'] = true; 79 $info['editable'] = true; 80 $info['lastmod'] = false; 81 $info['meta'] = array(); 82 $info['ip'] = null; 83 $info['user'] = null; 84 $info['sum'] = null; 85 $info['editor'] = null; 86 87 // basic test, no revision 88 $this->assertEquals(pageinfo(),$info); 89 90 // TODO: test with revision = current page 91 92 // TODO: test with true revision 93 94 // TODO: test with revision & range 95 96 // TODO: validate against the same test run on master branch pre this change 97 } 98 99 /** 100 * We're interested in the extra keys for $INFO when its a media request 101 */ 102 function test_mediainfo(){ 103 global $NS, $IMG; 104 $NS = ''; 105 $IMG = 'testimage.png'; 106 107 $info = $this->_get_info(); 108 $info['image'] = 'testimage.png'; 109 110 $this->assertEquals(mediainfo(),$info); 111 } 112} 113 114//Setup VIM: ex: et ts=4 : 115