Skip to content

Commit

Permalink
(tests) Replace assertEquals() with more strict assertSame()
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardspec committed Jan 7, 2025
1 parent 7df148f commit 717354a
Show file tree
Hide file tree
Showing 60 changed files with 271 additions and 271 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/blackbox/ModerationApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testModerationApi( $action, array $expectedResult, ModerationTes
$ret['moderation']['diff-html'] = '{{DIFF}}';
}

$this->assertEquals( [ 'moderation' => $expectedResult ], $ret );
$this->assertSame( [ 'moderation' => $expectedResult ], $ret );
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/blackbox/ModerationApproveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testApproveAll( ModerationTestsuite $t ) {

foreach ( $entries as $entry ) {
$rev = $t->getLastRevision( $entry->title );
$this->assertEquals( $t->unprivilegedUser->getName(), $rev['user'] );
$this->assertSame( $t->unprivilegedUser->getName(), $rev['user'] );
}

# Check the log entries: there should be
Expand All @@ -85,14 +85,14 @@ public function testApproveAll( ModerationTestsuite $t ) {
$this->assertNotNull( $le );
'@phan-var array $le';

$this->assertEquals( 'approveall', $le['action'],
$this->assertSame( 'approveall', $le['action'],
"testApproveAll(): Most recent log entry is not 'approveall'" );
$this->assertEquals( $t->moderator->getName(), $le['user'] );
$this->assertEquals( $t->unprivilegedUser->getUserPage(), $le['title'] );
$this->assertSame( $t->moderator->getName(), $le['user'] );
$this->assertSame( $t->unprivilegedUser->getUserPage(), $le['title'] );

foreach ( $events as $le ) {
$this->assertEquals( 'approve', $le['action'] );
$this->assertEquals( $t->moderator->getName(), $le['user'] );
$this->assertSame( 'approve', $le['action'] );
$this->assertSame( $t->moderator->getName(), $le['user'] );
}
}

Expand Down Expand Up @@ -188,9 +188,9 @@ public function testApproveAllTimestamp( ModerationTestsuite $t ) {
$ts = new MWTimestamp( $row->rev_timestamp );
$foundTimestamp = $ts->getTimestamp( TS_MW );

$this->assertEquals( $task['timestamp'], $foundTimestamp,
$this->assertSame( $task['timestamp'], $foundTimestamp,
"testApproveAllTimestamp(): approved edit has incorrect timestamp in the page history" );
$this->assertEquals( $task['ip'], $row->rc_ip,
$this->assertSame( $task['ip'], $row->rc_ip,
"testApproveAllTimestamp(): approved edit has incorrect IP in recentchanges" );
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/blackbox/ModerationCheckuserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testApiModerationCheckuser( ModerationTestsuite $t ) {
$ip = $this->getIpFromApi( $t, $t->moderatorAndCheckuser );
$this->assertNotNull( $ip,
"testModerationCheckuser(): API didn't show IP to checkuser" );
$this->assertEquals( "127.0.0.1", $ip,
$this->assertSame( "127.0.0.1", $ip,
"testModerationCheckuser(): incorrect IP shown via API" );
}

Expand Down Expand Up @@ -103,7 +103,7 @@ public function testApproveAllUploadPrevervesUA( ModerationTestsuite $t ) {
$this->assertNotEquals( $this->moderatorUA, $agent,
"testApproveAllUploadPrevervesUA(): Upload #$i: UserAgent in checkuser " .
"tables matches moderator's UserAgent" );
$this->assertEquals( $this->userUA . '#' . $i, $agent,
$this->assertSame( $this->userUA . '#' . $i, $agent,
"testApproveAllUploadPrevervesUA(): Upload #$i: UserAgent in checkuser " .
"tables doesn't match UserAgent of user who made the upload" );

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/blackbox/ModerationEditChangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public function testEditChangeForm( ModerationTestsuite $t ) {
'modid' => $entry->id,
'modaction' => 'editchangesubmit'
] );
$this->assertEquals( $expectedAction, $form->getAttribute( 'action' ),
$this->assertSame( $expectedAction, $form->getAttribute( 'action' ),
"testEditChangeForm(): Incorrect action= attribute in the edit form."
);

$textarea = $t->html->getElementById( 'wpTextbox1' );
$this->assertNotNull( $textarea,
"testEditChangeForm(): <textarea> not found." );
$this->assertEquals( $t->lastEdit['Text'], trim( $textarea->textContent ),
$this->assertSame( $t->lastEdit['Text'], trim( $textarea->textContent ),
"testEditChangeForm(): <textarea> doesn't contain the current text of pending change." );

$summaryInput = $t->html->getElementByXPath( '//input[@name="wpSummary"]' );
$this->assertEquals( $t->lastEdit['Summary'], $summaryInput->getAttribute( 'value' ),
$this->assertSame( $t->lastEdit['Summary'], $summaryInput->getAttribute( 'value' ),
"testEditChangeForm(): Preloaded summary doesn't match." );

$tokenInput = $t->html->getElementByXPath( '//input[@name="token"]' );
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/blackbox/ModerationEditConflictTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testResolvableEditConflict( ModerationTestsuite $t ) {
"testResolvableEditConflict(): Approval failed" );

$rev = $t->getLastRevision( $title );
$this->assertEquals( $expectedText, $rev['*'],
$this->assertSame( $expectedText, $rev['*'],
"testResolvableEditConflict(): Unexpected text after approving both edits"
);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/phpunit/blackbox/ModerationEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testEditSections( $useApi, ModerationTestsuite $t ) {

$expectedText = implode( '', $sections );

$this->assertEquals( $expectedText, $t->new_entries[0]->getDbText(),
$this->assertSame( $expectedText, $t->new_entries[0]->getDbText(),
"testEditSections(): Resulting text doesn't match expected" );

# Does PreSaveTransform work when editing sections?
Expand All @@ -111,7 +111,7 @@ public function testEditSections( $useApi, ModerationTestsuite $t ) {
$bot->edit( $title, $sections[2], null, 2 );

$expectedText = implode( '', $sections );
$this->assertEquals( $expectedText, $t->new_entries[0]->getDbText(),
$this->assertSame( $expectedText, $t->new_entries[0]->getDbText(),
"testEditSections(): When section header is deleted, resulting text doesn't match expected " );
}

Expand Down Expand Up @@ -145,7 +145,7 @@ public function testNewSizeAfterEditSection( ModerationTestsuite $t ) {
$this->assertNotEquals( strlen( $sections[0] ), $newlen,
"testNewSizeAfterEditSection(): Incorrect length: " .
"matches the length of the edited section" );
$this->assertEquals( strlen( $origText ), $newlen,
$this->assertSame( strlen( $origText ), $newlen,
"testNewSizeAfterEditSection(): Length changed after null edit in a section" );
}

Expand Down Expand Up @@ -191,7 +191,7 @@ public function testApiEditAppend( ModerationTestsuite $t ) {

$t->fetchSpecial();

$this->assertEquals( $expectedText, $t->new_entries[0]->getDbText(),
$this->assertSame( $expectedText, $t->new_entries[0]->getDbText(),
"testApiEditAppend(): Resulting text doesn't match expected" );
}

Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/blackbox/ModerationInterceptEditTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testPostEditRedirect( ModerationTestsuite $t ) {
$this->assertCount( 2, $params,
"testPostEditRedirect(): redirect URL has parameters other than 'title' and 'modqueued'" );

$this->assertEquals(
$this->assertSame(
$t->lastEdit['Title'],
preg_replace( '/_/', ' ', $params['title'] ),
"testPostEditRedirect(): Title in the redirect URL doesn't match the title of page we edited" );
Expand All @@ -73,7 +73,7 @@ public function testPostEditRedirect( ModerationTestsuite $t ) {
"but number of added entries in Pending folder isn't 1" );
$this->assertCount( 0, $t->deleted_entries,
"testPostEditRedirect(): Something was deleted from Pending folder during the queueing" );
$this->assertEquals( $t->lastEdit['User'], $t->new_entries[0]->user );
$this->assertEquals( $t->lastEdit['Title'], $t->new_entries[0]->title );
$this->assertSame( $t->lastEdit['User'], $t->new_entries[0]->user );
$this->assertSame( $t->lastEdit['Title'], $t->new_entries[0]->title );
}
}
16 changes: 8 additions & 8 deletions tests/phpunit/blackbox/ModerationMergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testMerge( ModerationTestsuite $t ) {
"testMerge(): Edit with not-yet-detected conflict is marked with class='modconflict'" );

$error = $t->html->loadUrl( $entry->approveLink )->getModerationError();
$this->assertEquals( '(moderation-edit-conflict)', $error,
$this->assertSame( '(moderation-edit-conflict)', $error,
"testMerge(): Edit conflict not detected by modaction=approve" );

$t->fetchSpecial();
Expand Down Expand Up @@ -122,9 +122,9 @@ public function testMerge( ModerationTestsuite $t ) {
$this->assertRegExp( '/\(editconflict: ' . $t->lastEdit['Title'] . '\)/', $title,
"testMerge(): Wrong HTML title from modaction=merge" );

$this->assertEquals( $this->text2, $t->html->getElementById( 'wpTextbox1' )->textContent,
$this->assertSame( $this->text2, $t->html->getElementById( 'wpTextbox1' )->textContent,
"testMerge(): The upper textarea doesn't contain the current page text" );
$this->assertEquals( $this->text1, $t->html->getElementById( 'wpTextbox2' )->textContent,
$this->assertSame( $this->text1, $t->html->getElementById( 'wpTextbox2' )->textContent,
"testMerge(): The lower textarea doesn't contain the text we attempted to approve" );

$form = $t->html->getElementById( 'editform' );
Expand All @@ -140,7 +140,7 @@ public function testMerge( ModerationTestsuite $t ) {

$this->assertArrayHasKey( 'wpMergeID', $inputs,
"testMerge(): Edit form doesn't contain wpMergeID field" );
$this->assertEquals( $id, $inputs['wpMergeID'],
$this->assertSame( $id, $inputs['wpMergeID'],
"testMerge(): Value of wpMergeID field doesn't match the entry id" );

# Try to edit now
Expand All @@ -155,7 +155,7 @@ public function testMerge( ModerationTestsuite $t ) {
"testMerge(): non-API edit with wpMergeID failed" );

$rev = $t->getLastRevision( $this->page );
$this->assertEquals( $t->moderator->getName(), $rev['user'] );
$this->assertSame( $t->moderator->getName(), $rev['user'] );

# Was the edit moved into the 'merged' folder?
Expand All @@ -164,7 +164,7 @@ public function testMerge( ModerationTestsuite $t ) {
"testMerge(): Something was added into Pending folder when the edit was merged" );
$this->assertCount( 1, $t->deleted_entries,
"testMerge(): One edit was merged, but number of deleted entries in Pending folder isn't 1" );
$this->assertEquals( $id, $t->deleted_entries[0]->id );
$this->assertSame( $id, $t->deleted_entries[0]->id );

$t->fetchSpecial( 'merged' );
$this->assertCount( 1, $t->new_entries,
Expand All @@ -173,7 +173,7 @@ public function testMerge( ModerationTestsuite $t ) {
"testMerge(): Something was deleted from Merged folder when the edit was merged" );

$entry = $t->new_entries[0];
$this->assertEquals( $id, $entry->id );
$this->assertSame( $id, $entry->id );

$this->assertNull( $entry->rejectLink,
"testMerge(): Reject link found for already merged edit" );
Expand All @@ -196,7 +196,7 @@ public function testMerge( ModerationTestsuite $t ) {
$params = wfCgiToArray( preg_replace( '/^.*?\?/', '', $entry->mergedDiffLink ) );

$this->assertArrayHasKey( 'diff', $params );
$this->assertEquals( $rev['revid'], $params['diff'],
$this->assertSame( $rev['revid'], $params['diff'],
"testMerge(): diff parameter doesn't match revid of the last revision on the page we edited" );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testModeratorIsNotified( ModerationTestsuite $t ) {

/* Notification "New changes await!" is shown to moderator on all pages... */
$t->loginAs( $t->moderator );
$this->assertEquals(
$this->assertSame(
"\n(moderation-new-changes-appeared)",
$this->getNotice( $t ),
"Notification not shown to moderator"
Expand Down Expand Up @@ -105,7 +105,7 @@ public function testNotificationHiddenOnlyForThisModerator( ModerationTestsuite

/* ... notification should still be shown to another moderator #2 */
$t->loginAs( $t->moderatorButNotAutomoderated );
$this->assertEquals(
$this->assertSame(
"\n(moderation-new-changes-appeared)",
$this->getNotice( $t ),
"Notification not shown to the second moderator"
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/blackbox/ModerationPageFormsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ public function testPageFormsPreload( $isExistingPage, ModerationTestsuite $t )
$input = $inputs->item( $idx++ );

// @phan-suppress-next-line PhanUndeclaredMethod
$this->assertEquals( "_section[$name]", $input->getAttribute( 'name' ),
$this->assertSame( "_section[$name]", $input->getAttribute( 'name' ),
"testPageFormsPreload(): name of the EditForm field doesn't match expected" );

$this->assertEquals( $expectedContent, $input->textContent,
$this->assertSame( $expectedContent, $input->textContent,
"testPageFormsPreload(): value of the EditForm field doesn't match expected" );
}
}
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/blackbox/ModerationPreloadIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testAnonymousPreload( ModerationTestsuite $t ) {
$t->logout();
$t->doTestEdit();

$this->assertEquals(
$this->assertSame(
$t->lastEdit['Text'],
$t->html->getPreloadedText( $t->lastEdit['Title'] ),
"testAnonymousPreload(): Preloaded text differs from what the user saved before" );
Expand All @@ -73,7 +73,7 @@ public function testAnonymousPreload( ModerationTestsuite $t ) {
// Note: phan doesn't know that markTestIncomplete() unconditionally throws an exception.
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable
$t->loginAs( $user );
$this->assertEquals(
$this->assertSame(
$t->lastEdit['Text'],
$t->html->getPreloadedText( $t->lastEdit['Title'] ),
"testAnonymousPreload(): Text was not preloaded after creating an account" );
Expand Down Expand Up @@ -109,12 +109,12 @@ public function testApiPreload( ModerationTestsuite $t ) {
$this->assertArrayHasKey( 'moderationpreload', $ret['query'] );

$mp = $ret['query']['moderationpreload'];
$this->assertEquals( $t->lastEdit['User'], $mp['user'] );
$this->assertEquals( $t->lastEdit['Title'], $mp['title'] );
$this->assertEquals( $t->lastEdit['Summary'], $mp['comment'] );
$this->assertSame( $t->lastEdit['User'], $mp['user'] );
$this->assertSame( $t->lastEdit['Title'], $mp['title'] );
$this->assertSame( $t->lastEdit['Summary'], $mp['comment'] );
$this->assertArrayHasKey( 'wikitext', $mp );
$this->assertArrayNotHasKey( 'parsed', $mp );
$this->assertEquals( $text, $mp['wikitext'] );
$this->assertSame( $text, $mp['wikitext'] );

/* Test 2: mpmode=parsed */
$ret = $t->query( [
Expand Down Expand Up @@ -149,17 +149,17 @@ public function testApiPreload( ModerationTestsuite $t ) {
'mptitle' => $t->lastEdit['Title'],
'mpsection' => 1
] );
$this->assertEquals( $extraSectionText, $ret['query']['moderationpreload']['wikitext'] );
$this->assertSame( $extraSectionText, $ret['query']['moderationpreload']['wikitext'] );
}

private function tryToPreload( ModerationTestsuite $t, $caller ) {
$this->assertEquals(
$this->assertSame(
$t->lastEdit['Text'],
$t->html->getPreloadedText( $t->lastEdit['Title'] ),
"$caller(): Preloaded text differs from what the user saved before" );

$elem = $t->html->getElementByXPath( '//input[@name="wpSummary"]' );
$this->assertEquals( $t->lastEdit['Summary'], $elem->getAttribute( 'value' ),
$this->assertSame( $t->lastEdit['Summary'], $elem->getAttribute( 'value' ),
"$caller(): Preloaded summary doesn't match"
);

Expand All @@ -169,7 +169,7 @@ private function tryToPreload( ModerationTestsuite $t, $caller ) {
$elem = $t->html->getElementById( 'mw-editing-your-version' );
$this->assertNotNull( $elem,
"$caller(): #mw-editing-your-version not found" );
$this->assertEquals( '(moderation-editing-your-version)', $elem->textContent,
$this->assertSame( '(moderation-editing-your-version)', $elem->textContent,
"$caller(): #mw-editing-your-version doesn't contain " .
"(moderation-editing-your-version) message" );
}
Expand Down
26 changes: 13 additions & 13 deletions tests/phpunit/blackbox/ModerationRejectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function testRejectAll( ModerationTestsuite $t ) {
$de = ModerationTestsuiteEntry::findById( $t->deleted_entries, $entry->id );
$this->assertNotNull( $de );

$this->assertEquals( $entry->user, $de->user );
$this->assertEquals( $entry->title, $de->title );
$this->assertSame( $entry->user, $de->user );
$this->assertSame( $entry->title, $de->title );
}

$t->fetchSpecial( 'rejected' );
Expand All @@ -80,10 +80,10 @@ public function testRejectAll( ModerationTestsuite $t ) {
$de = ModerationTestsuiteEntry::findById( $t->new_entries, $entry->id );
$this->assertNotNull( $de );

$this->assertEquals( $entry->user, $de->user );
$this->assertEquals( $entry->title, $de->title );
$this->assertSame( $entry->user, $de->user );
$this->assertSame( $entry->title, $de->title );

$this->assertEquals( $t->moderator->getName(), $de->rejected_by_user );
$this->assertSame( $t->moderator->getName(), $de->rejected_by_user );
$this->assertTrue( $de->rejected_batch,
"testRejectAll(): Edit rejected via modaction=rejectall has rejected_batch flag OFF" );
$this->assertFalse( $de->rejected_auto,
Expand All @@ -103,19 +103,19 @@ public function testRejectAll( ModerationTestsuite $t ) {
"testRejectAll(): Number of log entries isn't 1." );
$le = $events[0];

$this->assertEquals( 'rejectall', $le['action'],
$this->assertSame( 'rejectall', $le['action'],
"testRejectAll(): Most recent log entry is not 'rejectall'" );
$this->assertEquals( $t->moderator->getName(), $le['user'] );
$this->assertEquals( $t->unprivilegedUser->getUserPage(), $le['title'] );
$this->assertEquals( $t->TEST_EDITS_COUNT, $le['params']['count'] );
$this->assertSame( $t->moderator->getName(), $le['user'] );
$this->assertSame( $t->unprivilegedUser->getUserPage(), $le['title'] );
$this->assertSame( $t->TEST_EDITS_COUNT, $le['params']['count'] );

$events = $t->nonApiLogEntries( 1 );
$this->assertEquals( 'rejectall', $events[0]['type'] );
$this->assertSame( 'rejectall', $events[0]['type'] );

$this->assertEquals( $t->moderator->getName(),
$this->assertSame( $t->moderator->getName(),
$events[0]['params'][1] );
$this->assertEquals( $t->unprivilegedUser->getUserPage()->getText(),
$this->assertSame( $t->unprivilegedUser->getUserPage()->getText(),
$events[0]['params'][2] );
$this->assertEquals( $t->TEST_EDITS_COUNT, $events[0]['params'][3] );
$this->assertSame( $t->TEST_EDITS_COUNT, $events[0]['params'][3] );
}
}
2 changes: 1 addition & 1 deletion tests/phpunit/blackbox/ModerationReturntoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testReturnto( ModerationTestsuite $t ) {

/* 2) check if "Return to" link is present after error */
$t->html->loadUrl( $url );
$this->assertEquals( '(moderation-already-rejected)', $t->html->getModerationError(),
$this->assertSame( '(moderation-already-rejected)', $t->html->getModerationError(),
"testReturnto(): Error page doesn't contain (moderation-already-rejected)"
);
$this->assertRegExp( '/\(returnto: Special:Moderation\)/', $t->html->getMainText(),
Expand Down
Loading

0 comments on commit 717354a

Please sign in to comment.