MediaWiki REL1_33
SiteStatsUpdateTest.php
Go to the documentation of this file.
1<?php
2
4
13 public function testFactoryAndMerge() {
14 $update1 = SiteStatsUpdate::factory( [ 'pages' => 1, 'users' => 2 ] );
15 $update2 = SiteStatsUpdate::factory( [ 'users' => 1, 'images' => 1 ] );
16
17 $update1->merge( $update2 );
18 $wrapped = TestingAccessWrapper::newFromObject( $update1 );
19
20 $this->assertEquals( 1, $wrapped->pages );
21 $this->assertEquals( 3, $wrapped->users );
22 $this->assertEquals( 1, $wrapped->images );
23 $this->assertEquals( 0, $wrapped->edits );
24 $this->assertEquals( 0, $wrapped->articles );
25 }
26
31 public function testDoUpdate() {
32 $this->setMwGlobals( 'wgSiteStatsAsyncFactor', false );
33 $this->setMwGlobals( 'wgCommandLineMode', false ); // disable opportunistic updates
34
35 $dbw = wfGetDB( DB_MASTER );
36 $statsInit = new SiteStatsInit( $dbw );
37 $statsInit->refresh();
38
39 $ei = SiteStats::edits(); // trigger load
40 $pi = SiteStats::pages();
41 $ui = SiteStats::users();
42 $fi = SiteStats::images();
43 $ai = SiteStats::articles();
44
45 $dbw->begin( __METHOD__ ); // block opportunistic updates
46
47 $update = SiteStatsUpdate::factory( [ 'pages' => 2, 'images' => 1, 'edits' => 2 ] );
48 $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount() );
49 $update->doUpdate();
50 $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
51
52 // Still the same
54 $this->assertEquals( $pi, SiteStats::pages(), 'page count' );
55 $this->assertEquals( $ei, SiteStats::edits(), 'edit count' );
56 $this->assertEquals( $ui, SiteStats::users(), 'user count' );
57 $this->assertEquals( $fi, SiteStats::images(), 'file count' );
58 $this->assertEquals( $ai, SiteStats::articles(), 'article count' );
59 $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
60
61 $dbw->commit( __METHOD__ );
62
63 $this->assertEquals( 1, DeferredUpdates::pendingUpdatesCount() );
64 DeferredUpdates::doUpdates();
65 $this->assertEquals( 0, DeferredUpdates::pendingUpdatesCount() );
66
68 $this->assertEquals( $pi + 2, SiteStats::pages(), 'page count' );
69 $this->assertEquals( $ei + 2, SiteStats::edits(), 'edit count' );
70 $this->assertEquals( $ui, SiteStats::users(), 'user count' );
71 $this->assertEquals( $fi + 1, SiteStats::images(), 'file count' );
72 $this->assertEquals( $ai, SiteStats::articles(), 'article count' );
73
74 $statsInit = new SiteStatsInit();
75 $statsInit->refresh();
76 }
77}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Class designed for counting of stats.
testFactoryAndMerge()
SiteStatsUpdate::factory SiteStatsUpdate::merge.
testDoUpdate()
SiteStatsUpdate::doUpdate() SiteStatsInit::refresh()
static articles()
static images()
static edits()
Definition SiteStats.php:94
static users()
static pages()
static unload()
Trigger a reload next time a field is accessed.
Definition SiteStats.php:38
const DB_MASTER
Definition defines.php:26