Issue #3128746 by mondrake, longwave, dww: Replace assertions involving calls to strpos() with more accurate string assertions

merge-requests/2419/head
catch 2020-04-27 10:02:44 +01:00
parent bcec845d85
commit 4d02fe7c25
69 changed files with 258 additions and 250 deletions

View File

@ -67,7 +67,7 @@ class AddFeedTest extends AggregatorTestBase {
$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()));
}
/**

View File

@ -38,7 +38,7 @@ class FeedProcessorPluginTest extends AggregatorTestBase {
$this->updateFeedItems($feed);
foreach ($feed->items as $iid) {
$item = Item::load($iid);
$this->assertTrue(strpos($item->label(), 'testProcessor') === 0);
$this->assertStringStartsWith('testProcessor', $item->label());
}
}

View File

@ -47,7 +47,8 @@ class BasicAuthTest extends BrowserTestBase {
$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 @@ class BasicAuthTest extends BrowserTestBase {
$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');
}
/**

View File

@ -194,9 +194,9 @@ class BigPipeTest extends BrowserTestBase {
$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 @@ class BigPipeTest extends BrowserTestBase {
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 @@ class BigPipeTest extends BrowserTestBase {
// 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.');

View File

@ -280,7 +280,7 @@ class CKEditorAdminTest extends BrowserTestBase {
// 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]"]');

View File

@ -123,7 +123,7 @@ class ColorTest extends BrowserTestBase {
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 @@ class ColorTest extends BrowserTestBase {
$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 @@ class ColorTest extends BrowserTestBase {
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();
}

View File

@ -50,8 +50,8 @@ class CommentAnonymousTest extends CommentTestBase {
$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 @@ class CommentAnonymousTest extends CommentTestBase {
$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.

View File

@ -188,7 +188,7 @@ EOD;
$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.

View File

@ -91,9 +91,9 @@ class ContactPersonalTest extends BrowserTestBase {
];
$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();

View File

@ -879,28 +879,20 @@ www.example.com with a newline in comments -->
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 @@ body {color:red}
* 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 @@ body {color:red}
* 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);
}
}

View File

@ -152,7 +152,7 @@ class ImageAdminStylesTest extends ImageFieldTestBase {
// 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.

View File

@ -169,7 +169,7 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
// 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 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
$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 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
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 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
// (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 @@ class ImageStylesPathAndUrlTest extends BrowserTestBase {
$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.');

View File

@ -154,9 +154,9 @@ class ImageFormatterTest extends FieldKernelTestBase {
$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 @@ class ImageFormatterTest extends FieldKernelTestBase {
$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']);
}
/**

View File

@ -141,7 +141,7 @@ class LanguageNegotiationInfoTest extends BrowserTestBase {
// 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

View File

@ -56,9 +56,9 @@ class EntityUrlLanguageTest extends LanguageTestBase {
* 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 @@ class EntityUrlLanguageTest extends LanguageTestBase {
// 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,

View File

@ -84,7 +84,7 @@ class LocaleLocaleLookupTest extends BrowserTestBase {
// 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]');
}
/**

View File

@ -304,7 +304,12 @@ class LocaleLookupTest extends UnitTestCase {
->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));
}
}
/**

View File

@ -84,7 +84,7 @@ class PathPluginTest extends NodeTestBase {
$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.');
}
}

View File

@ -79,8 +79,8 @@ class RowPluginTest extends NodeTestBase {
$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 @@ class RowPluginTest extends NodeTestBase {
$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.');
}
}

View File

@ -165,8 +165,8 @@ class QuickEditAutocompleteTermTest extends WebDriverTestBase {
$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();

View File

@ -258,7 +258,7 @@ class QuickEditLoadingTest extends WebDriverTestBase {
];
$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.');
}
/**

View File

@ -157,7 +157,7 @@ class ResourceTest extends BrowserTestBase {
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.');
}
}
}

View File

@ -652,7 +652,7 @@ class StyleSerializerTest extends ViewTestBase {
$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);

View File

@ -115,7 +115,7 @@ class SearchLanguageTest extends BrowserTestBase {
$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];

View File

@ -53,12 +53,12 @@ class SearchExcerptTest extends KernelTestBase {
$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 @@ class SearchExcerptTest extends KernelTestBase {
// 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 @@ class SearchExcerptTest extends KernelTestBase {
// highlight "finding".
$text = "this tests finding a string";
$result = $this->doSearchExcerpt('finds', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>finding</strong>') !== FALSE, 'Search excerpt works with preprocess hook, search for finds');
$this->assertStringContainsString('<strong>finding</strong>', $result, 'Search excerpt works with preprocess hook, search for finds');
$result = $this->doSearchExcerpt('find', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>finding</strong>') !== FALSE, 'Search excerpt works with preprocess hook, search for find');
$this->assertStringContainsString('<strong>finding</strong>', $result, 'Search excerpt works with preprocess hook, search for find');
// Just to be sure, test with the replacement at the beginning and end.
$text = "finding at the beginning";
$result = $this->doSearchExcerpt('finds', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>finding</strong>') !== FALSE, 'Search excerpt works with preprocess hook, text at start');
$this->assertStringContainsString('<strong>finding</strong>', $result, 'Search excerpt works with preprocess hook, text at start');
$text = "at the end finding";
$result = $this->doSearchExcerpt('finds', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>finding</strong>') !== FALSE, 'Search excerpt works with preprocess hook, text at end');
$this->assertStringContainsString('<strong>finding</strong>', $result, 'Search excerpt works with preprocess hook, text at end');
// Testing with a one-to-many replacement: the test module replaces DIC
// with Dependency Injection Container.
$text = "something about the DIC is happening";
$result = $this->doSearchExcerpt('Dependency', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>DIC</strong>') !== FALSE, 'Search excerpt works with preprocess hook, acronym first word');
$this->assertStringContainsString('<strong>DIC</strong>', $result, 'Search excerpt works with preprocess hook, acronym first word');
$result = $this->doSearchExcerpt('Injection', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>DIC</strong>') !== FALSE, 'Search excerpt works with preprocess hook, acronym second word');
$this->assertStringContainsString('<strong>DIC</strong>', $result, 'Search excerpt works with preprocess hook, acronym second word');
$result = $this->doSearchExcerpt('Container', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>DIC</strong>') !== FALSE, 'Search excerpt works with preprocess hook, acronym third word');
$this->assertStringContainsString('<strong>DIC</strong>', $result, 'Search excerpt works with preprocess hook, acronym third word');
// Testing with a many-to-one replacement: the test module replaces
// hypertext markup language with HTML.
$text = "we always use hypertext markup language to describe things";
$result = $this->doSearchExcerpt('html', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>hypertext markup language</strong>') !== FALSE, 'Search excerpt works with preprocess hook, acronym many to one');
$this->assertStringContainsString('<strong>hypertext markup language</strong>', $result, 'Search excerpt works with preprocess hook, acronym many to one');
// Test with accents and caps in a longer piece of text with the target
// near the end.
$text = str_repeat($lorem2, 20) . ' ' . $lorem1;
$result = $this->doSearchExcerpt('Lìbêró', $text);
$this->assertTrue(strpos($result, '<strong>libero</strong>') !== FALSE, 'Search excerpt works with caps and accents in longer text');
$this->assertStringContainsString('<strong>libero</strong>', $result, 'Search excerpt works with caps and accents in longer text');
// Test with an acronym provided by the hook, with the target text in the
// middle of a long string.
$text = str_repeat($lorem2, 10) . ' DIC ' . str_repeat($lorem2, 10);
$result = $this->doSearchExcerpt('Dependency', $text, 'ex');
$this->assertTrue(strpos($result, '<strong>DIC</strong>') !== FALSE, 'Search excerpt works with acronym in longer text');
$this->assertStringContainsString('<strong>DIC</strong>', $result, 'Search excerpt works with acronym in longer text');
// Test a long string with a lot of whitespace in it.
$lorem3 = str_replace(' ', str_repeat(" \n", 20), $lorem2);
$text = str_repeat($lorem3, 20) . ' ' . $lorem1;
$result = $this->doSearchExcerpt('Lìbêró', $text);
$this->assertTrue(strpos($result, '<strong>libero</strong>') !== FALSE, 'Search excerpt works with caps and accents in longer text with whitespace');
$this->assertStringContainsString('<strong>libero</strong>', $result, 'Search excerpt works with caps and accents in longer text with whitespace');
$this->verbose('Elapsed time: ' . (microtime(TRUE) - $start_time));
}

View File

@ -33,7 +33,7 @@ class RenderWebTest extends BrowserTestBase {
*/
public function testWrapperFormatCacheContext() {
$this->drupalGet('common-test/type-link-active-class');
$this->assertIdentical(0, strpos($this->getSession()->getPage()->getContent(), "<!DOCTYPE html>\n<html"));
$this->assertStringStartsWith("<!DOCTYPE html>\n<html", $this->getSession()->getPage()->getContent());
$this->assertIdentical('text/html; charset=UTF-8', $this->drupalGetHeader('Content-Type'));
$this->assertTitle('Test active link class | Drupal');
$this->assertCacheContext('url.query_args:' . MainContentViewSubscriber::WRAPPER_FORMAT);

View File

@ -39,11 +39,13 @@ class UrlTest extends BrowserTestBase {
$encoded_path = "3CSCRIPT%3Ealert%28%27XSS%27%29%3C/SCRIPT%3E";
$link = Link::fromTextAndUrl($text, Url::fromUserInput('/' . $path))->toString();
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
$this->assertStringContainsString($encoded_path, $link, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
$this->assertStringNotContainsString($path, $link, new FormattableMarkup('XSS attack @path was filtered by \Drupal\Core\Utility\LinkGeneratorInterface::generate().', ['@path' => $path]));
// Test \Drupal\Core\Url.
$link = Url::fromUri('base:' . $path)->toString();
$this->assertTrue(strpos($link, $encoded_path) !== FALSE && strpos($link, $path) === FALSE, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
$this->assertStringContainsString($encoded_path, $link, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
$this->assertStringNotContainsString($path, $link, new FormattableMarkup('XSS attack @path was filtered by #theme', ['@path' => $path]));
}
/**

View File

@ -38,7 +38,7 @@ class AlterTest extends BrowserTestBase {
'system_form_form_test_alter_form_alter() executed.',
];
$content = preg_replace('/\s+/', ' ', Xss::filter($this->getSession()->getPage()->getContent(), []));
$this->assert(strpos($content, implode(' ', $expected)) !== FALSE, 'Form alter hooks executed in the expected order.');
$this->assertStringContainsString(implode(' ', $expected), $content, 'Form alter hooks executed in the expected order.');
}
}

View File

@ -237,7 +237,7 @@ class SessionHttpsTest extends BrowserTestBase {
$this->assertSame(303, $response->getStatusCode());
$location = $response->getHeader('location')[0];
$this->assertIdentical(strpos($location, $base_url), 0, 'Location header contains expected base URL');
$this->assertStringStartsWith($base_url, $location, 'Location header contains expected base URL');
return substr($location, strlen($base_url));
}

View File

@ -142,7 +142,7 @@ class ErrorHandlerTest extends BrowserTestBase {
$this->drupalGet('error-test/trigger-exception');
$this->assertNull($this->drupalGetHeader('X-Drupal-Cache'));
$this->assertIdentical(strpos($this->drupalGetHeader('Cache-Control'), 'public'), FALSE, 'Received expected HTTP status line.');
$this->assertSession()->responseHeaderNotContains('Cache-Control', 'public');
$this->assertSession()->statusCodeEquals(500);
$this->assertNoErrorMessage($error_exception);
}

View File

@ -51,19 +51,19 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $builder->view($node);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup found in theme output when debug is enabled.');
$this->assertTrue(strpos($output, "THEME HOOK: 'node'") !== FALSE, 'Theme call information found.');
$this->assertTrue(strpos($output, '* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension) !== FALSE, 'Suggested template files found in order and node ID specific template shown as current template.');
$this->assertStringContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup found in theme output when debug is enabled.');
$this->assertStringContainsString("THEME HOOK: 'node'", $output, 'Theme call information found.');
$this->assertStringContainsString('* node--1--full' . $extension . PHP_EOL . ' x node--1' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' * node' . $extension, $output, 'Suggested template files found in order and node ID specific template shown as current template.');
$this->assertStringContainsString(Html::escape('node--<script type="text/javascript">alert(\'yo\');</script>'), (string) $output);
$template_filename = $templates['node__1']['path'] . '/' . $templates['node__1']['template'] . $extension;
$this->assertTrue(strpos($output, "BEGIN OUTPUT from '$template_filename'") !== FALSE, 'Full path to current template file found.');
$this->assertStringContainsString("BEGIN OUTPUT from '$template_filename'", $output, 'Full path to current template file found.');
// Create another node and make sure the template suggestions shown in the
// debug markup are correct.
$node2 = $this->drupalCreateNode();
$build = $builder->view($node2);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, '* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
$this->assertStringContainsString('* node--2--full' . $extension . PHP_EOL . ' * node--2' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
// Create another node and make sure the template suggestions shown in the
// debug markup are correct.
@ -71,8 +71,8 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$build = ['#theme' => 'node__foo__bar'];
$build += $builder->view($node3);
$output = $renderer->renderRoot($build);
$this->assertTrue(strpos($output, "THEME HOOK: 'node__foo__bar'") !== FALSE, 'Theme call information found.');
$this->assertTrue(strpos($output, '* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension) !== FALSE, 'Suggested template files found in order and base template shown as current template.');
$this->assertStringContainsString("THEME HOOK: 'node__foo__bar'", $output, 'Theme call information found.');
$this->assertStringContainsString('* node--foo--bar' . $extension . PHP_EOL . ' * node--foo' . $extension . PHP_EOL . ' * node--&lt;script type=&quot;text/javascript&quot;&gt;alert(&#039;yo&#039;);&lt;/script&gt;' . $extension . PHP_EOL . ' * node--3--full' . $extension . PHP_EOL . ' * node--3' . $extension . PHP_EOL . ' * node--page--full' . $extension . PHP_EOL . ' * node--page' . $extension . PHP_EOL . ' * node--full' . $extension . PHP_EOL . ' x node' . $extension, $output, 'Suggested template files found in order and base template shown as current template.');
// Disable debug, rebuild the service container, and clear all caches.
$parameters = $this->container->getParameter('twig.config');
@ -83,7 +83,7 @@ class TwigDebugMarkupTest extends BrowserTestBase {
$build = $builder->view($node);
$output = $renderer->renderRoot($build);
$this->assertFalse(strpos($output, '<!-- THEME DEBUG -->') !== FALSE, 'Twig debug markup not found in theme output when debug is disabled.');
$this->assertStringNotContainsString('<!-- THEME DEBUG -->', $output, 'Twig debug markup not found in theme output when debug is disabled.');
}
}

View File

@ -488,8 +488,8 @@ class FunctionsTest extends KernelTestBase {
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
$this->assertEqual($list_elements->item(1)->nodeValue, 'First child link', 'Second expected link found.');
$this->assertEqual($list_elements->item(2)->nodeValue, 'Second child link', 'Third expected link found.');
$this->assertIdentical(strpos($html, 'Parent link copy'), FALSE, '"Parent link copy" link not found.');
$this->assertIdentical(strpos($html, 'Third child link'), FALSE, '"Third child link" link not found.');
$this->assertStringNotContainsString('Parent link copy', $html, '"Parent link copy" link not found.');
$this->assertStringNotContainsString('Third child link', $html, '"Third child link" link not found.');
// Now render 'first_child', followed by the rest of the links, and make
// sure we get two separate <ul>'s with the appropriate links contained
@ -513,8 +513,8 @@ class FunctionsTest extends KernelTestBase {
$this->assertEqual($list_elements->length, 2, 'Two "li" tags found in the rendered parent HTML.');
$this->assertEqual($list_elements->item(0)->nodeValue, 'Parent link original', 'First expected link found.');
$this->assertEqual($list_elements->item(1)->nodeValue, 'Second child link', 'Second expected link found.');
$this->assertIdentical(strpos($parent_html, 'First child link'), FALSE, '"First child link" link not found.');
$this->assertIdentical(strpos($parent_html, 'Third child link'), FALSE, '"Third child link" link not found.');
$this->assertStringNotContainsString('First child link', $parent_html, '"First child link" link not found.');
$this->assertStringNotContainsString('Third child link', $parent_html, '"Third child link" link not found.');
}
/**

View File

@ -97,7 +97,7 @@ class UserBlocksTest extends BrowserTestBase {
$this->drupalPostForm(NULL, $edit, t('Log in'));
$this->assertNoText(t('User login'), 'Logged in.');
$this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
$this->assertTrue(strpos($this->getUrl(), '/filter/tips?foo=bar') !== FALSE, 'Correct query arguments are displayed after login');
$this->assertStringContainsString('/filter/tips?foo=bar', $this->getUrl(), 'Correct query arguments are displayed after login');
// Repeat with different query arguments.
$this->drupalLogout();
@ -106,7 +106,7 @@ class UserBlocksTest extends BrowserTestBase {
$this->drupalPostForm(NULL, $edit, t('Log in'));
$this->assertNoText(t('User login'), 'Logged in.');
$this->assertPattern('!<title.*?' . t('Compose tips') . '.*?</title>!', 'Still on the same page after login for allowed page');
$this->assertTrue(strpos($this->getUrl(), '/filter/tips?foo=baz') !== FALSE, 'Correct query arguments are displayed after login');
$this->assertStringContainsString('/filter/tips?foo=baz', $this->getUrl(), 'Correct query arguments are displayed after login');
// Check that the user login block is not vulnerable to information
// disclosure to third party sites.

View File

@ -144,7 +144,7 @@ class UserTokenReplaceTest extends BrowserTestBase {
$link = Url::fromRoute('user.page', [], ['absolute' => TRUE])->toString();
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, ['user' => $account], ['langcode' => $language_interface->getId(), 'callback' => 'user_mail_tokens', 'clear' => TRUE]);
$this->assertTrue(strpos($output, $link) === 0, 'Generated URL is in interface language.');
$this->assertStringStartsWith($link, $output, 'Generated URL is in interface language.');
}
// Generate tokens with the user's preferred language.
@ -153,7 +153,7 @@ class UserTokenReplaceTest extends BrowserTestBase {
$link = Url::fromRoute('user.page', [], ['language' => \Drupal::languageManager()->getLanguage($account->getPreferredLangcode()), 'absolute' => TRUE])->toString();
foreach ($tests as $input => $expected) {
$output = $token_service->replace($input, ['user' => $account], ['callback' => 'user_mail_tokens', 'clear' => TRUE]);
$this->assertTrue(strpos($output, $link) === 0, "Generated URL is in the user's preferred language.");
$this->assertStringStartsWith($link, $output, "Generated URL is in the user's preferred language.");
}
// Generate tokens with one specific language.
@ -161,7 +161,7 @@ class UserTokenReplaceTest extends BrowserTestBase {
foreach ($tests as $input => $expected) {
foreach ([$user1, $user2] as $account) {
$output = $token_service->replace($input, ['user' => $account], ['langcode' => 'de', 'callback' => 'user_mail_tokens', 'clear' => TRUE]);
$this->assertTrue(strpos($output, $link) === 0, "Generated URL in the requested language.");
$this->assertStringStartsWith($link, $output, "Generated URL in the requested language.");
}
}

View File

@ -47,13 +47,13 @@ class HandlerFieldUserNameTest extends UserTestBase {
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertTrue(strpos($render, $anon_name) !== FALSE, 'For user 0 it should use the default anonymous name by default.');
$this->assertStringContainsString($anon_name, $render, 'For user 0 it should use the default anonymous name by default.');
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $new_user) {
return $view->field['name']->advancedRender($view->result[$new_user->id()]);
});
$this->assertTrue(strpos($render, $new_user->getDisplayName()) !== FALSE, 'If link to user is checked the username should be part of the output.');
$this->assertTrue(strpos($render, 'user/' . $new_user->id()) !== FALSE, 'If link to user is checked the link to the user should appear as well.');
$this->assertStringContainsString($new_user->getDisplayName(), $render, 'If link to user is checked the username should be part of the output.');
$this->assertStringContainsString('user/' . $new_user->id(), $render, 'If link to user is checked the link to the user should appear as well.');
$view->field['name']->options['link_to_user'] = FALSE;
$view->field['name']->options['type'] = 'string';
@ -80,7 +80,7 @@ class HandlerFieldUserNameTest extends UserTestBase {
$render = $renderer->executeInRenderContext(new RenderContext(), function () use ($view) {
return $view->field['name']->advancedRender($view->result[0]);
});
$this->assertTrue(strpos($render, $username) !== FALSE, 'If link to user is checked the username should be part of the output.');
$this->assertStringContainsString($username, $render, 'If link to user is checked the username should be part of the output.');
}
}

View File

@ -109,10 +109,10 @@ class AreaTest extends ViewTestBase {
// Check whether the strings exist in the output and are sanitized.
$output = $view->preview();
$output = $this->container->get('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, Xss::filterAdmin($header_string)) !== FALSE, 'Views header exists in the output and is sanitized');
$this->assertTrue(strpos($output, Xss::filterAdmin($footer_string)) !== FALSE, 'Views footer exists in the output and is sanitized');
$this->assertTrue(strpos($output, Xss::filterAdmin($empty_string)) !== FALSE, 'Views empty exists in the output and is sanitized');
$this->assertTrue(strpos($output, '<script') === FALSE, 'Script tags were escaped');
$this->assertStringContainsString(Xss::filterAdmin($header_string), $output, 'Views header exists in the output and is sanitized');
$this->assertStringContainsString(Xss::filterAdmin($footer_string), $output, 'Views footer exists in the output and is sanitized');
$this->assertStringContainsString(Xss::filterAdmin($empty_string), $output, 'Views empty exists in the output and is sanitized');
$this->assertStringNotContainsString('<script', $output, 'Script tags were escaped');
}
/**
@ -129,7 +129,7 @@ class AreaTest extends ViewTestBase {
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
// The area output should not be present since access was denied.
$this->assertFalse(strpos($output, 'a custom string') !== FALSE);
$this->assertStringNotContainsString('a custom string', $output);
$view->destroy();
// Test with access granted for the area handler.
@ -150,7 +150,7 @@ class AreaTest extends ViewTestBase {
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, 'a custom string') !== FALSE);
$this->assertStringContainsString('a custom string', $output);
$this->assertEqual(1, count($handlers));
}
@ -189,7 +189,7 @@ class AreaTest extends ViewTestBase {
$output = $view->preview();
$output = $this->container->get('renderer')->renderRoot($output);
$expected = \Drupal::token()->replace('[site:name]');
$this->assertTrue(strpos($output, $expected) !== FALSE);
$this->assertStringContainsString($expected, $output);
}
/**

View File

@ -129,7 +129,7 @@ class FieldWebTest extends ViewTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos($haystack, $needle) !== FALSE, $message, $group);
return $this->assertStringContainsString($needle, $haystack, $message);
}
/**
@ -147,7 +147,7 @@ class FieldWebTest extends ViewTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos($haystack, $needle) === FALSE, $message, $group);
return $this->assertStringNotContainsString($needle, $haystack, $message);
}
/**

View File

@ -109,7 +109,7 @@ class DisplayTest extends ViewTestBase {
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '<h1></h1>') !== FALSE, 'An empty value for test_option found in output.');
$this->assertStringContainsString('<h1></h1>', $output, 'An empty value for test_option found in output.');
// Change this option and check the title of out output.
$view->display_handler->overrideOption('test_option', 'Test option title');
@ -119,7 +119,7 @@ class DisplayTest extends ViewTestBase {
$output = $renderer->renderRoot($output);
// Test we have our custom <h1> tag in the output of the view.
$this->assertTrue(strpos($output, '<h1>Test option title</h1>') !== FALSE, 'The test_option value found in display output title.');
$this->assertStringContainsString('<h1>Test option title</h1>', $output, 'The test_option value found in display output title.');
// Test that the display category/summary is in the UI.
$this->drupalGet('admin/structure/views/view/test_view/edit/display_test_1');
@ -216,7 +216,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node') !== FALSE, 'The read more link with href "/node" was found.');
$this->assertStringContainsString('/node', $output, 'The read more link with href "/node" was found.');
// Test more link with leading slash.
$view->display_handler->setOption('link_display', 'custom_url');
@ -224,7 +224,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node') !== FALSE, 'The read more link with href "/node" was found.');
$this->assertStringContainsString('/node', $output, 'The read more link with href "/node" was found.');
// Test more link with absolute url.
$view->display_handler->setOption('link_display', 'custom_url');
@ -232,7 +232,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, 'http://drupal.org') !== FALSE, 'The read more link with href "http://drupal.org" was found.');
$this->assertStringContainsString('http://drupal.org', $output, 'The read more link with href "http://drupal.org" was found.');
// Test more link with query parameters in the url.
$view->display_handler->setOption('link_display', 'custom_url');
@ -240,7 +240,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node?page=1&amp;foo=bar') !== FALSE, 'The read more link with href "/node?page=1&foo=bar" was found.');
$this->assertStringContainsString('/node?page=1&amp;foo=bar', $output, 'The read more link with href "/node?page=1&foo=bar" was found.');
// Test more link with fragment in the url.
$view->display_handler->setOption('link_display', 'custom_url');
@ -248,7 +248,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node#target') !== FALSE, 'The read more link with href "/node#target" was found.');
$this->assertStringContainsString('/node#target', $output, 'The read more link with href "/node#target" was found.');
// Test more link with arguments.
$view = Views::getView('test_simple_argument');
@ -261,7 +261,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node?date=22&amp;foo=bar') !== FALSE, 'The read more link with href "/node?date=22&foo=bar" was found.');
$this->assertStringContainsString('/node?date=22&amp;foo=bar', $output, 'The read more link with href "/node?date=22&foo=bar" was found.');
// Test more link with 1 dimension array query parameters with arguments.
$view = Views::getView('test_simple_argument');
@ -274,7 +274,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node?f%5B0%5D=foo%3Abar&amp;f%5B1%5D=foo%3A22') !== FALSE, 'The read more link with href "/node?f[0]=foo:bar&f[1]=foo:22" was found.');
$this->assertStringContainsString('/node?f%5B0%5D=foo%3Abar&amp;f%5B1%5D=foo%3A22', $output, 'The read more link with href "/node?f[0]=foo:bar&f[1]=foo:22" was found.');
// Test more link with arguments in path.
$view->display_handler->setOption('link_url', 'node/{{ raw_arguments.age }}?date={{ raw_arguments.age }}&foo=bar');
@ -282,7 +282,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node/22?date=22&amp;foo=bar') !== FALSE, 'The read more link with href "/node/22?date=22&foo=bar" was found.');
$this->assertStringContainsString('/node/22?date=22&amp;foo=bar', $output, 'The read more link with href "/node/22?date=22&foo=bar" was found.');
// Test more link with arguments in fragment.
$view->display_handler->setOption('link_url', 'node?date={{ raw_arguments.age }}&foo=bar#{{ raw_arguments.age }}');
@ -290,7 +290,7 @@ class DisplayTest extends ViewTestBase {
$this->executeView($view);
$output = $view->preview();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, '/node?date=22&amp;foo=bar#22') !== FALSE, 'The read more link with href "/node?date=22&foo=bar#22" was found.');
$this->assertStringContainsString('/node?date=22&amp;foo=bar#22', $output, 'The read more link with href "/node?date=22&foo=bar#22" was found.');
}
/**

View File

@ -131,23 +131,23 @@ class AreaEntityTest extends ViewsKernelTestBase {
$footer_xpath = '//div[@class = "' . $view_class . '"]/footer[1]';
$result = $this->xpath($header_xpath);
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$this->assertStringContainsString($entities[0]->label(), (string) $result[0], 'The rendered entity appears in the header of the view.');
$this->assertStringContainsString('full', (string) $result[0], 'The rendered entity appeared in the right view mode.');
$result = $this->xpath($footer_xpath);
$this->assertTrue(strpos(trim((string) $result[0]), $entities[1]->label()) !== FALSE, 'The rendered entity appears in the footer of the view.');
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$this->assertStringContainsString($entities[1]->label(), (string) $result[0], 'The rendered entity appears in the footer of the view.');
$this->assertStringContainsString('full', (string) $result[0], 'The rendered entity appeared in the right view mode.');
$preview = $view->preview('default', [$entities[1]->id()]);
$this->setRawContent($renderer->renderRoot($preview));
$result = $this->xpath($header_xpath);
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$this->assertStringContainsString($entities[0]->label(), (string) $result[0], 'The rendered entity appears in the header of the view.');
$this->assertStringContainsString('full', (string) $result[0], 'The rendered entity appeared in the right view mode.');
$result = $this->xpath($footer_xpath);
$this->assertTrue(strpos(trim((string) $result[0]), $entities[1]->label()) !== FALSE, 'The rendered entity appears in the footer of the view.');
$this->assertTrue(strpos(trim((string) $result[0]), 'full') !== FALSE, 'The rendered entity appeared in the right view mode.');
$this->assertStringContainsString($entities[1]->label(), (string) $result[0], 'The rendered entity appears in the footer of the view.');
$this->assertStringContainsString('full', (string) $result[0], 'The rendered entity appeared in the right view mode.');
// Mark entity_test test view_mode as customizable.
$entity_view_mode = \Drupal::entityTypeManager()->getStorage('entity_view_mode')->load('entity_test.test');
@ -164,8 +164,8 @@ class AreaEntityTest extends ViewsKernelTestBase {
$this->setRawContent($renderer->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this->xpath('//div[@class = "' . $view_class . '"]/header[1]');
$this->assertTrue(strpos(trim((string) $result[0]), $entities[0]->label()) !== FALSE, 'The rendered entity appears in the header of the view.');
$this->assertTrue(strpos(trim((string) $result[0]), 'test') !== FALSE, 'The rendered entity appeared in the right view mode.');
$this->assertStringContainsString($entities[0]->label(), (string) $result[0], 'The rendered entity appears in the header of the view.');
$this->assertStringContainsString('test', (string) $result[0], 'The rendered entity appeared in the right view mode.');
// Test entity access.
$view = Views::getView('test_entity_area');
@ -173,7 +173,7 @@ class AreaEntityTest extends ViewsKernelTestBase {
$this->setRawContent($renderer->renderRoot($preview));
$view_class = 'js-view-dom-id-' . $view->dom_id;
$result = $this->xpath('//div[@class = "' . $view_class . '"]/footer[1]');
$this->assertTrue(strpos($result[0], $entities[2]->label()) === FALSE, 'The rendered entity does not appear in the footer of the view.');
$this->assertStringNotContainsString($entities[2]->label(), $result[0], 'The rendered entity does not appear in the footer of the view.');
// Test the available view mode options.
$form = [];

View File

@ -41,15 +41,15 @@ class AreaViewTest extends ViewsKernelTestBase {
$this->executeView($view);
$output = $view->render();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, 'js-view-dom-id-' . $view->dom_id) !== FALSE, 'The test view is correctly embedded.');
$this->assertStringContainsString('js-view-dom-id-' . $view->dom_id, $output, 'The test view is correctly embedded.');
$view->destroy();
$view->setArguments([27]);
$this->executeView($view);
$output = $view->render();
$output = $renderer->renderRoot($output);
$this->assertTrue(strpos($output, 'John') === FALSE, 'The test view is correctly embedded with inherited arguments.');
$this->assertTrue(strpos($output, 'George') !== FALSE, 'The test view is correctly embedded with inherited arguments.');
$this->assertStringNotContainsString('John', $output, 'The test view is correctly embedded with inherited arguments.');
$this->assertStringContainsString('George', $output, 'The test view is correctly embedded with inherited arguments.');
$view->destroy();
}

View File

@ -114,7 +114,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos($haystack, $needle) !== FALSE, $message, $group);
return $this->assertStringContainsString($needle, $haystack, $message);
}
/**
@ -139,7 +139,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertNotSubString($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos($haystack, $needle) === FALSE, $message, $group);
return $this->assertStringNotContainsString($needle, $haystack, $message);
}
/**
@ -251,7 +251,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
return $name_field_0->advancedRender($row);
});
$this->assertFalse(strpos((string) $output, '\Drupal\views_test_data\Controller\ViewsTestDataController::preRender executed') !== FALSE, 'Ensure that the pre_render function was not executed');
$this->assertStringNotContainsString('\Drupal\views_test_data\Controller\ViewsTestDataController::preRender executed', (string) $output, 'Ensure that the pre_render function was not executed');
$this->assertEqual('%1 !1', (string) $output, "Ensure that old style placeholders aren't replaced");
// This time use new style tokens but ensure that we still don't allow
@ -264,7 +264,7 @@ class FieldKernelTest extends ViewsKernelTestBase {
return $name_field_0->advancedRender($row);
});
$this->assertFalse(strpos((string) $output, '\Drupal\views_test_data\Controller\ViewsTestDataController::preRender executed') !== FALSE, 'Ensure that the pre_render function was not executed');
$this->assertStringNotContainsString('\Drupal\views_test_data\Controller\ViewsTestDataController::preRender executed', (string) $output, 'Ensure that the pre_render function was not executed');
$this->assertEqual('{{ { &quot;#pre_render&quot;: [&quot;\Drupal\views_test_data\Controller\ViewsTestDataController::preRender&quot;]} }} {{ { &quot;#pre_render&quot;: [&quot;\Drupal\views_test_data\Controller\ViewsTestDataController::preRender&quot;]} }}', (string) $output, 'Ensure that new style placeholders are replaced');
}

View File

@ -89,7 +89,7 @@ class ModuleTest extends ViewsKernelTestBase {
'field' => 'field_invalid',
];
$this->container->get('plugin.manager.views.field')->getHandler($item);
$this->assertTrue(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'views_test_data', '@field' => 'field_invalid', '@type' => 'field'])) !== FALSE, 'An invalid field name throws a debug message.');
$this->assertStringContainsString(new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'views_test_data', '@field' => 'field_invalid', '@type' => 'field']), $this->lastErrorMessage, 'An invalid field name throws a debug message.');
unset($this->lastErrorMessage);
$item = [
@ -97,7 +97,7 @@ class ModuleTest extends ViewsKernelTestBase {
'field' => 'id',
];
$this->container->get('plugin.manager.views.filter')->getHandler($item);
$this->assertEqual(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.');
$this->assertStringContainsString(new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter']), $this->lastErrorMessage, 'An invalid table name throws a debug message.');
unset($this->lastErrorMessage);
$item = [
@ -105,7 +105,7 @@ class ModuleTest extends ViewsKernelTestBase {
'field' => 'id',
];
$this->container->get('plugin.manager.views.filter')->getHandler($item);
$this->assertEqual(strpos($this->lastErrorMessage, new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter'])) !== FALSE, 'An invalid table name throws a debug message.');
$this->assertStringContainsString(new FormattableMarkup("Missing handler: @table @field @type", ['@table' => 'table_invalid', '@field' => 'id', '@type' => 'filter']), $this->lastErrorMessage, 'An invalid table name throws a debug message.');
unset($this->lastErrorMessage);
restore_error_handler();

View File

@ -65,7 +65,7 @@ class JoinTest extends RelationshipJoinTestBase {
$tables = $query->getTables();
$join_info = $tables['users_field_data'];
$this->assertTrue(strpos($join_info['condition'], "views_test_data.uid = $rand_int") !== FALSE, 'Make sure that the custom join plugin can extend the join base and alter the result.');
$this->assertStringContainsString("views_test_data.uid = $rand_int", $join_info['condition'], 'Make sure that the custom join plugin can extend the join base and alter the result.');
}
/**
@ -144,9 +144,9 @@ class JoinTest extends RelationshipJoinTestBase {
$tables = $query->getTables();
$join_info = $tables['users3'];
$this->assertTrue(strpos($join_info['condition'], "views_test_data.uid = users3.uid") !== FALSE, 'Make sure the join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users3.name = :views_join_condition_0") !== FALSE, 'Make sure the first extra join condition appears in the query and uses the first placeholder.');
$this->assertTrue(strpos($join_info['condition'], "users3.name <> :views_join_condition_1") !== FALSE, 'Make sure the second extra join condition appears in the query and uses the second placeholder.');
$this->assertStringContainsString("views_test_data.uid = users3.uid", $join_info['condition'], 'Make sure the join condition appears in the query.');
$this->assertStringContainsString("users3.name = :views_join_condition_0", $join_info['condition'], 'Make sure the first extra join condition appears in the query and uses the first placeholder.');
$this->assertStringContainsString("users3.name <> :views_join_condition_1", $join_info['condition'], 'Make sure the second extra join condition appears in the query and uses the second placeholder.');
$this->assertEqual(array_values($join_info['arguments']), [$random_name_1, $random_name_2], 'Make sure the arguments are in the right order');
// Test that 'IN' conditions are properly built.
@ -170,9 +170,9 @@ class JoinTest extends RelationshipJoinTestBase {
$tables = $query->getTables();
$join_info = $tables['users4'];
$this->assertTrue(strpos($join_info['condition'], "views_test_data.uid = users4.uid") !== FALSE, 'Make sure the join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users4.name = :views_join_condition_2") !== FALSE, 'Make sure the first extra join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users4.name IN ( :views_join_condition_3[] )") !== FALSE, 'The IN condition for the join is properly formed.');
$this->assertStringContainsString("views_test_data.uid = users4.uid", $join_info['condition'], 'Make sure the join condition appears in the query.');
$this->assertStringContainsString("users4.name = :views_join_condition_2", $join_info['condition'], 'Make sure the first extra join condition appears in the query.');
$this->assertStringContainsString("users4.name IN ( :views_join_condition_3[] )", $join_info['condition'], 'The IN condition for the join is properly formed.');
$this->assertEqual($join_info['arguments'][':views_join_condition_3[]'], [$random_name_2, $random_name_3, $random_name_4], 'Make sure the IN arguments are still part of an array.');
// Test that all the conditions are properly built.
@ -197,10 +197,10 @@ class JoinTest extends RelationshipJoinTestBase {
$tables = $query->getTables();
$join_info = $tables['users5'];
$this->assertTrue(strpos($join_info['condition'], "views_test_data.uid = users5.uid") !== FALSE, 'Make sure the join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users5.langcode = :views_join_condition_4") !== FALSE, 'Make sure the first extra join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "views_test_data.status = :views_join_condition_5") !== FALSE, 'Make sure the second extra join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users5.name = views_test_data.name") !== FALSE, 'Make sure the third extra join condition appears in the query.');
$this->assertStringContainsString("views_test_data.uid = users5.uid", $join_info['condition'], 'Make sure the join condition appears in the query.');
$this->assertStringContainsString("users5.langcode = :views_join_condition_4", $join_info['condition'], 'Make sure the first extra join condition appears in the query.');
$this->assertStringContainsString("views_test_data.status = :views_join_condition_5", $join_info['condition'], 'Make sure the second extra join condition appears in the query.');
$this->assertStringContainsString("users5.name = views_test_data.name", $join_info['condition'], 'Make sure the third extra join condition appears in the query.');
$this->assertEqual(array_values($join_info['arguments']), ['en', 0], 'Make sure the arguments are in the right order');
// Test that joins using 'left_formula' are properly built.
@ -211,10 +211,10 @@ class JoinTest extends RelationshipJoinTestBase {
$tables = $query->getTables();
$join_info = $tables['users6'];
$this->assertTrue(strpos($join_info['condition'], "MAX(views_test_data.uid) = users6.uid") !== FALSE, 'Make sure the join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users6.langcode = :views_join_condition_7") !== FALSE, 'Make sure the first extra join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "views_test_data.status = :views_join_condition_8") !== FALSE, 'Make sure the second extra join condition appears in the query.');
$this->assertTrue(strpos($join_info['condition'], "users6.name = views_test_data.name") !== FALSE, 'Make sure the third extra join condition appears in the query.');
$this->assertStringContainsString("MAX(views_test_data.uid) = users6.uid", $join_info['condition'], 'Make sure the join condition appears in the query.');
$this->assertStringContainsString("users6.langcode = :views_join_condition_7", $join_info['condition'], 'Make sure the first extra join condition appears in the query.');
$this->assertStringContainsString("views_test_data.status = :views_join_condition_8", $join_info['condition'], 'Make sure the second extra join condition appears in the query.');
$this->assertStringContainsString("users6.name = views_test_data.name", $join_info['condition'], 'Make sure the third extra join condition appears in the query.');
$this->assertEqual(array_values($join_info['arguments']), ['en', 0], 'Make sure the arguments are in the right order');
}

View File

@ -30,11 +30,11 @@ class StyleHtmlListTest extends ViewsKernelTestBase {
// Check that an empty class attribute is not added if the wrapper class is
// not set.
$this->assertTrue(strpos($output, '<div>') !== FALSE, 'Empty class is not added to DIV when class is not set');
$this->assertStringContainsString('<div>', $output, 'Empty class is not added to DIV when class is not set');
// Check that an empty class attribute is not added if the list class is
// not set.
$this->assertTrue(strpos($output, '<ul>') !== FALSE, 'Empty class is not added to UL when class is not set');
$this->assertStringContainsString('<ul>', $output, 'Empty class is not added to UL when class is not set');
// Set wrapper class and list class in style options.
$view->style_plugin->options['class'] = 'class';
@ -44,10 +44,10 @@ class StyleHtmlListTest extends ViewsKernelTestBase {
$output = \Drupal::service('renderer')->renderRoot($output);
// Check that class attribute is present if the wrapper class is set.
$this->assertTrue(strpos($output, '<div class="wrapper-class">') !== FALSE, 'Class is added to DIV');
$this->assertStringContainsString('<div class="wrapper-class">', $output, 'Class is added to DIV');
// Check that class attribute is present if the list class is set.
$this->assertTrue(strpos($output, '<ul class="class">') !== FALSE, 'Class is added to UL');
$this->assertStringContainsString('<ul class="class">', $output, 'Class is added to UL');
}
}

View File

@ -28,13 +28,13 @@ class StyleMappingTest extends StyleTestBase {
public function testMappedOutput() {
$view = Views::getView('test_style_mapping');
$output = $this->mappedOutputHelper($view);
$this->assertTrue(strpos($output, 'job') === FALSE, 'The job field is added to the view but not in the mapping.');
$this->assertStringNotContainsString('job', $output, 'The job field is added to the view but not in the mapping.');
$view->destroy();
$view->setDisplay();
$view->displayHandlers->get('default')->options['style']['options']['mapping']['name_field'] = 'job';
$output = $this->mappedOutputHelper($view);
$this->assertTrue(strpos($output, 'job') !== FALSE, 'The job field is added to the view and is in the mapping.');
$this->assertStringContainsString('job', $output, 'The job field is added to the view and is in the mapping.');
}
/**
@ -57,7 +57,7 @@ class StyleMappingTest extends StyleTestBase {
foreach ($rows as $row) {
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
$this->assertTrue(strpos($class, 'views-row-mapping-test') !== FALSE, 'Make sure that each row has the correct CSS class.');
$this->assertStringContainsString('views-row-mapping-test', $class, 'Make sure that each row has the correct CSS class.');
foreach ($row->div as $field) {
// Split up the field-level class, the first part is the mapping name

View File

@ -119,7 +119,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
$view->field['name']->options['exclude'] = TRUE;
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->assertFalse(strpos($output, 'views-field-name') !== FALSE, "Excluded field's wrapper was not rendered.");
$this->assertStringNotContainsString('views-field-name', $output, "Excluded field's wrapper was not rendered.");
$view->destroy();
// Render a non empty result, and ensure that the empty area handler is not
@ -128,7 +128,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->assertFalse(strpos($output, 'custom text') !== FALSE, 'Empty handler was not rendered on a non empty table.');
$this->assertStringNotContainsString('custom text', $output, 'Empty handler was not rendered on a non empty table.');
// Render an empty result, and ensure that the area handler is rendered.
$view->setDisplay('default');
@ -137,7 +137,7 @@ class StyleTableUnitTest extends PluginKernelTestBase {
$output = $view->preview();
$output = \Drupal::service('renderer')->renderRoot($output);
$this->assertTrue(strpos($output, 'custom text') !== FALSE, 'Empty handler got rendered on an empty table.');
$this->assertStringContainsString('custom text', $output, 'Empty handler got rendered on an empty table.');
}
/**

View File

@ -34,7 +34,7 @@ class StyleUnformattedTest extends StyleTestBase {
$count++;
$attributes = $row->attributes();
$class = (string) $attributes['class'][0];
$this->assertTrue(strpos($class, 'views-row') !== FALSE, 'Make sure that the views row class is set right.');
$this->assertStringContainsString('views-row', $class, 'Make sure that the views row class is set right.');
}
$this->assertIdentical($count, $count_result);
}

View File

@ -484,7 +484,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
// Test the view storage object is not present in the actual serialized
// string.
$this->assertIdentical(strpos($serialized, '"Drupal\views\Entity\View"'), FALSE, 'The Drupal\views\Entity\View class was not found in the serialized string.');
$this->assertStringNotContainsString('"Drupal\views\Entity\View"', $serialized, 'The Drupal\views\Entity\View class was not found in the serialized string.');
/** @var \Drupal\views\ViewExecutable $unserialized */
$unserialized = unserialize($serialized);

View File

@ -147,7 +147,7 @@ SQL;
$elements = $this->xpath('//div[@id="views-live-preview"]/div[contains(@class, views-query-info)]//td[text()=:text]', [':text' => 'Test row count']);
$this->assertEqual(count($elements), 1, 'Views Query Preview Info area altered.');
// Check that additional assets are attached.
$this->assertTrue(strpos($this->getDrupalSettings()['ajaxPageState']['libraries'], 'views_ui_test/views_ui_test.test') !== FALSE, 'Attached library found.');
$this->assertStringContainsString('views_ui_test/views_ui_test.test', $this->getDrupalSettings()['ajaxPageState']['libraries'], 'Attached library found.');
$this->assertRaw('css/views_ui_test.test.css', 'Attached CSS asset found.');
}

View File

@ -123,8 +123,8 @@ class SettingsTest extends UITestBase {
$this->drupalPostForm(NULL, [], t('Update preview'));
$xpath = $this->xpath('//div[@class="views-query-info"]//pre');
$this->assertEqual(count($xpath), 1, 'The views sql is shown.');
$this->assertFalse(strpos($xpath[0]->getText(), 'db_condition_placeholder') !== FALSE, 'No placeholders are shown in the views sql.');
$this->assertTrue(strpos($xpath[0]->getText(), Database::getConnection()->escapeField("node_field_data.status") . " = '1'") !== FALSE, 'The placeholders in the views sql is replace by the actual value.');
$this->assertStringNotContainsString('db_condition_placeholder', $xpath[0]->getText(), 'No placeholders are shown in the views sql.');
$this->assertStringContainsString(Database::getConnection()->escapeField("node_field_data.status") . " = '1'", $xpath[0]->getText(), 'The placeholders in the views sql is replace by the actual value.');
// Test the advanced settings form.

View File

@ -303,7 +303,7 @@ class PreviewTest extends WebDriverTestBase {
if (!isset($message)) {
$message = "Class .$class found.";
}
$this->assertTrue(strpos($element->getAttribute('class'), $class) !== FALSE, $message);
$this->assertStringContainsString($class, $element->getAttribute('class'), $message);
}
}

View File

@ -133,7 +133,7 @@ class ViewUIObjectTest extends UnitTestCase {
$serialized = serialize($view_ui);
// Make sure the ViewExecutable class is not found in the serialized string.
$this->assertFalse(strpos($serialized, '"Drupal\views\ViewExecutable"'));
$this->assertStringNotContainsString('"Drupal\views\ViewExecutable"', $serialized);
$unserialized = unserialize($serialized);
$this->assertInstanceOf('Drupal\views_ui\ViewUI', $unserialized);

View File

@ -280,12 +280,12 @@ class UncaughtExceptionTest extends BrowserTestBase {
// Find fatal error logged to the error.log
$errors = file(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
$this->assertIdentical(count($errors), 8, 'The error + the error that the logging service is broken has been written to the error log.');
$this->assertTrue(strpos($errors[0], 'Failed to log error') !== FALSE, 'The error handling logs when an error could not be logged to the logger.');
$this->assertStringContainsString('Failed to log error', $errors[0], 'The error handling logs when an error could not be logged to the logger.');
$expected_path = \Drupal::root() . '/core/modules/system/tests/modules/error_service_test/src/MonkeysInTheControlRoom.php';
$expected_line = 59;
$expected_entry = "Failed to log error: Exception: Deforestation in Drupal\\error_service_test\\MonkeysInTheControlRoom->handle() (line ${expected_line} of ${expected_path})";
$this->assert(strpos($errors[0], $expected_entry) !== FALSE, 'Original error logged to the PHP error log when an exception is thrown by a logger');
$this->assertStringContainsString($expected_entry, $errors[0], 'Original error logged to the PHP error log when an exception is thrown by a logger');
// The exception is expected. Do not interpret it as a test failure. Not
// using File API; a potential error must trigger a PHP warning.

View File

@ -434,7 +434,7 @@ trait AssertContentTrait {
if (!$message) {
$message = 'Raw "' . Html::escape($raw) . '" found';
}
return $this->assert(strpos($this->getRawContent(), (string) $raw) !== FALSE, $message, $group);
$this->assertStringContainsString((string) $raw, $this->getRawContent(), $message);
}
/**
@ -462,7 +462,7 @@ trait AssertContentTrait {
if (!$message) {
$message = 'Raw "' . Html::escape($raw) . '" not found';
}
return $this->assert(strpos($this->getRawContent(), (string) $raw) === FALSE, $message, $group);
$this->assertStringNotContainsString((string) $raw, $this->getRawContent(), $message);
}
/**
@ -490,7 +490,7 @@ trait AssertContentTrait {
if (!$message) {
$message = 'Escaped "' . Html::escape($raw) . '" found';
}
return $this->assert(strpos($this->getRawContent(), Html::escape($raw)) !== FALSE, $message, $group);
$this->assertStringContainsString(Html::escape($raw), $this->getRawContent(), $message);
}
/**
@ -519,7 +519,7 @@ trait AssertContentTrait {
if (!$message) {
$message = 'Escaped "' . Html::escape($raw) . '" not found';
}
return $this->assert(strpos($this->getRawContent(), Html::escape($raw)) === FALSE, $message, $group);
$this->assertStringNotContainsString(Html::escape($raw), $this->getRawContent(), $message);
}
/**
@ -606,7 +606,12 @@ trait AssertContentTrait {
if (!$message) {
$message = !$not_exists ? new FormattableMarkup('"@text" found', ['@text' => $text]) : new FormattableMarkup('"@text" not found', ['@text' => $text]);
}
return $this->assert($not_exists == (strpos($this->getTextContent(), (string) $text) === FALSE), $message, $group);
if ($not_exists) {
$this->assertStringNotContainsString((string) $text, $this->getTextContent(), $message);
}
else {
$this->assertStringContainsString((string) $text, $this->getTextContent(), $message);
}
}
/**

View File

@ -89,8 +89,8 @@ class AttachedAssetsTest extends KernelTestBase {
$rendered_css = $this->renderer->renderPlain($css_render_array);
$rendered_js = $this->renderer->renderPlain($js_render_array);
$query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
$this->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" media="all" href="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/bar.css')) . '?' . $query_string . '" />'), FALSE, 'Rendering an external CSS file.');
$this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/foo.js')) . '?' . $query_string . '"></script>'), FALSE, 'Rendering an external JavaScript file.');
$this->assertStringContainsString('<link rel="stylesheet" media="all" href="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/bar.css')) . '?' . $query_string . '" />', $rendered_css, 'Rendering an external CSS file.');
$this->assertStringContainsString('<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/foo.js')) . '?' . $query_string . '"></script>', $rendered_js, 'Rendering an external JavaScript file.');
}
/**
@ -128,8 +128,8 @@ class AttachedAssetsTest extends KernelTestBase {
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
$rendered_css = $this->renderer->renderPlain($css_render_array);
$rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" media="all" href="http://example.com/stylesheet.css" />'), FALSE, 'Rendering an external CSS file.');
$this->assertNotIdentical(strpos($rendered_js, '<script src="http://example.com/script.js"></script>'), FALSE, 'Rendering an external JavaScript file.');
$this->assertStringContainsString('<link rel="stylesheet" media="all" href="http://example.com/stylesheet.css" />', $rendered_css, 'Rendering an external CSS file.');
$this->assertStringContainsString('<script src="http://example.com/script.js"></script>', $rendered_js, 'Rendering an external JavaScript file.');
}
/**
@ -144,8 +144,8 @@ class AttachedAssetsTest extends KernelTestBase {
$rendered_js = $this->renderer->renderPlain($js_render_array);
$expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/deferred-internal.js')) . '?v=1" defer bar="foo"></script>';
$this->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
$this->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered internal JavaScript with correct defer and random attributes.');
$this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.');
$this->assertStringContainsString($expected_2, $rendered_js, 'Rendered internal JavaScript with correct defer and random attributes.');
}
/**
@ -160,8 +160,8 @@ class AttachedAssetsTest extends KernelTestBase {
$rendered_js = $this->renderer->renderPlain($js_render_array);
$expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/deferred-internal.js')) . '?v=1" defer bar="foo"></script>';
$this->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
$this->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered internal JavaScript with correct defer and random attributes.');
$this->assertStringContainsString($expected_1, $rendered_js, 'Rendered external JavaScript with correct defer and random attributes.');
$this->assertStringContainsString($expected_2, $rendered_js, 'Rendered internal JavaScript with correct defer and random attributes.');
}
/**
@ -179,7 +179,7 @@ class AttachedAssetsTest extends KernelTestBase {
$rendered_footer_js = \Drupal::service('asset.js.collection_renderer')->render($footer_js);
$this->assertEqual(2, count($rendered_footer_js), 'There are 2 JavaScript assets in the footer.');
$this->assertEqual('drupal-settings-json', $rendered_footer_js[0]['#attributes']['data-drupal-selector'], 'The first of the two JavaScript assets in the footer has drupal settings.');
$this->assertEqual(0, strpos($rendered_footer_js[1]['#attributes']['src'], base_path()), 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
$this->assertStringStartsWith(base_path(), $rendered_footer_js[1]['#attributes']['src'], 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
}
/**
@ -233,9 +233,9 @@ class AttachedAssetsTest extends KernelTestBase {
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
$rendered_js = $this->renderer->renderPlain($js_render_array);
$query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
$this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/header.js')) . '?' . $query_string . '"></script>'), FALSE, 'The JS asset in common_test/js-header appears in the header.');
$this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/misc/drupal.js'))), FALSE, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.');
$this->assertNotIdentical(strpos($rendered_js, '<script src="' . file_url_transform_relative(file_create_url('core/misc/drupalSettingsLoader.js'))), FALSE, 'The JS asset of the indirect dependency (core/drupalSettings) of common_test/js-header appears in the header.');
$this->assertStringContainsString('<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/header.js')) . '?' . $query_string . '"></script>', $rendered_js, 'The JS asset in common_test/js-header appears in the header.');
$this->assertStringContainsString('<script src="' . file_url_transform_relative(file_create_url('core/misc/drupal.js')), $rendered_js, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.');
$this->assertStringContainsString('<script src="' . file_url_transform_relative(file_create_url('core/misc/drupalSettingsLoader.js')), $rendered_js, 'The JS asset of the indirect dependency (core/drupalSettings) of common_test/js-header appears in the header.');
}
/**
@ -266,8 +266,8 @@ class AttachedAssetsTest extends KernelTestBase {
$expected_1 = "<!--[if lte IE 8]>\n" . '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/old-ie.js')) . '?' . $default_query_string . '"></script>' . "\n<![endif]-->";
$expected_2 = "<!--[if !IE]><!-->\n" . '<script src="' . file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/no-ie.js')) . '?' . $default_query_string . '"></script>' . "\n<!--<![endif]-->";
$this->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered JavaScript within downlevel-hidden conditional comments.');
$this->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered JavaScript within downlevel-revealed conditional comments.');
$this->assertStringContainsString($expected_1, $rendered_js, 'Rendered JavaScript within downlevel-hidden conditional comments.');
$this->assertStringContainsString($expected_2, $rendered_js, 'Rendered JavaScript within downlevel-revealed conditional comments.');
}
/**
@ -281,7 +281,7 @@ class AttachedAssetsTest extends KernelTestBase {
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
$rendered_js = $this->renderer->renderPlain($js_render_array);
$this->assertTrue(strpos($rendered_js, 'core/assets/vendor/backbone/backbone-min.js?v=1.4.0') > 0, 'JavaScript version identifiers correctly appended to URLs');
$this->assertStringContainsString('core/assets/vendor/backbone/backbone-min.js?v=1.4.0', $rendered_js, 'JavaScript version identifiers correctly appended to URLs');
}
/**
@ -472,8 +472,8 @@ class AttachedAssetsTest extends KernelTestBase {
$js_render_array = \Drupal::service('asset.js.collection_renderer')->render($js);
$rendered_js = $this->renderer->renderPlain($js_render_array);
$query_string = $this->container->get('state')->get('system.css_js_query_string') ?: '0';
$this->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" media="all" href="' . str_replace('&', '&amp;', file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2'))) . '&amp;' . $query_string . '" />'), FALSE, 'CSS file with query string gets version query string correctly appended..');
$this->assertNotIdentical(strpos($rendered_js, '<script src="' . str_replace('&', '&amp;', file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2'))) . '&amp;' . $query_string . '"></script>'), FALSE, 'JavaScript file with query string gets version query string correctly appended.');
$this->assertStringContainsString('<link rel="stylesheet" media="all" href="' . str_replace('&', '&amp;', file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2'))) . '&amp;' . $query_string . '" />', $rendered_css, 'CSS file with query string gets version query string correctly appended..');
$this->assertStringContainsString('<script src="' . str_replace('&', '&amp;', file_url_transform_relative(file_create_url('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2'))) . '&amp;' . $query_string . '"></script>', $rendered_js, 'JavaScript file with query string gets version query string correctly appended.');
}
}

View File

@ -83,7 +83,7 @@ class FileStorageTest extends ConfigStorageTestBase {
}
catch (UnsupportedDataTypeConfigException $e) {
$this->pass('Exception thrown when trying to read a field containing invalid data type.');
$this->assertTrue((strpos($e->getMessage(), $this->storage->getFilePath('core.extension')) !== FALSE), 'Erroneous file path is displayed.');
$this->assertStringContainsString($this->storage->getFilePath('core.extension'), $e->getMessage(), 'Erroneous file path is displayed.');
}
}

View File

@ -39,7 +39,7 @@ class SelectTest extends DatabaseTestBase {
$expected = "/* Testing query comments */";
$this->assertEqual(count($records), 4, 'Returned the correct number of rows.');
$this->assertNotIdentical(FALSE, strpos($query, $expected), 'The flattened query contains the comment string.');
$this->assertStringContainsString($expected, $query, 'The flattened query contains the comment string.');
}
/**

View File

@ -54,11 +54,11 @@ class HtaccessTest extends KernelTestBase {
mkdir($this->public, 0777, TRUE);
$this->assertTrue($this->htaccessWriter->write($this->public, FALSE));
$content = file_get_contents($this->public . '/.htaccess');
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE);
$this->assertFalse(strpos($content, "Require all denied") !== FALSE);
$this->assertFalse(strpos($content, "Deny from all") !== FALSE);
$this->assertTrue(strpos($content, "Options -Indexes -ExecCGI -Includes -MultiViews") !== FALSE);
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003") !== FALSE);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringNotContainsString("Require all denied", $content);
$this->assertStringNotContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($this->public . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter->write($this->public, FALSE));
@ -67,11 +67,11 @@ class HtaccessTest extends KernelTestBase {
mkdir($private, 0777, TRUE);
$this->assertTrue($this->htaccessWriter->write($private));
$content = file_get_contents($private . '/.htaccess');
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE);
$this->assertTrue(strpos($content, "Require all denied") !== FALSE);
$this->assertTrue(strpos($content, "Deny from all") !== FALSE);
$this->assertTrue(strpos($content, "Options -Indexes -ExecCGI -Includes -MultiViews") !== FALSE);
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003") !== FALSE);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringContainsString("Require all denied", $content);
$this->assertStringContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($private . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter->write($private));
@ -80,11 +80,11 @@ class HtaccessTest extends KernelTestBase {
mkdir($stream, 0777, TRUE);
$this->assertTrue($this->htaccessWriter->write($stream));
$content = file_get_contents($stream . '/.htaccess');
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE);
$this->assertTrue(strpos($content, "Require all denied") !== FALSE);
$this->assertTrue(strpos($content, "Deny from all") !== FALSE);
$this->assertTrue(strpos($content, "Options -Indexes -ExecCGI -Includes -MultiViews") !== FALSE);
$this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003") !== FALSE);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006", $content);
$this->assertStringContainsString("Require all denied", $content);
$this->assertStringContainsString("Deny from all", $content);
$this->assertStringContainsString("Options -Indexes -ExecCGI -Includes -MultiViews", $content);
$this->assertStringContainsString("SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003", $content);
$this->assertFilePermissions($stream . '/.htaccess', 0444);
$this->assertTrue($this->htaccessWriter->write($stream));

View File

@ -108,7 +108,7 @@ class ContentNegotiationRoutingTest extends KernelTestBase {
// see the error.
$this->assertTrue(TRUE, $message);
$this->assertEqual($response->getStatusCode(), Response::HTTP_OK);
$this->assertTrue(strpos($response->headers->get('Content-type'), $content_type) !== FALSE);
$this->assertStringContainsString($content_type, $response->headers->get('Content-type'));
}
}

View File

@ -113,15 +113,15 @@ class ExceptionHandlingTest extends KernelTestBase {
public function testExceptionResponseGeneratedForOriginalRequest() {
// Test with 404 path pointing to a route that uses '_controller'.
$response = $this->doTest404Route('/router_test/test25');
$this->assertTrue(strpos($response->getContent(), '/not-found') !== FALSE);
$this->assertStringContainsString('/not-found', $response->getContent());
// Test with 404 path pointing to a route that uses '_form'.
$response = $this->doTest404Route('/router_test/test26');
$this->assertTrue(strpos($response->getContent(), '<form class="system-logging-settings"') !== FALSE);
$this->assertStringContainsString('<form class="system-logging-settings"', $response->getContent());
// Test with 404 path pointing to a route that uses '_entity_form'.
$response = $this->doTest404Route('/router_test/test27');
$this->assertTrue(strpos($response->getContent(), '<form class="date-format-add-form date-format-form"') !== FALSE);
$this->assertStringContainsString('<form class="date-format-add-form date-format-form"', $response->getContent());
}
/**
@ -161,8 +161,8 @@ class ExceptionHandlingTest extends KernelTestBase {
// Test both that the backtrace is properly escaped, and that the unescaped
// string is not output at all.
$this->assertTrue(strpos($response->getContent(), Html::escape('<script>alert(\'xss\')</script>')) !== FALSE);
$this->assertTrue(strpos($response->getContent(), '<script>alert(\'xss\')</script>') === FALSE);
$this->assertStringContainsString(Html::escape('<script>alert(\'xss\')</script>'), $response->getContent());
$this->assertStringNotContainsString('<script>alert(\'xss\')</script>', $response->getContent());
}
/**

View File

@ -109,7 +109,7 @@ class TwigEnvironmentTest extends KernelTestBase {
$this->fail('Did not throw an exception as expected.');
}
catch (LoaderError $e) {
$this->assertTrue(strpos($e->getMessage(), 'Template "this-template-does-not-exist.html.twig" is not defined') === 0);
$this->assertStringStartsWith('Template "this-template-does-not-exist.html.twig" is not defined', $e->getMessage());
}
}

View File

@ -59,7 +59,7 @@ class JsonTest extends TestCase {
// Verify there aren't character encoding problems with the source string.
$this->assertSame(127, strlen($this->string), 'A string with the full ASCII table has the correct length.');
foreach ($this->htmlUnsafe as $char) {
$this->assertTrue(strpos($this->string, $char) > 0, sprintf('A string with the full ASCII table includes %s.', $char));
$this->assertStringContainsString($char, $this->string, sprintf('A string with the full ASCII table includes %s.', $char));
}
}
@ -102,11 +102,11 @@ class JsonTest extends TestCase {
$source = [TRUE, FALSE, 0, 1, '0', '1', $this->string, ['key1' => $this->string, 'key2' => ['nested' => TRUE]]];
$json = Json::encode($source);
foreach ($this->htmlUnsafe as $char) {
$this->assertTrue(strpos($json, $char) === FALSE, sprintf('A JSON encoded string does not contain %s.', $char));
$this->assertStringNotContainsString($char, $json, sprintf('A JSON encoded string does not contain %s.', $char));
}
// Verify that JSON encoding escapes the HTML unsafe characters
foreach ($this->htmlUnsafeEscaped as $char) {
$this->assertTrue(strpos($json, $char) > 0, sprintf('A JSON encoded string contains %s.', $char));
$this->assertStringContainsString($char, $json, sprintf('A JSON encoded string contains %s.', $char));
}
$json_decoded = Json::decode($json);
$this->assertNotSame($source, $json, 'An array encoded in JSON is identical to the source.');

View File

@ -594,7 +594,7 @@ class XssTest extends TestCase {
* (optional) The group this message belongs to. Defaults to 'Other'.
*/
protected function assertNormalized($haystack, $needle, $message = '', $group = 'Other') {
$this->assertTrue(strpos(strtolower(Html::decodeEntities($haystack)), $needle) !== FALSE, $message, $group);
$this->assertStringContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
/**
@ -616,7 +616,7 @@ class XssTest extends TestCase {
* (optional) The group this message belongs to. Defaults to 'Other'.
*/
protected function assertNotNormalized($haystack, $needle, $message = '', $group = 'Other') {
$this->assertTrue(strpos(strtolower(Html::decodeEntities($haystack)), $needle) === FALSE, $message, $group);
$this->assertStringNotContainsString($needle, strtolower(Html::decodeEntities($haystack)), $message);
}
}

View File

@ -55,7 +55,7 @@ class ComposerIntegrationTest extends UnitTestCase {
if (strpos($dependency, 'symfony/') === 0) {
continue;
}
$this->assertFalse(strpos($version, '~'), "Dependency $dependency in $path contains a tilde, use a caret.");
$this->assertStringNotContainsString('~', $version, "Dependency $dependency in $path contains a tilde, use a caret.");
}
}
}

View File

@ -59,7 +59,7 @@ class SessionCacheContextTest extends UnitTestCase {
$context1 = $cache_context->getContext();
$context2 = $cache_context->getContext();
$this->assertSame($context1, $context2);
$this->assertFalse(strpos($context1, $session_id), 'Session ID not contained in cache context');
$this->assertStringNotContainsString($session_id, $context1, 'Session ID not contained in cache context');
}
/**
@ -83,8 +83,8 @@ class SessionCacheContextTest extends UnitTestCase {
$context2 = $cache_context->getContext();
$this->assertNotEquals($context1, $context2);
$this->assertFalse(strpos($context1, $session1_id), 'Session ID not contained in cache context');
$this->assertFalse(strpos($context2, $session2_id), 'Session ID not contained in cache context');
$this->assertStringNotContainsString($session1_id, $context1, 'Session ID not contained in cache context');
$this->assertStringNotContainsString($session2_id, $context2, 'Session ID not contained in cache context');
}
/**

View File

@ -70,7 +70,7 @@ class RendererRecursionTest extends RendererTestBase {
$this->setUpRequest();
$callable = function ($markup) use ($renderer, $complex_child_template) {
$this->assertTrue(strpos($markup, '<drupal-render-placeholder') === 0, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
$this->assertStringStartsWith('<drupal-render-placeholder', $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
return $markup;
};

View File

@ -349,7 +349,7 @@ class AttributeTest extends UnitTestCase {
$this->assertID('example-id', $html);
$this->assertNoID('example-id2', $html);
$this->assertTrue(strpos($html, 'enabled') !== FALSE);
$this->assertStringContainsString('enabled', $html);
}
/**

View File

@ -191,7 +191,7 @@ class UrlTest extends UnitTestCase {
$this->assertInstanceOf('Drupal\Core\Url', $url);
$this->assertFalse($url->isRouted());
$this->assertEquals(0, strpos($uri, 'base:'));
$this->assertStringStartsWith('base:', $uri);
$parts = UrlHelper::parse($path);
$options = $url->getOptions();

View File

@ -437,7 +437,7 @@ class LinkGeneratorTest extends UnitTestCase {
'tag' => 'em',
],
], $result);
$this->assertTrue(strpos($result, '<em>HTML output</em>') !== FALSE);
$this->assertStringContainsString('<em>HTML output</em>', $result);
}
/**