3 class DeferredUpdatesTest
extends MediaWikiTestCase
{
4 public function testDoUpdatesWeb() {
5 $this->setMwGlobals( 'wgCommandLineMode', false );
8 '1' => 'deferred update 1',
9 '2' => 'deferred update 2',
10 '3' => 'deferred update 3',
11 '2-1' => 'deferred update 1 within deferred update 2',
13 DeferredUpdates
::addCallableUpdate(
14 function () use ( $updates ) {
18 DeferredUpdates
::addCallableUpdate(
19 function () use ( $updates ) {
21 DeferredUpdates
::addCallableUpdate(
22 function () use ( $updates ) {
28 DeferredUpdates
::addCallableUpdate(
29 function () use ( $updates ) {
34 $this->expectOutputString( implode( '', $updates ) );
36 DeferredUpdates
::doUpdates();
40 DeferredUpdates
::addCallableUpdate(
41 function () use ( &$x ) {
44 DeferredUpdates
::PRESEND
46 DeferredUpdates
::addCallableUpdate(
47 function () use ( &$y ) {
50 DeferredUpdates
::POSTSEND
53 $this->assertNull( $x, "Update not run yet" );
54 $this->assertNull( $y, "Update not run yet" );
56 DeferredUpdates
::doUpdates( 'run', DeferredUpdates
::PRESEND
);
57 $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
58 $this->assertNull( $y, "POSTSEND update not run yet" );
60 DeferredUpdates
::doUpdates( 'run', DeferredUpdates
::POSTSEND
);
61 $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
64 public function testDoUpdatesCLI() {
65 $this->setMwGlobals( 'wgCommandLineMode', true );
68 '1' => 'deferred update 1',
69 '2' => 'deferred update 2',
70 '2-1' => 'deferred update 1 within deferred update 2',
71 '3' => 'deferred update 3',
73 DeferredUpdates
::addCallableUpdate(
74 function () use ( $updates ) {
78 DeferredUpdates
::addCallableUpdate(
79 function () use ( $updates ) {
81 DeferredUpdates
::addCallableUpdate(
82 function () use ( $updates ) {
88 DeferredUpdates
::addCallableUpdate(
89 function () use ( $updates ) {
94 $this->expectOutputString( implode( '', $updates ) );
96 DeferredUpdates
::doUpdates();