MediaWiki REL1_31
SiteStatsUpdateTest.php
Go to the documentation of this file.
1<?php
2
3use Wikimedia\TestingAccessWrapper;
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}
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 factory(array $deltas)
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:29