<?php
-use MediaWiki\Block\BlockRestriction;
+use MediaWiki\Block\BlockRestrictionStore;
+use MediaWiki\Block\DatabaseBlock;
use MediaWiki\Block\Restriction\PageRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
use Wikimedia\TestingAccessWrapper;
+use Wikimedia\Rdbms\LoadBalancer;
/**
* @group Blocking
$block = $this->insertBlock();
// Refresh the block from the database.
- $block = Block::newFromTarget( $block->getTarget() );
+ $block = DatabaseBlock::newFromTarget( $block->getTarget() );
$page = $this->newSpecialPage();
$this->assertSame( $block->isCreateAccountBlocked(), $fields['CreateAccount']['default'] );
$this->assertSame( $block->isAutoblocking(), $fields['AutoBlock']['default'] );
$this->assertSame( !$block->isUsertalkEditAllowed(), $fields['DisableUTEdit']['default'] );
- $this->assertSame( $block->mReason, $fields['Reason']['default'] );
+ $this->assertSame( $block->getReason(), $fields['Reason']['default'] );
$this->assertSame( 'infinite', $fields['Expiry']['default'] );
}
$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 );
- $this->assertSame( $reason, $block->mReason );
+ $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 );
- $this->assertSame( $reason, $block->mReason );
+ $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 );
- $this->assertSame( $reason, $block->mReason );
+ $block = DatabaseBlock::newFromTarget( $badActor );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertCount( 2, $block->getRestrictions() );
- $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+ $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
new PageRestriction( $block->getId(), $pageMars->getId() ),
new PageRestriction( $block->getId(), $pageSaturn->getId() ),
] ) );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
- $this->assertSame( $reason, $block->mReason );
+ $block = DatabaseBlock::newFromTarget( $badActor );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertCount( 2, $block->getRestrictions() );
- $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+ $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
new PageRestriction( $block->getId(), $pageMars->getId() ),
new PageRestriction( $block->getId(), $pageSaturn->getId() ),
] ) );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
- $this->assertSame( $reason, $block->mReason );
+ $block = DatabaseBlock::newFromTarget( $badActor );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertCount( 1, $block->getRestrictions() );
- $this->assertTrue( BlockRestriction::equals( $block->getRestrictions(), [
+ $this->assertTrue( $this->getBlockRestrictionStore()->equals( $block->getRestrictions(), [
new PageRestriction( $block->getId(), $pageMars->getId() ),
] ) );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
- $this->assertSame( $reason, $block->mReason );
+ $block = DatabaseBlock::newFromTarget( $badActor );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertFalse( $block->isSitewide() );
$this->assertCount( 0, $block->getRestrictions() );
$this->assertTrue( $result );
- $block = Block::newFromTarget( $badActor );
- $this->assertSame( $reason, $block->mReason );
+ $block = DatabaseBlock::newFromTarget( $badActor );
+ $this->assertSame( $reason, $block->getReason() );
$this->assertSame( $expiry, $block->getExpiry() );
$this->assertTrue( $block->isSitewide() );
$this->assertCount( 0, $block->getRestrictions() );
$$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(),
$this->db->delete( 'ipblocks', '*', __METHOD__ );
$this->db->delete( 'ipblocks_restrictions', '*', __METHOD__ );
}
+
+ /**
+ * Get a BlockRestrictionStore instance
+ *
+ * @return BlockRestrictionStore
+ */
+ private function getBlockRestrictionStore() : BlockRestrictionStore {
+ $loadBalancer = $this->getMockBuilder( LoadBalancer::class )
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new BlockRestrictionStore( $loadBalancer );
+ }
}