diff --git a/includes/libs/StatusValue.php b/includes/libs/StatusValue.php index 201f29e59e3..866feb86552 100644 --- a/includes/libs/StatusValue.php +++ b/includes/libs/StatusValue.php @@ -358,6 +358,9 @@ class StatusValue { } /** + * Returns a string representation of the status for debugging. + * This is fairly verbose and may change without notice. + * * @return string */ public function __toString() { @@ -398,7 +401,8 @@ class StatusValue { } $keyChunks = str_split( $key, 25 ); - $paramsChunks = str_split( substr( $this->flattenParams( $params ), 0, 100 ), 25 ); + $paramsChunks = str_split( $this->flattenParams( $params, " | " ), 40 ); + // array_map(null,...) is like Python's zip() foreach ( array_map( null, [ $i ], $keyChunks, $paramsChunks ) as [ $iChunk, $keyChunk, $paramsChunk ] @@ -420,20 +424,24 @@ class StatusValue { /** * @param array $params Message parameters + * @param string $joiner + * * @return string String representation */ - private function flattenParams( array $params ): string { + private function flattenParams( array $params, string $joiner = ', ' ): string { $ret = []; foreach ( $params as $p ) { if ( is_array( $p ) ) { - $ret[] = '[ ' . self::flattenParams( $p ) . ' ]'; + $r = '[ ' . self::flattenParams( $p ) . ' ]'; } elseif ( $p instanceof MessageSpecifier ) { - $ret[] = '{ ' . $p->getKey() . ': ' . self::flattenParams( $p->getParams() ) . ' }'; + $r = '{ ' . $p->getKey() . ': ' . self::flattenParams( $p->getParams() ) . ' }'; } else { - $ret[] = (string)$p; + $r = (string)$p; } + + $ret[] = strlen( $r ) > 100 ? substr( $r, 0, 99 ) . "..." : $r; } - return implode( ' ', $ret ); + return implode( $joiner, $ret ); } /** diff --git a/tests/phpunit/MediaWikiTestCaseTrait.php b/tests/phpunit/MediaWikiTestCaseTrait.php index 782529cd244..8753c811cf7 100644 --- a/tests/phpunit/MediaWikiTestCaseTrait.php +++ b/tests/phpunit/MediaWikiTestCaseTrait.php @@ -298,4 +298,64 @@ trait MediaWikiTestCaseTrait { $msg->method( 'exists' )->willReturn( true ); return $msg; } + + private function failStatus( StatusValue $status, $reason, $message = '' ) { + $reason = $message === '' ? $reason : "$message\n$reason"; + $this->fail( "$reason\n$status" ); + } + + protected function assertStatusOK( StatusValue $status, $message = '' ) { + if ( !$status->isOK() ) { + $this->failStatus( $status, 'Status should be OK', $message ); + } else { + $this->addToAssertionCount( 1 ); + } + } + + protected function assertStatusGood( StatusValue $status, $message = '' ) { + if ( !$status->isGood() ) { + $this->failStatus( $status, 'Status should be Good', $message ); + } else { + $this->addToAssertionCount( 1 ); + } + } + + protected function assertStatusNotOK( StatusValue $status, $message = '' ) { + if ( $status->isOK() ) { + $this->failStatus( $status, 'Status should not be OK', $message ); + } else { + $this->addToAssertionCount( 1 ); + } + } + + protected function assertStatusNotGood( StatusValue $status, $message = '' ) { + if ( $status->isGood() ) { + $this->failStatus( $status, 'Status should not be Good', $message ); + } else { + $this->addToAssertionCount( 1 ); + } + } + + protected function assertStatusMessage( $messageKey, StatusValue $status, $message = '' ) { + if ( !$status->hasMessage( $messageKey ) ) { + $this->failStatus( $status, "Status should have message $messageKey", $message ); + } else { + $this->addToAssertionCount( 1 ); + } + } + + protected function assertStatusValue( $expected, StatusValue $status, $message = 'Status value' ) { + $this->assertEquals( $expected, $status->getValue(), $message ); + } + + protected function assertStatusError( $messageKey, StatusValue $status, $message = '' ) { + $this->assertStatusNotOK( $status, $message ); + $this->assertStatusMessage( $messageKey, $status, $message ); + } + + protected function assertStatusWarning( $messageKey, StatusValue $status, $message = '' ) { + $this->assertStatusNotGood( $status, $message ); + $this->assertStatusOK( $status, $message ); + $this->assertStatusMessage( $messageKey, $status, $message ); + } } diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index b2523ee3f12..978d1ec443c 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -876,8 +876,8 @@ hello 'format' => CONTENT_FORMAT_WIKITEXT, ] ); - $this->assertFalse( $status->isOK() ); - $this->assertEquals( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status->getValue() ); + $this->assertStatusNotOK( $status ); + $this->assertStatusValue( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status ); } /** @covers EditPage */ @@ -903,8 +903,8 @@ hello 'format' => CONTENT_FORMAT_WIKITEXT, ] ); - $this->assertFalse( $status->isOK() ); - $this->assertEquals( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status->getValue() ); + $this->assertStatusNotOK( $status ); + $this->assertStatusValue( EditPage::AS_NO_CHANGE_CONTENT_MODEL, $status ); } private function doEditDummyNonTextPage( array $edit ): Status { diff --git a/tests/phpunit/includes/MergeHistoryTest.php b/tests/phpunit/includes/MergeHistoryTest.php index 63886f74067..dfa2bc9fb2c 100644 --- a/tests/phpunit/includes/MergeHistoryTest.php +++ b/tests/phpunit/includes/MergeHistoryTest.php @@ -48,9 +48,9 @@ class MergeHistoryTest extends MediaWikiIntegrationTestCase { ); $status = $mh->isValidMerge(); if ( $error === true ) { - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } else { - $this->assertTrue( $status->hasMessage( $error ) ); + $this->assertStatusError( $error, $status ); } } @@ -100,7 +100,7 @@ class MergeHistoryTest extends MediaWikiIntegrationTestCase { ->willReturn( $limit + 1 ); $status = $mh->isValidMerge(); - $this->assertTrue( $status->hasMessage( 'mergehistory-fail-toobig' ) ); + $this->assertStatusError( 'mergehistory-fail-toobig', $status ); $errors = $status->getErrorsByType( 'error' ); $params = $errors[0]['params']; $this->assertEquals( $params[0], Message::numParam( $limit ) ); @@ -124,13 +124,13 @@ class MergeHistoryTest extends MediaWikiIntegrationTestCase { $this->mockRegisteredUltimateAuthority(), '' ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $status = $mh->$method( $this->mockRegisteredAuthorityWithoutPermissions( [ 'mergehistory' ] ), '' ); - $this->assertTrue( $status->hasMessage( 'mergehistory-fail-permission' ) ); + $this->assertStatusError( 'mergehistory-fail-permission', $status ); } } diff --git a/tests/phpunit/includes/MovePageTest.php b/tests/phpunit/includes/MovePageTest.php index 7fd82367e45..9d9031e4fbc 100644 --- a/tests/phpunit/includes/MovePageTest.php +++ b/tests/phpunit/includes/MovePageTest.php @@ -342,7 +342,7 @@ class MovePageTest extends MediaWikiIntegrationTestCase { ->getMovePageFactory() ->newMovePage( $old, $new ) ->move( $this->getTestUser()->getUser(), 'move reason', $createRedirect ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertMoved( $old, $new, $oldPageId, $createRedirect ); [ @@ -382,7 +382,7 @@ class MovePageTest extends MediaWikiIntegrationTestCase { $mp = $this->newMovePageWithMocks( $oldTitle, $newTitle ); $user = User::newFromName( 'TitleMove tester' ); $status = $mp->move( $user, 'Reason', true ); - $this->assertTrue( $status->hasMessage( $error ) ); + $this->assertStatusError( $error, $status ); } /** @@ -411,7 +411,7 @@ class MovePageTest extends MediaWikiIntegrationTestCase { ->newMovePage( $oldTitle, $newTitle ) ->moveSubpages( $this->getTestUser()->getUser(), 'Reason', true ); - $this->assertTrue( $status->isGood(), + $this->assertStatusGood( $status, "Moving subpages from Talk:{$name} to Talk:{$name} 2 was not completely successful." ); foreach ( $subPages as $page ) { $this->assertMoved( $page, str_replace( $name, "$name 2", $page ), $ids[$page] ); @@ -444,7 +444,7 @@ class MovePageTest extends MediaWikiIntegrationTestCase { ->newMovePage( $oldTitle, $newTitle ) ->moveSubpagesIfAllowed( $this->getTestUser()->getUser(), 'Reason', true ); - $this->assertTrue( $status->isGood(), + $this->assertStatusGood( $status, "Moving subpages from Talk:{$name} to Talk:{$name} 2 was not completely successful." ); foreach ( $subPages as $page ) { $this->assertMoved( $page, str_replace( $name, "$name 2", $page ), $ids[$page] ); @@ -553,7 +553,7 @@ class MovePageTest extends MediaWikiIntegrationTestCase { $status = $obj->move( $this->getTestUser()->getUser() ); // sanity checks - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertSame( $pageId, $new->getId() ); $this->assertNotSame( $pageId, $old->getId() ); diff --git a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php index 60db562265d..de896a7c4d4 100644 --- a/tests/phpunit/includes/Revision/RevisionStoreDbTest.php +++ b/tests/phpunit/includes/Revision/RevisionStoreDbTest.php @@ -998,7 +998,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { public function testGetLatestKnownRevision_foreigh() { $page = $this->getTestPage(); $status = $this->editPage( $page, __METHOD__ ); - $this->assertTrue( $status->isGood(), 'edited a page' ); + $this->assertStatusGood( $status, 'edited a page' ); /** @var RevisionRecord $revRecord */ $revRecord = $status->value['revision-record']; $dbDomain = 'some_foreign_wiki'; @@ -2290,13 +2290,13 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; $page2 = $this->getTestPage( $page1->getTitle()->getPrefixedText() . '_other' ); $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), $text . '2' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 2' ); + $this->assertStatusGood( $editStatus, 'must create revision 2' ); /** @var RevisionRecord $revRecord2 */ $revRecord2 = $editStatus->getValue()['revision-record']; @@ -2305,8 +2305,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { [ $revRecord1->getId(), $revRecord2->getId() ], $slots ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); $rowSetsByRevId = $result->getValue(); $this->assertArrayHasKey( $revRecord1->getId(), $rowSetsByRevId ); @@ -2335,7 +2334,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { (object)[ 'rev_id' => $revRecord2->getId() ], ], $slots ); - $this->assertTrue( $result2->isGood() ); + $this->assertStatusGood( $result2 ); $exp1 = var_export( $result->getValue(), true ); $exp2 = var_export( $result2->getValue(), true ); $this->assertSame( $exp1, $exp2 ); @@ -2349,14 +2348,14 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage( __METHOD__ ); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; $this->deletePage( $page1 ); $page2 = $this->getTestPage( $page1->getTitle()->getPrefixedText() . '_other' ); $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), $text . '2' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 2' ); + $this->assertStatusGood( $editStatus, 'must create revision 2' ); /** @var RevisionRecord $revRecord2 */ $revRecord2 = $editStatus->getValue()['revision-record']; $this->deletePage( $page2 ); @@ -2366,8 +2365,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { (object)[ 'ar_rev_id' => $revRecord1->getId() ], (object)[ 'ar_rev_id' => $revRecord2->getId() ], ] ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); $rowSetsByRevId = $result->getValue(); $this->assertArrayHasKey( $revRecord1->getId(), $rowSetsByRevId ); @@ -2381,9 +2379,8 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $rows = new FakeResultWrapper( [] ); $result = $this->getServiceContainer()->getRevisionStore() ->getContentBlobsForBatch( $rows ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getValue() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); + $this->assertStatusValue( [], $result ); } public function provideNewRevisionsFromBatchOptions() { @@ -2478,13 +2475,13 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; $page2 = $this->getTestPage( $otherPageTitle ); $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), $text . '2' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 2' ); + $this->assertStatusGood( $editStatus, 'must create revision 2' ); /** @var RevisionRecord $revRecord2 */ $revRecord2 = $editStatus->getValue()['revision-record']; @@ -2497,8 +2494,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $options, 0, $otherPageTitle ? null : $page1->getTitle() ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); /** @var RevisionRecord[] $records */ $records = $result->getValue(); $this->assertRevisionRecordsEqual( $revRecord1, $records[$revRecord1->getId()] ); @@ -2584,8 +2580,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $result = $store->newRevisionsFromBatch( $rows, $options, 0, $otherPageTitle ? null : $pageIdentity ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); /** @var RevisionRecord[] $records */ $records = $result->getValue(); $this->assertCount( 2, $records ); @@ -2627,9 +2622,8 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { 'content' => true ] ); - $this->assertTrue( $result->isGood() ); - $this->assertSame( [], $result->getValue() ); - $this->assertSame( [], $result->getErrors() ); + $this->assertStatusGood( $result ); + $this->assertStatusValue( [], $result ); } /** @@ -2639,7 +2633,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $rev1 */ $revRecord1 = $editStatus->getValue()['revision-record']; @@ -2660,7 +2654,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; @@ -2672,8 +2666,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { ] ); - $this->assertFalse( $status->isGood() ); - $this->assertTrue( $status->hasMessage( 'internalerror_info' ) ); + $this->assertStatusWarning( 'internalerror_info', $status ); } /** @@ -2687,7 +2680,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $revisionIds = []; for ( $revNum = 0; $revNum < $NUM; $revNum++ ) { $editStatus = $this->editPage( $page->getTitle()->getPrefixedDBkey(), 'Revision ' . $revNum ); - $this->assertTrue( $editStatus->isGood(), 'must create revision ' . $revNum ); + $this->assertStatusGood( $editStatus, 'must create revision ' . $revNum ); $newRevision = $editStatus->getValue()['revision-record']; /** @var RevisionRecord $newRevision */ $revisions[] = $newRevision; @@ -2784,7 +2777,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $revisions = []; for ( $revNum = 0; $revNum < $NUM; $revNum++ ) { $editStatus = $this->editPage( $page->getTitle()->getPrefixedDBkey(), 'Revision ' . $revNum ); - $this->assertTrue( $editStatus->isGood(), 'must create revision ' . $revNum ); + $this->assertStatusGood( $editStatus, 'must create revision ' . $revNum ); $revisions[] = $editStatus->getValue()['revision-record']; } @@ -2840,7 +2833,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { '', NS_MAIN, $users[$revNum] ); - $this->assertTrue( $editStatus->isGood(), 'must create revision ' . $revNum ); + $this->assertStatusGood( $editStatus, 'must create revision ' . $revNum ); $revisions[] = $editStatus->getValue()['revision-record']; } @@ -2889,10 +2882,10 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage( __METHOD__ ); $page2 = $this->getTestPage( 'Other_Page' ); $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), 'Revision 1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); $rev1 = $editStatus->getValue()['revision-record']; $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), 'Revision 1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); $rev2 = $editStatus->getValue()['revision-record']; $this->expectException( InvalidArgumentException::class ); @@ -2928,10 +2921,10 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { public function testGetFirstRevision( $getPageIdentity ) { list( $pageTitle, $pageIdentity ) = $getPageIdentity(); $editStatus = $this->editPage( $pageTitle->getPrefixedDBkey(), 'First Revision' ); - $this->assertTrue( $editStatus->isGood(), 'must create first revision' ); + $this->assertStatusGood( $editStatus, 'must create first revision' ); $firstRevId = $editStatus->getValue()['revision-record']->getID(); $editStatus = $this->editPage( $pageTitle->getPrefixedText(), 'New Revision' ); - $this->assertTrue( $editStatus->isGood(), 'must create new revision' ); + $this->assertStatusGood( $editStatus, 'must create new revision' ); $this->assertNotSame( $firstRevId, $editStatus->getValue()['revision-record']->getID(), @@ -3111,7 +3104,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; @@ -3130,8 +3123,8 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $wrappedRevStore->blobStore = $mockBlobStore; $result = $revStore->getContentBlobsForBatch( [ $revRecord1->getId() ] ); - $this->assertTrue( $result->isOK() ); - $this->assertFalse( $result->isGood() ); + $this->assertStatusOK( $result ); + $this->assertStatusNotGood( $result ); $this->assertNotEmpty( $result->getErrors() ); $records = $result->getValue(); @@ -3164,7 +3157,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; @@ -3193,7 +3186,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { [ $revRecord1->getId() ], [ SlotRecord::MAIN ] ); - $this->assertTrue( $result->isGood() ); + $this->assertStatusGood( $result ); $this->assertSame( 'Content_From_Mock', $result->getValue()[$revRecord1->getId()][SlotRecord::MAIN]->blob_data ); } @@ -3222,7 +3215,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { 'content' => true ] ); - $this->assertFalse( $result->isGood() ); + $this->assertStatusNotGood( $result ); $this->assertNotEmpty( $result->getErrors() ); $records = $result->getValue(); $this->assertRevisionRecordsEqual( $revRecord1, $records[$revRecord1->getId()] ); @@ -3247,7 +3240,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { $page1 = $this->getTestPage(); $text = __METHOD__ . 'b-ä'; $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' ); - $this->assertTrue( $editStatus->isGood(), 'must create revision 1' ); + $this->assertStatusGood( $editStatus, 'must create revision 1' ); /** @var RevisionRecord $revRecord1 */ $revRecord1 = $editStatus->getValue()['revision-record']; @@ -3279,7 +3272,7 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { 'content' => true ] ); - $this->assertTrue( $result->isGood() ); + $this->assertStatusGood( $result ); $content = $result->getValue()[$revRecord1->getId()]->getContent( SlotRecord::MAIN ); $this->assertInstanceOf( TextContent::class, $content ); $this->assertSame( @@ -3293,13 +3286,13 @@ class RevisionStoreDbTest extends MediaWikiIntegrationTestCase { // Prepare a page with 3 revisions $page = $this->getExistingTestPage( __METHOD__ ); $status = $this->editPage( $page, 'Content 1' ); - $this->assertTrue( $status->isGood(), 'edit 1' ); + $this->assertStatusGood( $status, 'edit 1' ); $originalRev = $status->value[ 'revision-record' ]; $this->assertTrue( $this->editPage( $page, 'Content 2' )->isGood(), 'edit 2' ); $status = $this->editPage( $page, 'Content 1' ); - $this->assertTrue( $status->isGood(), 'edit 3' ); + $this->assertStatusGood( $status, 'edit 3' ); $latestRev = $status->value[ 'revision-record' ]; $store = $this->getServiceContainer()->getRevisionStore(); diff --git a/tests/phpunit/includes/StatusTest.php b/tests/phpunit/includes/StatusTest.php index 87f60fe913c..a2914605ee7 100644 --- a/tests/phpunit/includes/StatusTest.php +++ b/tests/phpunit/includes/StatusTest.php @@ -216,7 +216,7 @@ class StatusTest extends MediaWikiLangTestCase { $expectedArray = array_merge( [ $message->getKey() ], $message->getParams() ); $this->assertEquals( $expectedArray, $errors[$key] ); } - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } /** @@ -991,12 +991,23 @@ class StatusTest extends MediaWikiLangTestCase { * @covers Status::__toString */ public function testToString() { + $loremIpsum = 'Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor' . + ' incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud ' . + 'exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure ' . + 'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.'; + $abc = [ + 'x' => [ 'a', 'b', 'c' ], + 'z' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ' . + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ ' + ]; + // This is a debug method, we don't care about the exact output. But it shouldn't cause - // an error as it's called in various logging codee. + // an error as it's called in various logging code. $this->expectNotToPerformAssertions(); (string)Status::newGood(); (string)Status::newGood( new MessageValue( 'foo' ) ); (string)Status::newFatal( 'foo' ); + (string)Status::newFatal( 'foo', $loremIpsum, $abc ); (string)Status::newFatal( wfMessage( 'foo' ) ); (string)( Status::newFatal( 'foo' )->fatal( 'bar' ) ); } diff --git a/tests/phpunit/includes/Storage/PageUpdaterTest.php b/tests/phpunit/includes/Storage/PageUpdaterTest.php index f4b31e65761..8ebdea1b790 100644 --- a/tests/phpunit/includes/Storage/PageUpdaterTest.php +++ b/tests/phpunit/includes/Storage/PageUpdaterTest.php @@ -183,8 +183,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); $this->assertFalse( $updater->wasRevisionCreated(), 'wasRevisionCreated' ); $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' ); - $this->assertTrue( $status->isOK(), 'getStatus()->isOK()' ); - $this->assertTrue( $status->hasMessage( 'edit-no-change' ), 'edit-no-change' ); + $this->assertStatusWarning( 'edit-no-change', $status, 'edit-no-change' ); } /** @@ -322,7 +321,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertNotSame( $parentId, $rev->getId(), 'new revision ID' ); $this->assertTrue( $updater->wasRevisionCreated(), 'wasRevisionCreated' ); $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' ); - $this->assertTrue( $status->isOK(), 'getStatus()->isOK()' ); + $this->assertStatusOK( $status, 'getStatus()->isOK()' ); $this->assertFalse( $status->hasMessage( 'edit-no-change' ), 'edit-no-change' ); // Setting setForceEmptyRevision causes the original revision to be set. $this->assertEquals( $parentId, $updater->getEditResult()->getOriginalRevisionId() ); @@ -528,7 +527,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { "MultiContentSave returned false, but revision was still created." ); $status = $updater->getStatus(); - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "MultiContentSave returned false, but Status is not fatal." ); $this->assertSame( $expectedError, $status->getMessage()->getKey() ); } @@ -559,8 +558,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' ); $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); - $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' ); - $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-conflict' ); + $this->assertStatusError( 'edit-already-exists', $status, 'edit-conflict' ); // start editing existing page $page = WikiPage::factory( $title ); @@ -579,8 +577,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' ); $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); - $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' ); - $this->assertTrue( $status->hasMessage( 'edit-conflict' ), 'edit-conflict' ); + $this->assertStatusError( 'edit-conflict', $status, 'edit-conflict' ); } /** @@ -603,8 +600,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' ); $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); - $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' ); - $this->assertTrue( $status->hasMessage( 'edit-gone-missing' ), 'edit-gone-missing' ); + $this->assertStatusError( 'edit-gone-missing', $status, 'edit-gone-missing' ); // create the page $this->createRevision( $page, __METHOD__ ); @@ -618,8 +614,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' ); $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); - $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' ); - $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-already-exists' ); + $this->assertStatusError( 'edit-already-exists', $status, 'edit-already-exists' ); } /** @@ -644,7 +639,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' ); $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' ); - $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' ); + $this->assertStatusNotOK( $status, 'getStatus()->isOK()' ); $this->assertTrue( $status->hasMessage( 'content-not-allowed-here' ), 'content-not-allowed-here' @@ -770,7 +765,7 @@ class PageUpdaterTest extends MediaWikiIntegrationTestCase { $updater->updateRevision(); $status = $updater->getStatus(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $rev = $status->getValue()['revision-record']; $slot = $rev->getSlot( 'derivedslot' ); $this->assertTrue( $slot->getContent()->equals( $content ) ); diff --git a/tests/phpunit/includes/actions/WatchActionTest.php b/tests/phpunit/includes/actions/WatchActionTest.php index 0737bed9d1f..f19f240733d 100644 --- a/tests/phpunit/includes/actions/WatchActionTest.php +++ b/tests/phpunit/includes/actions/WatchActionTest.php @@ -94,7 +94,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase { /** @var Status $actual */ $actual = $this->watchAction->onSubmit( [] ); - $this->assertTrue( $actual->isGood() ); + $this->assertStatusGood( $actual ); } /** @@ -134,7 +134,7 @@ class WatchActionTest extends MediaWikiIntegrationTestCase { $actual = $this->watchAction->onSubmit( [] ); $this->assertInstanceOf( Status::class, $actual ); - $this->assertTrue( $actual->hasMessage( 'hookaborted' ) ); + $this->assertStatusError( 'hookaborted', $actual ); } /** diff --git a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php index 584dda49db4..2dc2c1ce393 100644 --- a/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php +++ b/tests/phpunit/includes/api/query/ApiQueryUserInfoTest.php @@ -35,9 +35,9 @@ class ApiQueryUserInfoTest extends ApiTestCase { $this->assertArrayNotHasKey( 'latestcontrib', $apiResult[0]['query']['userinfo'] ); $status = $this->editPage( $page, 'one' ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $status = $this->editPage( $page, 'two' ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $revisionTimestamp = MWTimestamp::convert( TS_ISO_8601, $page->getTimestamp() ); diff --git a/tests/phpunit/includes/auth/AuthManagerTest.php b/tests/phpunit/includes/auth/AuthManagerTest.php index a691aa98ffb..fef2c018f1b 100644 --- a/tests/phpunit/includes/auth/AuthManagerTest.php +++ b/tests/phpunit/includes/auth/AuthManagerTest.php @@ -1551,8 +1551,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { $this->setGroupPermissions( '*', 'createaccount', false ); $this->initializeManager( true ); $status = $this->manager->checkAccountCreatePermissions( new \User ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'badaccess-groups' ) ); + $this->assertStatusError( 'badaccess-groups', $status ); } /** @@ -1596,8 +1595,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { $this->resetServices(); $this->initializeManager( true ); $status = $this->manager->checkAccountCreatePermissions( $user ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext' ) ); + $this->assertStatusError( 'blockedtext', $status ); } /** @@ -1619,8 +1617,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { $block = new DatabaseBlock( $blockOptions ); $blockStore->insertBlock( $block ); $status = $this->manager->checkAccountCreatePermissions( new \User ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext-partial' ) ); + $this->assertStatusError( 'blockedtext-partial', $status ); } /** @@ -1636,12 +1633,11 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { ] ); $this->initializeManager( true ); $status = $this->manager->checkAccountCreatePermissions( new \User ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'sorbs_create_account_reason' ) ); + $this->assertStatusError( 'sorbs_create_account_reason', $status ); $this->setMwGlobals( 'wgProxyWhitelist', [ '127.0.0.1' ] ); $this->initializeManager( true ); $status = $this->manager->checkAccountCreatePermissions( new \User ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -1683,8 +1679,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { $this->resetServices(); $this->initializeManager( true ); $status = $this->manager->checkAccountCreatePermissions( $user ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext-partial' ) ); + $this->assertStatusError( 'blockedtext-partial', $status ); } /** @@ -2950,7 +2945,7 @@ class AuthManagerTest extends \MediaWikiIntegrationTestCase { ->will( $this->returnCallback( function () use ( $username, &$user ) { $oldUser = \User::newFromName( $username ); $status = $oldUser->addToDatabase(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $user->setId( $oldUser->getId() ); return Status::newFatal( 'userexists' ); } ) ); diff --git a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php index 6935862a593..9fdd6f9ed0c 100644 --- a/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/CheckBlocksSecondaryAuthenticationProviderTest.php @@ -142,13 +142,11 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati $status = $provider->testUserForCreation( $blockedUser, AuthManager::AUTOCREATE_SOURCE_SESSION ); $this->assertInstanceOf( \StatusValue::class, $status ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext' ) ); + $this->assertStatusError( 'blockedtext', $status ); $status = $provider->testUserForCreation( $blockedUser, false ); $this->assertInstanceOf( \StatusValue::class, $status ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext' ) ); + $this->assertStatusError( 'blockedtext', $status ); } public function testPartialBlock() { @@ -182,12 +180,10 @@ class CheckBlocksSecondaryAuthenticationProviderTest extends \MediaWikiIntegrati $status = $provider->testUserForCreation( $newuser, AuthManager::AUTOCREATE_SOURCE_SESSION ); $this->assertInstanceOf( \StatusValue::class, $status ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext-partial' ) ); + $this->assertStatusError( 'blockedtext-partial', $status ); $status = $provider->testUserForCreation( $newuser, false ); $this->assertInstanceOf( \StatusValue::class, $status ); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'blockedtext-partial' ) ); + $this->assertStatusError( 'blockedtext-partial', $status ); } } diff --git a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php index e30014bedff..868ad0dd08b 100644 --- a/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php +++ b/tests/phpunit/includes/auth/ThrottlePreAuthenticationProviderTest.php @@ -217,7 +217,7 @@ class ThrottlePreAuthenticationProviderTest extends MediaWikiIntegrationTestCase $provider->testForAuthentication( [ $req ] ); $req->username = 'some user'; $status = $provider->testForAuthentication( [ $req ] ); - $this->assertFalse( $status->isGood(), 'denormalized usernames are normalized' ); + $this->assertStatusNotGood( $status, 'denormalized usernames are normalized' ); } public function testPostAuthentication() { diff --git a/tests/phpunit/includes/filebackend/FileBackendIntegrationTest.php b/tests/phpunit/includes/filebackend/FileBackendIntegrationTest.php index 5fec5055f59..c31649e7da4 100644 --- a/tests/phpunit/includes/filebackend/FileBackendIntegrationTest.php +++ b/tests/phpunit/includes/filebackend/FileBackendIntegrationTest.php @@ -160,9 +160,9 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->doOperation( $op ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Store from $source to $dest succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Store from $source to $dest succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Store from $source to $dest has proper 'success' field in Status ($backendName)." ); @@ -227,20 +227,20 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( is_string( $srcContent ) ) { $status = $this->backend->create( [ 'content' => $srcContent, 'dst' => $source ] ); - $this->assertGoodStatus( $status, "Creation of $source succeeded ($backendName)." ); + $this->assertStatusGood( $status, "Creation of $source succeeded ($backendName)." ); } if ( is_string( $dstContent ) ) { $status = $this->backend->create( [ 'content' => $dstContent, 'dst' => $dest ] ); - $this->assertGoodStatus( $status, "Creation of $dest succeeded ($backendName)." ); + $this->assertStatusGood( $status, "Creation of $dest succeeded ($backendName)." ); } $status = $this->backend->doOperation( $op ); if ( $okStatus ) { - $this->assertGoodStatus( + $this->assertStatusGood( $status, "Copy from $source to $dest succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Copy from $source to $dest succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Copy from $source to $dest has proper 'success' field in Status ($backendName)." ); @@ -266,7 +266,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { "Source and destination have the same props ($backendName)." ); } } else { - $this->assertBadStatus( + $this->assertStatusNotGood( $status, "Copy from $source to $dest fails ($backendName)." ); $this->assertSame( @@ -376,11 +376,11 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( is_string( $srcContent ) ) { $status = $this->backend->create( [ 'content' => $srcContent, 'dst' => $source ] ); - $this->assertGoodStatus( $status, "Creation of $source succeeded ($backendName)." ); + $this->assertStatusGood( $status, "Creation of $source succeeded ($backendName)." ); } if ( is_string( $dstContent ) ) { $status = $this->backend->create( [ 'content' => $dstContent, 'dst' => $dest ] ); - $this->assertGoodStatus( $status, "Creation of $dest succeeded ($backendName)." ); + $this->assertStatusGood( $status, "Creation of $dest succeeded ($backendName)." ); } $oldSrcProps = $this->backend->getFileProps( [ 'src' => $source ] ); @@ -388,10 +388,10 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->doOperation( $op ); if ( $okStatus ) { - $this->assertGoodStatus( + $this->assertStatusGood( $status, "Move from $source to $dest succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Move from $source to $dest succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Move from $source to $dest has proper 'success' field in Status ($backendName)." ); @@ -415,7 +415,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { "Source and destination have the same props ($backendName)." ); } } else { - $this->assertBadStatus( + $this->assertStatusNotGood( $status, "Move from $source to $dest fails ($backendName)." ); $this->assertSame( @@ -524,20 +524,20 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( is_string( $srcContent ) ) { $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $srcContent, 'dst' => $source ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $source succeeded ($backendName)." ); } $status = $this->backend->doOperation( $op ); if ( $okStatus ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Deletion of file at $source succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Deletion of file at $source succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Deletion of file at $source has proper 'success' field in Status ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Deletion of file at $source failed ($backendName)." ); } @@ -613,7 +613,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => 'blahblah', 'dst' => $source, 'headers' => [ 'Content-Disposition' => 'xxx' ] ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $source succeeded ($backendName)." ); if ( $this->backend->hasFeatures( FileBackend::ATTR_HEADERS ) ) { $attr = $this->backend->getFileXAttributes( [ 'src' => $source ] ); @@ -622,7 +622,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->describe( [ 'src' => $source, 'headers' => [ 'Content-Disposition' => '' ] ] ); // remove - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Removal of header for $source succeeded ($backendName)." ); if ( $this->backend->hasFeatures( FileBackend::ATTR_HEADERS ) ) { @@ -634,9 +634,9 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->doOperation( $op ); if ( $okStatus ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Describe of file at $source succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Describe of file at $source succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Describe of file at $source has proper 'success' field in Status ($backendName)." ); @@ -645,7 +645,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->assertHasHeaders( $op['headers'], $attr ); } } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Describe of file at $source failed ($backendName)." ); } @@ -713,20 +713,20 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( $alreadyExists ) { $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $oldText, 'dst' => $dest ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $dest succeeded ($backendName)." ); } $status = $this->backend->doOperation( $op ); if ( $okStatus ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $dest succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Creation of file at $dest succeeded ($backendName)." ); $this->assertEquals( [ 0 => true ], $status->success, "Creation of file at $dest has proper 'success' field in Status ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Creation of file at $dest failed ($backendName)." ); } @@ -836,12 +836,12 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { foreach ( $files as $path ) { $status = $this->prepare( [ 'dir' => dirname( $path ) ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Preparing $path succeeded without warnings ($backendName)." ); } foreach ( array_chunk( $createOps, $batchSize ) as $batchOps ) { - $this->assertGoodStatus( + $this->assertStatusGood( $this->backend->doQuickOperations( $batchOps ), "Creation of source files succeeded ($backendName)." ); @@ -854,7 +854,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { } foreach ( array_chunk( $copyOps, $batchSize ) as $batchOps ) { - $this->assertGoodStatus( + $this->assertStatusGood( $this->backend->doQuickOperations( $batchOps ), "Quick copy of source files succeeded ($backendName)." ); @@ -867,7 +867,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { } foreach ( array_chunk( $moveOps, $batchSize ) as $batchOps ) { - $this->assertGoodStatus( + $this->assertStatusGood( $this->backend->doQuickOperations( $batchOps ), "Quick move of source files succeeded ($backendName)." ); @@ -884,7 +884,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { } foreach ( array_chunk( $overSelfOps, $batchSize ) as $batchOps ) { - $this->assertGoodStatus( + $this->assertStatusGood( $this->backend->doQuickOperations( $batchOps ), "Quick copy/move of source files over themselves succeeded ($backendName)." ); @@ -897,7 +897,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { } foreach ( array_chunk( $deleteOps, $batchSize ) as $batchOps ) { - $this->assertGoodStatus( + $this->assertStatusGood( $this->backend->doQuickOperations( $batchOps ), "Quick deletion of source files succeeded ($backendName)." ); @@ -994,7 +994,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { } $status = $this->backend->doOperations( $ops ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of source files succeeded ($backendName)." ); $dest = $params['dst'] = $this->getNewTempFile(); @@ -1011,12 +1011,12 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { // Combine the files into one $status = $this->backend->concatenate( $params ); if ( $okStatus ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of concat file at $dest succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Creation of concat file at $dest succeeded ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Creation of concat file at $dest failed ($backendName)." ); } @@ -1109,7 +1109,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( $alreadyExists ) { $this->prepare( [ 'dir' => dirname( $path ) ] ); $status = $this->create( [ 'dst' => $path, 'content' => $content ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $path succeeded ($backendName)." ); $size = $this->backend->getFileSize( [ 'src' => $path ] ); @@ -1184,7 +1184,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { if ( $content !== null ) { $this->prepare( [ 'dir' => dirname( $path ) ] ); $status = $this->create( [ 'dst' => $path, 'content' => $content ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $path succeeded ($backendName)." ); ob_start(); @@ -1235,7 +1235,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->prepare( [ 'dir' => dirname( $path ) ] ); $status = $this->create( [ 'dst' => $path, 'content' => $content ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $path succeeded ($backendName)." ); static $ranges = [ @@ -1285,7 +1285,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $src succeeded ($backendName)." ); } @@ -1356,7 +1356,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $src succeeded ($backendName)." ); } @@ -1441,7 +1441,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->prepare( [ 'dir' => dirname( $src ) ] ); $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $content[$i], 'dst' => $src ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $src succeeded ($backendName)." ); } @@ -1542,7 +1542,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $this->prepare( [ 'dir' => dirname( $source ) ] ); $status = $this->backend->doOperation( [ 'op' => 'create', 'content' => $content, 'dst' => $source ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of file at $source succeeded ($backendName)." ); $url = $this->backend->getFileHttpUrl( [ 'src' => $source ] ); @@ -1595,45 +1595,45 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->prepare( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Preparing dir $path succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Preparing dir $path succeeded ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Preparing dir $path failed ($backendName)." ); } $status = $this->backend->secure( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Securing dir $path succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Securing dir $path succeeded ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Securing dir $path failed ($backendName)." ); } $status = $this->backend->publish( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Publishing dir $path succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Publishing dir $path succeeded ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Publishing dir $path failed ($backendName)." ); } $status = $this->backend->clean( [ 'dir' => dirname( $path ) ] ); if ( $isOK ) { - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Cleaning dir $path succeeded without warnings ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Cleaning dir $path succeeded ($backendName)." ); } else { - $this->assertFalse( $status->isOK(), + $this->assertStatusNotOK( $status, "Cleaning dir $path failed ($backendName)." ); } } @@ -1670,7 +1670,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { ]; foreach ( $dirs as $dir ) { $status = $this->prepare( [ 'dir' => $dir ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Preparing dir $dir succeeded without warnings ($backendName)." ); } @@ -1683,7 +1683,7 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->clean( [ 'dir' => "$base/unittest-cont1", 'recursive' => 1 ] ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Recursive cleaning of dir $dir succeeded without warnings ($backendName)." ); foreach ( $dirs as $dir ) { @@ -1754,8 +1754,8 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { // Does nothing ] ); - $this->assertGoodStatus( $status, "Operation batch succeeded" ); - $this->assertTrue( $status->isOK(), "Operation batch succeeded" ); + $this->assertStatusGood( $status, "Operation batch succeeded" ); + $this->assertStatusOK( $status, "Operation batch succeeded" ); $this->assertCount( 14, $status->success, "Operation batch has correct success array" ); @@ -1850,8 +1850,8 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { // Does nothing ] ); - $this->assertGoodStatus( $status, "Operation batch succeeded" ); - $this->assertTrue( $status->isOK(), "Operation batch succeeded" ); + $this->assertStatusGood( $status, "Operation batch succeeded" ); + $this->assertStatusOK( $status, "Operation batch succeeded" ); $this->assertCount( 16, $status->success, "Operation batch has correct success array" ); @@ -1924,8 +1924,8 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { // Does nothing ], [ 'force' => 1 ] ); - $this->assertNotEquals( [], $status->getErrors(), "Operation had warnings" ); - $this->assertTrue( $status->isOK(), "Operation batch succeeded" ); + $this->assertStatusNotGood( $status, "Operation had warnings" ); + $this->assertStatusOK( $status, "Operation batch succeeded" ); $this->assertCount( 8, $status->success, "Operation batch has correct success array" ); @@ -1993,9 +1993,9 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $ops[] = [ 'op' => 'create', 'content' => 'xxy', 'dst' => $file ]; } $status = $this->backend->doQuickOperations( $ops ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of files succeeded ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Creation of files succeeded with OK status ($backendName)." ); // Expected listing at root @@ -2175,9 +2175,9 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $ops[] = [ 'op' => 'create', 'content' => 'xxy', 'dst' => $file ]; } $status = $this->backend->doQuickOperations( $ops ); - $this->assertGoodStatus( $status, + $this->assertStatusGood( $status, "Creation of files succeeded ($backendName)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Creation of files succeeded with OK status ($backendName)." ); $this->assertTrue( @@ -2395,53 +2395,53 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { for ( $i = 0; $i < 2; $i++ ) { $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName). ($i)" ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); # # Flip the acquire/release ordering around ## $status = $this->backend->lockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->lockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_EX ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName). ($i)" ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); $status = $this->backend->unlockFiles( $paths, LockManager::LOCK_SH ); - $this->assertEquals( print_r( [], true ), print_r( $status->getErrors(), true ), + $this->assertStatusGood( $status, "Locking of files succeeded ($backendName) ($i)." ); - $this->assertTrue( $status->isOK(), + $this->assertStatusOK( $status, "Locking of files succeeded with OK status ($backendName) ($i)." ); } @@ -2449,18 +2449,14 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $sl = $this->backend->getScopedFileLocks( $paths, LockManager::LOCK_EX, $status ); $this->assertInstanceOf( ScopedLock::class, $sl, "Scoped locking of files succeeded ($backendName)." ); - $this->assertEquals( [], $status->getErrors(), + $this->assertStatusGood( $status, "Scoped locking of files succeeded ($backendName)." ); - $this->assertTrue( $status->isOK(), - "Scoped locking of files succeeded with OK status ($backendName)." ); ScopedLock::release( $sl ); $this->assertNull( $sl, "Scoped unlocking of files succeeded ($backendName)." ); - $this->assertEquals( [], $status->getErrors(), + $this->assertStatusGood( $status, "Scoped unlocking of files succeeded ($backendName)." ); - $this->assertTrue( $status->isOK(), - "Scoped unlocking of files succeeded with OK status ($backendName)." ); } /** @@ -2668,17 +2664,10 @@ class FileBackendIntegrationTest extends MediaWikiIntegrationTestCase { $status = $this->backend->consistencyCheck( $paths ); if ( $okSyncStatus ) { - $this->assertGoodStatus( $status, "Files synced: " . implode( ',', $paths ) ); + $this->assertStatusGood( $status, "Files synced: " . implode( ',', $paths ) ); } else { - $this->assertBadStatus( $status, "Files not synced: " . implode( ',', $paths ) ); + $this->assertStatusNotGood( $status, "Files not synced: " . implode( ',', $paths ) ); } } - private function assertGoodStatus( StatusValue $status, $msg ) { - $this->assertEquals( print_r( [], 1 ), print_r( $status->getErrors(), 1 ), $msg ); - } - - private function assertBadStatus( StatusValue $status, $msg ) { - $this->assertNotEquals( print_r( [], 1 ), print_r( $status->getErrors(), 1 ), $msg ); - } } diff --git a/tests/phpunit/includes/filerepo/StoreBatchTest.php b/tests/phpunit/includes/filerepo/StoreBatchTest.php index b921fbe2a90..0e1ae741a70 100644 --- a/tests/phpunit/includes/filerepo/StoreBatchTest.php +++ b/tests/phpunit/includes/filerepo/StoreBatchTest.php @@ -87,7 +87,7 @@ class StoreBatchTest extends MediaWikiIntegrationTestCase { */ private function storecohort( $fn, $infn, $otherfn, $fromrepo ) { $f = $this->storeit( $fn, $infn, 0 ); - $this->assertTrue( $f->isOK(), 'failed to store a new file' ); + $this->assertStatusOK( $f, 'failed to store a new file' ); $this->assertSame( 0, $f->failCount, "counts wrong {$f->successCount} {$f->failCount}" ); $this->assertSame( 1, $f->successCount, "counts wrong {$f->successCount} {$f->failCount}" ); if ( $fromrepo ) { @@ -96,17 +96,17 @@ class StoreBatchTest extends MediaWikiIntegrationTestCase { } // This should work because we're allowed to overwrite $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE ); - $this->assertTrue( $f->isOK(), 'We should be allowed to overwrite' ); + $this->assertStatusOK( $f, 'We should be allowed to overwrite' ); $this->assertSame( 0, $f->failCount, "counts wrong {$f->successCount} {$f->failCount}" ); $this->assertSame( 1, $f->successCount, "counts wrong {$f->successCount} {$f->failCount}" ); // This should fail because we're overwriting. $f = $this->storeit( $fn, $infn, 0 ); - $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite' ); + $this->assertStatusNotOK( $f, 'We should not be allowed to overwrite' ); $this->assertSame( 1, $f->failCount, "counts wrong {$f->successCount} {$f->failCount}" ); $this->assertSame( 0, $f->successCount, "counts wrong {$f->successCount} {$f->failCount}" ); // This should succeed because we're overwriting the same content. $f = $this->storeit( $fn, $infn, FileRepo::OVERWRITE_SAME ); - $this->assertTrue( $f->isOK(), 'We should be able to overwrite the same content' ); + $this->assertStatusOK( $f, 'We should be able to overwrite the same content' ); $this->assertSame( 0, $f->failCount, "counts wrong {$f->successCount} {$f->failCount}" ); $this->assertSame( 1, $f->successCount, "counts wrong {$f->successCount} {$f->failCount}" ); // This should fail because we're overwriting different content. @@ -115,7 +115,7 @@ class StoreBatchTest extends MediaWikiIntegrationTestCase { $otherfn = $f->value; } $f = $this->storeit( $fn, $otherfn, FileRepo::OVERWRITE_SAME ); - $this->assertFalse( $f->isOK(), 'We should not be allowed to overwrite different content' ); + $this->assertStatusNotOK( $f, 'We should not be allowed to overwrite different content' ); $this->assertSame( 1, $f->failCount, "counts wrong {$f->successCount} {$f->failCount}" ); $this->assertSame( 0, $f->successCount, "counts wrong {$f->successCount} {$f->failCount}" ); } diff --git a/tests/phpunit/includes/filerepo/file/LocalFileTest.php b/tests/phpunit/includes/filerepo/file/LocalFileTest.php index 6c3ddca2f43..bc72607ef67 100644 --- a/tests/phpunit/includes/filerepo/file/LocalFileTest.php +++ b/tests/phpunit/includes/filerepo/file/LocalFileTest.php @@ -849,7 +849,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase { $this->getTestSysop()->getUser(), $props ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); // Check properties of the same object immediately after upload $this->assertFileProperties( $props, $file ); // Check round-trip through the DB @@ -881,7 +881,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase { 'page text', 0 ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); // Test reupload $file = new LocalFile( $title, $repo ); @@ -892,7 +892,7 @@ class LocalFileTest extends MediaWikiIntegrationTestCase { 'page text', 0 ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); } public function provideReserializeMetadata() { diff --git a/tests/phpunit/includes/page/ParserOutputAccessTest.php b/tests/phpunit/includes/page/ParserOutputAccessTest.php index d6ae1b6f7dd..8856dbfcddc 100644 --- a/tests/phpunit/includes/page/ParserOutputAccessTest.php +++ b/tests/phpunit/includes/page/ParserOutputAccessTest.php @@ -37,7 +37,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $this->assertNotNull( $actual ); if ( $actual instanceof StatusValue ) { - $this->assertTrue( $actual->isOK(), 'isOK' ); + $this->assertStatusOK( $actual, 'isOK' ); } $this->assertStringContainsString( $needle, $this->getHtml( $actual ), $msg ); @@ -47,7 +47,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $this->assertNotNull( $actual ); if ( $actual instanceof StatusValue ) { - $this->assertTrue( $actual->isOK(), 'isOK' ); + $this->assertStatusOK( $actual, 'isOK' ); } $this->assertSame( $this->getHtml( $expected ), $this->getHtml( $actual ), $msg ); @@ -57,7 +57,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $this->assertNotNull( $actual ); if ( $actual instanceof StatusValue ) { - $this->assertTrue( $actual->isOK(), 'isOK' ); + $this->assertStatusOK( $actual, 'isOK' ); } $this->assertNotSame( $this->getHtml( $expected ), $this->getHtml( $actual ), $msg ); @@ -268,7 +268,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $parserOptions = $this->getParserOptions(); $status = $access->getParserOutput( $page, $parserOptions ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } /** @@ -431,7 +431,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { // output is for the first revision denied $parserOptions = $this->getParserOptions(); $status = $access->getParserOutput( $page, $parserOptions, $firstRev ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); // TODO: Once PoolWorkArticleView properly reports errors, check that the correct error // is propagated. } @@ -622,7 +622,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $parserOptions = $this->getParserOptions(); $status = $access->getParserOutput( $page, $parserOptions ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } /** @@ -684,8 +684,8 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $cachedResult = $access->getParserOutput( $page, $parserOptions ); $this->assertContainsHtml( 'World', $cachedResult ); - $this->assertTrue( $cachedResult->hasMessage( $expectedMessage ) ); - $this->assertTrue( $cachedResult->hasMessage( 'view-pool-dirty-output' ) ); + $this->assertStatusWarning( $expectedMessage, $cachedResult ); + $this->assertStatusWarning( 'view-pool-dirty-output', $cachedResult ); } /** @@ -706,7 +706,7 @@ class ParserOutputAccessTest extends MediaWikiIntegrationTestCase { $parserOptions = $this->getParserOptions(); $result = $access->getParserOutput( $page, $parserOptions ); - $this->assertFalse( $result->isOK() ); + $this->assertStatusNotOK( $result ); } /** diff --git a/tests/phpunit/includes/page/WikiPageDbTest.php b/tests/phpunit/includes/page/WikiPageDbTest.php index 32d6f7a2555..cd623a6133f 100644 --- a/tests/phpunit/includes/page/WikiPageDbTest.php +++ b/tests/phpunit/includes/page/WikiPageDbTest.php @@ -295,7 +295,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase { $status = $page->doEditContent( $content, "[[testing]] 1", EDIT_NEW ); - $this->assertTrue( $status->isOK(), 'OK' ); + $this->assertStatusOK( $status, 'OK' ); $this->assertTrue( $status->value['new'], 'new' ); $this->assertNotNull( $status->value['revision-record'], 'revision-record' ); @@ -319,7 +319,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase { ); $status = $page->doEditContent( $content, "testing 2", EDIT_UPDATE ); - $this->assertTrue( $status->isOK(), 'OK' ); + $this->assertStatusOK( $status, 'OK' ); $this->assertFalse( $status->value['new'], 'new' ); $this->assertNotNull( $status->value['revision-record'], 'revision-record' ); @@ -378,7 +378,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase { $status = $page->doUserEditContent( $content, $user1, "[[testing]] 1", EDIT_NEW ); - $this->assertTrue( $status->isOK(), 'OK' ); + $this->assertStatusOK( $status, 'OK' ); $this->assertTrue( $status->value['new'], 'new' ); $this->assertNotNull( $status->value['revision-record'], 'revision-record' ); @@ -436,7 +436,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase { // try null edit, with a different user $status = $page->doUserEditContent( $content, $user2, 'This changes nothing', EDIT_UPDATE, false ); - $this->assertTrue( $status->isOK(), 'OK' ); + $this->assertStatusOK( $status, 'OK' ); $this->assertFalse( $status->value['new'], 'new' ); $this->assertNull( $status->value['revision-record'], 'revision-record' ); $this->assertNotNull( $page->getRevisionRecord() ); @@ -454,7 +454,7 @@ class WikiPageDbTest extends MediaWikiLangTestCase { ); $status = $page->doUserEditContent( $content, $user1, "testing 2", EDIT_UPDATE ); - $this->assertTrue( $status->isOK(), 'OK' ); + $this->assertStatusOK( $status, 'OK' ); $this->assertFalse( $status->value['new'], 'new' ); $this->assertNotNull( $status->value['revision-record'], 'revision-record' ); $statusRevRecord = $status->value['revision-record']; @@ -547,8 +547,8 @@ class WikiPageDbTest extends MediaWikiLangTestCase { $status1 = $page->doUserEditContent( $content, $user, __METHOD__ ); $status2 = $page->doUserEditContent( $content, $user, __METHOD__ ); - $this->assertTrue( $status1->isOK(), 'OK' ); - $this->assertTrue( $status2->isOK(), 'OK' ); + $this->assertStatusOK( $status1, 'OK' ); + $this->assertStatusOK( $status2, 'OK' ); $this->assertTrue( isset( $status1->value['revision-record'] ), 'OK' ); $this->assertFalse( isset( $status2->value['revision-record'] ), 'OK' ); @@ -1897,7 +1897,7 @@ more stuff $logId = $status->getValue(); $allRestrictions = $page->getTitle()->getAllRestrictions(); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertIsInt( $logId ); $this->assertSame( $expectedRestrictions, $allRestrictions ); foreach ( $expectedRestrictionExpiries as $key => $value ) { @@ -1940,7 +1940,7 @@ more stuff $this->setService( 'ReadOnlyMode', $readOnly ); $status = $page->doUpdateRestrictions( [], [], $cascade, 'aReason', $user, [] ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); $this->assertSame( 'readonlytext', $status->getMessage()->getKey() ); } @@ -1963,7 +1963,7 @@ more stuff ); // The first entry should have a logId as it did something - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertIsInt( $status->getValue() ); $status = $page->doUpdateRestrictions( @@ -1976,7 +1976,7 @@ more stuff ); // The second entry should not have a logId as nothing changed - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertNull( $status->getValue() ); } @@ -1997,7 +1997,7 @@ more stuff $user, [] ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertIsInt( $status->getValue() ); $this->assertSelect( 'logging', @@ -2015,7 +2015,7 @@ more stuff $user, [] ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertIsInt( $status->getValue() ); $this->assertSelect( 'logging', @@ -2033,7 +2033,7 @@ more stuff $user, [] ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertIsInt( $status->getValue() ); $this->assertSelect( 'logging', diff --git a/tests/phpunit/includes/password/UserPasswordPolicyTest.php b/tests/phpunit/includes/password/UserPasswordPolicyTest.php index 926a24352a9..142f7bfaa6d 100644 --- a/tests/phpunit/includes/password/UserPasswordPolicyTest.php +++ b/tests/phpunit/includes/password/UserPasswordPolicyTest.php @@ -193,8 +193,8 @@ class UserPasswordPolicyTest extends MediaWikiIntegrationTestCase { $user->addToDatabase(); $status = $upp->checkUserPassword( $user, 'Passpass' ); - $this->assertFalse( $status->isGood(), 'password invalid' ); - $this->assertTrue( $status->isOK(), 'can login' ); + $this->assertStatusNotGood( $status, 'password invalid' ); + $this->assertStatusOK( $status, 'can login' ); } /** diff --git a/tests/phpunit/includes/upload/UploadFromUrlTest.php b/tests/phpunit/includes/upload/UploadFromUrlTest.php index c62be14fc35..2038a571679 100644 --- a/tests/phpunit/includes/upload/UploadFromUrlTest.php +++ b/tests/phpunit/includes/upload/UploadFromUrlTest.php @@ -221,7 +221,7 @@ class UploadFromUrlTest extends ApiTestCase { $upload->initialize( 'Test.png', 'http://www.example.com/test.png' ); $status = $upload->fetchFile(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertUploadOk( $upload ); } @@ -244,7 +244,7 @@ class UploadFromUrlTest extends ApiTestCase { $upload->initialize( 'Test.png', 'http://www.example.com/test.png' ); $status = $upload->fetchFile(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertUploadOk( $upload ); } diff --git a/tests/phpunit/includes/user/BotPasswordTest.php b/tests/phpunit/includes/user/BotPasswordTest.php index d68a41d1a4c..f4c66de8adb 100644 --- a/tests/phpunit/includes/user/BotPasswordTest.php +++ b/tests/phpunit/includes/user/BotPasswordTest.php @@ -330,7 +330,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase { ); $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request ); $this->assertInstanceOf( Status::class, $status ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $session = $status->getValue(); $this->assertInstanceOf( MediaWiki\Session\Session::class, $session ); $this->assertInstanceOf( @@ -450,7 +450,7 @@ class BotPasswordTest extends MediaWikiIntegrationTestCase { $status = $bp->save( 'insert' ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusNotGood( $status ); $this->assertNotEmpty( $status->getErrors() ); $this->assertSame( diff --git a/tests/phpunit/includes/user/PasswordResetTest.php b/tests/phpunit/includes/user/PasswordResetTest.php index 6828e859138..9c0a3c9f394 100644 --- a/tests/phpunit/includes/user/PasswordResetTest.php +++ b/tests/phpunit/includes/user/PasswordResetTest.php @@ -522,7 +522,7 @@ class PasswordResetTest extends MediaWikiIntegrationTestCase { 'Expected status to be good, result was: ' . $status->__toString() ); } else { - $this->assertFalse( $status->isGood(), 'Expected status to not be good' ); + $this->assertStatusNotGood( $status, 'Expected status to not be good' ); if ( is_string( $error ) ) { $this->assertNotEmpty( $status->getErrors() ); $message = $status->getErrors()[0]['message']; diff --git a/tests/phpunit/includes/user/TalkPageNotificationManagerTest.php b/tests/phpunit/includes/user/TalkPageNotificationManagerTest.php index f1152f90cd2..dea979bb11a 100644 --- a/tests/phpunit/includes/user/TalkPageNotificationManagerTest.php +++ b/tests/phpunit/includes/user/TalkPageNotificationManagerTest.php @@ -34,7 +34,7 @@ class TalkPageNotificationManagerTest extends MediaWikiIntegrationTestCase { NS_MAIN, $this->getTestSysop()->getUser() ); - $this->assertTrue( $status->isGood(), 'create revision of user talk' ); + $this->assertStatusGood( $status, 'create revision of user talk' ); return $status->getValue()['revision-record']; } diff --git a/tests/phpunit/includes/user/UserTest.php b/tests/phpunit/includes/user/UserTest.php index eb13292e85f..58dfd4534d0 100644 --- a/tests/phpunit/includes/user/UserTest.php +++ b/tests/phpunit/includes/user/UserTest.php @@ -369,8 +369,8 @@ class UserTest extends MediaWikiIntegrationTestCase { return false; } ); $status = $this->user->checkPasswordValidity( 'Password1234' ); - $this->assertTrue( $status->isOK() ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusOK( $status ); + $this->assertStatusNotGood( $status ); $this->assertSame( 'isValidPassword returned false', $status->getErrors()[0]['message'] ); $this->removeTemporaryHook( 'isValidPassword' ); @@ -380,9 +380,7 @@ class UserTest extends MediaWikiIntegrationTestCase { return true; } ); $status = $this->user->checkPasswordValidity( 'Password1234' ); - $this->assertTrue( $status->isOK() ); - $this->assertTrue( $status->isGood() ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); $this->removeTemporaryHook( 'isValidPassword' ); @@ -391,8 +389,8 @@ class UserTest extends MediaWikiIntegrationTestCase { return true; } ); $status = $this->user->checkPasswordValidity( 'Password1234' ); - $this->assertTrue( $status->isOK() ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusOK( $status ); + $this->assertStatusNotGood( $status ); $this->assertSame( 'isValidPassword returned true', $status->getErrors()[0]['message'] ); $this->removeTemporaryHook( 'isValidPassword' ); @@ -955,7 +953,7 @@ class UserTest extends MediaWikiIntegrationTestCase { $this->assertSame( $user->getTitleKey(), $titleKey ); $status = $user->addToDatabase(); - $this->assertTrue( $status->isOK(), 'User can be added to the database' ); + $this->assertStatusOK( $status, 'User can be added to the database' ); $this->assertSame( $name, User::whoIs( $user->getId() ) ); } diff --git a/tests/phpunit/includes/utils/ZipDirectoryReaderTest.php b/tests/phpunit/includes/utils/ZipDirectoryReaderTest.php index 51451675274..86a3f2e1fa9 100644 --- a/tests/phpunit/includes/utils/ZipDirectoryReaderTest.php +++ b/tests/phpunit/includes/utils/ZipDirectoryReaderTest.php @@ -20,13 +20,13 @@ class ZipDirectoryReaderTest extends MediaWikiIntegrationTestCase { public function readZipAssertError( $file, $error, $assertMessage ) { $this->entries = []; $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] ); - $this->assertTrue( $status->hasMessage( $error ), $assertMessage ); + $this->assertStatusError( $error, $status, $assertMessage ); } public function readZipAssertSuccess( $file, $assertMessage ) { $this->entries = []; $status = ZipDirectoryReader::read( "{$this->zipDir}/$file", [ $this, 'zipCallback' ] ); - $this->assertTrue( $status->isOK(), $assertMessage ); + $this->assertStatusOK( $status, $assertMessage ); } public function testEmpty() { diff --git a/tests/phpunit/integration/includes/block/BlockUserTest.php b/tests/phpunit/integration/includes/block/BlockUserTest.php index 216dfdecc35..a2aa31b89fa 100644 --- a/tests/phpunit/integration/includes/block/BlockUserTest.php +++ b/tests/phpunit/integration/includes/block/BlockUserTest.php @@ -38,7 +38,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test block' )->placeBlock(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $block = $this->user->getBlock(); $this->assertSame( 'test block', $block->getReasonComment()->text ); $this->assertInstanceOf( DatabaseBlock::class, $block ); @@ -62,7 +62,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'isHideUser' => true ] )->placeBlock(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $block = $this->user->getBlock(); $this->assertInstanceOf( DatabaseBlock::class, $block ); $this->assertSame( 'test hideuser', $block->getReasonComment()->text ); @@ -84,7 +84,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { [], [ $page ] )->placeBlock(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $block = $this->user->getBlock(); $this->assertInstanceOf( DatabaseBlock::class, $block ); $this->assertSame( 'test existingpage', $block->getReasonComment()->text ); @@ -104,8 +104,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { [], [ $page ] )->placeBlock(); - $this->assertFalse( $status->isOK() ); - $this->assertTrue( $status->hasMessage( 'cant-block-nonexistent-page' ) ); + $this->assertStatusError( 'cant-block-nonexistent-page', $status ); } /** @@ -118,7 +117,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test block' )->placeBlockUnsafe(); - $this->assertTrue( $blockStatus->isOK() ); + $this->assertStatusOK( $blockStatus ); $priorBlock = $this->user->getBlock(); $this->assertInstanceOf( DatabaseBlock::class, $priorBlock ); $this->assertSame( 'test block', $priorBlock->getReasonComment()->text ); @@ -131,7 +130,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test reblock' )->placeBlockUnsafe( /*reblock=*/false ); - $this->assertFalse( $reblockStatus->isOK() ); + $this->assertStatusNotOK( $reblockStatus ); $this->user->clearInstanceCache(); $block = $this->user->getBlock(); @@ -144,7 +143,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test block' )->placeBlockUnsafe( /*reblock=*/true ); - $this->assertFalse( $reblockStatus->isOK() ); + $this->assertStatusNotOK( $reblockStatus ); $this->user->clearInstanceCache(); $block = $this->user->getBlock(); @@ -157,7 +156,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test reblock' )->placeBlockUnsafe( /*reblock=*/true ); - $this->assertTrue( $reblockStatus->isOK() ); + $this->assertStatusOK( $reblockStatus ); $this->user->clearInstanceCache(); $block = $this->user->getBlock(); @@ -187,7 +186,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test block' )->placeBlockUnsafe(); - $this->assertTrue( $blockStatus->isOK() ); + $this->assertStatusOK( $blockStatus ); $priorBlock = $this->user->getBlock(); $this->assertInstanceOf( DatabaseBlock::class, $priorBlock ); $this->assertSame( $priorBlock->getId(), $hookBlock->getId() ); @@ -201,7 +200,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test reblock' )->placeBlockUnsafe( /*reblock=*/true ); - $this->assertTrue( $reblockStatus->isOK() ); + $this->assertStatusOK( $reblockStatus ); $this->user->clearInstanceCache(); $newBlock = $this->user->getBlock(); @@ -221,7 +220,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'test block with autoblocking', [ 'isAutoblocking' => true ] )->placeBlockUnsafe(); - $this->assertTrue( $blockStatus->isOK() ); + $this->assertStatusOK( $blockStatus ); $block = $blockStatus->getValue(); $target = '1.2.3.4'; @@ -244,7 +243,7 @@ class BlockUserTest extends MediaWikiIntegrationTestCase { 'infinity', 'test IP block' )->placeBlockUnsafe(); - $this->assertTrue( $IPBlockStatus->isOK() ); + $this->assertStatusOK( $IPBlockStatus ); $IPBlock = $IPBlockStatus->getValue(); $this->assertInstanceOf( DatabaseBlock::class, $IPBlock ); $this->assertNull( $hookPriorBlock ); diff --git a/tests/phpunit/integration/includes/block/UnblockUserTest.php b/tests/phpunit/integration/includes/block/UnblockUserTest.php index e7c593846ab..f31f6116ccd 100644 --- a/tests/phpunit/integration/includes/block/UnblockUserTest.php +++ b/tests/phpunit/integration/includes/block/UnblockUserTest.php @@ -58,7 +58,7 @@ class UnblockUserTest extends MediaWikiIntegrationTestCase { $performer, 'test' )->unblock(); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertNotInstanceOf( DatabaseBlock::class, User::newFromName( @@ -78,7 +78,7 @@ class UnblockUserTest extends MediaWikiIntegrationTestCase { $this->mockRegisteredUltimateAuthority(), 'test' )->unblock(); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); $this->assertContains( 'ipb_cant_unblock', $this->convertErrorsArray( diff --git a/tests/phpunit/integration/includes/page/DeletePageTest.php b/tests/phpunit/integration/includes/page/DeletePageTest.php index ba1cfd5c40c..dcadbc687b7 100644 --- a/tests/phpunit/integration/includes/page/DeletePageTest.php +++ b/tests/phpunit/integration/includes/page/DeletePageTest.php @@ -284,7 +284,7 @@ class DeletePageTest extends MediaWikiIntegrationTestCase { ->setLogSubtype( $logSubtype ) ->deleteUnsafe( $reason ); - $this->assertTrue( $status->isGood(), 'Deletion should succeed' ); + $this->assertStatusGood( $status, 'Deletion should succeed' ); DeferredUpdates::doUpdates(); diff --git a/tests/phpunit/integration/includes/page/RollbackPageTest.php b/tests/phpunit/integration/includes/page/RollbackPageTest.php index 154102f589c..fda99afa6b5 100644 --- a/tests/phpunit/integration/includes/page/RollbackPageTest.php +++ b/tests/phpunit/integration/includes/page/RollbackPageTest.php @@ -124,15 +124,15 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { // Make some edits $text = "one"; $status1 = $this->editPage( $page, $text, "section one", NS_MAIN, $admin ); - $this->assertTrue( $status1->isGood(), 'edit 1 success' ); + $this->assertStatusGood( $status1, 'edit 1 success' ); $text .= "\n\ntwo"; $status2 = $this->editPage( $page, $text, "adding section two", NS_MAIN, $user1 ); - $this->assertTrue( $status2->isGood(), 'edit 2 success' ); + $this->assertStatusGood( $status2, 'edit 2 success' ); $text .= "\n\nthree"; $status3 = $this->editPage( $page, $text, "adding section three", NS_MAIN, $user2 ); - $this->assertTrue( $status3->isGood(), 'edit 3 success' ); + $this->assertStatusGood( $status3, 'edit 3 success' ); /** @var RevisionRecord $rev1 */ /** @var RevisionRecord $rev2 */ @@ -161,7 +161,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { ->getRollbackPageFactory() ->newRollbackPage( $page, $admin, $user2 ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackStatus->isGood() ); + $this->assertStatusGood( $rollbackStatus ); $this->assertEquals( $rev2->getSha1(), @@ -191,27 +191,26 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { $text = "one"; $status1 = $this->editPage( $page, $text, "section one", NS_MAIN, $admin ); - $this->assertTrue( $status1->isGood(), 'edit 1 success' ); + $this->assertStatusGood( $status1, 'edit 1 success' ); $rev1 = $page->getRevisionRecord(); $user1 = $this->getTestUser( [ 'sysop' ] )->getUser(); $text .= "\n\ntwo"; $status1 = $this->editPage( $page, $text, "adding section two", NS_MAIN, $user1 ); - $this->assertTrue( $status1->isGood(), 'edit 2 success' ); + $this->assertStatusGood( $status1, 'edit 2 success' ); $rollbackResult = $this->getServiceContainer() ->getRollbackPageFactory() ->newRollbackPage( $page, $admin, $user1 ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); # now, try the rollback again $rollbackResult = $this->getServiceContainer() ->getRollbackPageFactory() ->newRollbackPage( $page, $admin, $user1 ) ->rollback(); - $this->assertFalse( $rollbackResult->isGood() ); - $this->assertTrue( $rollbackResult->hasMessage( 'alreadyrolled' ) ); + $this->assertStatusError( 'alreadyrolled', $rollbackResult ); $this->assertEquals( $rev1->getSha1(), $page->getRevisionRecord()->getSha1(), "rollback did not revert to the correct revision" ); @@ -227,8 +226,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { new UserIdentityValue( 0, '127.0.0.1' ) ) ->rollback(); - $this->assertFalse( $rollbackStatus->isGood() ); - $this->assertTrue( $rollbackStatus->hasMessage( 'notanarticle' ) ); + $this->assertStatusError( 'notanarticle', $rollbackStatus ); } /** @@ -243,12 +241,12 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { $result = []; $text = "one"; $status = $this->editPage( $page, $text, "section one", NS_MAIN, $user1 ); - $this->assertTrue( $status->isGood(), 'edit 1 success' ); + $this->assertStatusGood( $status, 'edit 1 success' ); $result['revision-one'] = $status->getValue()['revision-record']; $text .= "\n\ntwo"; $status = $this->editPage( $page, $text, "adding section two", NS_MAIN, $user2 ); - $this->assertTrue( $status->isGood(), 'edit 2 success' ); + $this->assertStatusGood( $status, 'edit 2 success' ); $result['revision-two'] = $status->getValue()['revision-record']; return $result; } @@ -269,7 +267,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { ->newRollbackPage( $page, $admin, $user1 ) ->setChangeTags( [ 'tag' ] ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); $this->assertContains( 'mw-rollback', $rollbackResult->getValue()['tags'] ); $this->assertContains( 'tag', $rollbackResult->getValue()['tags'] ); } @@ -286,7 +284,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { ->newRollbackPage( $page, $admin, $user1 ) ->markAsBot( true ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); $rc = $this->getServiceContainer()->getRevisionStore()->getRecentChange( $page->getRevisionRecord() ); $this->assertNotNull( $rc ); $this->assertSame( '1', $rc->getAttribute( 'rc_bot' ) ); @@ -305,7 +303,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { ->newRollbackPage( $page, $admin, $user1 ) ->markAsBot( true ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); $rc = $this->getServiceContainer()->getRevisionStore()->getRecentChange( $page->getRevisionRecord() ); $this->assertNotNull( $rc ); $this->assertSame( '0', $rc->getAttribute( 'rc_bot' ) ); @@ -323,7 +321,7 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { ->newRollbackPage( $page, $admin, $user1 ) ->setSummary( 'TEST! $1 $2 $3 $4 $5 $6' ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); $targetTimestamp = $this->getServiceContainer() ->getContentLanguage() ->timeanddate( $revisions['revision-one']->getTimestamp() ); @@ -348,18 +346,18 @@ class RollbackPageTest extends MediaWikiIntegrationTestCase { $status1 = $this->editPage( $page, new JsonContent( '{}' ), "it's json", NS_MAIN, $admin ); - $this->assertTrue( $status1->isGood(), 'edit 1 success' ); + $this->assertStatusGood( $status1, 'edit 1 success' ); $status1 = $this->editPage( $page, new WikitextContent( 'bla' ), "no, it's wikitext", NS_MAIN, $user1 ); - $this->assertTrue( $status1->isGood(), 'edit 2 success' ); + $this->assertStatusGood( $status1, 'edit 2 success' ); $rollbackResult = $this->getServiceContainer() ->getRollbackPageFactory() ->newRollbackPage( $page, $admin, $user1 ) ->setSummary( 'TESTING' ) ->rollbackIfAllowed(); - $this->assertTrue( $rollbackResult->isGood() ); + $this->assertStatusGood( $rollbackResult ); $logQuery = DatabaseLogEntry::getSelectQueryData(); $logRow = $this->db->selectRow( $logQuery['tables'], diff --git a/tests/phpunit/integration/includes/watchlist/WatchlistManagerTest.php b/tests/phpunit/integration/includes/watchlist/WatchlistManagerTest.php index 879968b20c8..b2a920c52f8 100644 --- a/tests/phpunit/integration/includes/watchlist/WatchlistManagerTest.php +++ b/tests/phpunit/integration/includes/watchlist/WatchlistManagerTest.php @@ -194,7 +194,7 @@ class WatchlistManagerTest extends MediaWikiIntegrationTestCase { $actual = $watchlistManager->addWatch( $performer, $title ); - $this->assertFalse( $actual->isGood() ); + $this->assertStatusNotGood( $actual ); $this->assertFalse( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -217,7 +217,7 @@ class WatchlistManagerTest extends MediaWikiIntegrationTestCase { $actual = $watchlistManager->removeWatch( $performer, $title ); - $this->assertFalse( $actual->isGood() ); + $this->assertStatusNotGood( $actual ); $this->assertTrue( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } diff --git a/tests/phpunit/structure/SettingsTest.php b/tests/phpunit/structure/SettingsTest.php index 5837607d04e..487bfb5ae16 100644 --- a/tests/phpunit/structure/SettingsTest.php +++ b/tests/phpunit/structure/SettingsTest.php @@ -65,13 +65,7 @@ class SettingsTest extends MediaWikiIntegrationTestCase { public function testConfigSchemaDefaultsValidate() { $settingsBuilder = $this->getSettingsBuilderWithSchema(); $validationResult = $settingsBuilder->apply()->validate(); - $this->assertArrayEquals( - [], - $validationResult->getErrorsByType( 'errors' ), - false, - false, - "$validationResult" - ); + $this->assertStatusOK( $validationResult ); } /** @@ -80,13 +74,7 @@ class SettingsTest extends MediaWikiIntegrationTestCase { public function testCurrentSettingsValidate() { global $wgSettings; $validationResult = $wgSettings->validate(); - $this->assertArrayEquals( - [], - $validationResult->getErrorsByType( 'error' ), - false, - false, - "$validationResult" - ); + $this->assertStatusOK( $validationResult ); } public function provideConfigGeneration() { diff --git a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php index c29e353064f..50fd12082f7 100644 --- a/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php +++ b/tests/phpunit/tests/MediaWikiIntegrationTestCaseTest.php @@ -430,7 +430,7 @@ class MediaWikiIntegrationTestCaseTest extends MediaWikiIntegrationTestCase { public function assertEditPage( $expected, $page, $content ) { $status = $this->editPage( $page, $content ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $this->assertNotNull( $status->getValue()['revision-record'] ); /** @var RevisionRecord $rev */ diff --git a/tests/phpunit/unit/includes/MovePageTest.php b/tests/phpunit/unit/includes/MovePageTest.php index 45ba1711793..4c899c70014 100644 --- a/tests/phpunit/unit/includes/MovePageTest.php +++ b/tests/phpunit/unit/includes/MovePageTest.php @@ -130,9 +130,9 @@ class MovePageTest extends MediaWikiUnitTestCase { ); foreach ( [ 'checkPermissions', 'authorizeMove', 'probablyCanMove' ] as $method ) { $notSpamStatus = $mp->$method( $this->mockRegisteredUltimateAuthority(), 'NOT_SPAM' ); - $this->assertTrue( $notSpamStatus->isGood() ); + $this->assertStatusGood( $notSpamStatus ); $spamStatus = $mp->$method( $this->mockRegisteredUltimateAuthority(), 'SPAM' ); - $this->assertFalse( $spamStatus->isGood() ); + $this->assertStatusNotGood( $spamStatus ); $this->assertArrayEquals( [ [ 'message' => 'spamprotectiontext', 'type' => 'error', diff --git a/tests/phpunit/unit/includes/Permissions/PermissionStatusTest.php b/tests/phpunit/unit/includes/Permissions/PermissionStatusTest.php index 40f0b1174e5..4fe06b13499 100644 --- a/tests/phpunit/unit/includes/Permissions/PermissionStatusTest.php +++ b/tests/phpunit/unit/includes/Permissions/PermissionStatusTest.php @@ -32,8 +32,8 @@ class PermissionStatusTest extends MediaWikiUnitTestCase { public function testNewEmpty() { $status = PermissionStatus::newEmpty(); - $this->assertTrue( $status->isOK() ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusOK( $status ); + $this->assertStatusGood( $status ); $this->assertEmpty( $status->getErrors() ); } diff --git a/tests/phpunit/unit/includes/Permissions/SimpleAuthorityTest.php b/tests/phpunit/unit/includes/Permissions/SimpleAuthorityTest.php index bd45b83be6f..fc465038e12 100644 --- a/tests/phpunit/unit/includes/Permissions/SimpleAuthorityTest.php +++ b/tests/phpunit/unit/includes/Permissions/SimpleAuthorityTest.php @@ -66,10 +66,10 @@ class SimpleAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->probablyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->probablyCan( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testDefinitlyCan() { @@ -83,10 +83,10 @@ class SimpleAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->definitelyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->definitelyCan( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testAuthorizeRead() { @@ -100,10 +100,10 @@ class SimpleAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeRead( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->authorizeRead( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testAuthorizeWrite() { @@ -117,10 +117,10 @@ class SimpleAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeWrite( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->authorizeWrite( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testIsAllowedAnyThrowsOnEmptySet() { diff --git a/tests/phpunit/unit/includes/Permissions/UltimateAuthorityTest.php b/tests/phpunit/unit/includes/Permissions/UltimateAuthorityTest.php index 7973f0cd5d7..7696b5a2374 100644 --- a/tests/phpunit/unit/includes/Permissions/UltimateAuthorityTest.php +++ b/tests/phpunit/unit/includes/Permissions/UltimateAuthorityTest.php @@ -61,7 +61,7 @@ class UltimateAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->probablyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); } public function testDefinitlyCan() { @@ -74,7 +74,7 @@ class UltimateAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->definitelyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); } public function testAuthorizeRead() { @@ -87,7 +87,7 @@ class UltimateAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeRead( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); } public function testAuthorizeWrite() { @@ -100,7 +100,7 @@ class UltimateAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeWrite( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); } public function testIsAllowedAnyThrowsOnEmptySet() { diff --git a/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php b/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php index 3716c9cb68a..2926dfb1b8d 100644 --- a/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php +++ b/tests/phpunit/unit/includes/Permissions/UserAuthorityTest.php @@ -144,7 +144,7 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = PermissionStatus::newEmpty(); $target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); $this->assertTrue( $authority->authorizeRead( 'read', $target, $status ) ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); } public function testBlockedUserCanNotWrite() { @@ -156,7 +156,7 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = PermissionStatus::newEmpty(); $target = new PageIdentityValue( 321, NS_MAIN, __METHOD__, PageIdentity::LOCAL ); $this->assertFalse( $authority->authorizeRead( 'edit', $target, $status ) ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); $this->assertSame( $block, $status->getBlock() ); } @@ -184,10 +184,10 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->probablyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->probablyCan( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testDefinitlyCan() { @@ -200,10 +200,10 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->definitelyCan( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->definitelyCan( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testAuthorizeRead() { @@ -216,10 +216,10 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeRead( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->authorizeRead( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testAuthorizeWrite() { @@ -232,10 +232,10 @@ class UserAuthorityTest extends MediaWikiUnitTestCase { $status = new PermissionStatus(); $authority->authorizeWrite( 'foo', $target, $status ); - $this->assertTrue( $status->isOK() ); + $this->assertStatusOK( $status ); $authority->authorizeWrite( 'quux', $target, $status ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public function testIsAllowedAnyThrowsOnEmptySet() { diff --git a/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintTestTrait.php b/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintTestTrait.php index 24c988b4f6d..6e78e880445 100644 --- a/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintTestTrait.php +++ b/tests/phpunit/unit/includes/editpage/Constraint/EditConstraintTestTrait.php @@ -38,7 +38,7 @@ trait EditConstraintTestTrait { ); $status = $constraint->getLegacyStatus(); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -53,8 +53,8 @@ trait EditConstraintTestTrait { ); $status = $constraint->getLegacyStatus(); - $this->assertFalse( $status->isGood() ); - $this->assertSame( $statusCode, $status->getValue() ); + $this->assertStatusNotGood( $status ); + $this->assertStatusValue( $statusCode, $status ); } } diff --git a/tests/phpunit/unit/includes/filebackend/lockmanager/MySqlLockManagerTest.php b/tests/phpunit/unit/includes/filebackend/lockmanager/MySqlLockManagerTest.php index aebbc755ef2..d83fdc74412 100644 --- a/tests/phpunit/unit/includes/filebackend/lockmanager/MySqlLockManagerTest.php +++ b/tests/phpunit/unit/includes/filebackend/lockmanager/MySqlLockManagerTest.php @@ -332,6 +332,6 @@ class MySqlLockManagerTest extends MediaWikiUnitTestCase { 'message' => 'lockmanager-fail-db-release', 'params' => [ 'main' ], ] ], $status->getErrors() ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } } diff --git a/tests/phpunit/unit/includes/installer/SqliteInstallerTest.php b/tests/phpunit/unit/includes/installer/SqliteInstallerTest.php index 493d5276599..1c74f8789b7 100644 --- a/tests/phpunit/unit/includes/installer/SqliteInstallerTest.php +++ b/tests/phpunit/unit/includes/installer/SqliteInstallerTest.php @@ -19,7 +19,7 @@ class SqliteInstallerTest extends MediaWikiUnitTestCase { mkdir( $dir, 0000 ); /** @var Status $status */ $status = $method->invoke( null, $dir ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusNotGood( $status ); $this->assertSame( 'config-sqlite-dir-unwritable', $status->getErrors()[0]['message'] ); rmdir( $dir ); } @@ -27,13 +27,13 @@ class SqliteInstallerTest extends MediaWikiUnitTestCase { # Test 2: Should return fatal Status if $dir not exist and it parent also not exist $dir = sys_get_temp_dir() . '/' . uniqid( 'MediaWikiTest' ) . '/' . uniqid( 'MediaWikiTest' ); $status = $method->invoke( null, $dir ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusNotGood( $status ); # Test 3: Should return good Status if $dir not exist and it parent writable $dir = sys_get_temp_dir() . '/' . uniqid( 'MediaWikiTest' ); /** @var Status $status */ $status = $method->invoke( null, $dir ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -51,7 +51,7 @@ class SqliteInstallerTest extends MediaWikiUnitTestCase { mkdir( sys_get_temp_dir() . "/$random", 0000 ); /** @var Status $status */ $status = $method->invoke( null, $dir ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusNotGood( $status ); $this->assertSame( 'config-sqlite-mkdir-error', $status->getErrors()[0]['message'] ); rmdir( sys_get_temp_dir() . "/$random" ); } @@ -59,7 +59,7 @@ class SqliteInstallerTest extends MediaWikiUnitTestCase { # Test 2: Test .htaccess content after created successfully $dir = sys_get_temp_dir() . '/' . uniqid( 'MediaWikiTest' ); $status = $method->invoke( null, $dir ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertSame( "Deny from all\n", file_get_contents( "$dir/.htaccess" ) ); unlink( "$dir/.htaccess" ); rmdir( $dir ); diff --git a/tests/phpunit/unit/includes/json/FormatJsonTest.php b/tests/phpunit/unit/includes/json/FormatJsonTest.php index 9c3adbcb074..de5fd3021c4 100644 --- a/tests/phpunit/unit/includes/json/FormatJsonTest.php +++ b/tests/phpunit/unit/includes/json/FormatJsonTest.php @@ -172,13 +172,13 @@ class FormatJsonTest extends MediaWikiUnitTestCase { $st = FormatJson::parse( $json ); $this->assertInstanceOf( Status::class, $st ); - $this->assertTrue( $st->isGood() ); - $this->assertEquals( $expected, $st->getValue() ); + $this->assertStatusGood( $st ); + $this->assertStatusValue( $expected, $st ); $st = FormatJson::parse( $json, FormatJson::FORCE_ASSOC ); $this->assertInstanceOf( Status::class, $st ); - $this->assertTrue( $st->isGood() ); - $this->assertEquals( $value, $st->getValue() ); + $this->assertStatusGood( $st ); + $this->assertStatusValue( $value, $st ); } public static function provideParseErrors() { @@ -197,7 +197,7 @@ class FormatJsonTest extends MediaWikiUnitTestCase { public function testParseErrors( $value, $error ) { $st = FormatJson::parse( $value ); $this->assertInstanceOf( Status::class, $st ); - $this->assertFalse( $st->isOK() ); + $this->assertStatusNotOK( $st ); $this->assertTrue( $st->hasMessage( $error ), "Does not have $error message" @@ -256,8 +256,8 @@ class FormatJsonTest extends MediaWikiUnitTestCase { public function testParseStripComments( $json, $expect ) { $st = FormatJson::parse( $json, FormatJson::STRIP_COMMENTS ); $this->assertInstanceOf( Status::class, $st ); - $this->assertTrue( $st->isGood() ); - $this->assertEquals( $expect, $st->getValue() ); + $this->assertStatusGood( $st ); + $this->assertStatusValue( $expect, $st ); } /** @@ -425,12 +425,12 @@ class FormatJsonTest extends MediaWikiUnitTestCase { $st = FormatJson::parse( $value, FormatJson::TRY_FIXING ); $this->assertInstanceOf( Status::class, $st ); if ( $expected === false ) { - $this->assertFalse( $st->isOK(), 'Expected isOK() == false' ); + $this->assertStatusNotOK( $st, 'Expected isOK() == false' ); } else { $this->assertSame( $expectedGoodStatus, $st->isGood(), 'Expected isGood() == ' . ( $expectedGoodStatus ? 'true' : 'false' ) ); - $this->assertTrue( $st->isOK(), 'Expected isOK == true' ); + $this->assertStatusOK( $st, 'Expected isOK == true' ); $val = FormatJson::encode( $st->getValue(), false, FormatJson::ALL_OK ); $this->assertEquals( $expected, $val ); } diff --git a/tests/phpunit/unit/includes/libs/DeflateTest.php b/tests/phpunit/unit/includes/libs/DeflateTest.php index b0305003fa4..2394631e2f8 100644 --- a/tests/phpunit/unit/includes/libs/DeflateTest.php +++ b/tests/phpunit/unit/includes/libs/DeflateTest.php @@ -22,6 +22,7 @@ * @covers Deflate */ class DeflateTest extends PHPUnit\Framework\TestCase { + use MediaWikiTestCaseTrait; public function provideIsDeflated() { return [ @@ -54,11 +55,10 @@ class DeflateTest extends PHPUnit\Framework\TestCase { public function testInflate( $data, $ok, $value ) { $actual = Deflate::inflate( $data ); if ( $ok ) { - $this->assertTrue( $actual->isOK() ); - $this->assertSame( $value, $actual->getValue() ); + $this->assertStatusOK( $actual ); + $this->assertStatusValue( $value, $actual ); } else { - $this->assertFalse( $actual->isOK() ); - $this->assertTrue( $actual->hasMessage( $value ) ); + $this->assertStatusError( $value, $actual ); } } } diff --git a/tests/phpunit/unit/includes/libs/filebackend/FileBackendTest.php b/tests/phpunit/unit/includes/libs/filebackend/FileBackendTest.php index 1b4e9988425..88fb33bf98c 100644 --- a/tests/phpunit/unit/includes/libs/filebackend/FileBackendTest.php +++ b/tests/phpunit/unit/includes/libs/filebackend/FileBackendTest.php @@ -417,7 +417,7 @@ class FileBackendTest extends MediaWikiUnitTestCase { 'message' => 'backend-fail-readonly', 'params' => [ 'test_name', '.' ], ] ], $status->getErrors() ); - $this->assertFalse( $status->isOK() ); + $this->assertStatusNotOK( $status ); } public static function provideReadOnly(): array { @@ -462,9 +462,8 @@ class FileBackendTest extends MediaWikiUnitTestCase { $status = $backend->$method( ...array_merge( $args, [ [ 'bypassReadOnly' => true ] ] ) ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( [], $status->getErrors() ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusGood( $status ); + $this->assertStatusValue( 'myvalue', $status ); } /** @@ -480,8 +479,7 @@ class FileBackendTest extends MediaWikiUnitTestCase { $backend->expects( $this->never() )->method( 'doQuickOperationsInternal' ); $status = $backend->$method( [] ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); } public static function provideDoMultipleOperations(): array { @@ -560,8 +558,8 @@ class FileBackendTest extends MediaWikiUnitTestCase { $method = $prefix ? $prefix . ucfirst( $action ) : $action; $status = $backend->$method( [ 'op' => 'ignored', 'foo' => 'bar' ], [ 'baz' => 'quuz' ] ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusOK( $status ); + $this->assertStatusValue( 'myvalue', $status ); } public static function provideAction(): array { @@ -590,9 +588,8 @@ class FileBackendTest extends MediaWikiUnitTestCase { $status = $backend->$method( [ 'foo' => 'bar' ] ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( [], $status->getErrors() ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusGood( $status ); + $this->assertStatusValue( 'myvalue', $status ); } public static function provideForwardToDo(): array { @@ -682,9 +679,8 @@ class FileBackendTest extends MediaWikiUnitTestCase { $status = $backend->$backendMethod( ...array_merge( $args, (array)$timeout ) ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( [], $status->getErrors() ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusGood( $status ); + $this->assertStatusValue( 'myvalue', $status ); } public static function provideLockUnlockFiles(): array { @@ -724,7 +720,7 @@ class FileBackendTest extends MediaWikiUnitTestCase { $status = StatusValue::newGood( 'myvalue' ); $scopedLock = $backend->getScopedFileLocks( $paths, $type, $status ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusValue( 'myvalue', $status ); $this->assertSame( $lockStatus->isOK(), $status->isOK() ); $this->assertSame( $lockStatus->getErrors(), $status->getErrors() ); @@ -736,7 +732,7 @@ class FileBackendTest extends MediaWikiUnitTestCase { $this->assertInstanceOf( ScopedLock::class, $scopedLock ); unset( $scopedLock ); - $this->assertSame( 'myvalue', $status->getValue() ); + $this->assertStatusValue( 'myvalue', $status ); $this->assertSame( $lockStatus->isOK(), $status->isOK() ); $this->assertSame( array_merge( $lockStatus->getErrors(), $unlockStatus->getErrors() ), $status->getErrors() ); @@ -1090,8 +1086,7 @@ class FileBackendTest extends MediaWikiUnitTestCase { } $status = $backend->$method( $op ); - $this->assertTrue( $status->isOK() ); - $this->assertSame( [], $status->getErrors() ); + $this->assertStatusGood( $status ); } /** diff --git a/tests/phpunit/unit/includes/page/DeletePageTest.php b/tests/phpunit/unit/includes/page/DeletePageTest.php index cefa6412ae2..37b25571ed1 100644 --- a/tests/phpunit/unit/includes/page/DeletePageTest.php +++ b/tests/phpunit/unit/includes/page/DeletePageTest.php @@ -134,7 +134,7 @@ class DeletePageTest extends MediaWikiUnitTestCase { $status = $dp->deleteIfAllowed( 'foobar' ); $this->assertSame( $expectedGood, $status->isGood() ); if ( $expectedMessage !== null ) { - $this->assertTrue( $status->hasMessage( $expectedMessage ) ); + $this->assertStatusError( $expectedMessage, $status ); } } @@ -257,10 +257,9 @@ class DeletePageTest extends MediaWikiUnitTestCase { $res = $delPage->canProbablyDeleteAssociatedTalk(); if ( $expectedMsg === null ) { - $this->assertTrue( $res->isGood() ); + $this->assertStatusGood( $res ); } else { - $this->assertFalse( $res->isOK() ); - $this->assertTrue( $res->hasMessage( $expectedMsg ) ); + $this->assertStatusError( $expectedMsg, $res ); } } diff --git a/tests/phpunit/unit/includes/password/PasswordPolicyChecksTest.php b/tests/phpunit/unit/includes/password/PasswordPolicyChecksTest.php index 6b8d1337ffa..f59cce104cf 100644 --- a/tests/phpunit/unit/includes/password/PasswordPolicyChecksTest.php +++ b/tests/phpunit/unit/includes/password/PasswordPolicyChecksTest.php @@ -54,7 +54,7 @@ class PasswordPolicyChecksTest extends MediaWikiUnitTestCase { $this->getUser(), // User 'password' // password ); - $this->assertTrue( $statusOK->isGood(), 'Password is longer than minimal policy' ); + $this->assertStatusGood( $statusOK, 'Password is longer than minimal policy' ); $statusShort = PasswordPolicyChecks::checkMinimalPasswordLength( 10, // policy value $this->getUser(), // User @@ -79,7 +79,7 @@ class PasswordPolicyChecksTest extends MediaWikiUnitTestCase { $this->getUser(), // User 'password' // password ); - $this->assertTrue( $statusOK->isGood(), 'Password is longer than minimal policy' ); + $this->assertStatusGood( $statusOK, 'Password is longer than minimal policy' ); $statusShort = PasswordPolicyChecks::checkMinimumPasswordLengthToLogin( 10, // policy value $this->getUser(), // User @@ -104,16 +104,16 @@ class PasswordPolicyChecksTest extends MediaWikiUnitTestCase { $this->getUser(), // User 'password' // password ); - $this->assertTrue( $statusOK->isGood(), 'Password is shorter than maximal policy' ); + $this->assertStatusGood( $statusOK, 'Password is shorter than maximal policy' ); $statusLong = PasswordPolicyChecks::checkMaximalPasswordLength( 4, // policy value $this->getUser(), // User 'password' // password ); - $this->assertFalse( $statusLong->isGood(), + $this->assertStatusNotGood( $statusLong, 'Password is longer than maximal policy' ); - $this->assertFalse( $statusLong->isOK(), + $this->assertStatusNotOK( $statusLong, 'Password is longer than maximal policy, fatal' ); } @@ -127,14 +127,14 @@ class PasswordPolicyChecksTest extends MediaWikiUnitTestCase { $this->getUser(), // User 'password' // password ); - $this->assertTrue( $statusOK->isGood(), 'Password is not a substring of username' ); + $this->assertStatusGood( $statusOK, 'Password is not a substring of username' ); $statusLong = PasswordPolicyChecks::checkPasswordCannotBeSubstringInUsername( 1, // policy value $this->getUser( '123user123' ), // User 'user' // password ); - $this->assertFalse( $statusLong->isGood(), 'Password is a substring of username' ); - $this->assertTrue( $statusLong->isOK(), 'Password is a substring of username, not fatal' ); + $this->assertStatusNotGood( $statusLong, 'Password is a substring of username' ); + $this->assertStatusOK( $statusLong, 'Password is a substring of username, not fatal' ); } /** @@ -154,11 +154,9 @@ class PasswordPolicyChecksTest extends MediaWikiUnitTestCase { ); if ( $failureExpected ) { - $this->assertFalse( $status->isGood(), 'Password matches defaults list' ); - $this->assertTrue( $status->isOK(), 'Password matches default list, not fatal' ); - $this->assertTrue( $status->hasMessage( 'password-login-forbidden' ) ); + $this->assertStatusWarning( 'password-login-forbidden', $status ); } else { - $this->assertTrue( $status->isGood(), 'Password is not on defaults list' ); + $this->assertStatusGood( $status, 'Password is not on defaults list' ); } } diff --git a/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php b/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php index 48aad0fe557..78b32223c91 100644 --- a/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php +++ b/tests/phpunit/unit/includes/watchlist/WatchlistManagerTest.php @@ -583,7 +583,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->setWatch( true, $authority, $title, '1 week' ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertTrue( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -607,7 +607,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->setWatch( true, $performer, $title ); // returns immediately with no error if not logged in - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -637,7 +637,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { // Same expiry $status = $watchlistManager->setWatch( true, $authority, $title, $expiry ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -663,7 +663,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->setWatch( false, $authority, $title ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); } /** @@ -688,7 +688,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->setWatch( true, $authority, $title ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertTrue( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -712,7 +712,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->setWatch( false, $authority, $title ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertFalse( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -736,7 +736,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $actual = $watchlistManager->addWatchIgnoringRights( $userIdentity, $title ); - $this->assertTrue( $actual->isGood() ); + $this->assertStatusGood( $actual ); $this->assertTrue( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -760,7 +760,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $actual = $watchlistManager->addWatch( $authority, $title ); - $this->assertTrue( $actual->isGood() ); + $this->assertStatusGood( $actual ); $this->assertTrue( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } @@ -792,7 +792,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->removeWatch( $authority, $title ); - $this->assertFalse( $status->isGood() ); + $this->assertStatusNotGood( $status ); $errors = $status->getErrors(); $this->assertCount( 1, $errors ); $this->assertEquals( 'hookaborted', $errors[0]['message'] ); @@ -821,7 +821,7 @@ class WatchlistManagerUnitTest extends MediaWikiUnitTestCase { $status = $watchlistManager->removeWatch( $authority, $title ); - $this->assertTrue( $status->isGood() ); + $this->assertStatusGood( $status ); $this->assertFalse( $watchlistManager->isWatchedIgnoringRights( $userIdentity, $title ) ); } }