X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Ftests%2FMediaWikiTestCaseTest.php;h=964180259722ae0a8009977b12144af71f37f3b8;hb=8b10eb6a8d7c5eeb773df8c3050a450889fe3c1c;hp=599b733e05a72932af961c81a02e315992e19a78;hpb=95e140cb71a8733d6e6cec9138908d00e192e93c;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/tests/MediaWikiTestCaseTest.php b/tests/phpunit/tests/MediaWikiTestCaseTest.php index 599b733e05..9641802597 100644 --- a/tests/phpunit/tests/MediaWikiTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiTestCaseTest.php @@ -1,4 +1,5 @@ hideDeprecated( 'MediaWikiTestCase::stashMwGlobals' ); - $this->stashMwGlobals( $globalKey ); - $GLOBALS[$globalKey] = $newValue; - $this->assertEquals( - $newValue, - $GLOBALS[$globalKey], - 'Global failed to correctly set' - ); - - $this->tearDown(); - - $this->assertEquals( - self::$startGlobals[$globalKey], - $GLOBALS[$globalKey], - 'Global failed to be restored on tearDown' - ); - } - - /** - * @covers MediaWikiTestCase::stashMwGlobals + * @covers MediaWikiTestCase::setMwGlobals * @covers MediaWikiTestCase::tearDown */ public function testSetNonExistentGlobalsAreUnsetOnTearDown() { @@ -173,4 +150,38 @@ class MediaWikiTestCaseTest extends MediaWikiTestCase { $this->assertSame( $logger1, $logger2 ); } + + /** + * @covers MediaWikiTestCase::setupDatabaseWithTestPrefix + * @covers MediaWikiTestCase::copyTestData + */ + public function testCopyTestData() { + $this->markTestSkippedIfDbType( 'sqlite' ); + + $this->tablesUsed[] = 'objectcache'; + $this->db->insert( + 'objectcache', + [ 'keyname' => __METHOD__, 'value' => 'TEST', 'exptime' => $this->db->timestamp( 11 ) ], + __METHOD__ + ); + + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lb = $lbFactory->newMainLB(); + $db = $lb->getConnection( DB_REPLICA, DBO_TRX ); + + // sanity + $this->assertNotSame( $this->db, $db ); + + // Make sure the DB connection has the fake table clones and the fake table prefix + MediaWikiTestCase::setupDatabaseWithTestPrefix( $db, $this->dbPrefix(), false ); + + $this->assertSame( $this->db->tablePrefix(), $db->tablePrefix(), 'tablePrefix' ); + + // Make sure the DB connection has all the test data + $this->copyTestData( $this->db, $db ); + + $value = $db->selectField( 'objectcache', 'value', [ 'keyname' => __METHOD__ ], __METHOD__ ); + $this->assertSame( 'TEST', $value, 'Copied Data' ); + } + }