Merge "Add SVG versions of enhanced recent changes collapse/show arrows"
[lhc/web/wiklou.git] / tests / phpunit / includes / db / LBFactoryTest.php
1 <?php
2 /**
3 * Holds tests for LBFactory abstract MediaWiki class.
4 *
5 * @section LICENSE
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @author Antoine Musso
23 * @copyright © 2013 Antoine Musso
24 * @copyright © 2013 Wikimedia Foundation Inc.
25 */
26
27 class FakeLBFactory extends LBFactory {
28 function __construct( $conf ) {}
29 function newMainLB( $wiki = false ) {}
30 function getMainLB( $wiki = false ) {}
31 function newExternalLB( $cluster, $wiki = false ) {}
32 function &getExternalLB( $cluster, $wiki = false ) {}
33 function forEachLB( $callback, $params = array() ) {}
34 }
35
36 class LBFactoryTest extends MediaWikiTestCase {
37
38 function setup() {
39 parent::setup();
40 FakeLBFactory::destroyInstance();
41 }
42
43 /**
44 * @dataProvider provideDeprecatedLbfactoryClasses
45 */
46 function testLbfactoryClassBackcompatibility( $expected, $deprecated ) {
47 $mockDB = $this->getMockBuilder( 'DatabaseMysql' )
48 -> disableOriginalConstructor()
49 ->getMock();
50 $this->setMwGlobals( 'wgLBFactoryConf',
51 array(
52 'class' => $deprecated,
53 'connection' => $mockDB,
54 # Various other parameters required:
55 'sectionsByDB' => array(),
56 'sectionLoads' => array(),
57 'serverTemplate' => array(),
58 )
59 );
60
61 global $wgLBFactoryConf;
62 $this->assertArrayHasKey( 'class', $wgLBFactoryConf );
63 $this->assertEquals( $wgLBFactoryConf['class'], $deprecated );
64
65 # The point of this test is to call a deprecated interface and make
66 # sure it keeps back compatibility, so skip the deprecation warning.
67 $this->hideDeprecated( '$wgLBFactoryConf must be updated. See RELEASE-NOTES for details' );
68 $lbfactory = FakeLBFactory::singleton();
69 $this->assertInstanceOf( $expected, $lbfactory,
70 "LBFactory passed $deprecated should yield the new class $expected" );
71 }
72
73 function provideDeprecatedLbfactoryClasses() {
74 return array(
75 # Format: new class, old class
76 array( 'LBFactorySimple', 'LBFactory_Simple' ),
77 array( 'LBFactorySingle', 'LBFactory_Single' ),
78 array( 'LBFactoryMulti', 'LBFactory_Multi' ),
79 array( 'LBFactoryFake', 'LBFactory_Fake' ),
80 );
81 }
82 }