Changeset 13791
- Timestamp:
- 01/23/12 06:00:05 (4 weeks ago)
- Location:
- trunk/UnitTestContrib/test/unit
- Files:
-
- 42 edited
-
AccessControlTests.pm (modified) (43 diffs)
-
AddressTests.pm (modified) (1 diff)
-
AdminOnlyAccessControlTests.pm (modified) (43 diffs)
-
AttrsTests.pm (modified) (1 diff)
-
CacheTests.pm (modified) (9 diffs)
-
ClientTests.pm (modified) (13 diffs)
-
ConfigureTests.pm (modified) (3 diffs)
-
EmptyTests.pm (modified) (8 diffs)
-
ExceptionTests.pm (modified) (10 diffs)
-
Fn_GROUPINFO.pm (modified) (11 diffs)
-
Fn_IF.pm (modified) (150 diffs)
-
Fn_REVINFO.pm (modified) (31 diffs)
-
Fn_SEARCH.pm (modified) (45 diffs)
-
Fn_VAR.pm (modified) (3 diffs)
-
FormDefTests.pm (modified) (1 diff)
-
FoswikiPmFunctionsTests.pm (modified) (6 diffs)
-
FuncTests.pm (modified) (4 diffs)
-
FuncUsersTests.pm (modified) (42 diffs)
-
HTMLValidationTests.pm (modified) (13 diffs)
-
HierarchicalWebsTests.pm (modified) (26 diffs)
-
ManageDotPmTests.pm (modified) (66 diffs)
-
MergeTests.pm (modified) (12 diffs)
-
MetaTests.pm (modified) (59 diffs)
-
PasswordTests.pm (modified) (35 diffs)
-
PluginHandlerTests.pm (modified) (34 diffs)
-
RESTTests.pm (modified) (21 diffs)
-
RegisterTests.pm (modified) (87 diffs)
-
RenameTests.pm (modified) (3 diffs)
-
RobustnessTests.pm (modified) (4 diffs)
-
SaveScriptTests.pm (modified) (100 diffs)
-
SemiAutomaticTestCaseTests.pm (modified) (7 diffs)
-
StoreTests.pm (modified) (55 diffs)
-
TemplatesTests.pm (modified) (31 diffs)
-
UIFnCompileTests.pm (modified) (11 diffs)
-
UploadScriptTests.pm (modified) (12 diffs)
-
VCMetaTests.pm (modified) (22 diffs)
-
VCStoreTests.pm (modified) (35 diffs)
-
VariableTests.pm (modified) (9 diffs)
-
ViewFileScriptTests.pm (modified) (21 diffs)
-
ViewParamSectionTests.pm (modified) (8 diffs)
-
ViewScriptTests.pm (modified) (11 diffs)
-
ZoneTests.pm (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/UnitTestContrib/test/unit/AccessControlTests.pm
r13730 r13791 3 3 use warnings; 4 4 5 use FoswikiFnTestCase ;5 use FoswikiFnTestCase(); 6 6 our @ISA = qw( FoswikiFnTestCase ); 7 7 … … 41 41 $this->SUPER::set_up(); 42 42 43 my $topicObject = Foswiki::Meta->new( 44 $this->{session}, 45 $Foswiki::cfg{UsersWebName}, 46 $Foswiki::cfg{DefaultUserWikiName}, '' 47 ); 48 $topicObject->save(); 43 my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 44 $Foswiki::cfg{DefaultUserWikiName} ); 45 $topicObject->text(''); 46 $topicObject->save(); 47 $topicObject->finish(); 49 48 $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); 50 49 $MrWhite = $this->{session}->{users}->getCanonicalUserID('white'); … … 58 57 $MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow'); 59 58 60 $topicObject = 61 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 62 "ReservoirDogsGroup", <<"THIS"); 59 $this->createNewFoswikiSession(); 60 ($topicObject) = 61 Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" ); 62 $topicObject->text(<<"THIS"); 63 63 * Set GROUP = MrWhite, $this->{users_web}.MrBlue 64 64 THIS 65 65 $topicObject->save(); 66 67 return; 68 } 69 70 sub tear_down { 71 my $this = shift; 72 $this->SUPER::tear_down(); 66 $topicObject->finish(); 73 67 74 68 return; … … 79 73 $web ||= $this->{test_web}; 80 74 $topic ||= $this->{test_topic}; 81 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );75 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 82 76 $this->assert( !$topicObject->haveAccess( $mode, $user ), 83 77 "$user $mode $web.$topic" ); … … 106 100 ); 107 101 } 102 $topicObject->finish(); 108 103 109 104 return; … … 114 109 $web ||= $this->{test_web}; 115 110 $topic ||= $this->{test_topic}; 116 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );111 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 117 112 $this->assert( $topicObject->haveAccess( $mode, $user ), 118 113 "$user $mode $web.$topic" ); … … 141 136 ); 142 137 } 138 $topicObject->finish(); 143 139 144 140 return; … … 152 148 sub test_denytopic { 153 149 my $this = shift; 154 my $topicObject=155 Foswiki:: Meta->new( $this->{session}, $this->{test_web},156 $this->{test_topic},<<"THIS");150 my ($topicObject) = 151 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 152 $topicObject->text(<<"THIS"); 157 153 If DENYTOPIC is set to a list of wikinames 158 154 * people in the list will be DENIED. … … 161 157 THIS 162 158 $topicObject->save(); 163 164 $this->{session}->finish(); 165 $this->{session} = Foswiki->new(); 166 159 $topicObject->finish(); 160 161 $this->createNewFoswikiSession(); 167 162 $this->PERMITTED( "VIEW", $MrGreen ); 168 163 $this->DENIED( "VIEW", $MrYellow ); … … 177 172 sub test_empty_denytopic { 178 173 my $this = shift; 179 my $topicObject=180 Foswiki:: Meta->new( $this->{session}, $this->{test_web},181 $this->{test_topic},<<'THIS');174 my ($topicObject) = 175 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 176 $topicObject->text(<<'THIS'); 182 177 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 183 178 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 185 180 THIS 186 181 $topicObject->save(); 187 188 $this->{session}->finish(); 189 $this-> {session} = Foswiki->new();182 $topicObject->finish(); 183 184 $this->createNewFoswikiSession(); 190 185 $this->PERMITTED( "VIEW", $MrGreen ); 191 186 $this->PERMITTED( "VIEW", $MrYellow ); … … 200 195 sub test_whitespace_denytopic { 201 196 my $this = shift; 202 my $topicObject=203 Foswiki:: Meta->new( $this->{session}, $this->{test_web},204 $this->{test_topic},<<'THIS');197 my ($topicObject) = 198 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 199 $topicObject->text(<<'THIS'); 205 200 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 206 201 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 208 203 THIS 209 204 $topicObject->save(); 210 211 $this->{session}->finish(); 212 $this-> {session} = Foswiki->new();205 $topicObject->finish(); 206 207 $this->createNewFoswikiSession(); 213 208 $this->PERMITTED( "VIEW", $MrGreen ); 214 209 $this->PERMITTED( "VIEW", $MrYellow ); … … 223 218 sub test_denytopic_whitespace { 224 219 my $this = shift; 225 my $topicObject=226 Foswiki:: Meta->new( $this->{session}, $this->{test_web},227 $this->{test_topic},<<'THIS');220 my ($topicObject) = 221 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 222 $topicObject->text(<<'THIS'); 228 223 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 229 224 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 231 226 THIS 232 227 $topicObject->save(); 233 234 $this->{session}->finish(); 235 $this-> {session} = Foswiki->new();228 $topicObject->finish(); 229 230 $this->createNewFoswikiSession(); 236 231 $this->PERMITTED( "VIEW", $MrGreen ); 237 232 $this->PERMITTED( "VIEW", $MrYellow ); … … 246 241 sub test_allowtopic { 247 242 my $this = shift; 248 my $topicObject=249 Foswiki:: Meta->new( $this->{session}, $this->{test_web},250 $this->{test_topic},<<'THIS');243 my ($topicObject) = 244 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 245 $topicObject->text(<<'THIS'); 251 246 If ALLOWTOPIC is set 252 247 1. people in the list are PERMITTED … … 255 250 THIS 256 251 $topicObject->save(); 257 258 $this->{session}->finish(); 259 $this-> {session} = Foswiki->new();252 $topicObject->finish(); 253 254 $this->createNewFoswikiSession(); 260 255 $this->PERMITTED( "VIEW", $MrOrange ); 261 256 $this->DENIED( "VIEW", $MrGreen ); … … 271 266 sub test_allowtopic_a { 272 267 my $this = shift; 273 my $topicObject=274 Foswiki:: Meta->new( $this->{session}, $this->{test_web},275 $this->{test_topic},<<'THIS');268 my ($topicObject) = 269 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 270 $topicObject->text(<<'THIS'); 276 271 If ALLOWTOPIC is set 277 272 1. people in the list are PERMITTED … … 280 275 THIS 281 276 $topicObject->save(); 277 $topicObject->finish(); 282 278 283 279 my $topicquery = Unit::Request->new(""); … … 285 281 286 282 # renew Foswiki, so WebPreferences gets re-read 287 $this->{session}->finish(); 288 $this->{session} = Foswiki->new( undef, $topicquery ); 283 $this->createNewFoswikiSession(); 289 284 $this->PERMITTED( "VIEW", $MrOrange ); 290 $this->{session}->finish(); 291 $this->{session} = Foswiki->new( undef, $topicquery ); 285 $this->createNewFoswikiSession( undef, $topicquery ); 292 286 $this->DENIED( "VIEW", $MrGreen ); 293 $this->{session}->finish(); 294 $this->{session} = Foswiki->new( undef, $topicquery ); 287 $this->createNewFoswikiSession( undef, $topicquery ); 295 288 $this->DENIED( "VIEW", $MrYellow ); 296 $this->{session}->finish(); 297 $this->{session} = Foswiki->new( undef, $topicquery ); 289 $this->createNewFoswikiSession( undef, $topicquery ); 298 290 $this->DENIED( "VIEW", $MrWhite ); 299 $this->{session}->finish(); 300 $this->{session} = Foswiki->new( undef, $topicquery ); 291 $this->createNewFoswikiSession( undef, $topicquery ); 301 292 $this->DENIED( "view", $MrBlue ); 302 293 … … 309 300 sub test_allowtopic_b { 310 301 my $this = shift; 311 my $topicObject=312 Foswiki:: Meta->new( $this->{session}, $this->{test_web},313 $this->{test_topic},<<'THIS');302 my ($topicObject) = 303 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 304 $topicObject->text(<<'THIS'); 314 305 If ALLOWTOPIC is set 315 306 1. people in the list are PERMITTED … … 318 309 THIS 319 310 $topicObject->save(); 311 $topicObject->finish(); 320 312 321 313 # renew Foswiki, so WebPreferences gets re-read 322 $this->{session}->finish(); 323 $this->{session} = Foswiki->new(); 314 $this->createNewFoswikiSession(); 324 315 $this->PERMITTED( "VIEW", $MrOrange ); 325 $this->{session}->finish(); 326 $this->{session} = Foswiki->new(); 316 $this->createNewFoswikiSession(); 327 317 $this->DENIED( "VIEW", $MrGreen ); 328 $this->{session}->finish(); 329 $this->{session} = Foswiki->new(); 318 $this->createNewFoswikiSession(); 330 319 $this->DENIED( "VIEW", $MrYellow ); 331 $this->{session}->finish(); 332 $this->{session} = Foswiki->new(); 320 $this->createNewFoswikiSession(); 333 321 $this->DENIED( "VIEW", $MrWhite ); 334 $this->{session}->finish(); 335 $this->{session} = Foswiki->new(); 322 $this->createNewFoswikiSession(); 336 323 $this->DENIED( "view", $MrBlue ); 337 324 … … 343 330 sub test_allowtopic_c { 344 331 my $this = shift; 345 my $topicObject=346 Foswiki:: Meta->new( $this->{session}, $this->{test_web},347 $this->{test_topic},<<'THIS');332 my ($topicObject) = 333 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 334 $topicObject->text(<<'THIS'); 348 335 If ALLOWTOPIC is set 349 336 1. people in the list are PERMITTED … … 360 347 ); 361 348 $topicObject->save(); 349 $topicObject->finish(); 362 350 363 351 # renew Foswiki, so WebPreferences gets re-read 364 $this->{session}->finish(); 365 $this->{session} = Foswiki->new(); 352 $this->createNewFoswikiSession(); 366 353 $this->PERMITTED( "VIEW", $MrOrange ); 367 $this->{session}->finish(); 368 $this->{session} = Foswiki->new(); 354 $this->createNewFoswikiSession(); 369 355 $this->DENIED( "VIEW", $MrGreen ); 370 $this->{session}->finish(); 371 $this->{session} = Foswiki->new(); 356 $this->createNewFoswikiSession(); 372 357 $this->PERMITTED( "VIEW", $MrYellow ); 373 $this->{session}->finish(); 374 $this->{session} = Foswiki->new(); 358 $this->createNewFoswikiSession(); 375 359 $this->DENIED( "VIEW", $MrWhite ); 376 $this->{session}->finish(); 377 $this->{session} = Foswiki->new(); 360 $this->createNewFoswikiSession(); 378 361 $this->DENIED( "view", $MrBlue ); 379 362 … … 384 367 sub test_denyweb { 385 368 my $this = shift; 386 my $topicObject = 387 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 388 $Foswiki::cfg{WebPrefsTopicName}, <<"THIS"); 369 my ($topicObject) = 370 Foswiki::Func::readTopic( $this->{test_web}, 371 $Foswiki::cfg{WebPrefsTopicName} ); 372 $topicObject->text(<<"THIS"); 389 373 If DENYWEB is set to a list of wikiname 390 374 * people in the list are DENIED access … … 392 376 THIS 393 377 $topicObject->save(); 378 $topicObject->finish(); 394 379 395 380 # renew Foswiki, so WebPreferences gets re-read 396 $this-> {session}->finish();397 $this->{session} = Foswiki->new();398 $topicObject = Foswiki::Meta->new(399 $this->{session}, $this->{test_web},400 $this->{test_topic}, "Null points"401 );402 $topicObject->save(); 381 $this->createNewFoswikiSession(); 382 ($topicObject) = 383 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 384 $topicObject->text("Null points"); 385 $topicObject->save(); 386 $topicObject->finish(); 387 403 388 $this->DENIED( "VIEW", $MrOrange ); 404 389 $this->PERMITTED( "VIEW", $MrGreen ); … … 412 397 # Test that ALLOWWEB works in a top-level web with no finalisation 413 398 sub test_allow_web { 414 my $this = shift; 415 my $topicObject = Foswiki::Meta->new( 416 $this->{session}, 417 $this->{test_web}, $Foswiki::cfg{WebPrefsTopicName}, 399 my $this = shift; 400 my ($topicObject) = 401 Foswiki::Func::readTopic( $this->{test_web}, 402 $Foswiki::cfg{WebPrefsTopicName} ); 403 $topicObject->text( 418 404 <<'THIS' 419 405 If ALLOWWEB is set to a list of wikinames … … 422 408 * Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite 423 409 THIS 424 , undef425 );426 $topicObject-> save();410 ); 411 $topicObject->save(); 412 $topicObject->finish(); 427 413 428 414 # renew Foswiki, so WebPreferences gets re-read 429 $this->{session}->finish(); 430 $this->{session} = Foswiki->new(); 431 $topicObject = Foswiki::Meta->new( 432 $this->{session}, $this->{test_web}, 433 $this->{test_topic}, "Null points" 434 ); 435 $topicObject->save(); 415 $this->createNewFoswikiSession(); 416 ($topicObject) = 417 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 418 $topicObject->text("Null points"); 419 $topicObject->save(); 420 $topicObject->finish(); 436 421 $this->DENIED( "VIEW", $MrOrange ); 437 422 $this->PERMITTED( "VIEW", $MrGreen ); … … 445 430 # Test that Web.UserName is equivalent to UserName in ACLs 446 431 sub test_webDotUserName { 447 my $this = shift; 448 my $topicObject = Foswiki::Meta->new( 449 $this->{session}, $this->{test_web}, $this->{test_topic}, 432 my $this = shift; 433 my ($topicObject) = 434 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 435 $topicObject->text( 450 436 <<'THIS' 451 437 If ALLOWTOPIC is set … … 454 440 * Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite 455 441 THIS 456 , undef 457 ); 458 $topicObject->save(); 459 $this->{session}->finish(); 460 $this->{session} = Foswiki->new(); 442 ); 443 $topicObject->save(); 444 $topicObject->finish(); 445 $this->createNewFoswikiSession(); 461 446 $this->PERMITTED( "VIEW", $MrOrange ); 462 447 $this->DENIED( "VIEW", $MrGreen ); … … 502 487 * Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen 503 488 THIS 504 my $topicObject = 505 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 506 $this->{test_topic}, $text ); 507 $topicObject->save(); 508 $this->{session}->finish(); 509 510 $this->{session} = Foswiki->new(); 511 $topicObject = 512 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 513 $this->{test_topic} ); 489 my ($topicObject) = 490 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 491 $topicObject->text($text); 492 $topicObject->save(); 493 $topicObject->finish(); 494 $this->createNewFoswikiSession(); 495 496 ($topicObject) = 497 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 514 498 $this->_checkSettings($topicObject); 499 $topicObject->finish(); 515 500 516 501 return; … … 521 506 my $this = shift; 522 507 523 my $topicObject=524 Foswiki:: Meta->new( $this->{session}, $this->{test_web},525 $this->{test_topic}, 'Empty');508 my ($topicObject) = 509 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 510 $topicObject->text('Empty'); 526 511 my $args = { 527 512 name => 'ALLOWTOPICVIEW', … … 532 517 $topicObject->putKeyed( 'PREFERENCE', $args ); 533 518 $topicObject->save(); 534 $this->{session}->finish(); 535 536 $this->{session} = Foswiki->new(); 537 $topicObject = 538 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 539 $this->{test_topic} ); 519 $topicObject->finish(); 520 $this->createNewFoswikiSession(); 521 522 ($topicObject) = 523 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 540 524 541 525 $this->_checkSettings($topicObject); 526 $topicObject->finish(); 542 527 543 528 return; … … 551 536 * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange 552 537 THIS 553 my $topicObject=554 Foswiki:: Meta->new( $this->{session}, $this->{test_web},555 $this->{test_topic}, $text);538 my ($topicObject) = 539 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 540 $topicObject->text($text); 556 541 my $args = { 557 542 name => 'ALLOWTOPICVIEW', … … 562 547 $topicObject->putKeyed( 'PREFERENCE', $args ); 563 548 $topicObject->save(); 564 $this->{session}->finish(); 565 566 $this->{session} = Foswiki->new(); 567 $topicObject = 568 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 569 $this->{test_topic} ); 549 $topicObject->finish(); 550 $this->createNewFoswikiSession(); 551 552 ($topicObject) = 553 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 570 554 $this->_checkSettings($topicObject); 555 $topicObject->finish(); 571 556 572 557 return; … … 581 566 582 567 # First build a parent web with view restricted to MrGreen 583 my $topicObject = 584 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 585 $this->{test_topic}, "Nowt" ); 586 $topicObject->save(); 587 588 $topicObject = 589 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 590 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 568 my ($topicObject) = 569 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 570 $topicObject->text("Nowt"); 571 $topicObject->save(); 572 $topicObject->finish(); 573 574 ($topicObject) = 575 Foswiki::Func::readTopic( $this->{test_web}, 576 $Foswiki::cfg{WebPrefsTopicName} ); 577 $topicObject->text(<<'THIS'); 591 578 * Set ALLOWWEBVIEW = MrGreen 592 579 THIS 593 580 $topicObject->save(); 581 $topicObject->finish(); 594 582 595 583 # Now build a subweb with view restricted to MrOrange 596 584 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 597 585 $webObject->populateNewWeb(); 598 $topicObject = 599 Foswiki::Meta->new( $this->{session}, $subweb, 600 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 586 $webObject->finish(); 587 ($topicObject) = 588 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 589 $topicObject->text(<<'THIS'); 601 590 * Set ALLOWWEBVIEW = MrOrange 602 591 THIS 603 592 $topicObject->save(); 604 $t his->{session}->finish();593 $topicObject->finish(); 605 594 606 595 # Ensure that MrOrange can read the subweb and MrGreen the parent web 607 $this-> {session} = Foswiki->new();596 $this->createNewFoswikiSession(); 608 597 $this->PERMITTED( "VIEW", $MrOrange, $subweb ); 609 598 $this->DENIED( "VIEW", $MrGreen, $subweb ); … … 623 612 # First build a parent web with view restricted to MrGreen, and 624 613 # finalise the setting 625 my $topicObject = 626 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 627 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 614 my ($topicObject) = 615 Foswiki::Func::readTopic( $this->{test_web}, 616 $Foswiki::cfg{WebPrefsTopicName} ); 617 $topicObject->text(<<'THIS'); 628 618 * Set ALLOWWEBVIEW = MrGreen 629 619 * Set FINALPREFERENCES = ALLOWWEBVIEW 630 620 THIS 631 621 $topicObject->save(); 622 $topicObject->finish(); 632 623 633 624 # Now build a subweb with no restrictions 634 625 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 635 626 $webObject->populateNewWeb(); 636 $topicObject = 637 Foswiki::Meta->new( $this->{session}, $subweb, 638 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 639 THIS 640 $topicObject->save(); 641 $this->{session}->finish(); 642 643 $this->{session} = Foswiki->new(); 627 $webObject->finish(); 628 ($topicObject) = 629 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 630 $topicObject->text(<<'THIS'); 631 THIS 632 $topicObject->save(); 633 $topicObject->finish(); 634 635 $this->createNewFoswikiSession(); 644 636 $this->PERMITTED( "VIEW", $MrGreen, $subweb ); 645 637 $this->DENIED( "VIEW", $MrOrange, $subweb ); … … 659 651 # First build a parent web with view restricted to MrGreen, and 660 652 # finalise the setting 661 my $topicObject = 662 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 663 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 653 my ($topicObject) = 654 Foswiki::Func::readTopic( $this->{test_web}, 655 $Foswiki::cfg{WebPrefsTopicName} ); 656 $topicObject->text(<<'THIS'); 664 657 * Set ALLOWWEBVIEW = MrGreen 665 658 * Set FINALPREFERENCES = ALLOWWEBVIEW 666 659 THIS 667 660 $topicObject->save(); 661 $topicObject->finish(); 668 662 669 663 # Now build a subweb with view restricted to MrOrange 670 664 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 671 665 $webObject->populateNewWeb(); 672 $topicObject = 673 Foswiki::Meta->new( $this->{session}, $subweb, 674 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 666 $webObject->finish(); 667 ($topicObject) = 668 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 669 $topicObject->text(<<'THIS'); 675 670 * Set ALLOWWEBVIEW = MrOrange 676 671 THIS 677 672 $topicObject->save(); 678 $t his->{session}->finish();679 680 $this->{session} = Foswiki->new(); 673 $topicObject->finish(); 674 $this->createNewFoswikiSession(); 675 681 676 $this->DENIED( "VIEW", $MrOrange, $subweb ); 682 677 $this->PERMITTED( "VIEW", $MrGreen, $subweb ); … … 696 691 697 692 # Create a topic with an anchor, viewable only by MrYellow 698 my $topicObject = Foswiki::Meta->new(699 $this->{session}, $this->{test_web}, $test_topic,700 <<'THIS'693 my ($topicObject) = 694 Foswiki::Func::readTopic( $this->{test_web}, $test_topic ); 695 $topicObject->text(<<'THIS'); 701 696 If there is an anchor, and some access restrictions, 702 697 anchor is preserved after login. … … 704 699 * Set ALLOWTOPICVIEW = MrYellow 705 700 THIS 706 , undef 707 ); 708 $topicObject->save(); 701 $topicObject->save(); 702 $topicObject->finish(); 709 703 710 704 # Request the page with the full UI … … 720 714 my $viewUrl = 721 715 $this->{session} 722 ->getScriptUrl( '0', 'view', $this->{test_web}, $test_topic );716 ->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic ); 723 717 $query->uri("$viewUrl"); 718 $this->finishFoswikiSession(); 724 719 my ($text) = $this->capture( 725 720 sub { 726 $Foswiki::Plugins::SESSION->{response} = 727 Foswiki::UI::handleRequest($query); 721 my $response = Foswiki::UI::handleRequest($query); 722 $this->createNewFoswikiSession( undef, $query ); 723 $this->{session}{response} = $response; 728 724 } 729 725 ); … … 732 728 my $loginUrl = 733 729 $this->{session} 734 ->getScriptUrl( '0', 'login', $this->{test_web}, $test_topic );730 ->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic ); 735 731 736 732 # Item11121: the test doesn't tolerate ShortURLs, for example. … … 748 744 749 745 # Check the redirect contains the login url + view to this topic 750 $this->assert_matches( 751 qr#^$loginUrl.*/view/$this->{test_web}/$test_topic$#, 752 $redirect_to, 753 "Login did not redirect to a page with the proper anchor:\n" 746 my $regex = qr#^\Q$loginUrl\E.*/view/$this->{test_web}/$test_topic$#; 747 $this->assert_matches( $regex, $redirect_to, 748 "Login did not redirect to a page with the proper anchor:\n" 754 749 . "Location: $redirect_to\n" 755 . "Expected: ^$loginUrl.*\%23anchor\$" 756 ); 750 . "Expected: $regex" ); 757 751 758 752 # Get the redirected page after login -
trunk/UnitTestContrib/test/unit/AddressTests.pm
r13376 r13791 266 266 $query->path_info("/$this->{test_web}/$this->{test_topic}"); 267 267 268 $this->{session}->finish() if $this->{session}; 269 $this->{session} = Foswiki->new( $Foswiki::cfg{AdminUserLogin}, $query ); 268 $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin}, $query ); 270 269 271 270 ( $this->{test_topicObject} ) = -
trunk/UnitTestContrib/test/unit/AdminOnlyAccessControlTests.pm
r13730 r13791 5 5 #Sven wishes he could use ISA AccessControlTest, but the unit test system doesn't do inherited test subs 6 6 7 use FoswikiFnTestCase ;7 use FoswikiFnTestCase(); 8 8 our @ISA = qw( FoswikiFnTestCase ); 9 9 … … 12 12 use Foswiki::Meta (); 13 13 use Foswiki::Plugins (); 14 use Foswiki::Configure::Dependency(); 14 15 15 16 # For Anchor test 16 17 use Foswiki::UI (); 18 19 my $post11 = 0; 17 20 18 21 sub new { … … 20 23 my $self = $class->SUPER::new( 'AccessControl', @args ); 21 24 25 my $dep = new Foswiki::Configure::Dependency( 26 type => "perl", 27 module => "Foswiki", 28 version => ">=1.2" 29 ); 30 my ( $ok, $message ) = $dep->check(); 31 $post11 = $ok; 32 22 33 return $self; 23 34 } 24 35 36 =todo 25 37 sub loadExtraConfig { 26 38 my ( $this, $context, @args ) = @_; … … 35 47 return; 36 48 } 49 =cut 37 50 38 51 my $MrWhite; … … 46 59 $this->SUPER::set_up(); 47 60 48 my $topicObject = Foswiki::Meta->new( 49 $this->{session}, 50 $Foswiki::cfg{UsersWebName}, 51 $Foswiki::cfg{DefaultUserWikiName}, '' 52 ); 53 $topicObject->save(); 61 my ($topicObject) = Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 62 $Foswiki::cfg{DefaultUserWikiName} ); 63 $topicObject->text(''); 64 $topicObject->save(); 65 $topicObject->finish(); 54 66 $this->registerUser( 'white', 'Mr', "White", 'white@example.com' ); 55 67 $MrWhite = $this->{session}->{users}->getCanonicalUserID('white'); … … 63 75 $MrYellow = $this->{session}->{users}->getCanonicalUserID('yellow'); 64 76 65 $topicObject = 66 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 67 "ReservoirDogsGroup", <<"THIS"); 77 $this->createNewFoswikiSession(); 78 ($topicObject) = 79 Foswiki::Func::readTopic( $this->{users_web}, "ReservoirDogsGroup" ); 80 $topicObject->text(<<"THIS"); 68 81 * Set GROUP = MrWhite, $this->{users_web}.MrBlue 69 82 THIS 70 83 $topicObject->save(); 71 72 return; 73 } 74 75 sub tear_down { 76 my $this = shift; 77 $this->SUPER::tear_down(); 84 $topicObject->finish(); 78 85 79 86 return; … … 84 91 $web ||= $this->{test_web}; 85 92 $topic ||= $this->{test_topic}; 86 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );93 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 87 94 $this->assert( !$topicObject->haveAccess( $mode, $user ), 88 95 "$user $mode $web.$topic" ); 96 97 if ($post11) { 98 require Foswiki::Address; 99 $this->assert( 100 !$this->{session}->access->haveAccess( $mode, $user, $topicObject ), 101 "$user $mode $web.$topic" 102 ); 103 $this->assert( 104 !$this->{session}->access->haveAccess( 105 $mode, $user, $topicObject->web, $topicObject->topic 106 ), 107 "$user $mode $web.$topic" 108 ); 109 $this->assert( 110 !$this->{session}->access->haveAccess( 111 $mode, $user, 112 Foswiki::Address->new( 113 web => $topicObject->web, 114 topic => $topicObject->topic 115 ) 116 ), 117 "$user $mode $web.$topic" 118 ); 119 } 120 $topicObject->finish(); 89 121 90 122 return; … … 95 127 $web ||= $this->{test_web}; 96 128 $topic ||= $this->{test_topic}; 97 my $topicObject = Foswiki::Meta->load( $this->{session},$web, $topic );129 my ($topicObject) = Foswiki::Func::readTopic( $web, $topic ); 98 130 $this->assert( $topicObject->haveAccess( $mode, $user ), 99 131 "$user $mode $web.$topic" ); 132 133 if ($post11) { 134 require Foswiki::Address; 135 $this->assert( 136 $this->{session}->access->haveAccess( $mode, $user, $topicObject ), 137 "$user $mode $web.$topic" 138 ); 139 $this->assert( 140 $this->{session}->access->haveAccess( 141 $mode, $user, $topicObject->web, $topicObject->topic 142 ), 143 "$user $mode $web.$topic" 144 ); 145 $this->assert( 146 $this->{session}->access->haveAccess( 147 $mode, $user, 148 Foswiki::Address->new( 149 web => $topicObject->web, 150 topic => $topicObject->topic 151 ) 152 ), 153 "$user $mode $web.$topic" 154 ); 155 } 156 $topicObject->finish(); 100 157 101 158 return; … … 109 166 sub test_denytopic { 110 167 my $this = shift; 111 my $topicObject=112 Foswiki:: Meta->new( $this->{session}, $this->{test_web},113 $this->{test_topic},<<"THIS");168 my ($topicObject) = 169 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 170 $topicObject->text(<<"THIS"); 114 171 If DENYTOPIC is set to a list of wikinames 115 172 * people in the list will be DENIED. … … 118 175 THIS 119 176 $topicObject->save(); 120 121 $this->{session}->finish(); 122 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 123 $this-> {session} = Foswiki->new();177 $topicObject->finish(); 178 179 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 180 $this->createNewFoswikiSession(); 124 181 125 182 $this->DENIED( "VIEW", $MrGreen ); … … 136 193 sub test_empty_denytopic { 137 194 my $this = shift; 138 my $topicObject=139 Foswiki:: Meta->new( $this->{session}, $this->{test_web},140 $this->{test_topic},<<'THIS');195 my ($topicObject) = 196 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 197 $topicObject->text(<<'THIS'); 141 198 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 142 199 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 144 201 THIS 145 202 $topicObject->save(); 146 147 $this->{session}->finish(); 148 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 149 $this-> {session} = Foswiki->new();203 $topicObject->finish(); 204 205 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 206 $this->createNewFoswikiSession(); 150 207 $this->DENIED( "VIEW", $MrGreen ); 151 208 $this->DENIED( "VIEW", $MrYellow ); … … 161 218 sub test_whitespace_denytopic { 162 219 my $this = shift; 163 my $topicObject=164 Foswiki:: Meta->new( $this->{session}, $this->{test_web},165 $this->{test_topic},<<'THIS');220 my ($topicObject) = 221 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 222 $topicObject->text(<<'THIS'); 166 223 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 167 224 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 169 226 THIS 170 227 $topicObject->save(); 171 172 $this->{session}->finish(); 173 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 174 $this-> {session} = Foswiki->new();228 $topicObject->finish(); 229 230 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 231 $this->createNewFoswikiSession(); 175 232 $this->DENIED( "VIEW", $MrGreen ); 176 233 $this->DENIED( "VIEW", $MrYellow ); … … 186 243 sub test_denytopic_whitespace { 187 244 my $this = shift; 188 my $topicObject=189 Foswiki:: Meta->new( $this->{session}, $this->{test_web},190 $this->{test_topic},<<'THIS');245 my ($topicObject) = 246 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 247 $topicObject->text(<<'THIS'); 191 248 If DENYTOPIC is set to empty ( i.e. Set DENYTOPIC = ) 192 249 * access is PERMITTED _i.e _ no-one is denied access to this topic … … 194 251 THIS 195 252 $topicObject->save(); 196 197 $this->{session}->finish(); 198 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 199 $this-> {session} = Foswiki->new();253 $topicObject->finish(); 254 255 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 256 $this->createNewFoswikiSession(); 200 257 $this->DENIED( "VIEW", $MrGreen ); 201 258 $this->DENIED( "VIEW", $MrYellow ); … … 211 268 sub test_allowtopic { 212 269 my $this = shift; 213 my $topicObject=214 Foswiki:: Meta->new( $this->{session}, $this->{test_web},215 $this->{test_topic},<<'THIS');270 my ($topicObject) = 271 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 272 $topicObject->text(<<'THIS'); 216 273 If ALLOWTOPIC is set 217 274 1. people in the list are PERMITTED … … 220 277 THIS 221 278 $topicObject->save(); 222 223 $this->{session}->finish(); 224 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 225 $this-> {session} = Foswiki->new();279 $topicObject->finish(); 280 281 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 282 $this->createNewFoswikiSession(); 226 283 $this->DENIED( "VIEW", $MrOrange ); 227 284 $this->DENIED( "VIEW", $MrGreen ); … … 238 295 sub test_allowtopic_a { 239 296 my $this = shift; 240 my $topicObject=241 Foswiki:: Meta->new( $this->{session}, $this->{test_web},242 $this->{test_topic},<<'THIS');297 my ($topicObject) = 298 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 299 $topicObject->text(<<'THIS'); 243 300 If ALLOWTOPIC is set 244 301 1. people in the list are PERMITTED … … 247 304 THIS 248 305 $topicObject->save(); 306 $topicObject->finish(); 249 307 250 308 my $topicquery = Unit::Request->new(""); 251 309 $topicquery->path_info("/$this->{test_web}/$this->{test_topic}"); 252 310 253 # reFoswiki->new, so WebPreferences gets re-read 254 $this->{session}->finish(); 255 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 256 $this->{session} = Foswiki->new( undef, $topicquery ); 257 $this->DENIED( "VIEW", $MrOrange ); 258 $this->{session}->finish(); 259 $this->{session} = Foswiki->new( undef, $topicquery ); 260 $this->DENIED( "VIEW", $MrGreen ); 261 $this->{session}->finish(); 262 $this->{session} = Foswiki->new( undef, $topicquery ); 263 $this->DENIED( "VIEW", $MrYellow ); 264 $this->{session}->finish(); 265 $this->{session} = Foswiki->new( undef, $topicquery ); 266 $this->DENIED( "VIEW", $MrWhite ); 267 $this->{session}->finish(); 268 $this->{session} = Foswiki->new( undef, $topicquery ); 269 $this->DENIED( "view", $MrBlue ); 270 $this->{session}->finish(); 271 $this->{session} = Foswiki->new(); 311 # renew Foswiki, so WebPreferences gets re-read 312 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 313 $this->createNewFoswikiSession( undef, $topicquery ); 314 $this->DENIED( "VIEW", $MrOrange ); 315 $this->createNewFoswikiSession( undef, $topicquery ); 316 $this->DENIED( "VIEW", $MrGreen ); 317 $this->createNewFoswikiSession( undef, $topicquery ); 318 $this->DENIED( "VIEW", $MrYellow ); 319 $this->createNewFoswikiSession( undef, $topicquery ); 320 $this->DENIED( "VIEW", $MrWhite ); 321 $this->createNewFoswikiSession( undef, $topicquery ); 322 $this->DENIED( "view", $MrBlue ); 323 $this->createNewFoswikiSession( undef, $topicquery ); 272 324 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 273 325 … … 280 332 sub test_allowtopic_b { 281 333 my $this = shift; 282 my $topicObject=283 Foswiki:: Meta->new( $this->{session}, $this->{test_web},284 $this->{test_topic},<<'THIS');334 my ($topicObject) = 335 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 336 $topicObject->text(<<'THIS'); 285 337 If ALLOWTOPIC is set 286 338 1. people in the list are PERMITTED … … 289 341 THIS 290 342 $topicObject->save(); 291 292 # reFoswiki->new, so WebPreferences gets re-read 293 $this->{session}->finish(); 294 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 295 $this->{session} = Foswiki->new(); 296 $this->DENIED( "VIEW", $MrOrange ); 297 $this->{session}->finish(); 298 $this->{session} = Foswiki->new(); 299 $this->DENIED( "VIEW", $MrGreen ); 300 $this->{session}->finish(); 301 $this->{session} = Foswiki->new(); 302 $this->DENIED( "VIEW", $MrYellow ); 303 $this->{session}->finish(); 304 $this->{session} = Foswiki->new(); 305 $this->DENIED( "VIEW", $MrWhite ); 306 $this->{session}->finish(); 307 $this->{session} = Foswiki->new(); 308 $this->DENIED( "view", $MrBlue ); 309 $this->{session}->finish(); 310 $this->{session} = Foswiki->new(); 343 $topicObject->finish(); 344 345 # renew Foswiki, so WebPreferences gets re-read 346 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 347 $this->createNewFoswikiSession(); 348 $this->DENIED( "VIEW", $MrOrange ); 349 $this->createNewFoswikiSession(); 350 $this->DENIED( "VIEW", $MrGreen ); 351 $this->createNewFoswikiSession(); 352 $this->DENIED( "VIEW", $MrYellow ); 353 $this->createNewFoswikiSession(); 354 $this->DENIED( "VIEW", $MrWhite ); 355 $this->createNewFoswikiSession(); 356 $this->DENIED( "view", $MrBlue ); 357 $this->createNewFoswikiSession(); 311 358 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 312 359 … … 318 365 sub test_allowtopic_c { 319 366 my $this = shift; 320 my $topicObject=321 Foswiki:: Meta->new( $this->{session}, $this->{test_web},322 $this->{test_topic},<<'THIS');367 my ($topicObject) = 368 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 369 $topicObject->text(<<'THIS'); 323 370 If ALLOWTOPIC is set 324 371 1. people in the list are PERMITTED … … 335 382 ); 336 383 $topicObject->save(); 337 338 # reFoswiki->new, so WebPreferences gets re-read 339 $this->{session}->finish(); 340 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 341 $this->{session} = Foswiki->new(); 342 $this->DENIED( "VIEW", $MrOrange ); 343 $this->{session}->finish(); 344 $this->{session} = Foswiki->new(); 345 $this->DENIED( "VIEW", $MrGreen ); 346 $this->{session}->finish(); 347 $this->{session} = Foswiki->new(); 348 $this->DENIED( "VIEW", $MrYellow ); 349 $this->{session}->finish(); 350 $this->{session} = Foswiki->new(); 351 $this->DENIED( "VIEW", $MrWhite ); 352 $this->{session}->finish(); 353 $this->{session} = Foswiki->new(); 354 $this->DENIED( "view", $MrBlue ); 355 $this->{session}->finish(); 356 $this->{session} = Foswiki->new(); 384 $topicObject->finish(); 385 386 # renew Foswiki, so WebPreferences gets re-read 387 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 388 $this->createNewFoswikiSession(); 389 $this->DENIED( "VIEW", $MrOrange ); 390 $this->createNewFoswikiSession(); 391 $this->DENIED( "VIEW", $MrGreen ); 392 $this->createNewFoswikiSession(); 393 $this->DENIED( "VIEW", $MrYellow ); 394 $this->createNewFoswikiSession(); 395 $this->DENIED( "VIEW", $MrWhite ); 396 $this->createNewFoswikiSession(); 397 $this->DENIED( "view", $MrBlue ); 398 $this->createNewFoswikiSession(); 357 399 $this->PERMITTED( "VIEW", 'BaseUserMapping_333' ); 358 400 … … 363 405 sub test_denyweb { 364 406 my $this = shift; 365 my $topicObject = 366 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 367 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 407 my ($topicObject) = 408 Foswiki::Func::readTopic( $this->{test_web}, 409 $Foswiki::cfg{WebPrefsTopicName} ); 410 $topicObject->text(<<"THIS"); 368 411 If DENYWEB is set to a list of wikiname 369 412 * people in the list are DENIED access … … 371 414 THIS 372 415 $topicObject->save(); 373 374 # reFoswiki->new, so WebPreferences gets re-read 375 $topicObject = Foswiki::Meta->new( 376 $this->{session}, $this->{test_web}, 377 $this->{test_topic}, "Null points" 378 ); 379 $topicObject->save(); 380 381 $this->{session}->finish(); 382 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 383 $this->{session} = Foswiki->new(); 416 $topicObject->finish(); 417 418 # renew Foswiki, so WebPreferences gets re-read 419 $this->createNewFoswikiSession(); 420 ($topicObject) = 421 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 422 $topicObject->text("Null points"); 423 $topicObject->save(); 424 $topicObject->finish(); 425 426 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 427 $this->createNewFoswikiSession(); 384 428 385 429 $this->DENIED( "VIEW", $MrOrange ); … … 395 439 # Test that ALLOWWEB works in a top-level web with no finalisation 396 440 sub test_allow_web { 397 my $this = shift; 398 my $topicObject = Foswiki::Meta->new( 399 $this->{session}, 400 $this->{test_web}, $Foswiki::cfg{WebPrefsTopicName}, 441 my $this = shift; 442 my ($topicObject) = 443 Foswiki::Func::readTopic( $this->{test_web}, 444 $Foswiki::cfg{WebPrefsTopicName} ); 445 $topicObject->text( 401 446 <<'THIS' 402 447 If ALLOWWEB is set to a list of wikinames … … 405 450 * Set ALLOWWEBVIEW = MrGreen MrYellow MrWhite 406 451 THIS 407 , undef 408 ); 409 $topicObject->save(); 410 411 $topicObject = Foswiki::Meta->new( 412 $this->{session}, $this->{test_web}, 413 $this->{test_topic}, "Null points" 414 ); 415 $topicObject->save(); 416 417 # reFoswiki->new, so WebPreferences gets re-read 418 $this->{session}->finish(); 419 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 420 $this->{session} = Foswiki->new(); 452 ); 453 $topicObject->save(); 454 $topicObject->finish(); 455 456 ($topicObject) = 457 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 458 $topicObject->text("Null points"); 459 $topicObject->save(); 460 $topicObject->finish(); 461 462 # renew Foswiki, so WebPreferences gets re-read 463 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 464 $this->createNewFoswikiSession(); 421 465 422 466 $this->DENIED( "VIEW", $MrOrange ); … … 432 476 # Test that Web.UserName is equivalent to UserName in ACLs 433 477 sub test_webDotUserName { 434 my $this = shift; 435 my $topicObject = Foswiki::Meta->new( 436 $this->{session}, $this->{test_web}, $this->{test_topic}, 478 my $this = shift; 479 my ($topicObject) = 480 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 481 $topicObject->text( 437 482 <<'THIS' 438 483 If ALLOWTOPIC is set … … 441 486 * Set ALLOWTOPICVIEW = MrYellow,%USERSWEB%.MrOrange,Nosuchweb.MrGreen,%MAINWEB%.MrBlue,%SYSTEMWEB%.MrWhite 442 487 THIS 443 , undef 444 ); 445 $topicObject->save(); 446 447 # reFoswiki->new, so WebPreferences gets re-read 448 $this->{session}->finish(); 449 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 450 $this->{session} = Foswiki->new(); 488 ); 489 $topicObject->save(); 490 $topicObject->finish(); 491 492 # renew Foswiki, so WebPreferences gets re-read 493 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 494 $this->createNewFoswikiSession(); 451 495 452 496 $this->DENIED( "VIEW", $MrOrange ); … … 498 542 * Set ALLOWTOPICVIEW = %USERSWEB%.MrGreen 499 543 THIS 500 my $topicObject = 501 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 502 $this->{test_topic}, $text ); 503 $topicObject->save(); 504 505 # reFoswiki->new, so WebPreferences gets re-read 506 $this->{session}->finish(); 507 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 508 $this->{session} = Foswiki->new(); 509 510 $topicObject = 511 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 512 $this->{test_topic} ); 544 my ($topicObject) = 545 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 546 $topicObject->text($text); 547 $topicObject->save(); 548 $topicObject->finish(); 549 550 # renew Foswiki, so WebPreferences gets re-read 551 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 552 $this->createNewFoswikiSession(); 553 554 ($topicObject) = 555 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 513 556 $this->_checkSettings($topicObject); 557 $topicObject->finish(); 514 558 515 559 return; … … 520 564 my $this = shift; 521 565 522 my $topicObject=523 Foswiki:: Meta->new( $this->{session}, $this->{test_web},524 $this->{test_topic}, 'Empty');566 my ($topicObject) = 567 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 568 $topicObject->text('Empty'); 525 569 my $args = { 526 570 name => 'ALLOWTOPICVIEW', … … 531 575 $topicObject->putKeyed( 'PREFERENCE', $args ); 532 576 $topicObject->save(); 533 534 # reFoswiki->new, so WebPreferences gets re-read 535 $this->{session}->finish(); 536 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 537 $this->{session} = Foswiki->new(); 538 539 $topicObject = 540 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 541 $this->{test_topic} ); 577 $topicObject->finish(); 578 579 # renew Foswiki, so WebPreferences gets re-read 580 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 581 $this->createNewFoswikiSession(); 582 583 ($topicObject) = 584 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 542 585 543 586 $this->_checkSettings($topicObject); 587 $topicObject->finish(); 544 588 545 589 return; … … 553 597 * Set ALLOWTOPICVIEW = %USERSWEB%.MrOrange 554 598 THIS 555 my $topicObject=556 Foswiki:: Meta->new( $this->{session}, $this->{test_web},557 $this->{test_topic}, $text);599 my ($topicObject) = 600 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 601 $topicObject->text($text); 558 602 my $args = { 559 603 name => 'ALLOWTOPICVIEW', … … 564 608 $topicObject->putKeyed( 'PREFERENCE', $args ); 565 609 $topicObject->save(); 566 567 # reFoswiki->new, so WebPreferences gets re-read 568 $this->{session}->finish(); 569 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 570 $this->{session} = Foswiki->new(); 571 572 $topicObject = 573 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 574 $this->{test_topic} ); 610 $topicObject->finish(); 611 612 # renew Foswiki, so WebPreferences gets re-read 613 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 614 $this->createNewFoswikiSession(); 615 616 ($topicObject) = 617 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 575 618 $this->_checkSettings($topicObject); 619 $topicObject->finish(); 576 620 577 621 return; … … 586 630 587 631 # First build a parent web with view restricted to MrGreen 588 my $topicObject = 589 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 590 $this->{test_topic}, "Nowt" ); 591 $topicObject->save(); 592 593 $topicObject = 594 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 595 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 632 my ($topicObject) = 633 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 634 $topicObject->text("Nowt"); 635 $topicObject->save(); 636 $topicObject->finish(); 637 638 ($topicObject) = 639 Foswiki::Func::readTopic( $this->{test_web}, 640 $Foswiki::cfg{WebPrefsTopicName} ); 641 $topicObject->text(<<'THIS'); 596 642 * Set ALLOWWEBVIEW = MrGreen 597 643 THIS 598 644 $topicObject->save(); 645 $topicObject->finish(); 599 646 600 647 # Now build a subweb with view restricted to MrOrange 601 648 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 602 649 $webObject->populateNewWeb(); 603 $topicObject = 604 Foswiki::Meta->new( $this->{session}, $subweb, 605 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 650 $webObject->finish(); 651 ($topicObject) = 652 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 653 $topicObject->text(<<'THIS'); 606 654 * Set ALLOWWEBVIEW = MrOrange 607 655 THIS 608 656 $topicObject->save(); 609 $t his->{session}->finish();610 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 611 $this-> {session} = Foswiki->new();657 $topicObject->finish(); 658 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 659 $this->createNewFoswikiSession(); 612 660 $this->DENIED( "VIEW", $MrOrange, $subweb ); 613 661 $this->DENIED( "VIEW", $MrGreen, $subweb ); … … 628 676 # First build a parent web with view restricted to MrGreen, and 629 677 # finalise the setting 630 my $topicObject = 631 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 632 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 678 my ($topicObject) = 679 Foswiki::Func::readTopic( $this->{test_web}, 680 $Foswiki::cfg{WebPrefsTopicName} ); 681 $topicObject->text(<<'THIS'); 633 682 * Set ALLOWWEBVIEW = MrGreen 634 683 * Set FINALPREFERENCES = ALLOWWEBVIEW 635 684 THIS 636 685 $topicObject->save(); 686 $topicObject->finish(); 637 687 638 688 # Now build a subweb with no restrictions 639 689 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 640 690 $webObject->populateNewWeb(); 641 $topicObject = 642 Foswiki::Meta->new( $this->{session}, $subweb, 643 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 644 THIS 645 $topicObject->save(); 646 $this->{session}->finish(); 647 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 648 $this->{session} = Foswiki->new(); 691 $webObject->finish(); 692 ($topicObject) = 693 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 694 $topicObject->text(<<'THIS'); 695 THIS 696 $topicObject->save(); 697 $topicObject->finish(); 698 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 699 $this->createNewFoswikiSession(); 649 700 $this->DENIED( "VIEW", $MrGreen, $subweb ); 650 701 $this->DENIED( "VIEW", $MrOrange, $subweb ); … … 665 716 # First build a parent web with view restricted to MrGreen, and 666 717 # finalise the setting 667 my $topicObject = 668 Foswiki::Meta->new( $this->{session}, $this->{test_web}, 669 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 718 my ($topicObject) = 719 Foswiki::Func::readTopic( $this->{test_web}, 720 $Foswiki::cfg{WebPrefsTopicName} ); 721 $topicObject->text(<<'THIS'); 670 722 * Set ALLOWWEBVIEW = MrGreen 671 723 * Set FINALPREFERENCES = ALLOWWEBVIEW 672 724 THIS 673 725 $topicObject->save(); 726 $topicObject->finish(); 674 727 675 728 # Now build a subweb with view restricted to MrOrange 676 729 my $webObject = Foswiki::Meta->new( $this->{session}, $subweb ); 677 730 $webObject->populateNewWeb(); 678 $topicObject = 679 Foswiki::Meta->new( $this->{session}, $subweb, 680 $Foswiki::cfg{WebPrefsTopicName}, <<'THIS'); 731 $webObject->finish(); 732 ($topicObject) = 733 Foswiki::Func::readTopic( $subweb, $Foswiki::cfg{WebPrefsTopicName} ); 734 $topicObject->text(<<'THIS'); 681 735 * Set ALLOWWEBVIEW = MrOrange 682 736 THIS 683 737 $topicObject->save(); 684 $t his->{session}->finish();685 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 686 $this-> {session} = Foswiki->new();738 $topicObject->finish(); 739 $Foswiki::cfg{AccessControl} = 'Foswiki::Access::AdminOnlyAccess'; 740 $this->createNewFoswikiSession(); 687 741 $this->DENIED( "VIEW", $MrOrange, $subweb ); 688 742 $this->DENIED( "VIEW", $MrGreen, $subweb ); … … 703 757 704 758 # Create a topic with an anchor, viewable only by MrYellow 705 my $topicObject = Foswiki::Meta->new(706 $this->{session}, $this->{test_web}, $test_topic,707 <<'THIS'759 my ($topicObject) = 760 Foswiki::Func::readTopic( $this->{test_web}, $test_topic ); 761 $topicObject->text( <<'THIS' ); 708 762 If there is an anchor, and some access restrictions, 709 763 anchor is preserved after login. … … 711 765 * Set ALLOWTOPICVIEW = MrYellow 712 766 THIS 713 , undef 714 ); 715 $topicObject->save(); 767 $topicObject->save(); 768 $topicObject->finish(); 716 769 717 770 # Request the page with the full UI … … 727 780 my $viewUrl = 728 781 $this->{session} 729 ->getScriptUrl( '0', 'view', $this->{test_web}, $test_topic );782 ->getScriptUrl( 0, 'view', $this->{test_web}, $test_topic ); 730 783 $query->uri("$viewUrl"); 784 $this->finishFoswikiSession(); 731 785 my ($text) = $this->capture( 732 786 sub { 733 $Foswiki::Plugins::SESSION->{response} = 734 Foswiki::UI::handleRequest($query); 787 my $response = Foswiki::UI::handleRequest($query); 788 $this->createNewFoswikiSession( undef, $query ); 789 $this->{session}{response} = $response; 735 790 } 736 791 ); … … 739 794 my $loginUrl = 740 795 $this->{session} 741 ->getScriptUrl( '0', 'login', $this->{test_web}, $test_topic );796 ->getScriptUrl( 0, 'login', $this->{test_web}, $test_topic ); 742 797 743 798 # Item11121: the test doesn't tolerate ShortURLs, for example. … … 755 810 756 811 # Check the redirect contains the login url + view to this topic 757 $this->assert_matches( 758 qr#^$loginUrl.*/view/$this->{test_web}/$test_topic$#, 759 $redirect_to, 760 "Login did not redirect to a page with the proper anchor:\n" 812 my $regex = qr#^\Q$loginUrl\E.*/view/$this->{test_web}/$test_topic$#; 813 $this->assert_matches( $regex, $redirect_to, 814 "Login did not redirect to a page with the proper anchor:\n" 761 815 . "Location: $redirect_to\n" 762 . "Expected: ^$loginUrl.*\%23anchor\$" 763 ); 816 . "Expected: $regex" ); 764 817 765 818 # Get the redirected page after login -
trunk/UnitTestContrib/test/unit/AttrsTests.pm
r13730 r13791 1 package AttrsTests; 1 2 use strict; 2 3 package AttrsTests; 4 5 use FoswikiTestCase; 3 use warnings; 4 5 use FoswikiTestCase(); 6 6 our @ISA = qw( FoswikiTestCase ); 7 7 8 use Foswiki::Attrs ;8 use Foswiki::Attrs(); 9 9 10 10 sub new { -
trunk/UnitTestContrib/test/unit/CacheTests.pm
r13730 r13791 1 1 package CacheTests; 2 use strict; 3 use warnings; 2 4 3 use FoswikiFnTestCase ;5 use FoswikiFnTestCase(); 4 6 our @ISA = qw( FoswikiFnTestCase ); 5 7 6 use strict; 7 use Foswiki; 8 use Foswiki::Meta; 8 use Foswiki(); 9 use Foswiki::Meta(); 10 use File::Spec(); 11 use Foswiki::OopsException(); 12 use Foswiki::PageCache(); 9 13 use Error qw( :try ); 10 use Foswiki::OopsException;11 use Foswiki::PageCache;12 14 use Benchmark qw(:hireswallclock); 13 15 … … 17 19 my $this = shift; 18 20 my @page; 21 19 22 foreach my $dir (@INC) { 20 if ( opendir( D, "$dir/Foswiki/Cache" ) ) { 21 foreach my $alg ( readdir D ) { 23 if ( opendir( my $D, File::Spec->catdir( $dir, 'Foswiki', 'Cache' ) ) ) 24 { 25 foreach my $alg ( readdir $D ) { 22 26 next unless $alg =~ s/^(.*)\.pm$/$1/; 23 next if defined & $alg;27 next if defined &{$alg}; 24 28 $ENV{PATH} =~ /^(.*)$/ms; 25 $ENV{PATH} = $1;29 local $ENV{PATH} = $1; 26 30 ($alg) = $alg =~ /^(.*)$/ms; 27 eval "require Foswiki::Cache::$alg"; 28 if ($@) { 29 print STDERR 30 "Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 31 } 32 else { 31 32 if ( eval "require Foswiki::Cache::$alg; 1;" ) { 33 33 no strict 'refs'; 34 * $alg= sub {34 *{$alg} = sub { 35 35 my $this = shift; 36 36 $Foswiki::cfg{CacheManager} = 'Foswiki::Cache::' . $alg; … … 39 39 push( @page, $alg ); 40 40 } 41 else { 42 print STDERR 43 "Cannot test Foswiki::Cache::$alg\nCompilation error when trying to 'require' it\n"; 44 } 41 45 } 42 closedir( D);46 closedir($D); 43 47 } 44 48 } … … 50 54 sub DBFileMeta { 51 55 $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::DB_File'; 56 57 return; 52 58 } 53 59 54 60 sub BDBMeta { 55 61 $Foswiki::cfg{MetaCacheManager} = 'Foswiki::Cache::BDB'; 62 63 return; 56 64 } 57 65 … … 59 67 $Foswiki::cfg{HttpCompress} = 1; 60 68 $Foswiki::cfg{Cache}{Compress} = 1; 69 70 return; 61 71 } 62 72 … … 64 74 $Foswiki::cfg{HttpCompress} = 0; 65 75 $Foswiki::cfg{Cache}{Compress} = 0; 76 77 return; 66 78 } 67 79 … … 90 102 $Foswiki::cfg{Cache}{Compress} = 0; 91 103 $UI_FN ||= $this->getUIFn('view'); 92 }93 104 94 sub tear_down { 95 my $this = shift; 96 $this->SUPER::tear_down(); 105 return; 97 106 } 98 107 … … 102 111 $UI_FN ||= $this->getUIFn('view'); 103 112 104 my $query = new Unit::Request( { skin => ['none'], } );113 my $query = Unit::Request->new( { skin => ['none'], } ); 105 114 $query->path_info("/"); 106 115 $query->method('POST'); 107 116 108 my $fatwilly = new Foswiki( $this->{test_user_login}, $query );117 $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 109 118 110 119 # This first request should *not* be satisfied from the cache, but 111 120 # the cache should be populated with the result. 112 my $p1start = new Benchmark();121 my $p1start = Benchmark->new(); 113 122 my ($one) = $this->capture( 114 123 sub { 115 124 no strict 'refs'; 116 & $UI_FN($fatwilly);125 &{$UI_FN}( $this->{session} ); 117 126 use strict 'refs'; 118 $Foswiki::engine->finalize( $ fatwilly->{response},119 $ fatwilly->{request} );127 $Foswiki::engine->finalize( $this->{session}{response}, 128 $this->{session}{request} ); 120 129 } 121 130 ); 122 131 123 my $p1end = new Benchmark();132 my $p1end = Benchmark->new(); 124 133 print STDERR "R1 " . timestr( timediff( $p1end, $p1start ) ) . "\n"; 125 $fatwilly->finish();126 134 127 $ fatwilly = new Foswiki( $this->{test_user_login}, $query );135 $this->createNewFoswikiSession( $this->{test_user_login}, $query ); 128 136 129 137 # This second request should be satisfied from the cache 130 my $p2start = new Benchmark();138 my $p2start = Benchmark->new(); 131 139 my ($two) = $this->capture( 132 140 sub { 133 141 no strict 'refs'; 134 & $UI_FN($fatwilly);142 &{$UI_FN}( $this->{session} ); 135 143 use strict 'refs'; 136 $Foswiki::engine->finalize( $ fatwilly->{response},137 $ fatwilly->{request} );144 $Foswiki::engine->finalize( $this->{session}{response}, 145 $this->{session}{request} ); 138 146 } 139 147 ); 140 my $p2end = new Benchmark();148 my $p2end = Benchmark->new(); 141 149 print STDERR "R2 " . timestr( timediff( $p2end, $p2start ) ) . "\n"; 142 $fatwilly->finish();143 150 144 151 # Massage the HTML for comparison … … 164 171 165 172 $this->assert_html_equals( $one, $two ); 173 174 return; 166 175 } 167 176 -
trunk/UnitTestContrib/test/unit/ClientTests.pm
r13730 r13791 1 package ClientTests; 1 2 use strict; 2 3 package ClientTests; 3 use warnings; 4 4 5 5 # This is woefully incomplete, but it does at least check that 6 6 # LoginManager.pm compiles okay. 7 7 8 use FoswikiFnTestCase ;8 use FoswikiFnTestCase(); 9 9 our @ISA = qw( FoswikiFnTestCase ); 10 10 11 use Unit::Request; 11 use Foswiki(); 12 use Foswiki::LoginManager(); 13 use Unit::Request(); 12 14 use Error qw( :try ); 13 14 use Foswiki;15 use Foswiki::LoginManager;16 15 17 16 my $agent = $Foswiki::cfg{Register}{RegistrationAgentWikiName}; … … 29 28 my $topicObject = Foswiki::Meta->new( 30 29 $this->{session}, $this->{test_web}, 31 $this->{test_topic}, << CONSTRAINT);30 $this->{test_topic}, <<'CONSTRAINT'); 32 31 * Set ALLOWTOPICCHANGE = AdminGroup 33 32 CONSTRAINT 34 33 $topicObject->save(); 34 35 return; 35 36 } 36 37 37 38 sub TemplateLoginManager { 38 39 $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::TemplateLogin'; 40 41 return; 39 42 } 40 43 41 44 sub ApacheLoginManager { 42 45 $Foswiki::cfg{LoginManager} = 'Foswiki::LoginManager::ApacheLogin'; 46 47 return; 43 48 } 44 49 45 50 sub NoLoginManager { 46 51 $Foswiki::cfg{LoginManager} = 'none'; 52 53 return; 47 54 } 48 55 … … 51 58 $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::BaseUserMapping'; 52 59 $this->set_up_for_verify(); 60 61 return; 53 62 } 54 63 … … 57 66 $Foswiki::cfg{UserMappingManager} = 'Foswiki::Users::TopicUserMapping'; 58 67 $this->set_up_for_verify(); 68 69 return; 59 70 } 60 71 … … 70 81 my $this = shift; 71 82 72 $this->{session}->finish() if $this->{session}; 73 $this->{session} = new Foswiki( undef, new Unit::Request() ); 83 $this->createNewFoswikiSession( undef, Unit::Request->new() ); 74 84 $this->assert( $Foswiki::cfg{TempfileDir} 75 85 && -d $Foswiki::cfg{TempfileDir} ); … … 80 90 $Foswiki::cfg{Register}{EnableNewUserRegistration} = 1; 81 91 $Foswiki::cfg{UsersWebName} = $this->{users_web}; 92 93 return; 82 94 } 83 95 … … 101 113 102 114 #print STDERR "\n------------- set_up_user (login: $userLogin) (cUID:$user_id) -----------------\n"; 115 116 return; 103 117 } 104 118 105 119 sub capture { 106 my $this = shift; 107 my ( $proc, $session ) = @_; 120 my ( $this, $proc, $session, @args ) = @_; 108 121 $session->getLoginManager()->checkAccess(); 109 $this->SUPER::capture(@_); 122 $this->SUPER::capture( $proc, $session, @args ); 123 124 return; 110 125 } 111 126 … … 118 133 119 134 #close this Foswiki session - its using the wrong mapper and login 120 $this->{session}->finish(); 121 122 $query = new Unit::Request(); 135 136 $query = Unit::Request->new(); 123 137 $query->path_info("/$this->{test_web}/$this->{test_topic}"); 124 $this-> {session} = new Foswiki( undef, $query );138 $this->createNewFoswikiSession( undef, $query ); 125 139 126 140 $this->set_up_user(); … … 135 149 }; 136 150 137 $query = new Unit::Request();151 $query = Unit::Request->new(); 138 152 $query->path_info("/$this->{test_web}/$this->{test_topic}?breaklock=1"); 139 $this->{session}->finish(); 140 141 $this->{session} = new Foswiki( undef, $query ); 153 154 $this->createNewFoswikiSession( undef, $query ); 142 155 143 156 try { … … 156 169 }; 157 170 158 $query = new Unit::Request();171 $query = Unit::Request->new(); 159 172 $query->path_info("/$this->{test_web}/$this->{test_topic}"); 160 $this->{session}->finish();161 173 162 174 $this->annotate("new session using $userLogin\n"); 163 175 164 $this-> {session} = new Foswiki( $userLogin, $query );176 $this->createNewFoswikiSession( $userLogin, $query ); 165 177 166 178 #clear the lease - one of the previous tests may have different usermapper & thus different user 167 179 Foswiki::Func::setTopicEditLock( $this->{test_web}, $this->{test_topic}, 168 180 0 ); 181 182 return; 169 183 } 170 184 … … 175 189 return; 176 190 } 177 $this->{session}->finish();178 191 my $secret = "a big mole on my left buttock"; 179 192 my $crypted = crypt( $secret, "12" ); 180 193 $Foswiki::cfg{Password} = $crypted; 181 194 182 my $query = new Unit::Request(195 my $query = Unit::Request->new( 183 196 { 184 197 username => [ $Foswiki::cfg{AdminUserLogin} ], … … 190 203 $query->path_info("/$this->{test_web}/$this->{test_topic}"); 191 204 192 $this-> {session} = new Foswiki( undef, $query );205 $this->createNewFoswikiSession( undef, $query ); 193 206 $this->{session}->getLoginManager()->login( $query, $this->{session} ); 194 207 my $script = $Foswiki::cfg{LoginManager} =~ /Apache/ ? 'viewauth' : 'view'; … … 199 212 $this->assert_matches( qr/^$surly/, 200 213 $this->{session}->{response}->headers()->{Location} ); 214 215 return; 201 216 } 202 217 -
trunk/UnitTestContrib/test/unit/ConfigureTests.pm
r13730 r13791 4 4 use warnings; 5 5 6 use FoswikiTestCase ;6 use FoswikiTestCase(); 7 7 our @ISA = qw( FoswikiTestCase ); 8 8 9 9 use Error qw( :try ); 10 use File::Temp ;10 use File::Temp(); 11 11 use FindBin; 12 12 use File::Path qw(mkpath rmtree); … … 32 32 $root =~ s|\\|/|g; 33 33 34 $this->{rootdir} = $root;35 $this->{user} = $Foswiki::cfg{AdminUserLogin};36 $this-> {session} = Foswiki->new( $this->{user} );34 $this->{rootdir} = $root; 35 $this->{user} = $Foswiki::cfg{AdminUserLogin}; 36 $this->createNewFoswikiSession( $this->{user} ); 37 37 $this->{test_web} = 'Testsystemweb1234'; 38 38 my $webObject = Foswiki::Meta->new( $this->{session}, $this->{test_web} ); 39 39 $webObject->populateNewWeb(); 40 $webObject->finish(); 40 41 $this->{trash_web} = 'Testtrashweb1234'; 41 42 $webObject = Foswiki::Meta->new( $this->{session}, $this->{trash_web} ); 42 43 $webObject->populateNewWeb(); 44 $webObject->finish(); 43 45 $this->{sandbox_web} = 'Testsandboxweb1234'; 44 46 $webObject = Foswiki::Meta->new( $this->{session}, $this->{sandbox_web} ); 45 47 $webObject->populateNewWeb(); 48 $webObject->finish(); 46 49 $this->{sandbox_subweb} = 'Testsandboxweb1234/Subweb'; 47 50 $webObject = 48 51 Foswiki::Meta->new( $this->{session}, $this->{sandbox_subweb} ); 49 52 $webObject->populateNewWeb(); 53 $webObject->finish(); 50 54 $this->{tempdir} = $Foswiki::cfg{TempfileDir} . '/test_ConfigureTests'; 51 55 rmtree( $this->{tempdir} ) … … 1926 1930 my ( $result, $err ) = $pkg->loadInstaller(); 1927 1931 1928 my $expected = << HERE;1932 my $expected = <<'HERE'; 1929 1933 I can't download http://foswiki.org/pub/Extensions/EmptyPluginx/EmptyPluginx_installer because of the following error: 1930 1934 Not Found -
trunk/UnitTestContrib/test/unit/EmptyTests.pm
r6912 r13791 1 use strict;2 3 1 # Example test case; use this as a basis to build your own 4 2 5 3 package EmptyTests; 4 use strict; 5 use warnings; 6 6 7 7 use FoswikiTestCase; … … 10 10 use Foswiki; 11 11 use Error qw( :try ); 12 13 my $topicquery;14 12 15 13 sub set_up { … … 20 18 # You can now safely modify $Foswiki::cfg 21 19 22 $topicquery = new Unit::Request('');20 my $topicquery = Unit::Request->new(''); 23 21 $topicquery->path_info('/TestCases/WebHome'); 24 22 try { 25 $this-> {session} = new Foswiki( 'AdminUser' || '' );23 $this->createNewFoswikiSession( 'AdminUser' || '' ); 26 24 my $user = $this->{session}->{user}; 27 25 … … 32 30 Foswiki::Meta->new( $this->{session}, "Temporarytestweb1" ); 33 31 $webObject->populateNewWeb("_default"); 32 $webObject->finish(); 34 33 35 34 # Copy a system web like this: … … 37 36 Foswiki::Meta->new( $this->{session}, "Temporarysystemweb" ); 38 37 $webObject->populateNewWeb("System"); 38 $webObject->finish(); 39 39 40 40 # Create a topic like this: … … 52 52 $this->assert( 0, shift->stringify() || '' ); 53 53 }; 54 55 return; 54 56 } 55 57 … … 61 63 $this->removeWebFixture( $this->{session}, "Temporarytestweb1" ); 62 64 $this->removeWebFixture( $this->{session}, "Temporarysystemweb" ); 63 $this->{session}->finish() if $this->{session};64 65 65 66 # Always do this, and always do it last 66 67 $this->SUPER::tear_down(); 68 69 return; 67 70 } 68 71 … … 77 80 sub test_ { 78 81 my $this = shift; 82 83 return; 79 84 } 80 85 -
trunk/UnitTestContrib/test/unit/ExceptionTests.pm
r13730 r13791 1 1 package ExceptionTests; 2 use FoswikiFnTestCase; 2 use strict; 3 use warnings; 4 5 use FoswikiFnTestCase(); 3 6 our @ISA = qw( FoswikiFnTestCase ); 4 7 5 use strict;6 7 8 use Error qw( :try ); 8 use Foswiki::OopsException ;9 use Foswiki::AccessControlException ;9 use Foswiki::OopsException(); 10 use Foswiki::AccessControlException(); 10 11 11 12 my $UI_FN; … … 15 16 $this->SUPER::set_up(); 16 17 $UI_FN ||= $this->getUIFn('oops'); 18 19 return; 17 20 } 18 21 … … 44 47 ); 45 48 }; 49 50 return; 46 51 } 47 52 … … 70 75 ); 71 76 }; 77 78 return; 72 79 } 73 80 74 81 sub upchuck { 75 82 my $session = shift; 76 my $e = new Foswiki::OopsException(83 my $e = Foswiki::OopsException->new( 77 84 'templatename', 78 85 web => 'webname', … … 81 88 ); 82 89 $e->redirect($session); 90 91 return; 83 92 } 84 93 … … 86 95 sub deprecated_test_redirectOopsException { 87 96 my $this = shift; 88 my $t = new Foswiki(); 89 my ($output) = $this->capture( \&upchuck, $t ); 90 $t->finish(); 97 $this->createNewFoswikiSession(); 98 my ($output) = $this->capture( \&upchuck, $this->{session} ); 91 99 $this->assert_matches( qr/^Status: 302.*$/m, $output ); 92 100 $this->assert_matches( … … 94 102 $output 95 103 ); 104 105 return; 96 106 } 97 107 98 108 sub test_AccessControlException { 99 109 my $this = shift; 100 my $ace = new Foswiki::AccessControlException( 'FRY', 'burger', 'Spiders',110 my $ace = Foswiki::AccessControlException->new( 'FRY', 'burger', 'Spiders', 101 111 'FlumpNuts', 'Because it was there.' ); 102 112 $this->assert_str_equals( … … 105 115 ); 106 116 117 return; 107 118 } 108 119 109 120 sub test_oopsScript { 110 121 my $this = shift; 111 my $query = new Unit::Request(122 my $query = Unit::Request->new( 112 123 { 113 124 skin => 'none', … … 121 132 } 122 133 ); 123 my $session = new Foswiki( undef, $query );134 $this->createNewFoswikiSession( undef, $query ); 124 135 my ($output) = 125 $this->capture( $UI_FN, $ session, "Flum", "DeDum", $query, 0 );136 $this->capture( $UI_FN, $this->{session}, "Flum", "DeDum", $query, 0 ); 126 137 $this->assert_matches( qr/^phlegm$/m, $output ); 127 138 $this->assert_matches( qr/^<pus>$/m, $output ); … … 132 143 $this->assert_matches( qr/^phlegm$/m, $output ); 133 144 134 $session->finish();145 return; 135 146 } 136 147 -
trunk/UnitTestContrib/test/unit/Fn_GROUPINFO.pm
r13730 r13791 1 # tests for the correct expansion of GROUPINFO 2 3 package Fn_GROUPINFO; 1 4 use strict; 2 3 # tests for the correct expansion of GROUPINFO 4 5 package Fn_GROUPINFO; 6 7 use FoswikiFnTestCase; 5 use warnings; 6 7 use FoswikiFnTestCase(); 8 8 our @ISA = qw( FoswikiFnTestCase ); 9 9 10 use Foswiki; 10 use Foswiki(); 11 use Foswiki::Func(); 11 12 use Error qw( :try ); 12 13 13 14 sub new { 15 my ( $class, @args ) = @_; 16 14 17 $Foswiki::cfg{Register}{AllowLoginName} = 1; 15 my $self = shift()->SUPER::new( 'GROUPINFO', @_ ); 16 return $ self;18 19 return $class->SUPER::new( 'GROUPINFO', @args ); 17 20 } 18 21 … … 20 23 my $this = shift; 21 24 $this->SUPER::set_up(@_); 22 my $topicObject = 23 Foswiki::Meta->new( $this->{session}, $this->{users_web}, "GropeGroup", 24 " * Set GROUP = ScumBag,WikiGuest\n" ); 25 $topicObject->save(); 26 $topicObject = 27 Foswiki::Meta->new( $this->{session}, $this->{users_web}, "PopGroup", 28 " * Set GROUP = WikiGuest\n" ); 29 $topicObject->save(); 30 $topicObject = Foswiki::Meta->new( 31 $this->{session}, $this->{users_web}, 32 "NestingGroup", " * Set GROUP = GropeGroup\n" 33 ); 34 $topicObject->save(); 35 $topicObject = 36 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 37 "OnlyAdminCanChangeGroup", 38 " * Set GROUP = WikiGuest\n * Set TOPICCHANGE = AdminGroup\n" ); 39 $topicObject->save(); 40 $topicObject = 41 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 42 "GroupWithHiddenGroup", " * Set GROUP = HiddenGroup,WikiGuest\n" ); 43 $topicObject->save(); 44 $topicObject = 45 Foswiki::Meta->new( $this->{session}, $this->{users_web}, "HiddenGroup", 46 " * Set GROUP = ScumBag\n * Set ALLOWTOPICVIEW = AdminUser\n" ); 47 $topicObject->save(); 48 49 $topicObject = 50 Foswiki::Meta->new( $this->{session}, $this->{users_web}, 51 "HiddenUserGroup", " * Set GROUP = ScumBag,HidemeGood\n" ); 52 $topicObject->save(); 53 54 $topicObject = 55 Foswiki::Meta->load( $this->{session}, $this->{users_web}, "HidemeGood" ); 25 my ($topicObject) = 26 Foswiki::Func::readTopic( $this->{users_web}, "GropeGroup" ); 27 $topicObject->text(" * Set GROUP = ScumBag,WikiGuest\n"); 28 $topicObject->save(); 29 $topicObject->finish(); 30 ($topicObject) = Foswiki::Func::readTopic( $this->{users_web}, "PopGroup" ); 31 $topicObject->text(" * Set GROUP = WikiGuest\n"); 32 $topicObject->save(); 33 $topicObject->finish(); 34 ($topicObject) = 35 Foswiki::Func::readTopic( $this->{users_web}, "NestingGroup" ); 36 $topicObject->text(" * Set GROUP = GropeGroup\n"); 37 $topicObject->save(); 38 $topicObject->finish(); 39 ($topicObject) = 40 Foswiki::Func::readTopic( $this->{users_web}, "OnlyAdminCanChangeGroup" ); 41 $topicObject->text( 42 " * Set GROUP = WikiGuest\n * Set TOPICCHANGE = AdminGroup\n"); 43 $topicObject->save(); 44 $topicObject->finish(); 45 ($topicObject) = 46 Foswiki::Func::readTopic( $this->{users_web}, "GroupWithHiddenGroup" ); 47 $topicObject->text(" * Set GROUP = HiddenGroup,WikiGuest\n"); 48 $topicObject->save(); 49 $topicObject->finish(); 50 ($topicObject) = 51 Foswiki::Func::readTopic( $this->{users_web}, "HiddenGroup" ); 52 $topicObject->text( 53 " * Set GROUP = ScumBag\n * Set ALLOWTOPICVIEW = AdminUser\n"); 54 $topicObject->save(); 55 $topicObject->finish(); 56 ($topicObject) = 57 Foswiki::Func::readTopic( $this->{users_web}, "HiddenUserGroup" ); 58 $topicObject->text(" * Set GROUP = ScumBag,HidemeGood\n"); 59 $topicObject->save(); 60 $topicObject->finish(); 61 ($topicObject) = 62 Foswiki::Func::readTopic( $this->{users_web}, "HidemeGood" ); 56 63 my $topText = $topicObject->text(); 57 64 $topText .= " * Set ALLOWTOPICVIEW = AdminUser\n"; 58 65 $topText = $topicObject->text($topText); 59 66 $topicObject->save(); 60 67 $topicObject->finish(); 68 69 return; 61 70 } 62 71 … … 70 79 $this->assert_matches( qr/\bGroupWithHiddenGroup\b/, $ui ); 71 80 $this->assert_does_not_match( qr/\bHiddenGroup\b/, $ui ); 81 82 return; 72 83 } 73 84 … … 79 90 $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui ); 80 91 $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 81 my @u = split( ',', $ui );92 my @u = split( /,/, $ui ); 82 93 $this->assert( 2, scalar(@u) ); 94 95 return; 83 96 } 84 97 … … 95 108 $this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui ); 96 109 $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 97 my @u = split( ',', $ui );110 my @u = split( /,/, $ui ); 98 111 $this->assert( 2, scalar(@u) ); 112 113 return; 99 114 } 100 115 … … 107 122 $this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui ); 108 123 $this->assert_does_not_match( qr/\b$this->{users_web}.HiddenGroup\b/, $ui ); 109 my @u = split( ',', $ui );124 my @u = split( /,/, $ui ); 110 125 $this->assert( 1, scalar(@u) ); 126 127 return; 111 128 } 112 129 … … 127 144 $ui, 'ScumBag revealed' ); 128 145 129 my @u = split( ',', $ui );146 my @u = split( /,/, $ui ); 130 147 $this->assert( 1, scalar(@u) ); 148 149 return; 131 150 } 132 151 … … 141 160 $this->assert_does_not_match( qr/\b$this->{users_web}.HidemeGood\b/, 142 161 $ui, 'HidemeGood revealed' ); 143 my @u = split( ',', $ui );162 my @u = split( /,/, $ui ); 144 163 $this->assert( 1, scalar(@u) ); 164 165 return; 145 166 } 146 167 … … 148 169 my $this = shift; 149 170 150 $this->{session}->finish(); 151 $this->{session} = new Foswiki( $Foswiki::cfg{AdminUserLogin} ); 152 $this->{test_topicObject} = Foswiki::Meta->new( 153 $this->{session}, $this->{test_web}, 154 $this->{test_topic}, "BLEEGLE\n" 155 ); 171 $this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin} ); 172 $this->{test_topicObject}->finish if $this->{test_topicObject}; 173 ( $this->{test_topicObject} ) = 174 Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} ); 175 $this->{test_topicObject}->text("BLEEGLE\n"); 156 176 $this->{test_topicObject}->save(); 157 177 … … 161 181 $this->assert_matches( qr/$this->{users_web}.ScumBag/, $ui ); 162 182 $this->assert_matches( qr/$this->{users_web}.HidemeGood/, $ui ); 163 my @u = split( ',', $ui );183 my @u = split( /,/, $ui ); 164 184 $this->assert( 2, scalar(@u) ); 185 $this->{test_topicObject}->finish(); 186 187 return; 165 188 } 166 189 … … 201 224 ); 202 225 $this->assert_matches( qr/^<\w+>LF$/, $ui ); 226 227 return; 203 228 } 204 229 -
trunk/UnitTestContrib/test/unit/Fn_IF.pm
r13730 r13791 2 2 3 3 package Fn_IF; 4 5 4 use strict; 6 7 use FoswikiFnTestCase; 5 use warnings; 6 7 use FoswikiFnTestCase(); 8 8 our @ISA = qw( FoswikiFnTestCase ); 9 9 10 use Foswiki ;10 use Foswiki(); 11 11 use Error qw( :try ); 12 12 use Assert; … … 17 17 18 18 sub new { 19 my $self = shift()->SUPER::new( 'IF', @_ );20 my $dep = new Foswiki::Configure::Dependency(19 my ( $class, @args ) = @_; 20 my $dep = Foswiki::Configure::Dependency->new( 21 21 type => "perl", 22 22 module => "Foswiki", … … 24 24 ); 25 25 ( $post11, my $message ) = $dep->check(); 26 return $self; 26 27 return $class->SUPER::new( 'IF', @args ); 27 28 } 28 29 … … 30 31 my $this = shift; 31 32 $this->simpleTest( test => "'A'='B'", then => 0, else => 1 ); 33 34 return; 32 35 } 33 36 … … 35 38 my $this = shift; 36 39 $this->simpleTest( test => "'A'!='B'", then => 1, else => 0 ); 40 41 return; 37 42 } 38 43 … … 40 45 my $this = shift; 41 46 $this->simpleTest( test => "'A'='A'", then => 1, else => 0 ); 47 48 return; 42 49 } 43 50 … … 45 52 my $this = shift; 46 53 $this->simpleTest( test => "'A'='B'", then => 0, else => 1 ); 54 55 return; 47 56 } 48 57 … … 50 59 my $this = shift; 51 60 $this->simpleTest( test => 'context test', then => 1, else => 0 ); 61 62 return; 52 63 } 53 64 … … 55 66 my $this = shift; 56 67 $this->simpleTest( test => 'context \'test\'', then => 1, else => 0 ); 68 69 return; 57 70 } 58 71 … … 60 73 my $this = shift; 61 74 $this->simpleTest( test => "{Fnargle}='Fleeble'", then => 1, else => 0 ); 75 76 return; 62 77 } 63 78 … … 65 80 my $this = shift; 66 81 $this->simpleTest( test => "{A}{B}='C'", then => 1, else => 0 ); 82 83 return; 67 84 } 68 85 … … 75 92 else => 0 76 93 ); 94 95 return; 77 96 } 78 97 … … 85 104 else => 0 86 105 ); 106 107 return; 87 108 } 88 109 … … 92 113 93 114 # See test_96* for other 'defined' tests 115 116 return; 94 117 } 95 118 … … 141 164 else => 1 142 165 ); 166 167 return; 143 168 } 144 169 … … 146 171 my $this = shift; 147 172 $this->simpleTest( test => '0>1', then => 0, else => 1 ); 173 174 return; 148 175 } 149 176 … … 151 178 my $this = shift; 152 179 $this->simpleTest( test => '1>0', then => 1, else => 0 ); 180 181 return; 153 182 } 154 183 … … 156 185 my $this = shift; 157 186 $this->simpleTest( test => '1<0', then => 0, else => 1 ); 187 188 return; 158 189 } 159 190 … … 161 192 my $this = shift; 162 193 $this->simpleTest( test => '0<1', then => 1, else => 0 ); 194 195 return; 163 196 } 164 197 … … 166 199 my $this = shift; 167 200 $this->simpleTest( test => "0>=\t1", then => 0, else => 1 ); 201 202 return; 168 203 } 169 204 … … 171 206 my $this = shift; 172 207 $this->simpleTest( test => '1>=0', then => 1, else => 0 ); 208 209 return; 173 210 } 174 211 … … 176 213 my $this = shift; 177 214 $this->simpleTest( test => '1>=1', then => 1, else => 0 ); 215 216 return; 178 217 } 179 218 … … 181 220 my $this = shift; 182 221 $this->simpleTest( test => '1<=0', then => 0, else => 1 ); 222 223 return; 183 224 } 184 225 … … 186 227 my $this = shift; 187 228 $this->simpleTest( test => '0<=1', then => 1, else => 0 ); 229 230 return; 188 231 } 189 232 … … 191 234 my $this = shift; 192 235 $this->simpleTest( test => '1<=1', then => 1, else => 0 ); 236 237 return; 193 238 } 194 239 … … 196 241 my $this = shift; 197 242 $this->simpleTest( test => "not 'A'='B'", then => 1, else => 0 ); 243 244 return; 198 245 } 199 246 … … 201 248 my $this = shift; 202 249 $this->simpleTest( test => "not NOT 'A'='B'", then => 0, else => 1 ); 250 251 return; 203 252 } 204 253 … … 206 255 my $this = shift; 207 256 $this->simpleTest( test => "'A'='A' AND 'B'='B'", then => 1, else => 0 ); 257 258 return; 208 259 } 209 260 … … 211 262 my $this = shift; 212 263 $this->simpleTest( test => "'A'='A' and 'B'='B'", then => 1, else => 0 ); 264 265 return; 213 266 } 214 267 … … 216 269 my $this = shift; 217 270 $this->simpleTest( test => "'A'='A' and 'B'='B'", then => 1, else => 0 ); 271 272 return; 218 273 } 219 274 … … 225 280 else => 0 226 281 ); 282 283 return; 227 284 } 228 285 … … 230 287 my $this = shift; 231 288 $this->simpleTest( test => "'A'='B' or 'B'='B'", then => 1, else => 0 ); 289 290 return; 232 291 } 233 292 … … 235 294 my $this = shift; 236 295 $this->simpleTest( test => "'A'='A' or 'B'='A'", then => 1, else => 0 ); 296 297 return; 237 298 } 238 299 … … 240 301 my $this = shift; 241 302 $this->simpleTest( test => "'A'='B' or 'B'='A'", then => 0, else => 1 ); 303 304 return; 242 305 } 243 306 …
