Minor cleanup of languages/ConverterRule.php
[lhc/web/wiklou.git] / tests / phpunit / includes / api / ApiQueryInfoTest.php
1 <?php
2
3 /**
4 * @group API
5 * @group medium
6 * @group Database
7 *
8 * @coversDefaultClass ApiQueryInfo
9 */
10 class ApiQueryInfoTest extends ApiTestCase {
11
12 /**
13 * @covers ::execute
14 * @covers ::extractPageInfo
15 */
16 public function testExecute() {
17 $page = $this->getExistingTestPage( 'Pluto' );
18 $title = $page->getTitle();
19
20 list( $data ) = $this->doApiRequest( [
21 'action' => 'query',
22 'prop' => 'info',
23 'titles' => $title->getText(),
24 ] );
25
26 $this->assertArrayHasKey( 'query', $data );
27 $this->assertArrayHasKey( 'pages', $data['query'] );
28 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
29
30 $info = $data['query']['pages'][$page->getId()];
31 $this->assertSame( $page->getId(), $info['pageid'] );
32 $this->assertSame( $title->getNamespace(), $info['ns'] );
33 $this->assertSame( $title->getText(), $info['title'] );
34 $this->assertSame( $title->getContentModel(), $info['contentmodel'] );
35 $this->assertSame( $title->getPageLanguage()->getCode(), $info['pagelanguage'] );
36 $this->assertSame( $title->getPageLanguage()->getHtmlCode(), $info['pagelanguagehtmlcode'] );
37 $this->assertSame( $title->getPageLanguage()->getDir(), $info['pagelanguagedir'] );
38 $this->assertSame( wfTimestamp( TS_ISO_8601, $title->getTouched() ), $info['touched'] );
39 $this->assertSame( $title->getLatestRevID(), $info['lastrevid'] );
40 $this->assertSame( $title->getLength(), $info['length'] );
41 $this->assertSame( $title->isNewPage(), $info['new'] );
42 $this->assertArrayNotHasKey( 'actions', $info );
43 }
44
45 /**
46 * @covers ::execute
47 * @covers ::extractPageInfo
48 */
49 public function testExecuteEditActions() {
50 $page = $this->getExistingTestPage( 'Pluto' );
51 $title = $page->getTitle();
52
53 list( $data ) = $this->doApiRequest( [
54 'action' => 'query',
55 'prop' => 'info',
56 'titles' => $title->getText(),
57 'intestactions' => 'edit'
58 ] );
59
60 $this->assertArrayHasKey( 'query', $data );
61 $this->assertArrayHasKey( 'pages', $data['query'] );
62 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
63
64 $info = $data['query']['pages'][$page->getId()];
65 $this->assertArrayHasKey( 'actions', $info );
66 $this->assertArrayHasKey( 'edit', $info['actions'] );
67 $this->assertTrue( $info['actions']['edit'] );
68 }
69
70 /**
71 * @covers ::execute
72 * @covers ::extractPageInfo
73 */
74 public function testExecuteEditActionsFull() {
75 $page = $this->getExistingTestPage( 'Pluto' );
76 $title = $page->getTitle();
77
78 list( $data ) = $this->doApiRequest( [
79 'action' => 'query',
80 'prop' => 'info',
81 'titles' => $title->getText(),
82 'intestactions' => 'edit',
83 'intestactionsdetail' => 'full',
84 ] );
85
86 $this->assertArrayHasKey( 'query', $data );
87 $this->assertArrayHasKey( 'pages', $data['query'] );
88 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
89
90 $info = $data['query']['pages'][$page->getId()];
91 $this->assertArrayHasKey( 'actions', $info );
92 $this->assertArrayHasKey( 'edit', $info['actions'] );
93 $this->assertInternalType( 'array', $info['actions']['edit'] );
94 $this->assertSame( [], $info['actions']['edit'] );
95 }
96
97 /**
98 * @covers ::execute
99 * @covers ::extractPageInfo
100 */
101 public function testExecuteEditActionsFullBlock() {
102 $badActor = $this->getTestUser()->getUser();
103 $sysop = $this->getTestSysop()->getUser();
104
105 $block = new \Block( [
106 'address' => $badActor->getName(),
107 'user' => $badActor->getId(),
108 'by' => $sysop->getId(),
109 'expiry' => 'infinity',
110 'sitewide' => 0,
111 'enableAutoblock' => true,
112 ] );
113
114 $block->insert();
115
116 $page = $this->getExistingTestPage( 'Pluto' );
117 $title = $page->getTitle();
118
119 list( $data ) = $this->doApiRequest( [
120 'action' => 'query',
121 'prop' => 'info',
122 'titles' => $title->getText(),
123 'intestactions' => 'edit',
124 'intestactionsdetail' => 'full',
125 ], null, false, $badActor );
126
127 $block->delete();
128
129 $this->assertArrayHasKey( 'query', $data );
130 $this->assertArrayHasKey( 'pages', $data['query'] );
131 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
132
133 $info = $data['query']['pages'][$page->getId()];
134 $this->assertArrayHasKey( 'actions', $info );
135 $this->assertArrayHasKey( 'edit', $info['actions'] );
136 $this->assertInternalType( 'array', $info['actions']['edit'] );
137 $this->assertArrayHasKey( 0, $info['actions']['edit'] );
138 $this->assertArrayHasKey( 'code', $info['actions']['edit'][0] );
139 $this->assertSame( 'blocked', $info['actions']['edit'][0]['code'] );
140 $this->assertArrayHasKey( 'data', $info['actions']['edit'][0] );
141 $this->assertArrayHasKey( 'blockinfo', $info['actions']['edit'][0]['data'] );
142 $this->assertArrayHasKey( 'blockid', $info['actions']['edit'][0]['data']['blockinfo'] );
143 $this->assertSame( $block->getId(), $info['actions']['edit'][0]['data']['blockinfo']['blockid'] );
144 }
145
146 }