Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / tests / phpunit / includes / deferred / DeferredUpdatesTest.php
blob4227693a2e8f54dacc077a442b83efa6f1b8cb04
1 <?php
3 class DeferredUpdatesTest extends MediaWikiTestCase {
4 public function testDoUpdatesWeb() {
5 $this->setMwGlobals( 'wgCommandLineMode', false );
7 $updates = [
8 '1' => "deferred update 1;\n",
9 '2' => "deferred update 2;\n",
10 '2-1' => "deferred update 1 within deferred update 2;\n",
11 '2-2' => "deferred update 2 within deferred update 2;\n",
12 '3' => "deferred update 3;\n",
13 '3-1' => "deferred update 1 within deferred update 3;\n",
14 '3-2' => "deferred update 2 within deferred update 3;\n",
15 '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
16 '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
18 DeferredUpdates::addCallableUpdate(
19 function () use ( $updates ) {
20 echo $updates['1'];
23 DeferredUpdates::addCallableUpdate(
24 function () use ( $updates ) {
25 echo $updates['2'];
26 DeferredUpdates::addCallableUpdate(
27 function () use ( $updates ) {
28 echo $updates['2-1'];
31 DeferredUpdates::addCallableUpdate(
32 function () use ( $updates ) {
33 echo $updates['2-2'];
38 DeferredUpdates::addCallableUpdate(
39 function () use ( $updates ) {
40 echo $updates['3'];
41 DeferredUpdates::addCallableUpdate(
42 function () use ( $updates ) {
43 echo $updates['3-1'];
44 DeferredUpdates::addCallableUpdate(
45 function () use ( $updates ) {
46 echo $updates['3-1-1'];
51 DeferredUpdates::addCallableUpdate(
52 function () use ( $updates ) {
53 echo $updates['3-2'];
54 DeferredUpdates::addCallableUpdate(
55 function () use ( $updates ) {
56 echo $updates['3-2-1'];
64 $this->assertEquals( 3, DeferredUpdates::pendingUpdatesCount() );
66 $this->expectOutputString( implode( '', $updates ) );
68 DeferredUpdates::doUpdates();
70 $x = null;
71 $y = null;
72 DeferredUpdates::addCallableUpdate(
73 function () use ( &$x ) {
74 $x = 'Sherity';
76 DeferredUpdates::PRESEND
78 DeferredUpdates::addCallableUpdate(
79 function () use ( &$y ) {
80 $y = 'Marychu';
82 DeferredUpdates::POSTSEND
85 $this->assertNull( $x, "Update not run yet" );
86 $this->assertNull( $y, "Update not run yet" );
88 DeferredUpdates::doUpdates( 'run', DeferredUpdates::PRESEND );
89 $this->assertEquals( "Sherity", $x, "PRESEND update ran" );
90 $this->assertNull( $y, "POSTSEND update not run yet" );
92 DeferredUpdates::doUpdates( 'run', DeferredUpdates::POSTSEND );
93 $this->assertEquals( "Marychu", $y, "POSTSEND update ran" );
96 public function testDoUpdatesCLI() {
97 $this->setMwGlobals( 'wgCommandLineMode', true );
98 $updates = [
99 '1' => "deferred update 1;\n",
100 '2' => "deferred update 2;\n",
101 '2-1' => "deferred update 1 within deferred update 2;\n",
102 '2-2' => "deferred update 2 within deferred update 2;\n",
103 '3' => "deferred update 3;\n",
104 '3-1' => "deferred update 1 within deferred update 3;\n",
105 '3-2' => "deferred update 2 within deferred update 3;\n",
106 '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n",
107 '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n",
110 wfGetLBFactory()->commitMasterChanges( __METHOD__ ); // clear anything
112 DeferredUpdates::addCallableUpdate(
113 function () use ( $updates ) {
114 echo $updates['1'];
117 DeferredUpdates::addCallableUpdate(
118 function () use ( $updates ) {
119 echo $updates['2'];
120 DeferredUpdates::addCallableUpdate(
121 function () use ( $updates ) {
122 echo $updates['2-1'];
125 DeferredUpdates::addCallableUpdate(
126 function () use ( $updates ) {
127 echo $updates['2-2'];
132 DeferredUpdates::addCallableUpdate(
133 function () use ( $updates ) {
134 echo $updates['3'];
135 DeferredUpdates::addCallableUpdate(
136 function () use ( $updates ) {
137 echo $updates['3-1'];
138 DeferredUpdates::addCallableUpdate(
139 function () use ( $updates ) {
140 echo $updates['3-1-1'];
145 DeferredUpdates::addCallableUpdate(
146 function () use ( $updates ) {
147 echo $updates['3-2'];
148 DeferredUpdates::addCallableUpdate(
149 function () use ( $updates ) {
150 echo $updates['3-2-1'];
158 $this->expectOutputString( implode( '', $updates ) );
160 DeferredUpdates::doUpdates();