MediaWiki REL1_31
PagePropsTest.php
Go to the documentation of this file.
1<?php
2
13
17 private $title1;
18
22 private $title2;
23
28
29 protected function setUp() {
31
32 parent::setUp();
33
34 $wgExtraNamespaces[12312] = 'Dummy';
35 $wgExtraNamespaces[12313] = 'Dummy_talk';
36
37 $wgNamespaceContentModels[12312] = 'DUMMY';
38 $wgContentHandlers['DUMMY'] = 'DummyContentHandlerForTesting';
39
40 MWNamespace::clearCaches();
41 $wgContLang->resetNamespaces(); # reset namespace cache
42
43 if ( !$this->the_properties ) {
44 $this->the_properties = [
45 "property1" => "value1",
46 "property2" => "value2",
47 "property3" => "value3",
48 "property4" => "value4"
49 ];
50 }
51
52 if ( !$this->title1 ) {
53 $page = $this->createPage(
54 'PagePropsTest_page_1',
55 "just a dummy page",
57 );
58 $this->title1 = $page->getTitle();
59 $page1ID = $this->title1->getArticleID();
60 $this->setProperties( $page1ID, $this->the_properties );
61 }
62
63 if ( !$this->title2 ) {
64 $page = $this->createPage(
65 'PagePropsTest_page_2',
66 "just a dummy page",
68 );
69 $this->title2 = $page->getTitle();
70 $page2ID = $this->title2->getArticleID();
71 $this->setProperties( $page2ID, $this->the_properties );
72 }
73 }
74
75 protected function tearDown() {
77
78 parent::tearDown();
79
80 unset( $wgExtraNamespaces[12312] );
81 unset( $wgExtraNamespaces[12313] );
82
83 unset( $wgNamespaceContentModels[12312] );
84 unset( $wgContentHandlers['DUMMY'] );
85
86 MWNamespace::clearCaches();
87 $wgContLang->resetNamespaces(); # reset namespace cache
88 }
89
95 $pageProps = PageProps::getInstance();
96 $page1ID = $this->title1->getArticleID();
97 $result = $pageProps->getProperties( $this->title1, "property1" );
98 $this->assertArrayHasKey( $page1ID, $result, "Found property" );
99 $this->assertEquals( $result[$page1ID], "value1", "Get property" );
100 }
101
107 $pageProps = PageProps::getInstance();
108 $page1ID = $this->title1->getArticleID();
109 $page2ID = $this->title2->getArticleID();
110 $titles = [
113 ];
114 $result = $pageProps->getProperties( $titles, "property1" );
115 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
116 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
117 $this->assertEquals( $result[$page1ID], "value1", "Get property page 1" );
118 $this->assertEquals( $result[$page2ID], "value1", "Get property page 2" );
119 }
120
126 $pageProps = PageProps::getInstance();
127 $page1ID = $this->title1->getArticleID();
128 $page2ID = $this->title2->getArticleID();
129 $titles = [
132 ];
133 $properties = [
134 "property1",
135 "property2"
136 ];
137 $result = $pageProps->getProperties( $titles, $properties );
138 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
139 $this->assertArrayHasKey( "property1", $result[$page1ID], "Found page 1 property 1" );
140 $this->assertArrayHasKey( "property2", $result[$page1ID], "Found page 1 property 2" );
141 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
142 $this->assertArrayHasKey( "property1", $result[$page2ID], "Found page 2 property 1" );
143 $this->assertArrayHasKey( "property2", $result[$page2ID], "Found page 2 property 2" );
144 $this->assertEquals( $result[$page1ID]["property1"], "value1", "Get page 1 property 1" );
145 $this->assertEquals( $result[$page1ID]["property2"], "value2", "Get page 1 property 2" );
146 $this->assertEquals( $result[$page2ID]["property1"], "value1", "Get page 2 property 1" );
147 $this->assertEquals( $result[$page2ID]["property2"], "value2", "Get page 2 property 2" );
148 }
149
161 public function testGetAllProperties() {
162 $pageProps = PageProps::getInstance();
163 $page1ID = $this->title1->getArticleID();
164 $result = $pageProps->getAllProperties( $this->title1 );
165 $this->assertArrayHasKey( $page1ID, $result, "Found properties" );
166 $properties = $result[$page1ID];
167 $patched = array_replace_recursive( $properties, $this->the_properties );
168 $this->assertEquals( $patched, $properties, "Get all properties" );
169 }
170
176 $pageProps = PageProps::getInstance();
177 $page1ID = $this->title1->getArticleID();
178 $page2ID = $this->title2->getArticleID();
179 $titles = [
182 ];
183 $result = $pageProps->getAllProperties( $titles );
184 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 properties" );
185 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 properties" );
186 $properties1 = $result[$page1ID];
187 $patched = array_replace_recursive( $properties1, $this->the_properties );
188 $this->assertEquals( $patched, $properties1, "Get all properties page 1" );
189 $properties2 = $result[$page2ID];
190 $patched = array_replace_recursive( $properties2, $this->the_properties );
191 $this->assertEquals( $patched, $properties2, "Get all properties page 2" );
192 }
193
200 public function testSingleCache() {
201 $pageProps = PageProps::getInstance();
202 $page1ID = $this->title1->getArticleID();
203 $value1 = $pageProps->getProperties( $this->title1, "property1" );
204 $this->setProperty( $page1ID, "property1", "another value" );
205 $value2 = $pageProps->getProperties( $this->title1, "property1" );
206 $this->assertEquals( $value1, $value2, "Single cache" );
207 }
208
215 public function testMultiCache() {
216 $pageProps = PageProps::getInstance();
217 $page1ID = $this->title1->getArticleID();
218 $properties1 = $pageProps->getAllProperties( $this->title1 );
219 $this->setProperty( $page1ID, "property1", "another value" );
220 $properties2 = $pageProps->getAllProperties( $this->title1 );
221 $this->assertEquals( $properties1, $properties2, "Multi Cache" );
222 }
223
232 public function testClearCache() {
233 $pageProps = PageProps::getInstance();
234 $page1ID = $this->title1->getArticleID();
235 $pageProps->getProperties( $this->title1, "property1" );
236 $new_value = "another value";
237 $this->setProperty( $page1ID, "property1", $new_value );
238 $pageProps->getAllProperties( $this->title1 );
239 $result = $pageProps->getProperties( $this->title1, "property1" );
240 $this->assertArrayHasKey( $page1ID, $result, "Found property" );
241 $this->assertEquals( $result[$page1ID], "another value", "Clear cache" );
242 }
243
244 protected function createPage( $page, $text, $model = null ) {
245 if ( is_string( $page ) ) {
246 if ( !preg_match( '/:/', $page ) &&
247 ( $model === null || $model === CONTENT_MODEL_WIKITEXT )
248 ) {
249 $ns = $this->getDefaultWikitextNS();
250 $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page;
251 }
252
253 $page = Title::newFromText( $page );
254 }
255
256 if ( $page instanceof Title ) {
257 $page = new WikiPage( $page );
258 }
259
260 if ( $page->exists() ) {
261 $page->doDeleteArticle( "done" );
262 }
263
264 $content = ContentHandler::makeContent( $text, $page->getTitle(), $model );
265 $page->doEditContent( $content, "testing", EDIT_NEW );
266
267 return $page;
268 }
269
270 protected function setProperties( $pageID, $properties ) {
271 $rows = [];
272
273 foreach ( $properties as $propertyName => $propertyValue ) {
274 $row = [
275 'pp_page' => $pageID,
276 'pp_propname' => $propertyName,
277 'pp_value' => $propertyValue
278 ];
279
280 $rows[] = $row;
281 }
282
283 $dbw = wfGetDB( DB_MASTER );
284 $dbw->replace(
285 'page_props',
286 [
287 [
288 'pp_page',
289 'pp_propname'
290 ]
291 ],
292 $rows,
293 __METHOD__
294 );
295 }
296
297 protected function setProperty( $pageID, $propertyName, $propertyValue ) {
298 $properties = [];
299 $properties[$propertyName] = $propertyValue;
300
301 $this->setProperties( $pageID, $properties );
302 }
303}
we sometimes make exceptions for this Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally NO WARRANTY BECAUSE THE PROGRAM IS LICENSED FREE OF THERE IS NO WARRANTY FOR THE TO THE EXTENT PERMITTED BY APPLICABLE LAW EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND OR OTHER PARTIES PROVIDE THE PROGRAM AS IS WITHOUT WARRANTY OF ANY EITHER EXPRESSED OR BUT NOT LIMITED THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU SHOULD THE PROGRAM PROVE YOU ASSUME THE COST OF ALL NECESSARY REPAIR OR CORRECTION IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT OR ANY OTHER PARTY WHO MAY MODIFY AND OR REDISTRIBUTE THE PROGRAM AS PERMITTED BE LIABLE TO YOU FOR INCLUDING ANY INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new and you want it to be of the greatest possible use to the public
Definition COPYING.txt:285
$wgExtraNamespaces
Additional namespaces.
$wgNamespaceContentModels
Associative array mapping namespace IDs to the name of the content model pages in that namespace shou...
$wgContentHandlers
Plugins for page content model handling.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Base class that store and restore the Language objects.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
testClearCache()
Test that getting all properties clears the single properties that have been cached by getting a prop...
testGetSinglePropertyMultiplePages()
Test getting a single property from multiple pages.
setProperty( $pageID, $propertyName, $propertyValue)
testMultiCache()
Test caching when retrieving all properties by getting all properties, saving a new value for a prope...
setProperties( $pageID, $properties)
testGetMultiplePropertiesMultiplePages()
Test getting multiple properties from multiple pages.
testGetAllProperties()
Test getting all properties from a single page.
testGetSingleProperty()
Test getting a single property from a single page.
createPage( $page, $text, $model=null)
testSingleCache()
Test caching when retrieving single properties by getting a property, saving a new value for the prop...
testGetAllPropertiesMultiplePages()
Test getting all properties from multiple pages.
static getInstance()
Definition PageProps.php:66
Represents a title within MediaWiki.
Definition Title.php:39
Class representing a MediaWiki article and history.
Definition WikiPage.php:37
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
when a variable name is used in a function
Definition design.txt:94
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
Definition hooks.txt:2783
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:245
const EDIT_NEW
Definition Defines.php:162
linkcache txt The LinkCache class maintains a list of article titles and the information about whether or not the article exists in the database This is used to mark up links when displaying a page If the same link appears more than once on any page then it only has to be looked up once In most cases link lookups are done in batches with the LinkBatch class or the equivalent in so the link cache is mostly useful for short snippets of parsed and for links in the navigation areas of the skin The link cache was formerly used to track links used in a document for the purposes of updating the link tables This application is now deprecated To create a you can use the following $titles
Definition linkcache.txt:17
you have access to all of the normal MediaWiki so you can get a DB use the cache
const DB_MASTER
Definition defines.php:29