Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F585081
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/maintenance/nukePage.php b/maintenance/nukePage.php
index 137e36c9521..a932894d634 100644
--- a/maintenance/nukePage.php
+++ b/maintenance/nukePage.php
@@ -54,7 +54,7 @@ class NukePage extends Maintenance {
# Get page ID
$this->output( "Searching for \"$name\"..." );
$title = Title::newFromText( $name );
- if ( $title ) {
+ if ( $title && $title->exists() ) {
$id = $title->getArticleID();
$real = $title->getPrefixedText();
$isGoodArticle = $title->isContentPage();
diff --git a/tests/phpunit/maintenance/NukePageTest.php b/tests/phpunit/maintenance/NukePageTest.php
new file mode 100644
index 00000000000..eec14f9589a
--- /dev/null
+++ b/tests/phpunit/maintenance/NukePageTest.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace MediaWiki\Tests\Maintenance;
+
+use NukePage;
+
+/**
+ * @covers \NukePage
+ * @group Database
+ * @group Maintenance
+ */
+class NukePageTest extends MaintenanceBaseTestCase {
+
+ public function getMaintenanceClass() {
+ return NukePage::class;
+ }
+
+ public function testExecuteWhenPageDoesNotExist() {
+ $this->expectOutputRegex( '/Searching for "Non-existing-test-page"[\s\S]*not found in database/' );
+ $this->maintenance->setArg( 'title', 'Non-existing-test-page' );
+ $this->maintenance->execute();
+ }
+
+ public function testExecuteWhenPageExistsButInDryRun() {
+ $page = $this->getExistingTestPage();
+ $pageTitle = $page->getTitle()->getPrefixedText();
+ $revId = $page->getRevisionRecord()->getId();
+
+ $this->maintenance->setArg( 'title', $pageTitle );
+ $this->maintenance->execute();
+
+ // Check that the script has found the page but does not delete it.
+ $actualOutput = $this->getActualOutputForAssertion();
+ $this->assertStringContainsString( "Searching for \"$pageTitle\"", $actualOutput );
+ $this->assertStringContainsString(
+ "found \"$pageTitle\" with ID {$page->getId()}", $actualOutput
+ );
+ $this->assertStringContainsString( "Searching for revisions...found 1", $actualOutput );
+ $this->assertStringNotContainsString( "Deleting page record...", $actualOutput );
+
+ $page->clear();
+ $this->assertTrue( $page->exists() );
+ $this->newSelectQueryBuilder()
+ ->select( 'COUNT(*)' )
+ ->from( 'revision' )
+ ->where( [ 'rev_id' => $revId ] )
+ ->caller( __METHOD__ )
+ ->assertFieldValue( 1 );
+ }
+
+ public function testExecuteWhenPageExistsAndDeleting() {
+ $page = $this->getExistingTestPage();
+ $pageTitle = $page->getTitle()->getPrefixedText();
+ $revId = $page->getRevisionRecord()->getId();
+
+ $this->maintenance->setOption( 'delete', 1 );
+ $this->maintenance->setArg( 'title', $pageTitle );
+ $this->maintenance->execute();
+
+ // Assert that the script wiped the page from the DB
+ $actualOutput = $this->getActualOutputForAssertion();
+ $this->assertStringContainsString( "Searching for \"$pageTitle\"", $actualOutput );
+ $this->assertStringContainsString(
+ "found \"$pageTitle\" with ID {$page->getId()}", $actualOutput
+ );
+ $this->assertStringContainsString( 'Deleting page record...done', $actualOutput );
+ $this->assertStringContainsString( 'Cleaning up recent changes...done', $actualOutput );
+ $this->assertStringContainsString( 'Deleting revisions...done', $actualOutput );
+ $this->assertStringContainsString( 'Updating site stats...done', $actualOutput );
+
+ $page->clear();
+ $this->assertFalse( $page->exists() );
+ $this->newSelectQueryBuilder()
+ ->select( 'COUNT(*)' )
+ ->from( 'revision' )
+ ->where( [ 'rev_id' => $revId ] )
+ ->caller( __METHOD__ )
+ ->assertFieldValue( 0 );
+ $this->newSelectQueryBuilder()
+ ->select( 'COUNT(*)' )
+ ->from( 'recentchanges' )
+ ->where( [ 'rc_this_oldid' => $revId ] )
+ ->caller( __METHOD__ )
+ ->assertFieldValue( 0 );
+ $this->newSelectQueryBuilder()
+ ->select( [ 'ss_total_pages', 'ss_total_edits' ] )
+ ->from( 'site_stats' )
+ ->caller( __METHOD__ )
+ ->assertRowValue( [ 0, 0 ] );
+ }
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:32 AM (14 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227514
Default Alt Text
(3 KB)
Attached To
Mode
rMW mediawiki
Attached
Detach File
Event Timeline
Log In to Comment