Debian Codegraph @

tests/phpunit/unit/includes/Permissions/UltimateAuthorityTest.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
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 * @covers \MediaWiki\Permissions\UltimateAuthority
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 }