Page MenuHomePhorge

No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None
diff --git a/maintenance/renameDbPrefix.php b/maintenance/renameDbPrefix.php
index 81fffc0af43..a035a0bc848 100644
--- a/maintenance/renameDbPrefix.php
+++ b/maintenance/renameDbPrefix.php
@@ -51,7 +51,7 @@ class RenameDbPrefix extends Maintenance {
$dbName = $this->getConfig()->get( MainConfigNames::DBname );
// Allow for no old prefix
- if ( $this->getOption( 'old', 0 ) === '0' ) {
+ if ( $this->getOption( 'old', '0' ) === '0' ) {
$old = '';
} else {
// Use nice safe, sensible, prefixes
@@ -59,7 +59,7 @@ class RenameDbPrefix extends Maintenance {
$old = $m[0] ?? false;
}
// Allow for no new prefix
- if ( $this->getOption( 'new', 0 ) === '0' ) {
+ if ( $this->getOption( 'new', '0' ) === '0' ) {
$new = '';
} else {
// Use nice safe, sensible, prefixes
@@ -72,6 +72,7 @@ class RenameDbPrefix extends Maintenance {
}
if ( $old === $new ) {
$this->output( "Same prefix. Nothing to rename!\n" );
+ return;
}
$this->output( "Renaming DB prefix for tables of $dbName from '$old' to '$new'\n" );
diff --git a/tests/phpunit/maintenance/RenameDbPrefixTest.php b/tests/phpunit/maintenance/RenameDbPrefixTest.php
new file mode 100644
index 00000000000..d819a72960e
--- /dev/null
+++ b/tests/phpunit/maintenance/RenameDbPrefixTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace MediaWiki\Tests\Maintenance;
+
+use RenameDbPrefix;
+
+/**
+ * @covers \RenameDbPrefix
+ * @author Dreamy Jazz
+ */
+class RenameDbPrefixTest extends MaintenanceBaseTestCase {
+
+ protected function getMaintenanceClass() {
+ return RenameDbPrefix::class;
+ }
+
+ /** @dataProvider provideExecuteForFatalError */
+ public function testExecuteForFatalError( $options, $expectedOutputRegex ) {
+ foreach ( $options as $name => $value ) {
+ $this->maintenance->setOption( $name, $value );
+ }
+ $this->expectCallToFatalError();
+ $this->expectOutputRegex( $expectedOutputRegex );
+ $this->maintenance->execute();
+ }
+
+ public static function provideExecuteForFatalError() {
+ return [
+ '--old is invalid' => [ [ 'old' => '$£"!abc**;' ], '/Invalid prefix/' ],
+ '--new is invalid' => [ [ 'new' => '$£"!abc**;' ], '/Invalid prefix/' ],
+ '--new and --old are invalid' => [ [ 'new' => '$£"!abc**;', 'old' => '!"£$' ], '/Invalid prefix/' ],
+ ];
+ }
+
+ /** @dataProvider provideExecuteForOldAndNewTheSame */
+ public function testExecuteWhenOldAndNewTheSame( $prefix ) {
+ $this->maintenance->setOption( 'old', $prefix );
+ $this->maintenance->setOption( 'new', $prefix );
+ $this->expectOutputString( "Same prefix. Nothing to rename!\n" );
+ $this->maintenance->execute();
+ }
+
+ public static function provideExecuteForOldAndNewTheSame() {
+ return [
+ '--old and --new are "abc"' => [ 'abc_', 'abc_' ],
+ '--old and --new are empty' => [ null, null ],
+ ];
+ }
+}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:31 AM (14 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227467
Default Alt Text
(2 KB)

Event Timeline