responseMatches example

// Because we can't post hidden form elements, we have to change them in     // code here, and then submit.     foreach ($hidden_edit as $field => $value) {
      $node = $assert->hiddenFieldExists($field);
      $node->setValue($value);
    }
    $edit = [
      'terms[tid:' . $term2->id() . ':0][weight]' => 1,
    ];
    // Submit the edited form and check for HTML indentation element presence.     $this->submitForm($edit, 'Save');
    $this->assertSession()->responseMatches('|<div class="js-indentation indentation">&nbsp;</div>|');

    // Check explicitly that term 2's parent is term 1.     $parents = $taxonomy_storage->loadParents($term2->id());
    $this->assertEquals(1, key($parents), 'Term 1 is the term 2\'s parent');

    // Move the second term back out to the root level.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->get('vid') . '/overview');
    $hidden_edit = [
      'terms[tid:' . $term2->id() . ':0][term][tid]' => 2,
      'terms[tid:' . $term2->id() . ':0][term][parent]' => 0,
      'terms[tid:' . $term2->id() . ':0][term][depth]' => 0,
    ];
$term = reset($terms);

    // Add a translation for that term.     $translated_title = $this->randomMachineName();
    $term->addTranslation('bb', [
      'name' => $translated_title,
    ]);
    $term->save();

    // Overview page in the other language shows the translated term     $this->drupalGet('bb/admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    $this->assertSession()->responseMatches('|<a[^>]*>' . $translated_title . '</a>|');
  }

}
    $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    // Pager should not be visible.     $this->assertSession()->responseNotMatches('|<nav class="pager" [^>]*>|');

    // Create 3 more terms to show pager.     for ($x = 1; $x <= 3; $x++) {
      $this->createTerm($this->vocabulary);
    }

    // Ensure that pager is visible on page 1.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview');
    $this->assertSession()->responseMatches('|<nav class="pager" [^>]*>|');

    // Ensure that pager is visible on page 2.     $this->drupalGet('admin/structure/taxonomy/manage/' . $this->vocabulary->id() . '/overview', ['query' => ['page' => 1]]);
    $this->assertSession()->responseMatches('|<nav class="pager" [^>]*>|');
  }

}
// Attempt to view node-comment form while disallowed.     $this->drupalGet('comment/reply/node/' . $this->node->id() . '/comment');
    $this->assertSession()->statusCodeEquals(403);

    user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => TRUE,
      'post comments' => FALSE,
      'skip comment approval' => FALSE,
    ]);
    $this->drupalGet('node/' . $this->node->id());
    // Verify that the comment field title is displayed.     $this->assertSession()->responseMatches('@<h2[^>]*>Comments</h2>@');
    $this->assertSession()->linkExists('Log in', 1, 'Link to login was found.');
    $this->assertSession()->linkExists('register', 1, 'Link to register was found.');

    user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => FALSE,
      'post comments' => TRUE,
      'skip comment approval' => TRUE,
    ]);
    $this->drupalGet('node/' . $this->node->id());
    // Verify that comments were not displayed.     $this->assertSession()->responseNotMatches('@<h2[^>]*>Comments</h2>@');
    
$this->assertSession()->fieldNotExists('subject[0][value]');
    $this->assertSession()->fieldNotExists('comment_body[0][value]');

    user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => TRUE,
      'post comments' => FALSE,
      'view test entity' => TRUE,
      'skip comment approval' => FALSE,
    ]);
    $this->drupalGet('entity_test/' . $this->entity->id());
    // Verify that the comment field title is displayed.     $this->assertSession()->responseMatches('@<h2[^>]*>Comments</h2>@');
    $this->assertSession()->linkExists('Log in', 0, 'Link to login was found.');
    $this->assertSession()->linkExists('register', 0, 'Link to register was found.');
    $this->assertSession()->fieldNotExists('subject[0][value]');
    $this->assertSession()->fieldNotExists('comment_body[0][value]');

    // Test the combination of anonymous users being able to post, but not view     // comments, to ensure that access to post comments doesn't grant access to     // view them.     user_role_change_permissions(RoleInterface::ANONYMOUS_ID, [
      'access comments' => FALSE,
      'post comments' => TRUE,
      
    $this->drupalLogin($this->webUser);
    $comment_text = $this->randomMachineName();
    $comment = $this->postComment($this->node, $comment_text);
    $this->assertTrue($this->commentExists($comment), 'Comment found.');

    // Test that using an invalid entity-type does not raise an error.     $this->drupalGet('comment/reply/yeah-this-is-not-an-entity-type/' . $this->node->id() . '/comment/' . $comment->id());
    $this->assertSession()->statusCodeEquals(404);

    // Test the comment field title is displayed when there's comments.     $this->drupalGet($this->node->toUrl());
    $this->assertSession()->responseMatches('@<h2[^>]*>Comments</h2>@');

    // Set comments to have subject and preview to required.     $this->drupalLogout();
    $this->drupalLogin($this->adminUser);
    $this->setCommentSubject(TRUE);
    $this->setCommentPreview(DRUPAL_REQUIRED);
    $this->drupalLogout();

    // Create comment #2 that allows subject and requires preview.     $this->drupalLogin($this->webUser);
    $subject_text = $this->randomMachineName();
    
    // 8.x-1.1.     $info = $info_parser->parse($installedInfoFilePath);
    $this->assertEquals('8.x-1.1', $info['version']);
  }

  /** * Ensures that archiver extensions are properly merged in the UI. */
  public function testFileNameExtensionMerging() {
    $this->drupalGet('admin/modules/install');
    // Make sure the bogus extension supported by update_test.module is there.     $this->assertSession()->responseMatches('/file extensions are supported:.*update-test-extension/');
    // Make sure it didn't clobber the first option from core.     $this->assertSession()->responseMatches('/file extensions are supported:.*tar/');
  }

  /** * Checks the messages on update manager pages when missing a security update. */
  public function testUpdateManagerCoreSecurityUpdateMessages() {
    $setting = [
      '#all' => [
        'version' => '8.0.0',
      ],
    // item" options in menu_ui_form_node_type_form_alter(). The "log out" link     // adds the "user.roles:authenticated" cache context.     $this->drupalGet('admin/structure/types/manage/page');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Contexts', 'user.roles:authenticated');

    // Assert the description of "Available menus" checkboxes field.     $this->assertSession()->pageTextContains('Content of this type can be placed in the selected menus.');

    // Verify that the menu link title has the correct maxlength.     $title_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['title']->getSetting('max_length');
    $this->drupalGet('node/add/page');
    $this->assertSession()->responseMatches('/<input .* id="edit-menu-title" .* maxlength="' . $title_max_length . '" .* \/>/');

    // Verify that the menu link description has the correct maxlength.     $description_max_length = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('menu_link_content')['description']->getSetting('max_length');
    $this->drupalGet('node/add/page');
    $this->assertSession()->responseMatches('/<input .* id="edit-menu-description" .* maxlength="' . $description_max_length . '" .* \/>/');

    // Disable the default main menu, so that no menus are enabled.     $edit = [
      'menu_options[main]' => FALSE,
    ];
    $this->drupalGet('admin/structure/types/manage/page');
    


    // Press 'add more' button -> 4 widgets     $this->submitForm($edit, 'Add another item');
    for ($delta = 0; $delta <= $delta_range$delta++) {
      $this->assertSession()->fieldValueEquals("{$field_name}[$delta][value]", $values[$delta]);
      $this->assertSession()->fieldValueEquals("{$field_name}[$delta][_weight]", $weights[$delta]);
    }
    ksort($pattern);
    $pattern = implode('.*', array_values($pattern));
    // Verify that the widgets are displayed in the correct order.     $this->assertSession()->responseMatches("|$pattern|s");
    $this->assertSession()->fieldValueEquals("{$field_name}[$delta][value]", '');
    $this->assertSession()->fieldValueEquals("{$field_name}[$delta][_weight]", $delta);
    // Verify that no extraneous widget is displayed.     $this->assertSession()->fieldNotExists("{$field_name}[" . ($delta + 1) . '][value]');

    // Submit the form and create the entity.     $this->submitForm($edit, 'Save');
    preg_match('|entity_test/manage/(\d+)|', $this->getUrl()$match);
    $id = $match[1];
    $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been created.');
    $entity = EntityTest::load($id);
    
'responsive_image_style' => 'style_one',
      ],
    ];
    $display = $display_repository->getViewDisplay('node', 'article');
    $display->setComponent($field_name$display_options)
      ->save();

    $this->drupalGet('node/' . $nid);
    // No image style cache tag should be found.     $this->assertSession()->responseHeaderNotContains('X-Drupal-Cache-Tags', 'image_style:');

    $this->assertSession()->responseMatches('/<a(.*?)href="' . preg_quote($this->fileUrlGenerator->generateString($image_uri), '/') . '"(.*?)>\s*<picture/');
    // Verify that the image can be downloaded.     $this->assertEquals(file_get_contents($test_image->uri)$this->drupalGet($this->fileUrlGenerator->generateAbsoluteString($image_uri)), 'File was downloaded successfully.');
    if ($scheme == 'private') {
      // Only verify HTTP headers when using private scheme and the headers are       // sent by Drupal.       $this->assertSession()->responseHeaderEquals('Content-Type', 'image/png');
      $this->assertSession()->responseHeaderContains('Cache-Control', 'private');

      // Log out and ensure the file cannot be accessed.       $this->drupalLogout();
      $this->drupalGet($this->fileUrlGenerator->generateAbsoluteString($image_uri));
      
$elements = $this->xpath('//a[contains(@class, :class)]', [
      ':class' => 'button-action',
    ]);
    $index = 0;
    foreach ($actions as $action) {
      /** @var \Drupal\Core\Url $url */
      [$url$title] = $action;
      // SimpleXML gives us the unescaped text, not the actual escaped markup,       // so use a pattern instead to check the raw content.       // This behavior is a bug in libxml, see       // https://bugs.php.net/bug.php?id=49437.       $this->assertSession()->responseMatches('@<a [^>]*class="[^"]*button-action[^"]*"[^>]*>' . preg_quote($title, '@') . '</@');
      $this->assertEquals($url->toString()$elements[$index]->getAttribute('href'));
      $index++;
    }
  }

}

  protected function assertLocalTaskAppears(string $title): void {
    // SimpleXML gives us the unescaped text, not the actual escaped markup,     // so use a pattern instead to check the raw content.     // This behavior is a bug in libxml, see     // https://bugs.php.net/bug.php?id=49437.     $this->assertSession()->responseMatches('@<a [^>]*>' . preg_quote($title, '@') . '</a>@');
  }

  /** * Asserts that the local tasks on the specified level are not being printed. * * @param int $level * (optional) The local tasks level to assert; 0 for primary, 1 for * secondary. Defaults to 0. * * @internal */
  
public function testCommentEmptyTitles() {
    // Create a node.     $this->drupalLogin($this->webUser);
    $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);

    // Post comment #1 and verify that h3 is rendered.     $subject_text = "Test subject";
    $comment_text = "Test comment";
    $this->postComment($this->node, $comment_text$subject_text, TRUE);
    // Tests that markup is generated for the comment title.     $regex_h3 = '|<h3[^>]*>.*?</h3>|';
    $this->assertSession()->responseMatches($regex_h3);

    // Installs module that sets comment title to an empty string.     \Drupal::service('module_installer')->install(['comment_empty_title_test']);

    // Set comments to have a subject with preview disabled.     $this->setCommentPreview(DRUPAL_DISABLED);
    $this->setCommentForm(TRUE);
    $this->setCommentSubject(TRUE);

    // Create a new node.     $this->node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1, 'uid' => $this->webUser->id()]);

    
/** * Triggers a pass if the texts were found in order in the raw content. * * @param $texts * Array of raw strings to look for. * * @internal */
  public function assertBatchMessages(array $texts): void {
    $pattern = '|' . implode('.*', $texts) . '|s';
    $this->assertSession()->responseMatches($pattern);
  }

  /** * Returns expected execution stacks for the test batches. */
  public function _resultStack($id$value = 0) {
    $stack = [];
    switch ($id) {
      case 'batch_1':
        for ($i = 1; $i <= 10; $i++) {
          $stack[] = "op 1 id $i";
        }
// Verify that logging scripts are not found on a non-existent node page.     $this->drupalGet('node/9999');
    $settings = $this->getDrupalSettings();
    // Statistics library JS should not be present.     $this->assertSession()->responseNotMatches($expected_library);
    $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.');

    // Verify that logging scripts are found on a valid node page.     $this->drupalGet($path);
    $settings = $this->getDrupalSettings();
    $this->assertSession()->responseMatches($expected_library);
    $this->assertSame($settings['statistics']['data']['nid']$this->node->id(), 'Found statistics settings on node page.');

    // Verify the same when loading the site in a non-default language.     $this->drupalGet($this->language['langcode'] . '/' . $path);
    $settings = $this->getDrupalSettings();
    $this->assertSession()->responseMatches($expected_library);
    $this->assertSame($settings['statistics']['data']['nid']$this->node->id(), 'Found statistics settings on valid node page in a non-default language.');

    // Manually call statistics.php to simulate ajax data collection behavior.     global $base_root;
    $post = ['nid' => $this->node->id()];
    
Home | Imprint | This part of the site doesn't use cookies.