3 use MediaWiki\Block\Restriction\PageRestriction
;
10 * @covers ApiQueryBlocks
12 class ApiQueryBlocksTest
extends ApiTestCase
{
14 protected $tablesUsed = [
16 'ipblocks_restrictions',
19 public function testExecute() {
20 list( $data ) = $this->doApiRequest( [
24 $this->assertEquals( [ 'batchcomplete' => true, 'query' => [ 'blocks' => [] ] ], $data );
27 public function testExecuteBlock() {
28 $badActor = $this->getTestUser()->getUser();
29 $sysop = $this->getTestSysop()->getUser();
32 'address' => $badActor->getName(),
33 'user' => $badActor->getId(),
34 'by' => $sysop->getId(),
35 'expiry' => 'infinity',
40 list( $data ) = $this->doApiRequest( [
44 $this->arrayHasKey( 'query', $data );
45 $this->arrayHasKey( 'blocks', $data['query'] );
46 $this->assertCount( 1, $data['query']['blocks'] );
48 'id' => $block->getId(),
49 'user' => $badActor->getName(),
50 'expiry' => $block->getExpiry(),
52 $this->assertArraySubset( $subset, $data['query']['blocks'][0] );
55 public function testExecuteSitewide() {
56 $badActor = $this->getTestUser()->getUser();
57 $sysop = $this->getTestSysop()->getUser();
60 'address' => $badActor->getName(),
61 'user' => $badActor->getId(),
62 'by' => $sysop->getId(),
63 'ipb_expiry' => 'infinity',
69 list( $data ) = $this->doApiRequest( [
73 $this->arrayHasKey( 'query', $data );
74 $this->arrayHasKey( 'blocks', $data['query'] );
75 $this->assertCount( 1, $data['query']['blocks'] );
77 'id' => $block->getId(),
78 'user' => $badActor->getName(),
79 'expiry' => $block->getExpiry(),
80 'partial' => !$block->isSitewide(),
82 $this->assertArraySubset( $subset, $data['query']['blocks'][0] );
85 public function testExecuteRestrictions() {
86 $badActor = $this->getTestUser()->getUser();
87 $sysop = $this->getTestSysop()->getUser();
90 'address' => $badActor->getName(),
91 'user' => $badActor->getId(),
92 'by' => $sysop->getId(),
93 'expiry' => 'infinity',
100 'id' => $block->getId(),
101 'user' => $badActor->getName(),
102 'expiry' => $block->getExpiry(),
105 $title = 'Lady Macbeth';
106 $pageData = $this->insertPage( $title );
107 $pageId = $pageData['id'];
109 $this->db
->insert( 'ipblocks_restrictions', [
110 'ir_ipb_id' => $block->getId(),
111 'ir_type' => PageRestriction
::TYPE_ID
,
112 'ir_value' => $pageId,
114 $this->db
->insert( 'ipblocks_restrictions', [
115 'ir_ipb_id' => $block->getId(),
120 // Test without requesting restrictions.
121 list( $data ) = $this->doApiRequest( [
125 $this->arrayHasKey( 'query', $data );
126 $this->arrayHasKey( 'blocks', $data['query'] );
127 $this->assertCount( 1, $data['query']['blocks'] );
128 $flagSubset = array_merge( $subset, [
129 'partial' => !$block->isSitewide(),
131 $this->assertArraySubset( $flagSubset, $data['query']['blocks'][0] );
132 $this->assertArrayNotHasKey( 'restrictions', $data['query']['blocks'][0] );
134 // Test requesting the restrictions.
135 list( $data ) = $this->doApiRequest( [
138 'bkprop' => 'id|user|expiry|restrictions'
140 $this->arrayHasKey( 'query', $data );
141 $this->arrayHasKey( 'blocks', $data['query'] );
142 $this->assertCount( 1, $data['query']['blocks'] );
143 $restrictionsSubset = array_merge( $subset, [
154 $this->assertArraySubset( $restrictionsSubset, $data['query']['blocks'][0] );
155 $this->assertArrayNotHasKey( 'partial', $data['query']['blocks'][0] );