Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 20 | class PermissionResolverTest extends BaseTest |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Test for the getCurrentUser() method. |
||
| 24 | * |
||
| 25 | * @see \eZ\Publish\API\Repository\PermissionResolver::getCurrentUserReference() |
||
| 26 | */ |
||
| 27 | public function testGetCurrentUserReferenceReturnsAnonymousUserReference() |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Test for the setCurrentUser() method. |
||
| 56 | * |
||
| 57 | * @see \eZ\Publish\API\Repository\PermissionResolver::setCurrentUserReference() |
||
| 58 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function testSetCurrentUserReference() |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Test for the hasAccess() method. |
||
| 98 | * |
||
| 99 | * @see \eZ\Publish\API\Repository\PermissionResolver::hasAccess() |
||
| 100 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 101 | */ |
||
| 102 | public function testHasAccessWithAnonymousUserNo() |
||
| 103 | { |
||
| 104 | $repository = $this->getRepository(); |
||
| 105 | |||
| 106 | $anonymousUserId = $this->generateId('user', 10); |
||
| 107 | |||
| 108 | /* BEGIN: Use Case */ |
||
| 109 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
||
| 110 | // Publish demo installation. |
||
| 111 | |||
| 112 | $userService = $repository->getUserService(); |
||
| 113 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 114 | |||
| 115 | // Load anonymous user |
||
| 116 | $anonymousUser = $userService->loadUser($anonymousUserId); |
||
| 117 | |||
| 118 | // This call will return false because anonymous user does not have access |
||
| 119 | // to content removal |
||
| 120 | $hasAccess = $permissionResolver->hasAccess('content', 'remove', $anonymousUser); |
||
| 121 | /* END: Use Case */ |
||
| 122 | |||
| 123 | $this->assertFalse($hasAccess); |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Test for the hasAccess() method. |
||
| 128 | * |
||
| 129 | * @see \eZ\Publish\API\Repository\PermissionResolver::hasAccess() |
||
| 130 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 131 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessWithAnonymousUserNo |
||
| 132 | */ |
||
| 133 | View Code Duplication | public function testHasAccessForCurrentUserNo() |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Test for the hasAccess() method. |
||
| 162 | * |
||
| 163 | * @see \eZ\Publish\API\Repository\PermissionResolver::hasAccess() |
||
| 164 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 165 | */ |
||
| 166 | public function testHasAccessWithAdministratorUser() |
||
| 167 | { |
||
| 168 | $repository = $this->getRepository(); |
||
| 169 | |||
| 170 | $administratorUserId = $this->generateId('user', 14); |
||
| 171 | |||
| 172 | /* BEGIN: Use Case */ |
||
| 173 | // $administratorUserId contains the ID of the administrator user |
||
| 174 | |||
| 175 | $userService = $repository->getUserService(); |
||
| 176 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 177 | |||
| 178 | // Load administrator user |
||
| 179 | $administratorUser = $userService->loadUser($administratorUserId); |
||
| 180 | |||
| 181 | // This call will return true |
||
| 182 | $hasAccess = $permissionResolver->hasAccess('content', 'read', $administratorUser); |
||
| 183 | /* END: Use Case */ |
||
| 184 | |||
| 185 | $this->assertTrue($hasAccess); |
||
| 186 | } |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Test for the hasAccess() method. |
||
| 190 | * |
||
| 191 | * @see \eZ\Publish\API\Repository\PermissionResolver::hasAccess() |
||
| 192 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 193 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testSetCurrentUserReference |
||
| 194 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessWithAdministratorUser |
||
| 195 | */ |
||
| 196 | View Code Duplication | public function testHasAccessForCurrentUserYes() |
|
| 220 | |||
| 221 | /** |
||
| 222 | * Test for the hasAccess() method. |
||
| 223 | * |
||
| 224 | * @see \eZ\Publish\API\Repository\PermissionResolver::hasAccess() |
||
| 225 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 226 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testSetCurrentUserReference |
||
| 227 | */ |
||
| 228 | View Code Duplication | public function testHasAccessLimited() |
|
| 251 | |||
| 252 | /** |
||
| 253 | * Test for the canUser() method. |
||
| 254 | * |
||
| 255 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 256 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 257 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 258 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessForCurrentUserNo |
||
| 259 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 260 | */ |
||
| 261 | public function testCanUserForAnonymousUserNo() |
||
| 262 | { |
||
| 263 | $repository = $this->getRepository(); |
||
| 264 | |||
| 265 | $homeId = $this->generateId('object', 57); |
||
| 266 | |||
| 267 | $anonymousUserId = $this->generateId('user', 10); |
||
| 268 | /* BEGIN: Use Case */ |
||
| 269 | // $anonymousUserId is the ID of the "Anonymous" user in a eZ |
||
| 270 | // Publish demo installation. |
||
| 271 | // $homeId contains the ID of the "Home" frontpage |
||
| 272 | |||
| 273 | $contentService = $repository->getContentService(); |
||
| 274 | $userService = $repository->getUserService(); |
||
| 275 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 276 | |||
| 277 | // Load anonymous user |
||
| 278 | $anonymousUser = $userService->loadUser($anonymousUserId); |
||
| 279 | |||
| 280 | // Set anonymous user as current user reference |
||
| 281 | $permissionResolver->setCurrentUserReference($anonymousUser); |
||
| 282 | |||
| 283 | // Load the ContentInfo for "Home" frontpage |
||
| 284 | $contentInfo = $contentService->loadContentInfo($homeId); |
||
| 285 | |||
| 286 | // This call will return false because anonymous user does not have access |
||
| 287 | // to content removal and hence no permission to remove given content |
||
| 288 | $canUser = $permissionResolver->canUser('content', 'remove', $contentInfo); |
||
| 289 | |||
| 290 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
||
| 291 | if (!$canUser) { |
||
| 292 | $contentService->deleteContent($contentInfo); |
||
| 293 | } |
||
| 294 | /* END: Use Case */ |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Test for the canUser() method. |
||
| 299 | * |
||
| 300 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 301 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 302 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 303 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessForCurrentUserYes |
||
| 304 | * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 305 | */ |
||
| 306 | public function testCanUserForAdministratorUser() |
||
| 307 | { |
||
| 308 | $repository = $this->getRepository(); |
||
| 309 | |||
| 310 | $administratorUserId = $this->generateId('user', 14); |
||
| 311 | $homeId = $this->generateId('object', 57); |
||
| 312 | |||
| 313 | /* BEGIN: Use Case */ |
||
| 314 | // $administratorUserId contains the ID of the administrator user |
||
| 315 | // $homeId contains the ID of the "Home" frontpage |
||
| 316 | |||
| 317 | $contentService = $repository->getContentService(); |
||
| 318 | $userService = $repository->getUserService(); |
||
| 319 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 320 | |||
| 321 | // Load administrator user |
||
| 322 | $administratorUser = $userService->loadUser($administratorUserId); |
||
| 323 | |||
| 324 | // Set administrator user as current user reference |
||
| 325 | $permissionResolver->setCurrentUserReference($administratorUser); |
||
| 326 | |||
| 327 | // Load the ContentInfo for "Home" frontpage |
||
| 328 | $contentInfo = $contentService->loadContentInfo($homeId); |
||
| 329 | |||
| 330 | // This call will return true |
||
| 331 | $canUser = $permissionResolver->canUser('content', 'remove', $contentInfo); |
||
| 332 | |||
| 333 | // Performing an action having necessary permissions will succeed |
||
| 334 | $contentService->deleteContent($contentInfo); |
||
| 335 | /* END: Use Case */ |
||
| 336 | |||
| 337 | $this->assertTrue($canUser); |
||
| 338 | $contentService->loadContent($homeId); |
||
| 339 | } |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Test for the canUser() method. |
||
| 343 | * |
||
| 344 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 345 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 346 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 347 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 348 | */ |
||
| 349 | View Code Duplication | public function testCanUserWithLimitationYes() |
|
| 350 | { |
||
| 351 | $repository = $this->getRepository(); |
||
| 352 | |||
| 353 | $imagesFolderId = $this->generateId('object', 49); |
||
| 354 | |||
| 355 | /* BEGIN: Use Case */ |
||
| 356 | // $imagesFolderId contains the ID of the "Images" folder |
||
| 357 | |||
| 358 | $user = $this->createUserVersion1(); |
||
| 359 | |||
| 360 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 361 | |||
| 362 | // Set created user as current user reference |
||
| 363 | $permissionResolver->setCurrentUserReference($user); |
||
| 364 | |||
| 365 | $contentService = $repository->getContentService(); |
||
| 366 | |||
| 367 | // Performing an action having necessary permissions will succeed |
||
| 368 | $imagesFolder = $contentService->loadContent($imagesFolderId); |
||
| 369 | |||
| 370 | // This call will return true |
||
| 371 | $canUser = $permissionResolver->canUser('content', 'read', $imagesFolder); |
||
| 372 | /* END: Use Case */ |
||
| 373 | |||
| 374 | $this->assertTrue($canUser); |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Test for the canUser() method. |
||
| 379 | * |
||
| 380 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 381 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 382 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 383 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 384 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 385 | */ |
||
| 386 | public function testCanUserWithLimitationNo() |
||
| 387 | { |
||
| 388 | $repository = $this->getRepository(); |
||
| 389 | |||
| 390 | $administratorUserId = $this->generateId('user', 14); |
||
| 391 | |||
| 392 | /* BEGIN: Use Case */ |
||
| 393 | // $administratorUserId contains the ID of the administrator user |
||
| 394 | |||
| 395 | $user = $this->createUserVersion1(); |
||
| 396 | |||
| 397 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 398 | |||
| 399 | // Set created user as current user reference |
||
| 400 | $permissionResolver->setCurrentUserReference($user); |
||
| 401 | |||
| 402 | $userService = $repository->getUserService(); |
||
| 403 | |||
| 404 | // Load administrator user using UserService, this does not check for permissions |
||
| 405 | $administratorUser = $userService->loadUser($administratorUserId); |
||
| 406 | |||
| 407 | // This call will return false as user with Editor role does not have |
||
| 408 | // permission to read "Users" subtree |
||
| 409 | $canUser = $permissionResolver->canUser('content', 'read', $administratorUser); |
||
| 410 | |||
| 411 | $contentService = $repository->getContentService(); |
||
| 412 | |||
| 413 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
||
| 414 | if (!$canUser) { |
||
| 415 | $content = $contentService->loadContent($administratorUserId); |
||
|
|
|||
| 416 | } |
||
| 417 | /* END: Use Case */ |
||
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Test for the canUser() method. |
||
| 422 | * |
||
| 423 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 424 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 425 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 426 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testSetCurrentUserReference |
||
| 427 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 428 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 429 | */ |
||
| 430 | public function testCanUserThrowsInvalidArgumentException() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Test for the canUser() method. |
||
| 460 | * |
||
| 461 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 462 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 463 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 464 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 465 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 466 | */ |
||
| 467 | View Code Duplication | public function testCanUserWithTargetYes() |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Test for the canUser() method. |
||
| 521 | * |
||
| 522 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 523 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 524 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 525 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 526 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 527 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 528 | */ |
||
| 529 | public function testCanUserWithTargetNo() |
||
| 530 | { |
||
| 531 | $repository = $this->getRepository(); |
||
| 532 | |||
| 533 | $homeLocationId = $this->generateId('location', 2); |
||
| 534 | |||
| 535 | /* BEGIN: Use Case */ |
||
| 536 | // $homeLocationId contains the ID of the "Home" frontpage location |
||
| 537 | |||
| 538 | $user = $this->createUserVersion1(); |
||
| 539 | |||
| 540 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 541 | |||
| 542 | // Set created user as current user reference |
||
| 543 | $permissionResolver->setCurrentUserReference($user); |
||
| 544 | |||
| 545 | $contentTypeService = $repository->getContentTypeService(); |
||
| 546 | |||
| 547 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forum'); |
||
| 548 | |||
| 549 | $contentService = $repository->getContentService(); |
||
| 550 | |||
| 551 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
||
| 552 | $contentCreateStruct->setField('name', 'My awesome forum'); |
||
| 553 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 554 | $contentCreateStruct->alwaysAvailable = true; |
||
| 555 | |||
| 556 | $locationService = $repository->getLocationService(); |
||
| 557 | $locationCreateStruct = $locationService->newLocationCreateStruct($homeLocationId); |
||
| 558 | |||
| 559 | // This call will return false because user with Editor role has permission to |
||
| 560 | // create "forum" type content only under "folder" type content. |
||
| 561 | $canUser = $permissionResolver->canUser( |
||
| 562 | 'content', |
||
| 563 | 'create', |
||
| 564 | $contentCreateStruct, |
||
| 565 | [$locationCreateStruct] |
||
| 566 | ); |
||
| 567 | |||
| 568 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
||
| 569 | if (!$canUser) { |
||
| 570 | $contentDraft = $contentService->createContent( |
||
| 571 | $contentCreateStruct, |
||
| 572 | [$locationCreateStruct] |
||
| 573 | ); |
||
| 574 | } |
||
| 575 | /* END: Use Case */ |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Test for the canUser() method. |
||
| 580 | * |
||
| 581 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 582 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 583 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 584 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 585 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 586 | */ |
||
| 587 | View Code Duplication | public function testCanUserWithMultipleTargetsYes() |
|
| 639 | |||
| 640 | /** |
||
| 641 | * Test for the canUser() method. |
||
| 642 | * |
||
| 643 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 644 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 645 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 646 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 647 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 648 | * @expectedException \eZ\Publish\API\Repository\Exceptions\UnauthorizedException |
||
| 649 | */ |
||
| 650 | public function testCanUserWithMultipleTargetsNo() |
||
| 651 | { |
||
| 652 | $repository = $this->getRepository(); |
||
| 653 | |||
| 654 | $homeLocationId = $this->generateId('location', 2); |
||
| 655 | $administratorUsersLocationId = $this->generateId('location', 13); |
||
| 656 | |||
| 657 | /* BEGIN: Use Case */ |
||
| 658 | // $homeLocationId contains the ID of the "Home" location |
||
| 659 | // $administratorUsersLocationId contains the ID of the "Administrator users" location |
||
| 660 | |||
| 661 | $user = $this->createUserVersion1(); |
||
| 662 | |||
| 663 | $permissionResolver = $repository->getPermissionResolver(); |
||
| 664 | |||
| 665 | // Set created user as current user reference |
||
| 666 | $permissionResolver->setCurrentUserReference($user); |
||
| 667 | |||
| 668 | $contentTypeService = $repository->getContentTypeService(); |
||
| 669 | |||
| 670 | $contentType = $contentTypeService->loadContentTypeByIdentifier('forums'); |
||
| 671 | |||
| 672 | $contentService = $repository->getContentService(); |
||
| 673 | |||
| 674 | $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-US'); |
||
| 675 | $contentCreateStruct->setField('name', 'My awesome forums'); |
||
| 676 | $contentCreateStruct->remoteId = 'abcdef0123456789abcdef0123456789'; |
||
| 677 | $contentCreateStruct->alwaysAvailable = true; |
||
| 678 | |||
| 679 | $locationService = $repository->getLocationService(); |
||
| 680 | $locationCreateStruct1 = $locationService->newLocationCreateStruct($homeLocationId); |
||
| 681 | $locationCreateStruct2 = $locationService->newLocationCreateStruct($administratorUsersLocationId); |
||
| 682 | $locationCreateStructs = [$locationCreateStruct1, $locationCreateStruct2]; |
||
| 683 | |||
| 684 | // This call will return false because user with Editor role does not have permission to |
||
| 685 | // create content in the "Administrator users" location subtree |
||
| 686 | $canUser = $permissionResolver->canUser( |
||
| 687 | 'content', |
||
| 688 | 'create', |
||
| 689 | $contentCreateStruct, |
||
| 690 | $locationCreateStructs |
||
| 691 | ); |
||
| 692 | |||
| 693 | // Performing an action without necessary permissions will fail with "UnauthorizedException" |
||
| 694 | if (!$canUser) { |
||
| 695 | $contentDraft = $contentService->createContent($contentCreateStruct, $locationCreateStructs); |
||
| 696 | } |
||
| 697 | /* END: Use Case */ |
||
| 698 | } |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Test for the canUser() method. |
||
| 702 | * |
||
| 703 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 704 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetUserService |
||
| 705 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentService |
||
| 706 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetContentTypeService |
||
| 707 | * @depends eZ\Publish\API\Repository\Tests\RepositoryTest::testGetURLAliasService |
||
| 708 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testSetCurrentUserReference |
||
| 709 | * @depends eZ\Publish\API\Repository\Tests\PermissionResolverTest::testHasAccessLimited |
||
| 710 | * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 711 | */ |
||
| 712 | View Code Duplication | public function testCanUserWithTargetThrowsInvalidArgumentException() |
|
| 747 | |||
| 748 | /** |
||
| 749 | * Test for the canUser() method. |
||
| 750 | * |
||
| 751 | * @see \eZ\Publish\API\Repository\PermissionResolver::canUser() |
||
| 752 | * @expectedException \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 753 | */ |
||
| 754 | public function testCanUserThrowsBadStateException() |
||
| 760 | |||
| 761 | /** |
||
| 762 | * Test PermissionResolver::canUser for Users with different Limitations. |
||
| 763 | * |
||
| 764 | * @covers \eZ\Publish\API\Repository\PermissionResolver::canUser |
||
| 765 | * |
||
| 766 | * @dataProvider getDataForTestCanUserWithLimitations |
||
| 767 | * |
||
| 768 | * @param \eZ\Publish\API\Repository\Values\User\Limitation $limitation |
||
| 769 | * @param string $module |
||
| 770 | * @param string $function |
||
| 771 | * @param \eZ\Publish\API\Repository\Values\ValueObject $object |
||
| 772 | * @param array $targets |
||
| 773 | * @param bool $expectedResult expected result of canUser check |
||
| 774 | * |
||
| 775 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException |
||
| 776 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException |
||
| 777 | */ |
||
| 778 | public function testCanUserWithLimitations( |
||
| 809 | |||
| 810 | /** |
||
| 811 | * Data provider for testCanUserWithLimitations. |
||
| 812 | * @see testCanUserWithLimitations |
||
| 813 | * |
||
| 814 | * @return array |
||
| 815 | * |
||
| 816 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException |
||
| 817 | */ |
||
| 818 | public function getDataForTestCanUserWithLimitations() |
||
| 865 | } |
||
| 866 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.