Commit 4d02fe7c authored by catch's avatar catch

Issue #3128746 by mondrake, longwave, dww: Replace assertions involving calls...

Issue #3128746 by mondrake, longwave, dww: Replace assertions involving calls to strpos() with more accurate string assertions
parent bcec845d
......@@ -67,7 +67,7 @@ public function testFeedLabelEscaping() {
$this->assertNoRaw('Test feed title <script>alert(123);</script>');
// Ensure the feed icon title is escaped.
$this->assertTrue(strpos(str_replace(["\n", "\r"], '', $this->getSession()->getPage()->getContent()), 'class="feed-icon"> Subscribe to Test feed title &lt;script&gt;alert(123);&lt;/script&gt; feed</a>') !== FALSE);
$this->assertStringContainsString('class="feed-icon"> Subscribe to Test feed title &lt;script&gt;alert(123);&lt;/script&gt; feed</a>', str_replace(["\n", "\r"], '', $this->getSession()->getPage()->getContent()));
}
/**
......
......@@ -38,7 +38,7 @@ public function testProcess() {
$this->updateFeedItems($feed);
foreach ($feed->items as $iid) {
$item = Item::load($iid);
$this->assertTrue(strpos($item->label(), 'testProcessor') === 0);
$this->assertStringStartsWith('testProcessor', $item->label());
}
}
......
......@@ -47,7 +47,8 @@ public function testBasicAuth() {
$this->assertResponse('200', 'HTTP response is OK');
$this->mink->resetSessions();
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Cache-Control is not set to public');
// Check that Cache-Control is not set to public.
$this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');
$this->basicAuthGet($url, $account->getAccountName(), $this->randomMachineName());
$this->assertNoText($account->getAccountName(), 'Bad basic auth credentials do not authenticate the user.');
......@@ -75,7 +76,8 @@ public function testBasicAuth() {
$this->assertEqual($this->drupalGetHeader('X-Drupal-Cache'), 'MISS');
$this->basicAuthGet($url, $account->getAccountName(), $account->pass_raw);
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'No page cache response when requesting a cached page with basic auth credentials.');
// Check that Cache-Control is not set to public.
$this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');
}
/**
......
......@@ -194,9 +194,9 @@ public function testBigPipe() {
$this->assertEqual($log_count + 2, $connection->query('SELECT COUNT(*) FROM {watchdog}')->fetchField(), 'Two new watchdog entries.');
$records = $connection->query('SELECT * FROM {watchdog} ORDER BY wid DESC LIMIT 2')->fetchAll();
$this->assertEqual(RfcLogLevel::ERROR, $records[0]->severity);
$this->assertTrue(FALSE !== strpos((string) unserialize($records[0]->variables)['@message'], 'Oh noes!'));
$this->assertStringContainsString('Oh noes!', (string) unserialize($records[0]->variables)['@message']);
$this->assertEqual(RfcLogLevel::ERROR, $records[1]->severity);
$this->assertTrue(FALSE !== strpos((string) unserialize($records[1]->variables)['@message'], 'You are not allowed to say llamas are not cool!'));
$this->assertStringContainsString('You are not allowed to say llamas are not cool!', (string) unserialize($records[1]->variables)['@message']);
// Verify that 4xx responses work fine. (4xx responses are handled by
// subrequests to a route pointing to a controller with the desired output.)
......@@ -321,7 +321,8 @@ public function testBigPipeMultiOccurrencePlaceholders() {
protected function assertBigPipeResponseHeadersPresent() {
$this->pass('Verifying BigPipe response headers…', 'Debug');
$this->assertTrue(FALSE !== strpos($this->drupalGetHeader('Cache-Control'), 'private'), 'Cache-Control header set to "private".');
// Check that Cache-Control header set to "private".
$this->assertSession()->responseHeaderContains('Cache-Control', 'private');
$this->assertEqual('no-store, content="BigPipe/1.0"', $this->drupalGetHeader('Surrogate-Control'));
$this->assertEqual('no', $this->drupalGetHeader('X-Accel-Buffering'));
}
......@@ -477,7 +478,7 @@ protected function assertBigPipeNoJsMetaRefreshRedirect() {
// First response: redirect.
$this->assertEqual(302, $statuses[0], 'The first response was a 302 (redirect).');
$this->assertIdentical(0, strpos($headers[0]['Set-Cookie'][0], 'big_pipe_nojs=1'), 'The first response sets the big_pipe_nojs cookie.');
$this->assertStringStartsWith('big_pipe_nojs=1', $headers[0]['Set-Cookie'][0], 'The first response sets the big_pipe_nojs cookie.');
$this->assertEqual($original_url, $headers[0]['Location'][0], 'The first response redirected back to the original page.');
$this->assertTrue(empty(array_diff(['cookies:big_pipe_nojs', 'session.exists'], explode(' ', $headers[0]['X-Drupal-Cache-Contexts'][0]))), 'The first response varies by the "cookies:big_pipe_nojs" and "session.exists" cache contexts.');
$this->assertFalse(isset($headers[0]['Surrogate-Control']), 'The first response has no "Surrogate-Control" header.');
......
......@@ -280,7 +280,7 @@ public function testNewFormat() {
// Regression test for https://www.drupal.org/node/2606460.
$settings = $this->getDrupalSettings();
$expected = $settings['ckeditor']['toolbarAdmin'];
$this->assertTrue(strpos($expected, '<li data-drupal-ckeditor-button-name="Bold" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="bold" aria-label="bold"><span class="cke_button_icon cke_button__bold_icon">bold</span></a></li>') !== FALSE);
$this->assertStringContainsString('<li data-drupal-ckeditor-button-name="Bold" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="bold" aria-label="bold"><span class="cke_button_icon cke_button__bold_icon">bold</span></a></li>', $expected);
// Ensure the styles textarea exists and is initialized empty.
$styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]');
......
......@@ -123,7 +123,7 @@ public function _testColor($theme, $test_values) {
foreach ($stylesheets as $stylesheet) {
$this->assertPattern('|' . file_url_transform_relative(file_create_url($stylesheet)) . '|', 'Make sure the color stylesheet is included in the content. (' . $theme . ')');
$stylesheet_content = implode("\n", file($stylesheet));
$this->assertTrue(strpos($stylesheet_content, 'color: #123456') !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
$this->assertStringContainsString('color: #123456', $stylesheet_content, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
}
$this->drupalGet($settings_path);
......@@ -135,7 +135,7 @@ public function _testColor($theme, $test_values) {
$stylesheets = $this->config('color.theme.' . $theme)->get('stylesheets');
foreach ($stylesheets as $stylesheet) {
$stylesheet_content = implode("\n", file($stylesheet));
$this->assertTrue(strpos($stylesheet_content, 'color: ' . $test_values['scheme_color']) !== FALSE, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
$this->assertStringContainsString('color: ' . $test_values['scheme_color'], $stylesheet_content, 'Make sure the color we changed is in the color stylesheet. (' . $theme . ')');
}
// Test with aggregated CSS turned on.
......@@ -148,7 +148,7 @@ public function _testColor($theme, $test_values) {
foreach ($stylesheets as $uri) {
$stylesheet_content .= implode("\n", file(\Drupal::service('file_system')->realpath($uri)));
}
$this->assertTrue(strpos($stylesheet_content, 'public://') === FALSE, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
$this->assertStringNotContainsString('public://', $stylesheet_content, 'Make sure the color paths have been translated to local paths. (' . $theme . ')');
$config->set('css.preprocess', 0);
$config->save();
}
......
......@@ -50,8 +50,8 @@ public function testAnonymous() {
$this->drupalPostForm($this->node->toUrl(), $edit, t('Preview'));
// Cannot use assertRaw here since both title and body are in the form.
$preview = (string) $this->cssSelect('.preview')[0]->getHtml();
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
$this->assertStringContainsString($title, $preview, 'Anonymous user can preview comment title.');
$this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.');
// Preview comments (without `skip comment approval` permission).
user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']);
......@@ -63,8 +63,8 @@ public function testAnonymous() {
$this->drupalPostForm($this->node->toUrl(), $edit, t('Preview'));
// Cannot use assertRaw here since both title and body are in the form.
$preview = (string) $this->cssSelect('.preview')[0]->getHtml();
$this->assertTrue(strpos($preview, $title) !== FALSE, 'Anonymous user can preview comment title.');
$this->assertTrue(strpos($preview, $body) !== FALSE, 'Anonymous user can preview comment body.');
$this->assertStringContainsString($title, $preview, 'Anonymous user can preview comment title.');
$this->assertStringContainsString($body, $preview, 'Anonymous user can preview comment body.');
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['skip comment approval']);
// Post anonymous comment without contact info.
......
......@@ -188,7 +188,7 @@ public function testImport() {
$entity = $storage->load('second');
$this->assertRaw(t('The configuration was imported successfully.'));
$this->assertTrue(is_string($entity->label()), 'Entity label is a string');
$this->assertTrue(strpos($entity->label(), 'ObjectSerialization') > 0, 'Label contains serialized object');
$this->assertStringContainsString('ObjectSerialization', $entity->label(), 'Label contains serialized object');
}
else {
// If the Symfony parser is used there will be an error.
......
......@@ -91,9 +91,9 @@ public function testSendPersonalContactMessage() {
];
$subject = PlainTextOutput::renderFromHtml(t('[@site-name] @subject', $variables));
$this->assertEqual($mail['subject'], $subject, 'Subject is in sent message.');
$this->assertTrue(strpos($mail['body'], 'Hello ' . $variables['@recipient-name']) !== FALSE, 'Recipient name is in sent message.');
$this->assertTrue(strpos($mail['body'], $this->webUser->getDisplayName()) !== FALSE, 'Sender name is in sent message.');
$this->assertTrue(strpos($mail['body'], $message['message[0][value]']) !== FALSE, 'Message body is in sent message.');
$this->assertStringContainsString('Hello ' . $variables['@recipient-name'], $mail['body'], 'Recipient name is in sent message.');
$this->assertStringContainsString($this->webUser->getDisplayName(), $mail['body'], 'Sender name is in sent message.');
$this->assertStringContainsString($message['message[0][value]'], $mail['body'], 'Message body is in sent message.');
// Check there was no problems raised during sending.
$this->drupalLogout();
......
......@@ -879,28 +879,20 @@ public function assertFilteredString($filter, $tests) {
foreach ($tests as $source => $tasks) {
$result = $filter->process($source, $filter)->getProcessedText();
foreach ($tasks as $value => $is_expected) {
// Not using assertIdentical, since combination with strpos() is hard to grok.
if ($is_expected) {
$success = $this->assertTrue(strpos($result, $value) !== FALSE, new FormattableMarkup('@source: @value found. Filtered result: @result.', [
$this->assertStringContainsString($value, $result, new FormattableMarkup('@source: @value found. Filtered result: @result.', [
'@source' => var_export($source, TRUE),
'@value' => var_export($value, TRUE),
'@result' => var_export($result, TRUE),
]));
}
else {
$success = $this->assertTrue(strpos($result, $value) === FALSE, new FormattableMarkup('@source: @value not found. Filtered result: @result.', [
$this->assertStringNotContainsString($value, $result, new FormattableMarkup('@source: @value not found. Filtered result: @result.', [
'@source' => var_export($source, TRUE),
'@value' => var_export($value, TRUE),
'@result' => var_export($result, TRUE),
]));
}
if (!$success) {
$this->verbose('Source:<pre>' . Html::escape(var_export($source, TRUE)) . '</pre>'
. '<hr />' . 'Result:<pre>' . Html::escape(var_export($result, TRUE)) . '</pre>'
. '<hr />' . ($is_expected ? 'Expected:' : 'Not expected:')
. '<pre>' . Html::escape(var_export($value, TRUE)) . '</pre>'
);
}
}
}
}
......@@ -1151,7 +1143,7 @@ public function testHtmlCorrectorFilter() {
* TRUE on pass, FALSE on fail.
*/
public function assertNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos(strtolower(Html::decodeEntities($haystack)), $needle) !== FALSE, $message, $group);
return $this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
/**
......@@ -1176,7 +1168,7 @@ public function assertNormalized($haystack, $needle, $message = '', $group = 'Ot
* TRUE on pass, FALSE on fail.
*/
public function assertNoNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos(strtolower(Html::decodeEntities($haystack)), $needle) === FALSE, $message, $group);
return $this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
}
......@@ -152,7 +152,7 @@ public function testStyle() {
// Ensure that the image style URI matches our expected path.
$style_uri_path = $style->toUrl()->toString();
$this->assertTrue(strpos($style_uri_path, $style_path) !== FALSE, 'The image style URI is correct.');
$this->assertStringContainsString($style_path, $style_uri_path, 'The image style URI is correct.');
// Confirm that all effects on the image style have settings that match
// what was saved.
......
......@@ -169,7 +169,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// Make sure that language prefix is never added to the image style URL.
if ($langcode) {
$this->assertTrue(strpos($generate_url, "/$langcode/") === FALSE, 'Langcode was not found in the image style URL.');
$this->assertStringNotContainsString("/$langcode/", $generate_url, 'Langcode was not found in the image style URL.');
}
// Ensure that the tests still pass when the file is generated by accessing
......@@ -181,7 +181,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
$generate_url = $this->style->buildUrl($modified_uri, $clean_url);
}
if (!$clean_url) {
$this->assertTrue(strpos($generate_url, 'index.php/') !== FALSE, 'When using non-clean URLS, the system path contains the script name.');
$this->assertStringContainsString('index.php/', $generate_url, 'When using non-clean URLS, the system path contains the script name.');
}
// Add some extra chars to the token.
$this->drupalGet(str_replace(IMAGE_DERIVATIVE_TOKEN . '=', IMAGE_DERIVATIVE_TOKEN . '=Zo', $generate_url));
......@@ -217,7 +217,8 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
if ($scheme == 'private') {
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertNotEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header contains \'no-cache\' to prevent caching.');
// Check that Cache-Control header contains 'no-cache' to prevent caching.
$this->assertSession()->responseHeaderContains('Cache-Control', 'no-cache');
$this->assertEqual($this->drupalGetHeader('X-Image-Owned-By'), 'image_module_test', 'Expected custom header has been added.');
// Make sure that a second request to the already existing derivative
......@@ -257,12 +258,12 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
// (cf. http://www.libpng.org/pub/png/book/chapter08.html#png.ch08.div.2)
// in the response body.
$raw = $this->getSession()->getPage()->getContent();
$this->assertFalse(strpos($raw, chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10)));
$this->assertStringNotContainsString(chr(137) . chr(80) . chr(78) . chr(71) . chr(13) . chr(10) . chr(26) . chr(10), $raw);
}
}
else {
$this->assertEqual($this->drupalGetHeader('Expires'), 'Sun, 19 Nov 1978 05:00:00 GMT', 'Expires header was sent.');
$this->assertEqual(strpos($this->drupalGetHeader('Cache-Control'), 'no-cache'), FALSE, 'Cache-Control header contains \'no-cache\' to prevent caching.');
$this->assertStringNotContainsString('no-cache', $this->drupalGetHeader('Cache-Control'), 'Cache-Control header contains \'no-cache\' to prevent caching.');
if ($clean_url) {
// Add some extra chars to the token.
......@@ -292,7 +293,7 @@ public function doImageStyleUrlAndPathTests($scheme, $clean_url = TRUE, $extra_s
$generated_uri = $this->style->buildUri($original_uri);
$this->assertFalse(file_exists($generated_uri), 'Generated file does not exist.');
$generate_url = $this->style->buildUrl($original_uri, $clean_url);
$this->assertIdentical(strpos($generate_url, IMAGE_DERIVATIVE_TOKEN . '='), FALSE, 'The security token does not appear in the image style URL.');
$this->assertStringNotContainsString(IMAGE_DERIVATIVE_TOKEN . '=', $generate_url, 'The security token does not appear in the image style URL.');
$this->drupalGet($generate_url);
$this->assertResponse(200, 'Image was accessible at the URL with a missing token.');
......
......@@ -154,9 +154,9 @@ public function testImageFormatterSvg() {
$this->assertEquals('medium', $build[$this->fieldName][0]['#image_style']);
// We check that the image URL contains the expected style directory
// structure.
$this->assertTrue(strpos($build[$this->fieldName][0]['#markup'], 'styles/medium/public/test-image.png') !== FALSE);
$this->assertTrue(strpos($build[$this->fieldName][0]['#markup'], 'width="220"') !== FALSE);
$this->assertTrue(strpos($build[$this->fieldName][0]['#markup'], 'height="220"') !== FALSE);
$this->assertStringContainsString('styles/medium/public/test-image.png', $build[$this->fieldName][0]['#markup']);
$this->assertStringContainsString('width="220"', $build[$this->fieldName][0]['#markup']);
$this->assertStringContainsString('height="220"', $build[$this->fieldName][0]['#markup']);
// The second image is an SVG, which is not supported by the GD toolkit.
// The image style should still be applied with its cache tags, but image
......@@ -167,11 +167,11 @@ public function testImageFormatterSvg() {
$this->assertEquals('medium', $build[$this->fieldName][1]['#image_style']);
// We check that the image URL does not contain the style directory
// structure.
$this->assertFalse(strpos($build[$this->fieldName][1]['#markup'], 'styles/medium/public/test-image.svg'));
$this->assertStringNotContainsString('styles/medium/public/test-image.svg', $build[$this->fieldName][1]['#markup']);
// Since we did not store original image dimensions, width and height
// HTML attributes will not be present.
$this->assertFalse(strpos($build[$this->fieldName][1]['#markup'], 'width'));
$this->assertFalse(strpos($build[$this->fieldName][1]['#markup'], 'height'));
$this->assertStringNotContainsString('width', $build[$this->fieldName][1]['#markup']);
$this->assertStringNotContainsString('height', $build[$this->fieldName][1]['#markup']);
}
/**
......
......@@ -141,7 +141,7 @@ public function testInfoAlterations() {
// Check that only the core language types are available.
foreach ($this->languageManager()->getDefinedLanguageTypes() as $type) {
$this->assertTrue(strpos($type, 'test') === FALSE, new FormattableMarkup('The %type language is still available', ['%type' => $type]));
$this->assertStringNotContainsString('test', $type, new FormattableMarkup('The %type language is still available', ['%type' => $type]));
}
// Check that fixed language types are properly configured, even those
......
......@@ -56,9 +56,9 @@ protected function setUp(): void {
* Ensures that entity URLs in a language have the right language prefix.
*/
public function testEntityUrlLanguage() {
$this->assertTrue(strpos($this->entity->toUrl()->toString(), '/en/entity_test/' . $this->entity->id()) !== FALSE);
$this->assertTrue(strpos($this->entity->getTranslation('es')->toUrl()->toString(), '/es/entity_test/' . $this->entity->id()) !== FALSE);
$this->assertTrue(strpos($this->entity->getTranslation('fr')->toUrl()->toString(), '/fr/entity_test/' . $this->entity->id()) !== FALSE);
$this->assertStringContainsString('/en/entity_test/' . $this->entity->id(), $this->entity->toUrl()->toString());
$this->assertStringContainsString('/es/entity_test/' . $this->entity->id(), $this->entity->getTranslation('es')->toUrl()->toString());
$this->assertStringContainsString('/fr/entity_test/' . $this->entity->id(), $this->entity->getTranslation('fr')->toUrl()->toString());
}
/**
......@@ -89,9 +89,9 @@ public function testEntityUrlLanguageWithLanguageContentEnabled() {
// The method language-content-entity should run before language-url and
// append query parameter for the content language and prevent language-url
// from overwriting the url.
$this->assertTrue(strpos($this->entity->toUrl('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en') !== FALSE);
$this->assertTrue(strpos($this->entity->getTranslation('es')->toUrl('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es') !== FALSE);
$this->assertTrue(strpos($this->entity->getTranslation('fr')->toUrl('canonical')->toString(), '/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr') !== FALSE);
$this->assertStringContainsString('/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=en', $this->entity->toUrl('canonical')->toString());
$this->assertStringContainsString('/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=es', $this->entity->getTranslation('es')->toUrl('canonical')->toString());
$this->assertStringContainsString('/en/entity_test/' . $this->entity->id() . '?' . LanguageNegotiationContentEntity::QUERY_PARAMETER . '=fr', $this->entity->getTranslation('fr')->toUrl('canonical')->toString());
// Define the method language-url with a higher priority than
// language-content-entity. This configuration should match the default one,
......
......@@ -84,7 +84,7 @@ public function testFixOldPluralStyle($translation_value, $expected) {
// Check that 'count[2]' was saved for source value.
$translation = $string_storage->findTranslation(['language' => 'fr', 'lid' => $lid])->translation;
$this->assertSame($translation_value, $translation, 'Source value not changed');
$this->assertNotFalse(strpos($translation, '@count[2]'), 'Source value contains @count[2]');
$this->assertStringContainsString('@count[2]', $translation, 'Source value contains @count[2]');
}
/**
......
......@@ -304,7 +304,12 @@ public function testFixOldPluralStyleTranslations($translations, $langcode, $str
->with('locale:' . $langcode . '::anonymous', FALSE);
$locale_lookup = new LocaleLookup($langcode, '', $this->storage, $this->cache, $this->lock, $this->configFactory, $this->languageManager, $this->requestStack);
$this->assertSame($is_fix, strpos($locale_lookup->get($string), '@count[2]') === FALSE);
if ($is_fix) {
$this->assertStringNotContainsString('@count[2]', $locale_lookup->get($string));
}
else {
$this->assertStringContainsString('@count[2]', $locale_lookup->get($string));
}
}
/**
......
......@@ -84,7 +84,7 @@ public function testPathPlugin() {
$output = $view->preview();
$output = $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertTrue(strpos($output, 'This is <strong>not escaped</strong> and this is ' . $node->toLink('the link')->toString()) !== FALSE, 'Make sure path field rewriting is not escaped.');
$this->assertStringContainsString('This is <strong>not escaped</strong> and this is ' . $node->toLink('the link')->toString(), $output, 'Make sure path field rewriting is not escaped.');
}
}
......
......@@ -79,8 +79,8 @@ public function testRowPlugin() {
$output = $view->preview();
$output = $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertFalse(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
$this->assertTrue(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text appears in the output of the view.');
$this->assertStringNotContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
$this->assertStringContainsString($node->body->value, $output, 'Make sure the full text appears in the output of the view.');
}
// Test with teasers.
......@@ -88,8 +88,8 @@ public function testRowPlugin() {
$output = $view->preview();
$output = $renderer->renderRoot($output);
foreach ($this->nodes as $node) {
$this->assertTrue(strpos($output, $node->body->summary) !== FALSE, 'Make sure the teaser appears in the output of the view.');
$this->assertFalse(strpos($output, $node->body->value) !== FALSE, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.');
$this->assertStringContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
$this->assertStringNotContainsString($node->body->value, $output, 'Make sure the full text does not appears in the output of the view if teaser is set as viewmode.');
}
}
......
......@@ -165,8 +165,8 @@ public function testAutocompleteQuickEdit() {
$tags = $tag_field->getValue();
// Check existing terms.
$this->assertTrue(strpos($tags, $this->term1->label()) !== FALSE);
$this->assertTrue(strpos($tags, $this->term2->label()) !== FALSE);
$this->assertStringContainsString($this->term1->label(), $tags);
$this->assertStringContainsString($this->term2->label(), $tags);
// Add new term.
$new_tag = $this->randomMachineName();
......
......@@ -258,7 +258,7 @@ public function testDisplayOptions() {
];
$build = $node->body->view($display_settings);
$output = \Drupal::service('renderer')->renderRoot($build);
$this->assertFalse(strpos($output, 'data-quickedit-field-id'), 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
$this->assertStringNotContainsString('data-quickedit-field-id', $output, 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
}
/**
......
......@@ -157,7 +157,7 @@ public function testUriPaths() {
foreach ($manager->getDefinitions() as $resource => $definition) {
foreach ($definition['uri_paths'] as $key => $uri_path) {
$this->assertFalse(strpos($uri_path, '//'), 'The resource URI path does not have duplicate slashes.');
$this->assertStringNotContainsString('//', $uri_path, 'The resource URI path does not have duplicate slashes.');
}
}
}
......
......@@ -652,7 +652,7 @@ public function testFieldapiField() {
$node->save();
$result = Json::decode($this->drupalGet('test/serialize/node-field', ['query' => ['_format' => 'json']]));
$this->assertEqual($result[1]['nid'], $node->id());
$this->assertTrue(strpos($this->getSession()->getPage()->getContent(), "<script") === FALSE, "No script tag is present in the raw page contents.");
$this->assertStringNotContainsString("<script", $this->getSession()->getPage()->getContent(), "No script tag is present in the raw page contents.");
$this->drupalLogin($this->adminUser);
......
......@@ -115,7 +115,7 @@ public function testLanguages() {
$url = $this->getUrl();
$parts = parse_url($url);
$query_string = isset($parts['query']) ? rawurldecode($parts['query']) : '';
$this->assertTrue(strpos($query_string, '=language:fr') !== FALSE, 'Language filter language:fr add to the query string.');
$this->assertStringContainsString('=language:fr', $query_string, 'Language filter language:fr add to the query string.');
// Search for keyword node and language filter as Spanish.
$edit = ['keys' => 'node', 'language[es]' => TRUE];
......
......@@ -53,12 +53,12 @@ public function testSearchExcerpt() {
$longtext = str_repeat($text . ' ', 10);
$result = $this->doSearchExcerpt('nothing', $longtext);
$expected = 'The quick brown fox &amp; jumps over the lazy dog';
$this->assertTrue(strpos($result, $expected) === 0, 'When keyword is not found in long string, return value starts as expected');
$this->assertStringStartsWith($expected, $result, 'When keyword is not found in long string, return value starts as expected');
$entities = str_repeat('k&eacute;sz&iacute;t&eacute;se ', 20);
$result = $this->doSearchExcerpt('nothing', $entities);
$this->assertFalse(strpos($result, '&'), 'Entities are not present in excerpt');
$this->assertTrue(strpos($result, 'í') > 0, 'Entities are converted in excerpt');
$this->assertStringNotContainsString('&', $result, 'Entities are not present in excerpt');
$this->assertStringContainsString('í', $result, 'Entities are converted in excerpt');
// The node body that will produce this rendered $text is:
// 123456789 HTMLTest +123456789+&lsquo; +&lsquo; +&lsquo; +&lsquo; +12345678 &nbsp;&nbsp; +&lsquo; +&lsquo; +&lsquo; &lsquo;
......@@ -85,37 +85,37 @@ public function testSearchExcerptSimplified() {
// Note: The search_excerpt() function adds some extra spaces -- not
// important for HTML formatting. Remove these for comparison.
$result = $this->doSearchExcerpt('123456.7890', $text);
$this->assertTrue(strpos($result, 'Number: <strong>123456.7890</strong>') !== FALSE, 'Numeric keyword is highlighted with exact match');
$this->assertStringContainsString('Number: <strong>123456.7890</strong>', $result, 'Numeric keyword is highlighted with exact match');
$result = $this->doSearchExcerpt('1234567890', $text);
$this->assertTrue(strpos($result, 'Number: <strong>123456.7890</strong>') !== FALSE, 'Numeric keyword is highlighted with simplified match');
$this->assertStringContainsString('Number: <strong>123456.7890</strong>', $result, 'Numeric keyword is highlighted with simplified match');
$result = $this->doSearchExcerpt('Number 1234567890', $text);
$this->assertTrue(strpos($result, '<strong>Number</strong>: <strong>123456.7890</strong>') !== FALSE, 'Punctuated and numeric keyword is highlighted with simplified match');
$this->assertStringContainsString('<strong>Number</strong>: <strong>123456.7890</strong>', $result, 'Punctuated and numeric keyword is highlighted with simplified match');
$result = $this->doSearchExcerpt('"Number 1234567890"', $text);
$this->assertTrue(strpos($result, '<strong>Number: 123456.7890</strong>') !== FALSE, 'Phrase with punctuated and numeric keyword is highlighted with simplified match');
$this->assertStringContainsString('<strong>Number: 123456.7890</strong>', $result, 'Phrase with punctuated and numeric keyword is highlighted with simplified match');
$result = $this->doSearchExcerpt('"Hyphenated onetwo"', $text);
$this->assertTrue(strpos($result, '<strong>Hyphenated: one-two</strong>') !== FALSE, 'Phrase with punctuated and hyphenated keyword is highlighted with simplified match');
$this->assertStringContainsString('<strong>Hyphenated: one-two</strong>', $result, 'Phrase with punctuated and hyphenated keyword is highlighted with simplified match');
$result = $this->doSearchExcerpt('"abc def"', $text);
$this->assertTrue(strpos($result, '<strong>abc,def</strong>') !== FALSE, 'Phrase with keyword simplified into two separate words is highlighted with simplified match');
$this->assertStringContainsString('<strong>abc,def</strong>', $result, 'Phrase with keyword simplified into two separate words is highlighted with simplified match');
// Test phrases with characters which are being truncated.
$result = $this->doSearchExcerpt('"ipsum _"', $text);
$this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part containing "_" is ignored.');
$this->assertStringContainsString('<strong>ipsum</strong>', $result, 'Only valid part of the phrase is highlighted and invalid part containing "_" is ignored.');
$result = $this->doSearchExcerpt('"ipsum 0000"', $text);
$this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid part of the phrase is highlighted and invalid part "0000" is ignored.');
$this->assertStringContainsString('<strong>ipsum</strong>', $result, 'Only valid part of the phrase is highlighted and invalid part "0000" is ignored.');
// Test combination of the valid keyword and keyword containing only
// characters which are being truncated during simplification.
$result = $this->doSearchExcerpt('ipsum _', $text);
$this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "_" is ignored.');
$this->assertStringContainsString('<strong>ipsum</strong>', $result, 'Only valid keyword is highlighted and invalid keyword "_" is ignored.');
$result = $this->doSearchExcerpt('ipsum 0000', $text);
$this->assertTrue(strpos($result, '<strong>ipsum</strong>') !== FALSE, 'Only valid keyword is highlighted and invalid keyword "0000" is ignored.');
$this->assertStringContainsString('<strong>ipsum</strong>', $result, 'Only valid keyword is highlighted and invalid keyword "0000" is ignored.');
// Test using the hook_search_preprocess() from the test module.
// The hook replaces "finding" or "finds" with "find".
......@@ -123,54 +123,54 @@ public function testSearchExcerptSimplified() {
// highlight "finding".
$text = "this tests finding a string";