1<?php 2 3namespace dokuwiki\plugin\aclinfo\test; 4 5use DokuWikiTest; 6 7/** 8 * Tests for the aclinfo plugin 9 * 10 * @group plugin_aclinfo 11 * @group plugins 12 */ 13class AclInfoTest extends DokuWikiTest 14{ 15 16 /** 17 * @return array 18 * @see testProcessAclMatches 19 */ 20 public function provideProcessAclMatches() 21 { 22 return [ 23 'empty array' => [ 24 [], 25 [] 26 ], 27 'single user permission' => [ 28 ['wiki:page user 1'], 29 ['user' => 1] 30 ], 31 'multiple user permissions' => [ 32 ['wiki:page user1 1', 'wiki:page user2 2'], 33 ['user1' => 1, 'user2' => 2] 34 ], 35 'comment removal' => [ 36 ['wiki:page user 1 # this is a comment'], 37 ['user' => 1] 38 ], 39 'admin capped to delete' => [ 40 ['wiki:page admin 255'], 41 ['admin' => 16] // AUTH_DELETE = 16 42 ], 43 'first permission wins for duplicate user' => [ 44 ['wiki:page user 1', 'wiki:page user 8'], 45 ['user' => 1] 46 ], 47 ]; 48 } 49 50 /** 51 * @dataProvider provideProcessAclMatches 52 * @param array $matches 53 * @param array $expected 54 */ 55 public function testProcessAclMatches(array $matches, array $expected) 56 { 57 $plugin = new \syntax_plugin_aclinfo(); 58 $result = $this->callInaccessibleMethod($plugin, 'processAclMatches', [$matches]); 59 $this->assertEquals($expected, $result); 60 } 61 62 /** 63 * @return array 64 * @see testAclCheck 65 */ 66 public function provideAclCheck() 67 { 68 return [ 69 'exact page match' => [ 70 'wiki:page', 71 [ 72 'wiki:page @ALL 1', 73 'wiki:page user1 2', 74 ], 75 ['@ALL' => 1, 'user1' => 2] 76 ], 77 'namespace match' => [ 78 'namespace:page', 79 [ 80 'namespace:* @ALL 1', 81 ], 82 ['@ALL' => 1] 83 ], 84 'exact match takes precedence over namespace' => [ 85 'namespace:page', 86 [ 87 'namespace:page user1 8', 88 'namespace:* @ALL 1', 89 ], 90 ['user1' => 8, '@ALL' => 1] 91 ], 92 'root page namespace' => [ 93 ':page', 94 [ 95 '* @ALL 1', 96 ], 97 ['@ALL' => 1] 98 ], 99 'empty namespace climbs to root' => [ 100 'namespace:sub:page', 101 [ 102 '* @ALL 1', 103 ], 104 ['@ALL' => 1] 105 ], 106 'multiple namespace levels' => [ 107 'a:b:c:page', 108 [ 109 'a:b:c:page user1 2', 110 'a:b:* user2 4', 111 'a:* user3 8', 112 ], 113 ['user1' => 2, 'user2' => 4, 'user3' => 8] 114 ], 115 ]; 116 } 117 118 /** 119 * @dataProvider provideAclCheck 120 * @param string $id 121 * @param array $authAcl 122 * @param array $expected 123 */ 124 public function testAclCheck(string $id, array $authAcl, array $expected) 125 { 126 global $AUTH_ACL; 127 $AUTH_ACL = $authAcl; 128 129 $plugin = new \syntax_plugin_aclinfo(); 130 $result = $this->callInaccessibleMethod($plugin, 'aclCheck', [$id]); 131 132 $this->assertEquals($expected, $result); 133 } 134 135 public function testAclCheckNoMatch() 136 { 137 global $AUTH_ACL; 138 $AUTH_ACL = []; 139 140 $plugin = new \syntax_plugin_aclinfo(); 141 $result = $this->callInaccessibleMethod($plugin, 'aclCheck', ['nonexistent:page']); 142 143 $this->assertEquals([], $result); 144 } 145} 146