responseContains example

// Test that the default formatter is being used.     $image_uri = File::load($node->{$field_name}->target_id)->getFileUri();
    $image = [
      '#theme' => 'image',
      '#uri' => $image_uri,
      '#width' => 360,
      '#height' => 240,
      '#alt' => $alt,
      '#attributes' => ['loading' => 'lazy'],
    ];
    $default_output = str_replace("\n", '', $renderer->renderRoot($image));
    $this->assertSession()->responseContains($default_output);

    // Test field not being configured. This should not cause a fatal error.     $display_options = [
      'type' => 'responsive_image_test',
      'settings' => ResponsiveImageFormatter::defaultSettings(),
    ];
    $display = $this->container->get('entity_type.manager')
      ->getStorage('entity_view_display')
      ->load('node.article.default');
    if (!$display) {
      $values = [
        
// First step: navigate to the re-use field page.     $this->drupalGet("{$bundle_path}/fields/");
    // Confirm that the local action is visible.     $this->assertSession()->linkExists('Re-use an existing field');
    $this->clickLink('Re-use an existing field');
    $this->assertSession()->elementExists('css', "input[value=Re-use][name=$existing_storage_name]");
    $this->click("input[value=Re-use][name=$existing_storage_name]");

    // Set the main content to only the content region because the label can     // contain HTML which will be auto-escaped by Twig.     $this->assertSession()->responseContains('field-config-edit-form');
    // Check that the page does not have double escaped HTML tags.     $this->assertSession()->responseNotContains('<');

    // Second step: 'Field settings' form.     $this->submitForm($field_edit, 'Save settings');
    $this->assertSession()->pageTextContains("Saved $label configuration.");

    // Check that the field appears in the overview form.     $xpath = $this->assertSession()->buildXPathQuery("//table[@id=\"field-overview\"]//tr/td[1 and text() = :label]", [
      ':label' => $label,
    ]);
    
$edit['roles[' . RoleInterface::ANONYMOUS_ID . ']'] = 0;
    $edit['roles[' . RoleInterface::AUTHENTICATED_ID . ']'] = 1;
    $this->drupalGet('admin/config/content/formats/manage/' . $full);
    $this->submitForm($edit, 'Save configuration');
    $this->assertSession()->addressEquals('admin/config/content/formats/manage/' . $full);
    $this->assertSession()->statusMessageContains("The text format {$format->label()} has been updated.", 'status');

    // Switch user.     $this->drupalLogin($this->webUser);

    $this->drupalGet('node/add/page');
    $this->assertSession()->responseContains('<option value="' . $full . '">Full HTML</option>');

    // Use basic HTML and see if it removes tags that are not allowed.     $body = '<em>' . $this->randomMachineName() . '</em>';
    $extra_text = 'text';
    $text = $body . '<random>' . $extra_text . '</random>';

    $edit = [];
    $edit['title[0][value]'] = $this->randomMachineName();
    $edit['body[0][value]'] = $text;
    $edit['body[0][format]'] = $basic;
    $this->drupalGet('node/add/page');
    

  protected static $modules = ['file'];

  /** * Tests the fast 404 functionality. */
  public function testFast404(): void {
    $this->drupalGet('does-not-exist');
    $this->assertSession()->statusCodeEquals(404);
    // Regular 404s will contain CSS from the system module.     $this->assertSession()->responseContains('modules/system/css/');
    $this->drupalGet('does-not-exist.txt');
    $this->assertSession()->statusCodeEquals(404);
    // Fast 404s do not have any CSS.     $this->assertSession()->responseNotContains('modules/system/css/');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache', 'Miss');
    // Fast 404s can be cached.     $this->drupalGet('does-not-exist.txt');
    $this->assertSession()->statusCodeEquals(404);
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache', 'Hit');
    $this->assertSession()->pageTextNotContains('Oops I did it again!');

    
'predefined_langcode' => 'custom',
      'langcode' => $langcode,
      'label' => $name,
      'direction' => LanguageInterface::DIRECTION_LTR,
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add custom language');
    // Add string.     t($name[]['langcode' => $langcode])->render();
    // Reset locale cache.     $this->container->get('string_translation')->reset();
    $this->assertSession()->responseContains('"edit-languages-' . $langcode . '-weight"');
    // Ensure that test language was added.     $this->assertSession()->pageTextContains($name);
    $this->drupalLogout();

    // Add a whitespace at the end of string to ensure it is found.     $name_ws = $name . " ";

    // Search for the name and translate it.     $this->drupalLogin($translate_user);
    $search = [
      'string' => $name_ws,
      

  protected function assertLinkMarkup(string $path, int $status, string $marker, string $restricted, bool $found = FALSE): void {
    $this->drupalGet($path);
    $this->assertSession()->statusCodeEquals($status);
    $this->assertSession()->pageTextContains($marker);
    if ($found) {
      $this->assertSession()->responseContains($restricted);
    }
    else {
      $this->assertSession()->responseNotContains($restricted);
    }

    // Assert that all languages had a link passed to     // hook_language_switch_links_alter() to allow alternatives to be provided.     $languages = \Drupal::languageManager()->getNativeLanguages();
    $links_for_alter = \Drupal::state()->get('language_test.language_switch_link_ids');
    $this->assertSame(array_keys($languages)$links_for_alter);
  }

  
// Create two taxonomy terms and set term2 as the parent of term1.     $term1 = $this->createTerm($this->vocabulary);
    $term2 = $this->createTerm($this->vocabulary);
    $term1->parent = [$term2->id()];
    $term1->save();

    // Verify that the page breadcrumbs include a link to the parent term.     $this->drupalGet('taxonomy/term/' . $term1->id());
    // Breadcrumbs are not rendered with a language, prevent the term     // language from being added to the options.     // Check that parent term link is displayed when viewing the node.     $this->assertSession()->responseContains(Link::fromTextAndUrl($term2->getName()$term2->toUrl('canonical', ['language' => NULL]))->toString());
  }

}
/** * Tests the theme used when adding, viewing and editing taxonomy terms. */
  public function testTaxonomyTermThemes() {
    // Adding a term to a vocabulary is considered an administrative action and     // should use the administrative theme.     $vocabulary = $this->createVocabulary();
    $this->drupalGet('admin/structure/taxonomy/manage/' . $vocabulary->id() . '/add');
    // Check that the administrative theme's CSS appears on the page for adding     // a taxonomy term.     $this->assertSession()->responseContains('claro/css/base/elements.css');

    // Viewing a taxonomy term should use the default theme.     $term = $this->createTerm($vocabulary);
    $this->drupalGet('taxonomy/term/' . $term->id());
    // Check that the default theme's CSS appears on the page for viewing     // a taxonomy term.     $this->assertSession()->responseContains('olivero/css/base/base.css');

    // Editing a taxonomy term should use the same theme as adding one.     $this->drupalGet('taxonomy/term/' . $term->id() . '/edit');
    // Check that the administrative theme's CSS appears on the page for editing
$this->assertSession()->pageTextContains('Last viewed');

    $tags = Cache::mergeTags($node->getCacheTags()$block->getCacheTags());
    $tags = Cache::mergeTags($tags$this->blockingUser->getCacheTags());
    $tags = Cache::mergeTags($tags['block_view', 'config:block_list', 'node_list', 'rendered', 'user_view']);
    $this->assertCacheTags($tags);
    $contexts = Cache::mergeContexts($node->getCacheContexts()$block->getCacheContexts());
    $contexts = Cache::mergeContexts($contexts['url.query_args:_wrapper_format', 'url.site']);
    $this->assertCacheContexts($contexts);

    // Check if the node link is displayed.     $this->assertSession()->responseContains(Link::fromTextAndUrl($node->label()$node->toUrl('canonical'))->toString());
  }

}
// Change the formatter and check that the summary is updated.     $page = $this->getSession()->getPage();

    $field_image_type = $page->findField('fields[field_image][type]');
    $field_image_type->setValue('responsive_image');

    $summary_text = $assert_session->waitForElement('xpath', $this->cssSelectToXpath('#field-image .ajax-new-content .field-plugin-summary'));
    $this->assertEquals('Select a responsive image style. Loading attribute: lazy', $summary_text->getText());

    $page->pressButton('Save');
    $assert_session->responseContains("Select a responsive image style.");

    // Create responsive image styles.     $responsive_image_style = ResponsiveImageStyle::create([
      'id' => 'style_one',
      'label' => 'Style One',
      'breakpoint_group' => 'responsive_image_test_module',
      'fallback_image_style' => 'thumbnail',
    ]);
    $responsive_image_style
      ->addImageStyleMapping('responsive_image_test_module.mobile', '1x', [
        'image_mapping_type' => 'image_style',
        
protected $defaultTheme = 'claro';

  /** * Testing that Claro theme's global library is always attached. * * @see claro.info.yml */
  public function testRegressionMissingElementsCss() {
    $this->drupalGet('');
    $this->assertSession()->statusCodeEquals(200);
    // This can be any CSS file from the global library.     $this->assertSession()->responseContains('claro/css/base/elements.css');
  }

  /** * Tests Claro's configuration schema. */
  public function testConfigSchema() {
    $this->drupalLogin($this->rootUser);
    $this->drupalGet('admin/modules');
    $this->assertSession()->elementNotExists('css', '#block-claro-help');

    // Install the block module to ensure Claro's configuration is valid
$this->assertSession()->pageTextContains($node2->label());

    // Check if we have the feed.     $this->assertSession()->linkByHrefExists(Url::fromRoute('view.' . $view2['id'] . '.feed_1')->toString());
    $elements = $this->cssSelect('link[href="' . Url::fromRoute('view.' . $view2['id'] . '.feed_1', []['absolute' => TRUE])->toString() . '"]');
    $this->assertCount(1, $elements, 'Feed found.');
    $this->drupalGet($view2['page[feed_properties][path]']);
    // Because the response is XML we can't use the page which depends on an     // HTML tag being present.     $this->assertEquals('2.0', $this->getSession()->getDriver()->getAttribute('//rss', 'version'));
    // The feed should have the same title and nodes as the page.     $this->assertSession()->responseContains($view2['page[title]']);
    $this->assertSession()->responseContains($node1->toUrl('canonical', ['absolute' => TRUE])->toString());
    $this->assertSession()->responseContains($node1->label());
    $this->assertSession()->responseContains($node2->toUrl('canonical', ['absolute' => TRUE])->toString());
    $this->assertSession()->responseContains($node2->label());

    // Go back to the views page and check if this view is there.     $this->drupalGet('admin/structure/views');
    $this->assertSession()->pageTextContains($view2['label']);
    $this->assertSession()->pageTextContains($view2['description']);
    $this->assertSession()->linkByHrefExists(Url::fromRoute('view.' . $view2['id'] . '.page_1')->toString());

    
// Upload a different file.     $edit = [];
    $edit['title[0][value]'] = 'Scarlett Johansson';
    $name = 'files[' . $this->fieldName . '_0]';
    $edit[$name] = \Drupal::service('file_system')->realpath($this->drupalGetTestFiles('image')[1]->uri);
    $this->submitForm($edit, 'Save (this translation)');
    $edit = [$this->fieldName . '[0][alt]' => 'Scarlett Johansson image', $this->fieldName . '[0][title]' => 'Scarlett Johansson image title'];
    $this->submitForm($edit, 'Save (this translation)');
    // This inspects the HTML after the post of the translation, the image     // should be displayed on the original node.     $this->assertSession()->responseContains('alt="Lost in translation image"');
    $this->assertSession()->responseContains('title="Lost in translation image title"');
    $second_fid = $this->getLastFileId();
    // View the translated node.     $this->drupalGet('fr/node/' . $default_language_node->id());
    $this->assertSession()->responseContains('alt="Scarlett Johansson image"');

    \Drupal::entityTypeManager()->getStorage('file')->resetCache();

    /** @var \Drupal\file\FileInterface $file */

    // Ensure the file status of the first file permanent.
$this->submitForm([], 'Add Page');
    $this->drupalGet('admin/structure/views/nojs/display/test_view/page_4/path');
    $this->submitForm(['path' => '<script>alert("hello I have placeholders %");</script>'], 'Apply');
    $this->drupalGet('admin/structure/views/view/test_view');
    $this->submitForm([], 'Save');
    $this->drupalGet('admin/structure/views');
    // The anchor text should be escaped.     $this->assertSession()->assertEscaped('/<object>malformed_path</object>');
    $this->assertSession()->assertEscaped('/<script>alert("hello");</script>');
    $this->assertSession()->assertEscaped('/<script>alert("hello I have placeholders %");</script>');
    // Links should be URL-encoded.     $this->assertSession()->responseContains('/%3Cobject%3Emalformed_path%3C/object%3E');
    $this->assertSession()->responseContains('/%3Cscript%3Ealert%28%22hello%22%29%3B%3C/script%3E');
  }

  /** * Tests a couple of invalid path patterns. */
  protected function doAdvancedPathsValidationTest() {
    $url = 'admin/structure/views/nojs/display/test_view/page_1/path';

    $this->drupalGet($url);
    $this->submitForm(['path' => '%/magrathea'], 'Apply');
    
    // bypassed.     $this->drupalGet('admin/config/content/formats/manage/llama');
    $assert_session->pageTextNotContains('ckeditor_stylesheets configured without a corresponding ckeditor5-stylesheets configuration.');

    // Install a theme with ckeditor5-stylesheets configured. Do this manually     // to confirm `library_info` cache tags are invalidated.     $this->drupalGet('admin/appearance');
    $this->clickLink('Set Test relative CKEditor stylesheets as default theme');

    // Confirm the stylesheet added via `ckeditor5-stylesheets` is present.     $this->drupalGet('node/add/article');
    $assert_session->responseContains('test_ckeditor_stylesheets_relative/css/yokotsoko.css');

    // Change the default theme to Stark, and confirm the stylesheet added via     // `ckeditor5-stylesheets` is no longer present.     $this->drupalGet('admin/appearance');
    $this->clickLink('Set Stark as default theme');
    $this->drupalGet('node/add/article');
    $assert_session->responseNotContains('test_ckeditor_stylesheets_relative/css/yokotsoko.css');
  }

}
Home | Imprint | This part of the site doesn't use cookies.