<?php
use MediaWiki\Block\BlockRestrictionStore;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
use Wikimedia\TestingAccessWrapper;
$block = $this->insertBlock();
// Refresh the block from the database.
- $block = Block::newFromTarget( $block->getTarget() );
+ $block = DatabaseBlock::newFromTarget( $block->getTarget() );
$page = $this->newSpecialPage();
$pageSaturn = $this->getExistingTestPage( 'Saturn' );
$pageMars = $this->getExistingTestPage( 'Mars' );
- $block = new \Block( [
+ $block = new DatabaseBlock( [
'address' => $badActor->getName(),
'user' => $badActor->getId(),
'by' => $sysop->getId(),
$block->insert();
// Refresh the block from the database.
- $block = Block::newFromTarget( $block->getTarget() );
+ $block = DatabaseBlock::newFromTarget( $block->getTarget() );
$page = $this->newSpecialPage();
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
}
$context = RequestContext::getMain();
// Create a block that will be updated.
- $block = new \Block( [
+ $block = new DatabaseBlock( [
'address' => $badActor->getName(),
'user' => $badActor->getId(),
'by' => $sysop->getId(),
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertSame( '1', $block->isAutoblocking() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertCount( 2, $block->getRestrictions() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
+ $block = DatabaseBlock::newFromTarget( $badActor );
$this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertTrue( $block->isSitewide() );
$this->assertSame( 0, $count );
}
+ /**
+ * @dataProvider provideProcessFormErrors
+ * @covers ::processForm()
+ */
+ public function testProcessFormErrors( $data, $expected, $config = [] ) {
+ $defaultConfig = [
+ 'wgEnablePartialBlocks' => true,
+ 'wgBlockAllowsUTEdit' => true,
+ ];
+
+ $this->setMwGlobals( array_merge( $defaultConfig, $config ) );
+
+ $defaultData = [
+ 'Target' => '1.2.3.4',
+ 'Expiry' => 'infinity',
+ 'Reason' => [ 'bad reason' ],
+ 'Confirm' => false,
+ 'PageRestrictions' => '',
+ 'NamespaceRestrictions' => '',
+ ];
+
+ $context = RequestContext::getMain();
+ $page = $this->newSpecialPage();
+ $result = $page->processForm( array_merge( $defaultData, $data ), $context );
+
+ $this->assertEquals( $result[0], $expected );
+ }
+
+ public function provideProcessFormErrors() {
+ return [
+ 'Invalid expiry' => [
+ [
+ 'Expiry' => 'invalid',
+ ],
+ 'ipb_expiry_invalid',
+ ],
+ 'Expiry is in the past' => [
+ [
+ 'Expiry' => 'yesterday',
+ ],
+ 'ipb_expiry_old',
+ ],
+ 'HideUser with wrong permissions' => [
+ [
+ 'HideUser' => 1,
+ ],
+ 'badaccess-group0',
+ ],
+ 'Bad ip address' => [
+ [
+ 'Target' => '1.2.3.4/1234',
+ ],
+ 'badipaddress',
+ ],
+ 'Edit user talk page invalid with no restrictions' => [
+ [
+ 'EditingRestriction' => 'partial',
+ 'DisableUTEdit' => 1,
+ ],
+ 'ipb-prevent-user-talk-edit',
+ ],
+ 'Edit user talk page invalid with namespace restriction != NS_USER_TALK ' => [
+ [
+ 'EditingRestriction' => 'partial',
+ 'DisableUTEdit' => 1,
+ 'NamespaceRestrictions' => NS_USER
+ ],
+ 'ipb-prevent-user-talk-edit',
+ ],
+ ];
+ }
+
/**
* @dataProvider provideCheckUnblockSelf
* @covers ::checkUnblockSelf
$$var = $users[$$var];
}
- $block = new \Block( [
+ $block = new DatabaseBlock( [
'address' => $blockedUser->getName(),
'user' => $blockedUser->getId(),
'by' => $blockPerformer->getId(),
$badActor = $this->getTestUser()->getUser();
$sysop = $this->getTestSysop()->getUser();
- $block = new \Block( [
+ $block = new DatabaseBlock( [
'address' => $badActor->getName(),
'user' => $badActor->getId(),
'by' => $sysop->getId(),