3aaad486e9adbd4d9512de85de0e1ae4fe725f61
8 * @coversDefaultClass ApiQueryInfo
10 class ApiQueryInfoTest
extends ApiTestCase
{
14 * @covers ::extractPageInfo
16 public function testExecute() {
17 $page = $this->getExistingTestPage( 'Pluto' );
18 $title = $page->getTitle();
20 list( $data ) = $this->doApiRequest( [
23 'titles' => $title->getText(),
26 $this->assertArrayHasKey( 'query', $data );
27 $this->assertArrayHasKey( 'pages', $data['query'] );
28 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
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 );
47 * @covers ::extractPageInfo
49 public function testExecuteEditActions() {
50 $page = $this->getExistingTestPage( 'Pluto' );
51 $title = $page->getTitle();
53 list( $data ) = $this->doApiRequest( [
56 'titles' => $title->getText(),
57 'intestactions' => 'edit'
60 $this->assertArrayHasKey( 'query', $data );
61 $this->assertArrayHasKey( 'pages', $data['query'] );
62 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
64 $info = $data['query']['pages'][$page->getId()];
65 $this->assertArrayHasKey( 'actions', $info );
66 $this->assertArrayHasKey( 'edit', $info['actions'] );
67 $this->assertTrue( $info['actions']['edit'] );
72 * @covers ::extractPageInfo
74 public function testExecuteEditActionsFull() {
75 $page = $this->getExistingTestPage( 'Pluto' );
76 $title = $page->getTitle();
78 list( $data ) = $this->doApiRequest( [
81 'titles' => $title->getText(),
82 'intestactions' => 'edit',
83 'intestactionsdetail' => 'full',
86 $this->assertArrayHasKey( 'query', $data );
87 $this->assertArrayHasKey( 'pages', $data['query'] );
88 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
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'] );
99 * @covers ::extractPageInfo
101 public function testExecuteEditActionsFullBlock() {
102 $badActor = $this->getTestUser()->getUser();
103 $sysop = $this->getTestSysop()->getUser();
105 $block = new \
Block( [
106 'address' => $badActor->getName(),
107 'user' => $badActor->getId(),
108 'by' => $sysop->getId(),
109 'expiry' => 'infinity',
111 'enableAutoblock' => true,
116 $page = $this->getExistingTestPage( 'Pluto' );
117 $title = $page->getTitle();
119 list( $data ) = $this->doApiRequest( [
122 'titles' => $title->getText(),
123 'intestactions' => 'edit',
124 'intestactionsdetail' => 'full',
125 ], null, false, $badActor );
129 $this->assertArrayHasKey( 'query', $data );
130 $this->assertArrayHasKey( 'pages', $data['query'] );
131 $this->assertArrayHasKey( $page->getId(), $data['query']['pages'] );
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'] );