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