Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / tests / phpunit / includes / specialpage / FormSpecialPageTestCase.php
1 <?php
2
3 use MediaWiki\Block\DatabaseBlock;
4
5 /**
6 * Factory for handling the special page list and generating SpecialPage objects.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @group SpecialPage
24 */
25 abstract class FormSpecialPageTestCase extends SpecialPageTestBase {
26
27 /**
28 * @covers FormSpecialPage::checkExecutePermissions
29 */
30 public function testCheckExecutePermissionsSitewideBlock() {
31 $special = $this->newSpecialPage();
32 $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
33
34 $user = clone $this->getTestUser()->getUser();
35 $user->mBlockedby = $user->getName();
36 $user->mBlock = new DatabaseBlock( [
37 'address' => '127.0.8.1',
38 'by' => $user->getId(),
39 'reason' => 'sitewide block',
40 'timestamp' => time(),
41 'sitewide' => true,
42 'expiry' => 10,
43 ] );
44
45 $this->expectException( UserBlockedError::class );
46 $checkExecutePermissions( $user );
47 }
48
49 /**
50 * @covers FormSpecialPage::checkExecutePermissions
51 */
52 public function testCheckExecutePermissionsPartialBlock() {
53 $special = $this->newSpecialPage();
54 $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' );
55
56 $user = clone $this->getTestUser()->getUser();
57 $user->mBlockedby = $user->getName();
58 $user->mBlock = new DatabaseBlock( [
59 'address' => '127.0.8.1',
60 'by' => $user->getId(),
61 'reason' => 'partial block',
62 'timestamp' => time(),
63 'sitewide' => false,
64 'expiry' => 10,
65 ] );
66
67 $this->assertNull( $checkExecutePermissions( $user ) );
68 }
69
70 /**
71 * Get a protected/private method.
72 *
73 * @param object $obj
74 * @param string $name
75 * @return callable
76 */
77 protected function getMethod( $obj, $name ) {
78 $method = new ReflectionMethod( $obj, $name );
79 $method->setAccessible( true );
80 return $method->getClosure( $obj );
81 }
82 }