Skip to content

Commit

Permalink
Issue #3113077 by mondrake, sja112, Hardik_Patel_12, Neslee Canil Pin…
Browse files Browse the repository at this point in the history
…to, prabha1997, swatichouhan012, neelam_wadhwani, shaktik, Berdir, xjm, longwave, alexpott: [backport] Replace assertContains() on strings with assertStringContainsString() or assertStringContainsStringIgnoringCase()
  • Loading branch information
xjm committed May 20, 2020
1 parent 72c743d commit adf3131
Show file tree
Hide file tree
Showing 103 changed files with 374 additions and 359 deletions.
16 changes: 8 additions & 8 deletions modules/aggregator/tests/src/Kernel/AggregatorTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ public function testStringFormatter() {
$build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
$result = $this->render($build);

$this->assertContains('testing title', $result);
$this->assertContains('href="' . $aggregator_feed->getUrl() . '"', $result);
$this->assertStringContainsString('testing title', $result);
$this->assertStringContainsString('href="' . $aggregator_feed->getUrl() . '"', $result);

$build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
$result = $this->render($build);
$this->assertContains('testing title', $result);
$this->assertNotContains($aggregator_feed->getUrl(), $result);
$this->assertStringContainsString('testing title', $result);
$this->assertStringNotContainsString($aggregator_feed->getUrl(), $result);

// Verify aggregator item title with and without links.
$build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
$result = $this->render($build);

$this->assertContains('test title', $result);
$this->assertContains('href="' . $aggregator_item->getLink() . '"', $result);
$this->assertStringContainsString('test title', $result);
$this->assertStringContainsString('href="' . $aggregator_item->getLink() . '"', $result);

$build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
$result = $this->render($build);
$this->assertContains('test title', $result);
$this->assertNotContains($aggregator_item->getLink(), $result);
$this->assertStringContainsString('test title', $result);
$this->assertStringNotContainsString($aggregator_item->getLink(), $result);
}

}
2 changes: 1 addition & 1 deletion modules/comment/tests/src/Functional/CommentTitleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function testCommentPopulatedTitles() {
$comment_permalink = $this->cssSelect('.permalink');
$comment_permalink = $comment_permalink[0]->getAttribute('href');
// Tests that the comment's title link contains the url fragment.
$this->assertContains('#comment-' . $comment1->id(), $comment_permalink, "The comment's title link contains the url fragment.");
$this->assertStringContainsString('#comment-' . $comment1->id(), $comment_permalink, "The comment's title link contains the url fragment.");
$this->assertEqual($comment1->permalink()->toString(), $comment_permalink, "The comment's title has the correct link.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ protected function copyTestingOverrides() {
*/
public function testInstalled() {
if ($this->expectedException) {
$this->assertContains('Configuration objects provided by <em class="placeholder">testing_config_overrides</em> have unmet dependencies: <em class="placeholder">system.action.user_block_user_action (does_not_exist)</em>', $this->expectedException->getMessage());
$this->assertContains('Drupal\Core\Config\UnmetDependenciesException', $this->expectedException->getMessage());
$this->assertStringContainsString('Configuration objects provided by <em class="placeholder">testing_config_overrides</em> have unmet dependencies: <em class="placeholder">system.action.user_block_user_action (does_not_exist)</em>', $this->expectedException->getMessage());
$this->assertStringContainsString('Drupal\Core\Config\UnmetDependenciesException', $this->expectedException->getMessage());
}
else {
$this->fail('Expected Drupal\Core\Config\UnmetDependenciesException exception not thrown');
Expand Down
4 changes: 2 additions & 2 deletions modules/contact/tests/src/Functional/ContactSitewideTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,8 @@ public function testSiteWideContact() {
$mails = $this->getMails();
$mail = array_pop($mails);
$this->assertEqual($mail['subject'], t('[@label] @subject', ['@label' => $label, '@subject' => $edit['subject[0][value]']]));
$this->assertContains($field_label, $mail['body']);
$this->assertContains($edit[$field_name . '[0][value]'], $mail['body']);
$this->assertStringContainsString($field_label, $mail['body']);
$this->assertStringContainsString($edit[$field_name . '[0][value]'], $mail['body']);

// Test messages and redirect.
/** @var \Drupal\contact\ContactFormInterface $form */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testContentTranslationContextualLinks() {
$this->drupalLogin($this->translator);
$this->drupalGet('node/' . $node->id());
$link = $this->assertSession()->waitForElement('css', '[data-contextual-id^="node:node=1"] .contextual-links a:contains("Translate")');
$this->assertContains('node/1/translations', $link->getAttribute('href'));
$this->assertStringContainsString('node/1/translations', $link->getAttribute('href'));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function testDifferentPermissions() {
}
$response = $this->renderContextualLinks([], 'node');
$this->assertSame(400, $response->getStatusCode());
$this->assertContains('No contextual ids specified.', (string) $response->getBody());
$this->assertStringContainsString('No contextual ids specified.', (string) $response->getBody());
$response = $this->renderContextualLinks($ids, 'node');
$this->assertSame(200, $response->getStatusCode());
$json = Json::decode((string) $response->getBody());
Expand All @@ -127,7 +127,7 @@ public function testDifferentPermissions() {
}
$response = $this->renderContextualLinks([], 'node');
$this->assertSame(400, $response->getStatusCode());
$this->assertContains('No contextual ids specified.', (string) $response->getBody());
$this->assertStringContainsString('No contextual ids specified.', (string) $response->getBody());
$response = $this->renderContextualLinks($ids, 'node');
$this->assertSame(200, $response->getStatusCode());
$json = Json::decode((string) $response->getBody());
Expand Down Expand Up @@ -184,23 +184,23 @@ public function testTokenProtection() {
'http_errors' => FALSE,
]);
$this->assertEquals('400', $response->getStatusCode());
$this->assertContains('No contextual ID tokens specified.', (string) $response->getBody());
$this->assertStringContainsString('No contextual ID tokens specified.', (string) $response->getBody());

$response = $http_client->request('POST', $url, [
'cookies' => $this->getSessionCookies(),
'form_params' => ['ids' => [$id], 'tokens' => ['wrong_token']],
'http_errors' => FALSE,
]);
$this->assertEquals('400', $response->getStatusCode());
$this->assertContains('Invalid contextual ID specified.', (string) $response->getBody());
$this->assertStringContainsString('Invalid contextual ID specified.', (string) $response->getBody());

$response = $http_client->request('POST', $url, [
'cookies' => $this->getSessionCookies(),
'form_params' => ['ids' => [$id], 'tokens' => ['wrong_key' => $this->createContextualIdToken($id)]],
'http_errors' => FALSE,
]);
$this->assertEquals('400', $response->getStatusCode());
$this->assertContains('Invalid contextual ID specified.', (string) $response->getBody());
$this->assertStringContainsString('Invalid contextual ID specified.', (string) $response->getBody());

$response = $http_client->request('POST', $url, [
'cookies' => $this->getSessionCookies(),
Expand Down
24 changes: 12 additions & 12 deletions modules/datetime/tests/src/Functional/DateTimeFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function testDateField() {
$expected_iso = $date_formatter->format($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', DateTimeItemInterface::STORAGE_TIMEZONE);
$output = $this->renderTestEntity($id);
$expected_markup = '<time datetime="' . $expected_iso . '" class="datetime">' . $expected . '</time>';
$this->assertContains($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
$this->assertStringContainsString($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute in %timezone.', [
'%value' => $new_value,
'%expected' => $expected,
'%expected_iso' => $expected_iso,
Expand All @@ -147,7 +147,7 @@ public function testDateField() {
->save();
$expected = $date->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
Expand All @@ -161,7 +161,7 @@ public function testDateField() {
->save();
$expected = $date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected in %timezone.', [
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
Expand All @@ -174,7 +174,7 @@ public function testDateField() {
->save();
$expected = '<strong>' . $date->format('m/d/Y') . '</strong>alert(String.fromCharCode(88,83,83))';
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using daterange_custom format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
Expand Down Expand Up @@ -204,7 +204,7 @@ public function testDateField() {
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
]);
$output = $this->renderTestEntity($id);
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
$this->assertStringContainsString((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
Expand All @@ -228,7 +228,7 @@ public function testDateField() {
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
]);
$output = $this->renderTestEntity($id);
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
$this->assertStringContainsString((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected in %timezone.', [
'%expected' => $expected,
'%timezone' => $timezone,
]));
Expand Down Expand Up @@ -299,7 +299,7 @@ public function testDatetimeField() {
$expected_iso = $date_formatter->format($date->getTimestamp(), 'custom', 'Y-m-d\TH:i:s\Z', 'UTC');
$output = $this->renderTestEntity($id);
$expected_markup = '<time datetime="' . $expected_iso . '" class="datetime">' . $expected . '</time>';
$this->assertContains($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso]));
$this->assertStringContainsString($expected_markup, $output, new FormattableMarkup('Formatted date field using %value format displayed as %expected with %expected_iso attribute.', ['%value' => $new_value, '%expected' => $expected, '%expected_iso' => $expected_iso]));
break;
}
}
Expand All @@ -314,7 +314,7 @@ public function testDatetimeField() {
->save();
$expected = $date->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using plain format displayed as %expected.', ['%expected' => $expected]));

// Verify that the 'datetime_custom' formatter works.
$this->displayOptions['type'] = 'datetime_custom';
Expand All @@ -324,7 +324,7 @@ public function testDatetimeField() {
->save();
$expected = $date->format($this->displayOptions['settings']['date_format']);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));

// Verify that the 'timezone_override' setting works.
$this->displayOptions['type'] = 'datetime_custom';
Expand All @@ -334,7 +334,7 @@ public function testDatetimeField() {
->save();
$expected = $date->format($this->displayOptions['settings']['date_format'], ['timezone' => 'America/New_York']);
$output = $this->renderTestEntity($id);
$this->assertContains($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));
$this->assertStringContainsString($expected, $output, new FormattableMarkup('Formatted date field using datetime_custom format displayed as %expected.', ['%expected' => $expected]));

// Verify that the 'datetime_time_ago' formatter works for intervals in the
// past. First update the test entity so that the date difference always
Expand All @@ -361,7 +361,7 @@ public function testDatetimeField() {
'@interval' => $this->dateFormatter->formatTimeDiffSince($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
]);
$output = $this->renderTestEntity($id);
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
$this->assertStringContainsString((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));

// Verify that the 'datetime_time_ago' formatter works for intervals in the
// future. First update the test entity so that the date difference always
Expand All @@ -383,7 +383,7 @@ public function testDatetimeField() {
'@interval' => $this->dateFormatter->formatTimeDiffUntil($timestamp, ['granularity' => $this->displayOptions['settings']['granularity']]),
]);
$output = $this->renderTestEntity($id);
$this->assertContains((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
$this->assertStringContainsString((string) $expected, $output, new FormattableMarkup('Formatted date field using datetime_time_ago format displayed as %expected.', ['%expected' => $expected]));
}

/**
Expand Down

0 comments on commit adf3131

Please sign in to comment.