1<?php 2 3namespace dokuwiki\plugin\bureaucracyau\test; 4 5/** 6 * @group plugin_bureaucracyau 7 * @group plugins 8 */ 9class syntax_plugin_bureaucracyau_fielduser_test extends BureaucracyauTest 10{ 11 12 /** 13 * Create some users 14 */ 15 public function setUp() 16 { 17 parent::setUp(); 18 19 /** @var \DokuWiki_Auth_Plugin $auth */ 20 global $auth; 21 22 $auth->createUser("user1", "54321", "user1Name", "user1@example.com"); 23 $auth->createUser("user2", "543210", "user2Name", "user2@example.com"); 24 $auth->createUser("mwuser", "12345", "Wiki User", "wikiuser@example.com", ['group1', 'group2']); 25 } 26 27 public function dataProvider() 28 { 29 return [ 30 [ 31 'user:@@user@@', 32 'user user', 33 'mwuser', 34 'user:mwuser', 35 [], 36 'default substitution', 37 ], 38 [ 39 'user:@@user@@', 40 'user user', 41 '', 42 'user:', 43 ['user'], 44 'error for empty substitution', 45 ], 46 [ 47 'user:@@user@@', 48 'user user !', 49 '', 50 'user:', 51 [], 52 'ok for empty substitution in optional field', 53 ], 54 [ 55 'user:@@user.name@@', 56 'user user', 57 'mwuser', 58 'user:Wiki User', 59 [], 60 'name substitution', 61 ], 62 [ 63 'user:@@user.mail@@', 64 'user user', 65 'mwuser', 66 'user:wikiuser@example.com', 67 [], 68 'mail substitution', 69 ], 70 [ 71 'user:@@user.grps@@', 72 'user user', 73 'mwuser', 74 'user:group1, group2', 75 [], 76 'groups substitution', 77 ], 78 [ 79 'user:@@user.grps(;)@@', 80 'user user', 81 'mwuser', 82 'user:group1;group2', 83 [], 84 'groups substitution custom delimiter', 85 ], 86 [ 87 'user:@@user.grps())@@', 88 'user user', 89 'mwuser', 90 'user:group1)group2', 91 [], 92 'groups substitution custom delimiter with brackets', 93 ], 94 [ 95 'user:@@user.no_sutch_attribute@@', 96 'user user', 97 'mwuser', 98 'user:@@user.no_sutch_attribute@@', 99 [], 100 'template unknown attribute substitution', 101 ], 102 [ 103 'user:##user##', 104 'user user', 105 'mwuser', 106 'user:mwuser', 107 [], 108 'hash substitution', 109 ], 110 [ 111 'user:##user.mail##', 112 'user user', 113 'mwuser', 114 'user:wikiuser@example.com', 115 [], 116 'hash substitution with attribute', 117 ], 118 [ 119 'user:##user@@', 120 'user user', 121 'mwuser', 122 'user:##user@@', 123 [], 124 'hash substitution sign mismatch', 125 ], 126 [ 127 "user:@@user@@\n\nmail:@@user.mail@@\n\ngrps:@@user.grps(\n)@@", 128 'user user', 129 'mwuser', 130 "user:mwuser\n\nmail:wikiuser@example.com\n\ngrps:group1\ngroup2", 131 [], 132 'multiple replacements', 133 ], 134 [ 135 "grps1:@@user.grps(\n)@@\n\ngrps2:@@user.grps(())@@", 136 'user user', 137 'mwuser', 138 "grps1:group1\ngroup2\n\ngrps2:group1()group2", 139 [], 140 'groups twice', 141 ], 142 [ 143 'grps:@@user.grps(end))@@', 144 'user user', 145 'mwuser', 146 'grps:group1end)group2', 147 [], 148 'groups special glue', 149 ], 150 [ 151 'grps:@@user.grps()@@', 152 'user user', 153 'mwuser', 154 'grps:group1group2', 155 [], 156 'groups with empty delimiter', 157 ], 158 [ 159 'user:@@user@@', 160 'user user', 161 'non_existant_user', 162 'user:non_existant_user', 163 ['user'], 164 'error for non existant user', 165 ], 166 [ 167 'user:@@user.name@@', 168 'user user', 169 'non_existant_user', 170 'user:@@user.name@@', 171 ['user'], 172 'error for non existant user with attribute', 173 ], 174 ]; 175 } 176 177 178 /** 179 * @dataProvider dataProvider 180 * 181 * @param string $templateSyntax 182 * @param string $formSyntax 183 * @param string $postedValue value of 'user' field 184 * @param string $expectedWikiText 185 * @param string $expectedValidationErrors 186 * @param string $msg 187 * 188 */ 189 public function test_field_user( 190 $templateSyntax, 191 $formSyntax, 192 $postedValue, 193 $expectedWikiText, 194 $expectedValidationErrors, 195 $msg 196 ) { 197 $actualValidationErrors = []; 198 199 $actualWikiText = parent::send_form_action_template( 200 $formSyntax, 201 $templateSyntax, 202 $actualValidationErrors, 203 $postedValue 204 ); 205 206 $this->assertEquals($expectedValidationErrors, $actualValidationErrors, $msg); 207 $this->assertEquals($expectedWikiText, $actualWikiText, $msg); 208 } 209} 210