Merge "Add checkDependencies.php"
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiQueryInfoTest.php
1 <?php
2
3 use MediaWiki\Block\DatabaseBlock;
4
5 /**
6 * @group API
7 * @group medium
8 * @group Database
9 *
10 * @coversDefaultClass ApiQueryInfo
11 */
12 class ApiQueryInfoTest extends ApiTestCase {
13
14 /**
15 * @covers ::execute
16 * @covers ::extractPageInfo
17 */
18 public function testExecute() {
19 $page = $this->getExistingTestPage( 'Pluto' );
20 $title = $page->getTitle();
21
22 list( $data ) = $this->doApiRequest( [
23 'action' => 'query',
24 'prop' => 'info',
25 'titles' => $title->getText(),
26 ] );
27
28 $this->assertArrayHasKey( 'query', $data );
29 $this->assertArrayHasKey( 'pages', $data['query'] );
30 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
31
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 );
45 }
46
47 /**
48 * @covers ::execute
49 * @covers ::extractPageInfo
50 */
51 public function testExecuteEditActions() {
52 $page = $this->getExistingTestPage( 'Pluto' );
53 $title = $page->getTitle();
54
55 list( $data ) = $this->doApiRequest( [
56 'action' => 'query',
57 'prop' => 'info',
58 'titles' => $title->getText(),
59 'intestactions' => 'edit'
60 ] );
61
62 $this->assertArrayHasKey( 'query', $data );
63 $this->assertArrayHasKey( 'pages', $data['query'] );
64 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
65
66 $info = $data['query']['pages'][$page->getId()];
67 $this->assertArrayHasKey( 'actions', $info );
68 $this->assertArrayHasKey( 'edit', $info['actions'] );
69 $this->assertTrue( $info['actions']['edit'] );
70 }
71
72 /**
73 * @covers ::execute
74 * @covers ::extractPageInfo
75 */
76 public function testExecuteEditActionsFull() {
77 $page = $this->getExistingTestPage( 'Pluto' );
78 $title = $page->getTitle();
79
80 list( $data ) = $this->doApiRequest( [
81 'action' => 'query',
82 'prop' => 'info',
83 'titles' => $title->getText(),
84 'intestactions' => 'edit',
85 'intestactionsdetail' => 'full',
86 ] );
87
88 $this->assertArrayHasKey( 'query', $data );
89 $this->assertArrayHasKey( 'pages', $data['query'] );
90 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
91
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'] );
97 }
98
99 /**
100 * @covers ::execute
101 * @covers ::extractPageInfo
102 */
103 public function testExecuteEditActionsFullBlock() {
104 $badActor = $this->getTestUser()->getUser();
105 $sysop = $this->getTestSysop()->getUser();
106
107 $block = new DatabaseBlock( [
108 'address' => $badActor->getName(),
109 'user' => $badActor->getId(),
110 'by' => $sysop->getId(),
111 'expiry' => 'infinity',
112 'sitewide' => 1,
113 'enableAutoblock' => true,
114 ] );
115
116 $block->insert();
117
118 $page = $this->getExistingTestPage( 'Pluto' );
119 $title = $page->getTitle();
120
121 list( $data ) = $this->doApiRequest( [
122 'action' => 'query',
123 'prop' => 'info',
124 'titles' => $title->getText(),
125 'intestactions' => 'edit',
126 'intestactionsdetail' => 'full',
127 ], null, false, $badActor );
128
129 $block->delete();
130
131 $this->assertArrayHasKey( 'query', $data );
132 $this->assertArrayHasKey( 'pages', $data['query'] );
133 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
134
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'] );
146 }
147
148 }