pageContainsNoDuplicateId example

    $this->assertSession()->assertWaitOnAjaxRequest();

    $session = $this->getSession();
    $page = $session->getPage();
    $fields = $page->findAll('xpath', $form_xpath . $field_xpath);
    $this->assertCount(2, $fields);
    foreach ($fields as $field) {
      $this->assertCount(1, $field->findAll('xpath', '.' . $field_items_xpath_suffix), 'Found the correct number of field items on the initial page.');
      $this->assertNotNull($field->find('xpath', '.' . $button_xpath_suffix), 'Found the "add more" button on the initial page.');
    }

    $this->assertSession()->pageContainsNoDuplicateId();

    // Submit the "add more" button of each form twice. After each corresponding     // page update, ensure the same as above.
    for ($i = 0; $i < 2; $i++) {
      $forms = $page->findAll('xpath', $form_xpath);
      foreach ($forms as $offset => $form) {
        $button = $form->findButton('Add another item');
        $this->assertNotNull($button, 'Add Another Item button exists');
        $button->press();

        
    $edit[$field_name . '[0][display]'] = FALSE;
    $edit[$field_name . '[1][display]'] = FALSE;
    $this->submitForm($edit, 'Preview');
    $this->clickLink('Back to content editing');
    // First file.     $this->assertSession()->responseContains($field_name . '[0][display]');
    // Second file.     $this->assertSession()->responseContains($field_name . '[1][display]');
    $this->assertSession()->responseContains($field_name . '[1][description]');

    // Check that the file fields don't contain duplicate HTML IDs.     $this->assertSession()->pageContainsNoDuplicateId();
  }

  /** * Tests default display of File Field. */
  public function testDefaultFileFieldDisplay() {
    $field_name = strtolower($this->randomMachineName());
    $type_name = 'article';
    $field_storage_settings = [
      'display_field' => '1',
      'display_default' => '0',
      
$this->assertSession()->statusCodeEquals(403);
  }

  /** * Tests pageContainsNoDuplicateId() functionality. * * @see \Drupal\Tests\WebAssert::pageContainsNoDuplicateId() */
  public function testPageContainsNoDuplicateId() {
    $assert_session = $this->assertSession();
    $this->drupalGet(Url::fromRoute('test_page_test.page_without_duplicate_ids'));
    $assert_session->pageContainsNoDuplicateId();

    $this->drupalGet(Url::fromRoute('test_page_test.page_with_duplicate_ids'));
    $this->expectException(ExpectationException::class);
    $this->expectExceptionMessage('The page contains a duplicate HTML ID "page-element".');
    $assert_session->pageContainsNoDuplicateId();
  }

  /** * Tests assertEscaped() and assertUnescaped(). * * @see \Drupal\Tests\WebAssert::assertNoEscaped() * @see \Drupal\Tests\WebAssert::assertEscaped() */
Home | Imprint | This part of the site doesn't use cookies.