MediaWiki REL1_33
ApiQueryInfoTest.php
Go to the documentation of this file.
1<?php
2
11
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
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
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
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' => 1,
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}
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
API medium Database.
testExecute()
execute ::extractPageInfo
testExecuteEditActionsFull()
execute ::extractPageInfo
testExecuteEditActionsFullBlock()
execute ::extractPageInfo
testExecuteEditActions()
execute ::extractPageInfo
doApiRequest(array $params, array $session=null, $appendModule=false, User $user=null, $tokenType=null)
Does the API request and returns the result.
getExistingTestPage( $title=null)
Returns a WikiPage representing an existing page.
static getTestSysop()
Convenience method for getting an immutable admin test user.
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
namespace and then decline to actually register it file or subcat img or subcat $title
Definition hooks.txt:955
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37