<?php
+
use MediaWiki\Logger\LoggerFactory;
use MediaWiki\MediaWikiServices;
use Psr\Log\LoggerInterface;
/**
* @covers MediaWikiTestCase
* @group MediaWikiTestCaseTest
+ * @group Database
*
* @author Addshore
*/
}
/**
- * @dataProvider provideExistingKeysAndNewValues
- *
- * @covers MediaWikiTestCase::stashMwGlobals
- * @covers MediaWikiTestCase::tearDown
- */
- public function testStashedGlobalsAreRestoredOnTearDown( $globalKey, $newValue ) {
- $this->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() {
$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' );
+ }
+
}