newSpecialPage(); $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' ); $user = $this->getMockBuilder( User::class ) ->setMethods( [ 'getBlock' ] ) ->getMock(); $user->method( 'getBlock' ) ->willReturn( new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $user->getId(), 'reason' => 'sitewide block', 'timestamp' => time(), 'sitewide' => true, 'expiry' => 10, ] ) ); $this->expectException( UserBlockedError::class ); $checkExecutePermissions( $user ); } /** * @covers FormSpecialPage::checkExecutePermissions */ public function testCheckExecutePermissionsPartialBlock() { $special = $this->newSpecialPage(); $checkExecutePermissions = $this->getMethod( $special, 'checkExecutePermissions' ); $user = $this->getMockBuilder( User::class ) ->setMethods( [ 'getBlock' ] ) ->getMock(); $user->method( 'getBlock' ) ->willReturn( new DatabaseBlock( [ 'address' => '127.0.8.1', 'by' => $user->getId(), 'reason' => 'partial block', 'timestamp' => time(), 'sitewide' => false, 'expiry' => 10, ] ) ); $this->assertNull( $checkExecutePermissions( $user ) ); } /** * Get a protected/private method. * * @param object $obj * @param string $name * @return callable */ protected function getMethod( $obj, $name ) { $method = new ReflectionMethod( $obj, $name ); $method->setAccessible( true ); return $method->getClosure( $obj ); } }