MediaWiki REL1_30
PagePropsTest.php
Go to the documentation of this file.
1<?php
2
11
15 private $title1;
16
20 private $title2;
21
26
27 protected function setUp() {
29
30 parent::setUp();
31
32 $wgExtraNamespaces[12312] = 'Dummy';
33 $wgExtraNamespaces[12313] = 'Dummy_talk';
34
35 $wgNamespaceContentModels[12312] = 'DUMMY';
36 $wgContentHandlers['DUMMY'] = 'DummyContentHandlerForTesting';
37
38 MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
39 $wgContLang->resetNamespaces(); # reset namespace cache
40
41 if ( !$this->the_properties ) {
42 $this->the_properties = [
43 "property1" => "value1",
44 "property2" => "value2",
45 "property3" => "value3",
46 "property4" => "value4"
47 ];
48 }
49
50 if ( !$this->title1 ) {
51 $page = $this->createPage(
52 'PagePropsTest_page_1',
53 "just a dummy page",
55 );
56 $this->title1 = $page->getTitle();
57 $page1ID = $this->title1->getArticleID();
58 $this->setProperties( $page1ID, $this->the_properties );
59 }
60
61 if ( !$this->title2 ) {
62 $page = $this->createPage(
63 'PagePropsTest_page_2',
64 "just a dummy page",
66 );
67 $this->title2 = $page->getTitle();
68 $page2ID = $this->title2->getArticleID();
69 $this->setProperties( $page2ID, $this->the_properties );
70 }
71 }
72
73 protected function tearDown() {
75
76 parent::tearDown();
77
78 unset( $wgExtraNamespaces[12312] );
79 unset( $wgExtraNamespaces[12313] );
80
81 unset( $wgNamespaceContentModels[12312] );
82 unset( $wgContentHandlers['DUMMY'] );
83
84 MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache
85 $wgContLang->resetNamespaces(); # reset namespace cache
86 }
87
93 $pageProps = PageProps::getInstance();
94 $page1ID = $this->title1->getArticleID();
95 $result = $pageProps->getProperties( $this->title1, "property1" );
96 $this->assertArrayHasKey( $page1ID, $result, "Found property" );
97 $this->assertEquals( $result[$page1ID], "value1", "Get property" );
98 }
99
105 $pageProps = PageProps::getInstance();
106 $page1ID = $this->title1->getArticleID();
107 $page2ID = $this->title2->getArticleID();
108 $titles = [
111 ];
112 $result = $pageProps->getProperties( $titles, "property1" );
113 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
114 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
115 $this->assertEquals( $result[$page1ID], "value1", "Get property page 1" );
116 $this->assertEquals( $result[$page2ID], "value1", "Get property page 2" );
117 }
118
124 $pageProps = PageProps::getInstance();
125 $page1ID = $this->title1->getArticleID();
126 $page2ID = $this->title2->getArticleID();
127 $titles = [
130 ];
131 $properties = [
132 "property1",
133 "property2"
134 ];
135 $result = $pageProps->getProperties( $titles, $properties );
136 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 property" );
137 $this->assertArrayHasKey( "property1", $result[$page1ID], "Found page 1 property 1" );
138 $this->assertArrayHasKey( "property2", $result[$page1ID], "Found page 1 property 2" );
139 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 property" );
140 $this->assertArrayHasKey( "property1", $result[$page2ID], "Found page 2 property 1" );
141 $this->assertArrayHasKey( "property2", $result[$page2ID], "Found page 2 property 2" );
142 $this->assertEquals( $result[$page1ID]["property1"], "value1", "Get page 1 property 1" );
143 $this->assertEquals( $result[$page1ID]["property2"], "value2", "Get page 1 property 2" );
144 $this->assertEquals( $result[$page2ID]["property1"], "value1", "Get page 2 property 1" );
145 $this->assertEquals( $result[$page2ID]["property2"], "value2", "Get page 2 property 2" );
146 }
147
159 public function testGetAllProperties() {
160 $pageProps = PageProps::getInstance();
161 $page1ID = $this->title1->getArticleID();
162 $result = $pageProps->getAllProperties( $this->title1 );
163 $this->assertArrayHasKey( $page1ID, $result, "Found properties" );
164 $properties = $result[$page1ID];
165 $patched = array_replace_recursive( $properties, $this->the_properties );
166 $this->assertEquals( $patched, $properties, "Get all properties" );
167 }
168
174 $pageProps = PageProps::getInstance();
175 $page1ID = $this->title1->getArticleID();
176 $page2ID = $this->title2->getArticleID();
177 $titles = [
180 ];
181 $result = $pageProps->getAllProperties( $titles );
182 $this->assertArrayHasKey( $page1ID, $result, "Found page 1 properties" );
183 $this->assertArrayHasKey( $page2ID, $result, "Found page 2 properties" );
184 $properties1 = $result[$page1ID];
185 $patched = array_replace_recursive( $properties1, $this->the_properties );
186 $this->assertEquals( $patched, $properties1, "Get all properties page 1" );
187 $properties2 = $result[$page2ID];
188 $patched = array_replace_recursive( $properties2, $this->the_properties );
189 $this->assertEquals( $patched, $properties2, "Get all properties page 2" );
190 }
191
198 public function testSingleCache() {
199 $pageProps = PageProps::getInstance();
200 $page1ID = $this->title1->getArticleID();
201 $value1 = $pageProps->getProperties( $this->title1, "property1" );
202 $this->setProperty( $page1ID, "property1", "another value" );
203 $value2 = $pageProps->getProperties( $this->title1, "property1" );
204 $this->assertEquals( $value1, $value2, "Single cache" );
205 }
206
213 public function testMultiCache() {
214 $pageProps = PageProps::getInstance();
215 $page1ID = $this->title1->getArticleID();
216 $properties1 = $pageProps->getAllProperties( $this->title1 );
217 $this->setProperty( $page1ID, "property1", "another value" );
218 $properties2 = $pageProps->getAllProperties( $this->title1 );
219 $this->assertEquals( $properties1, $properties2, "Multi Cache" );
220 }
221
230 public function testClearCache() {
231 $pageProps = PageProps::getInstance();
232 $page1ID = $this->title1->getArticleID();
233 $pageProps->getProperties( $this->title1, "property1" );
234 $new_value = "another value";
235 $this->setProperty( $page1ID, "property1", $new_value );
236 $pageProps->getAllProperties( $this->title1 );
237 $result = $pageProps->getProperties( $this->title1, "property1" );
238 $this->assertArrayHasKey( $page1ID, $result, "Found property" );
239 $this->assertEquals( $result[$page1ID], "another value", "Clear cache" );
240 }
241
242 protected function createPage( $page, $text, $model = null ) {
243 if ( is_string( $page ) ) {
244 if ( !preg_match( '/:/', $page ) &&
245 ( $model === null || $model === CONTENT_MODEL_WIKITEXT )
246 ) {
247 $ns = $this->getDefaultWikitextNS();
248 $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page;
249 }
250
251 $page = Title::newFromText( $page );
252 }
253
254 if ( $page instanceof Title ) {
255 $page = new WikiPage( $page );
256 }
257
258 if ( $page->exists() ) {
259 $page->doDeleteArticle( "done" );
260 }
261
262 $content = ContentHandler::makeContent( $text, $page->getTitle(), $model );
263 $page->doEditContent( $content, "testing", EDIT_NEW );
264
265 return $page;
266 }
267
268 protected function setProperties( $pageID, $properties ) {
269 $rows = [];
270
271 foreach ( $properties as $propertyName => $propertyValue ) {
272 $row = [
273 'pp_page' => $pageID,
274 'pp_propname' => $propertyName,
275 'pp_value' => $propertyValue
276 ];
277
278 $rows[] = $row;
279 }
280
281 $dbw = wfGetDB( DB_MASTER );
282 $dbw->replace(
283 'page_props',
284 [
285 [
286 'pp_page',
287 'pp_propname'
288 ]
289 ],
290 $rows,
291 __METHOD__
292 );
293 }
294
295 protected function setProperty( $pageID, $propertyName, $propertyValue ) {
296 $properties = [];
297 $properties[$propertyName] = $propertyValue;
298
299 $this->setProperties( $pageID, $properties );
300 }
301}
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.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
Base class that store and restore the Language objects.
getDefaultWikitextNS()
Returns the ID of a namespace that defaults to Wikitext.
static getInstance()
Definition PageProps.php:66
Database ^— tell jenkins this test needs the database.
testGetAllProperties()
Test getting all properties from a single page.
testMultiCache()
Test caching when retrieving all properties by getting all properties, saving a new value for a prope...
testGetAllPropertiesMultiplePages()
Test getting all properties from multiple pages.
testGetSingleProperty()
Test getting a single property from a single page.
createPage( $page, $text, $model=null)
setProperty( $pageID, $propertyName, $propertyValue)
testClearCache()
Test that getting all properties clears the single properties that have been cached by getting a prop...
setProperties( $pageID, $properties)
testSingleCache()
Test caching when retrieving single properties by getting a property, saving a new value for the prop...
testGetSinglePropertyMultiplePages()
Test getting a single property from multiple pages.
testGetMultiplePropertiesMultiplePages()
Test getting multiple properties from multiple pages.
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:2746
const CONTENT_MODEL_WIKITEXT
Definition Defines.php:236
const EDIT_NEW
Definition Defines.php:153
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:26