Merge "Improved fail-over in ReplicatedBagOStuff for redis"
[lhc/web/wiklou.git] / tests / phpunit / includes / deferred / DeferredUpdatesTest.php
1 <?php
2
3 class DeferredUpdatesTest extends MediaWikiTestCase {
4 public function testDoUpdatesWeb() {
5 $this->setMwGlobals( 'wgCommandLineMode', false );
6
7 $updates = array(
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',
12 );
13 DeferredUpdates::addCallableUpdate(
14 function () use ( $updates ) {
15 echo $updates['1'];
16 }
17 );
18 DeferredUpdates::addCallableUpdate(
19 function () use ( $updates ) {
20 echo $updates['2'];
21 DeferredUpdates::addCallableUpdate(
22 function () use ( $updates ) {
23 echo $updates['2-1'];
24 }
25 );
26 }
27 );
28 DeferredUpdates::addCallableUpdate(
29 function () use ( $updates ) {
30 echo $updates[3];
31 }
32 );
33
34 $this->expectOutputString( implode( '', $updates ) );
35
36 DeferredUpdates::doUpdates();
37 }
38
39 public function testDoUpdatesCLI() {
40 $this->setMwGlobals( 'wgCommandLineMode', true );
41
42 $updates = array(
43 '1' => 'deferred update 1',
44 '2' => 'deferred update 2',
45 '2-1' => 'deferred update 1 within deferred update 2',
46 '3' => 'deferred update 3',
47 );
48 DeferredUpdates::addCallableUpdate(
49 function () use ( $updates ) {
50 echo $updates['1'];
51 }
52 );
53 DeferredUpdates::addCallableUpdate(
54 function () use ( $updates ) {
55 echo $updates['2'];
56 DeferredUpdates::addCallableUpdate(
57 function () use ( $updates ) {
58 echo $updates['2-1'];
59 }
60 );
61 }
62 );
63 DeferredUpdates::addCallableUpdate(
64 function () use ( $updates ) {
65 echo $updates[3];
66 }
67 );
68
69 $this->expectOutputString( implode( '', $updates ) );
70
71 DeferredUpdates::doUpdates();
72 }
73 }