}
public function testBlockWithTag() {
- $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_WRITE_BOTH );
- ChangeTags::defineTag( 'custom tag' );
-
- $this->doBlock( [ 'tags' => 'custom tag' ] );
-
- $dbw = wfGetDB( DB_MASTER );
- $this->assertSame( 1, (int)$dbw->selectField(
- [ 'change_tag', 'logging' ],
- 'COUNT(*)',
- [ 'log_type' => 'block', 'ct_tag' => 'custom tag' ],
- __METHOD__,
- [],
- [ 'change_tag' => [ 'INNER JOIN', 'ct_log_id = log_id' ] ]
- ) );
- }
-
- public function testBlockWithTagNewBackend() {
- $this->setMwGlobals( 'wgChangeTagsSchemaMigrationStage', MIGRATION_NEW );
ChangeTags::defineTag( 'custom tag' );
$this->doBlock( [ 'tags' => 'custom tag' ] );
$this->doBlock( [ 'expiry' => '' ] );
}
+ public function testBlockWithRestrictions() {
+ $this->setMwGlobals( [
+ 'wgEnablePartialBlocks' => true,
+ ] );
+
+ $title = 'Foo';
+ $page = $this->getExistingTestPage( $title );
+
+ $this->doBlock( [
+ 'partial' => true,
+ 'pagerestrictions' => $title,
+ ] );
+
+ $block = Block::newFromTarget( $this->mUser->getName() );
+
+ $this->assertFalse( $block->isSitewide() );
+ $this->assertCount( 1, $block->getRestrictions() );
+ $this->assertEquals( $title, $block->getRestrictions()[0]->getTitle()->getText() );
+ }
+
/**
* @expectedException ApiUsageException
* @expectedExceptionMessage The "token" parameter must be set
self::$users['sysop']->getUser()
);
}
+
+ /**
+ * @expectedException ApiUsageException
+ * @expectedExceptionMessage Invalid value "127.0.0.1/64" for user parameter "user".
+ */
+ public function testBlockWithLargeRange() {
+ $tokens = $this->getTokens();
+
+ $this->doApiRequest(
+ [
+ 'action' => 'block',
+ 'user' => '127.0.0.1/64',
+ 'reason' => 'Some reason',
+ 'token' => $tokens['blocktoken'],
+ ],
+ null,
+ false,
+ self::$users['sysop']->getUser()
+ );
+ }
+
+ /**
+ * @expectedException ApiUsageException
+ * @expectedExceptionMessage Too many values supplied for parameter "pagerestrictions". The
+ * limit is 10.
+ */
+ public function testBlockingToManyRestrictions() {
+ $this->setMwGlobals( [
+ 'wgEnablePartialBlocks' => true,
+ ] );
+
+ $tokens = $this->getTokens();
+
+ $this->doApiRequest(
+ [
+ 'action' => 'block',
+ 'user' => $this->mUser->getName(),
+ 'reason' => 'Some reason',
+ 'partial' => true,
+ 'pagerestrictions' => 'One|Two|Three|Four|Five|Six|Seven|Eight|Nine|Ten|Eleven',
+ 'token' => $tokens['blocktoken'],
+ ],
+ null,
+ false,
+ self::$users['sysop']->getUser()
+ );
+ }
}