| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
namespace MediaWiki\Tests\Unit\Permissions; |
| 22 |
|
| 23 |
use InvalidArgumentException; |
| 24 |
use MediaWiki\Page\PageIdentity; |
| 25 |
use MediaWiki\Page\PageIdentityValue; |
| 26 |
use MediaWiki\Permissions\PermissionStatus; |
| 27 |
use MediaWiki\Permissions\UltimateAuthority; |
| 28 |
use MediaWiki\User\UserIdentityValue; |
| 29 |
use MediaWikiUnitTestCase; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
class UltimateAuthorityTest extends MediaWikiUnitTestCase { |
| 35 |
|
| 36 |
public function testGetAuthor() { |
| 37 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 38 |
$authority = new UltimateAuthority( $actor ); |
| 39 |
|
| 40 |
$this->assertSame( $actor, $authority->getUser() ); |
| 41 |
} |
| 42 |
|
| 43 |
public function testPermissions() { |
| 44 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 45 |
$authority = new UltimateAuthority( $actor ); |
| 46 |
|
| 47 |
$this->assertTrue( $authority->isAllowed( 'foo' ) ); |
| 48 |
$this->assertTrue( $authority->isAllowed( 'bar' ) ); |
| 49 |
|
| 50 |
$this->assertTrue( $authority->isAllowedAll( 'foo', 'bar' ) ); |
| 51 |
$this->assertTrue( $authority->isAllowedAny( 'bar', 'quux' ) ); |
| 52 |
} |
| 53 |
|
| 54 |
public function testProbablyCan() { |
| 55 |
$target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); |
| 56 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 57 |
$authority = new UltimateAuthority( $actor ); |
| 58 |
|
| 59 |
$this->assertTrue( $authority->probablyCan( 'foo', $target ) ); |
| 60 |
$this->assertTrue( $authority->probablyCan( 'bar', $target ) ); |
| 61 |
|
| 62 |
$status = new PermissionStatus(); |
| 63 |
$authority->probablyCan( 'foo', $target, $status ); |
| 64 |
$this->assertStatusOK( $status ); |
| 65 |
} |
| 66 |
|
| 67 |
public function testDefinitelyCan() { |
| 68 |
$target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); |
| 69 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 70 |
$authority = new UltimateAuthority( $actor ); |
| 71 |
|
| 72 |
$this->assertTrue( $authority->definitelyCan( 'foo', $target ) ); |
| 73 |
$this->assertTrue( $authority->definitelyCan( 'bar', $target ) ); |
| 74 |
|
| 75 |
$status = new PermissionStatus(); |
| 76 |
$authority->definitelyCan( 'foo', $target, $status ); |
| 77 |
$this->assertStatusOK( $status ); |
| 78 |
} |
| 79 |
|
| 80 |
public function testAuthorizeRead() { |
| 81 |
$target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); |
| 82 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 83 |
$authority = new UltimateAuthority( $actor ); |
| 84 |
|
| 85 |
$this->assertTrue( $authority->authorizeRead( 'foo', $target ) ); |
| 86 |
$this->assertTrue( $authority->authorizeRead( 'bar', $target ) ); |
| 87 |
|
| 88 |
$status = new PermissionStatus(); |
| 89 |
$authority->authorizeRead( 'foo', $target, $status ); |
| 90 |
$this->assertStatusOK( $status ); |
| 91 |
} |
| 92 |
|
| 93 |
public function testAuthorizeWrite() { |
| 94 |
$target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); |
| 95 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 96 |
$authority = new UltimateAuthority( $actor ); |
| 97 |
|
| 98 |
$this->assertTrue( $authority->authorizeWrite( 'foo', $target ) ); |
| 99 |
$this->assertTrue( $authority->authorizeWrite( 'bar', $target ) ); |
| 100 |
|
| 101 |
$status = new PermissionStatus(); |
| 102 |
$authority->authorizeWrite( 'foo', $target, $status ); |
| 103 |
$this->assertStatusOK( $status ); |
| 104 |
} |
| 105 |
|
| 106 |
public function testIsAllowedAnyThrowsOnEmptySet() { |
| 107 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 108 |
$authority = new UltimateAuthority( $actor ); |
| 109 |
|
| 110 |
$this->expectException( InvalidArgumentException::class ); |
| 111 |
$authority->isAllowedAny(); |
| 112 |
} |
| 113 |
|
| 114 |
public function testIsAllowedAllThrowsOnEmptySet() { |
| 115 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 116 |
$authority = new UltimateAuthority( $actor ); |
| 117 |
|
| 118 |
$this->expectException( InvalidArgumentException::class ); |
| 119 |
$authority->isAllowedAll(); |
| 120 |
} |
| 121 |
|
| 122 |
public function testGetBlock() { |
| 123 |
$actor = new UserIdentityValue( 12, 'Test' ); |
| 124 |
$authority = new UltimateAuthority( $actor ); |
| 125 |
|
| 126 |
$this->assertNull( $authority->getBlock() ); |
| 127 |
} |
| 128 |
|
| 129 |
} |