3 use MediaWiki\Block\DatabaseBlock
;
10 * @coversDefaultClass ApiQueryInfo
12 class ApiQueryInfoTest
extends ApiTestCase
{
16 * @covers ::extractPageInfo
18 public function testExecute() {
19 $page = $this->getExistingTestPage( 'Pluto' );
20 $title = $page->getTitle();
22 list( $data ) = $this->doApiRequest( [
25 'titles' => $title->getText(),
28 $this->assertArrayHasKey( 'query', $data );
29 $this->assertArrayHasKey( 'pages', $data['query'] );
30 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
32 $info = $data['query']['pages'][$page->getId()];
33 $this->assertSame( $page->getId(), $info['pageid'] );
34 $this->assertSame( $title->getNamespace(), $info['ns'] );
35 $this->assertSame( $title->getText(), $info['title'] );
36 $this->assertSame( $title->getContentModel(), $info['contentmodel'] );
37 $this->assertSame( $title->getPageLanguage()->getCode(), $info['pagelanguage'] );
38 $this->assertSame( $title->getPageLanguage()->getHtmlCode(), $info['pagelanguagehtmlcode'] );
39 $this->assertSame( $title->getPageLanguage()->getDir(), $info['pagelanguagedir'] );
40 $this->assertSame( wfTimestamp( TS_ISO_8601
, $title->getTouched() ), $info['touched'] );
41 $this->assertSame( $title->getLatestRevID(), $info['lastrevid'] );
42 $this->assertSame( $title->getLength(), $info['length'] );
43 $this->assertSame( $title->isNewPage(), $info['new'] );
44 $this->assertArrayNotHasKey( 'actions', $info );
49 * @covers ::extractPageInfo
51 public function testExecuteEditActions() {
52 $page = $this->getExistingTestPage( 'Pluto' );
53 $title = $page->getTitle();
55 list( $data ) = $this->doApiRequest( [
58 'titles' => $title->getText(),
59 'intestactions' => 'edit'
62 $this->assertArrayHasKey( 'query', $data );
63 $this->assertArrayHasKey( 'pages', $data['query'] );
64 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
66 $info = $data['query']['pages'][$page->getId()];
67 $this->assertArrayHasKey( 'actions', $info );
68 $this->assertArrayHasKey( 'edit', $info['actions'] );
69 $this->assertTrue( $info['actions']['edit'] );
74 * @covers ::extractPageInfo
76 public function testExecuteEditActionsFull() {
77 $page = $this->getExistingTestPage( 'Pluto' );
78 $title = $page->getTitle();
80 list( $data ) = $this->doApiRequest( [
83 'titles' => $title->getText(),
84 'intestactions' => 'edit',
85 'intestactionsdetail' => 'full',
88 $this->assertArrayHasKey( 'query', $data );
89 $this->assertArrayHasKey( 'pages', $data['query'] );
90 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
92 $info = $data['query']['pages'][$page->getId()];
93 $this->assertArrayHasKey( 'actions', $info );
94 $this->assertArrayHasKey( 'edit', $info['actions'] );
95 $this->assertInternalType( 'array', $info['actions']['edit'] );
96 $this->assertSame( [], $info['actions']['edit'] );
101 * @covers ::extractPageInfo
103 public function testExecuteEditActionsFullBlock() {
104 $badActor = $this->getTestUser()->getUser();
105 $sysop = $this->getTestSysop()->getUser();
107 $block = new DatabaseBlock( [
108 'address' => $badActor->getName(),
109 'user' => $badActor->getId(),
110 'by' => $sysop->getId(),
111 'expiry' => 'infinity',
113 'enableAutoblock' => true,
118 $page = $this->getExistingTestPage( 'Pluto' );
119 $title = $page->getTitle();
121 list( $data ) = $this->doApiRequest( [
124 'titles' => $title->getText(),
125 'intestactions' => 'edit',
126 'intestactionsdetail' => 'full',
127 ], null, false, $badActor );
131 $this->assertArrayHasKey( 'query', $data );
132 $this->assertArrayHasKey( 'pages', $data['query'] );
133 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
135 $info = $data['query']['pages'][$page->getId()];
136 $this->assertArrayHasKey( 'actions', $info );
137 $this->assertArrayHasKey( 'edit', $info['actions'] );
138 $this->assertInternalType( 'array', $info['actions']['edit'] );
139 $this->assertArrayHasKey( 0, $info['actions']['edit'] );
140 $this->assertArrayHasKey( 'code', $info['actions']['edit'][0] );
141 $this->assertSame( 'blocked', $info['actions']['edit'][0]['code'] );
142 $this->assertArrayHasKey( 'data', $info['actions']['edit'][0] );
143 $this->assertArrayHasKey( 'blockinfo', $info['actions']['edit'][0]['data'] );
144 $this->assertArrayHasKey( 'blockid', $info['actions']['edit'][0]['data']['blockinfo'] );
145 $this->assertSame( $block->getId(), $info['actions']['edit'][0]['data']['blockinfo']['blockid'] );