elementNotExists example

$this->drupalGet('');
    $this->assertSession()->elementTextEquals('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->responseNotContains('<script>alert("Community carpentry");</script>');

    // Turn just the logo off.     $this->config('block.block.site-branding')
      ->set('settings.use_site_logo', 0)
      ->save();
    $this->drupalGet('');

    // Re-test all branding elements.     $this->assertSession()->elementNotExists('xpath', $site_logo_xpath);
    $this->assertSession()->elementExists('xpath', $site_name_xpath);
    $this->assertSession()->elementTextContains('xpath', $site_slogan_xpath, 'alert("Community carpentry");');
    $this->assertSession()->responseNotContains('<script>alert("Community carpentry");</script>');
    $this->assertSession()->responseHeaderContains('X-Drupal-Cache-Tags', 'config:system.site');

    // Turn just the site name off.     $this->config('block.block.site-branding')
      ->set('settings.use_site_logo', 1)
      ->set('settings.use_site_name', 0)
      ->save();
    $this->drupalGet('');

    
$this->clickLink('Place block');
    $this->assertSession()->elementExists('xpath', '//tr[.//td/div[text()="Display message"] and .//td[text()="Custom category"] and .//td//a[contains(@href, "admin/structure/block/add/test_block_instantiation/stark")]]');
  }

  /** * Tests the behavior of unsatisfied context-aware blocks. */
  public function testContextAwareUnsatisfiedBlocks() {
    $this->drupalGet('admin/structure/block');
    $this->clickLink('Place block');
    // Verify that the context-aware test block does not appear.     $this->assertSession()->elementNotExists('xpath', '//tr[.//td/div[text()="Test context-aware unsatisfied block"] and .//td[text()="Block test"] and .//td//a[contains(@href, "admin/structure/block/add/test_context_aware_unsatisfied/stark")]]');

    $definition = \Drupal::service('plugin.manager.block')->getDefinition('test_context_aware_unsatisfied');
    $this->assertNotEmpty($definition, 'The context-aware test block does not exist.');
  }

  /** * Tests the behavior of context-aware blocks. */
  public function testContextAwareBlocks() {
    $expected_text = '<div id="test_context_aware--username">' . \Drupal::currentUser()->getAccountName() . '</div>';
    $this->drupalGet('');
    
$this->assertSession()->elementTextEquals('xpath', $xpath, 1);

    // Ensure that just the filtered entry is returned.     $this->drupalGet('test_route_with_suffix/1/suffix');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementsCount('xpath', $xpath, 1);
    $this->assertSession()->elementTextEquals('xpath', $xpath, 1);

    // Ensure that no result is returned.     $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementNotExists('xpath', $xpath);

    // Ensure that just the filtered entry is returned.     $this->drupalGet('test_route_with_suffix_and_argument/1/suffix/1');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementsCount('xpath', $xpath, 1);
    $this->assertSession()->elementTextEquals('xpath', $xpath, 1);

    // Ensure that just the filtered entry is returned.     $this->drupalGet('test_route_with_long_argument/1');
    $this->assertSession()->statusCodeEquals(200);
    $this->assertSession()->elementsCount('xpath', $xpath, 1);
    
/** * Tests update.php when there are no updates to apply. */
  public function testNoUpdateFunctionality() {
    // Click through update.php with 'administer software updates' permission.     $this->drupalLogin($this->updateUser);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    $this->clickLink('Continue');
    $this->assertSession()->pageTextContains('No pending updates.');
    $this->assertSession()->linkNotExists('Administration pages');
    $this->assertSession()->elementNotExists('xpath', '//main//a[contains(@href, "update.php")]');
    $this->clickLink('Front page');
    $this->assertSession()->statusCodeEquals(200);

    // Click through update.php with 'access administration pages' permission.     $admin_user = $this->drupalCreateUser([
      'administer software updates',
      'access administration pages',
    ]);
    $this->drupalLogin($admin_user);
    $this->drupalGet($this->updateUrl, ['external' => TRUE]);
    $this->updateRequirementsProblem();
    
$this->assertSession()->elementExists('xpath', '//ul[@class="entity-moderation-form"]');

    $node = $this->drupalGetNodeByTitle('Some moderated content');
    $this->assertNotEmpty($node->language(), 'en');
    $edit_path = sprintf('node/%d/edit', $node->id());
    $translate_path = sprintf('node/%d/translations/add/en/fr', $node->id());
    $latest_version_path = sprintf('node/%d/latest', $node->id());
    $french = \Drupal::languageManager()->getLanguage('fr');

    $this->drupalGet($latest_version_path);
    $this->assertSession()->statusCodeEquals('403');
    $this->assertSession()->elementNotExists('xpath', '//ul[@class="entity-moderation-form"]');

    // Add french translation (revision 2).     $this->drupalGet($translate_path);
    $this->assertSession()->optionExists('moderation_state[0][state]', 'draft');
    $this->assertSession()->optionExists('moderation_state[0][state]', 'published');
    $this->assertSession()->optionNotExists('moderation_state[0][state]', 'archived');
    $this->submitForm([
      'body[0][value]' => 'Second version of the content.',
      'moderation_state[0][state]' => 'published',
    ], 'Save (this translation)');

    
// Add a table via the editor buttons.     $table_button = $page->find('css', '.ck-dropdown button');
    $table_button->click();

    // Add a single table cell.     $grid_button = $assert_session->waitForElementVisible('css', '.ck-insert-table-dropdown-grid-box[data-row="1"][data-column="1"]');
    $grid_button->click();

    // Confirm the table has been added and no caption is present.     $this->assertNotNull($table_figure = $assert_session->waitForElementVisible('css', 'figure.table'));
    $assert_session->elementNotExists('css', 'figure.table > figcaption');

    // Enable captions and update caption content.     $caption_button = $this->getBalloonButton('Toggle caption on');
    $caption_button->click();
    $caption = $assert_session->waitForElementVisible('css', 'figure.table > figcaption');
    $this->assertEmpty($caption->getText());
    $caption->setValue($this->captionText);
    $this->assertEquals($this->captionText, $caption->getText());

    // Update table cell content.     $table_cell = $assert_session->waitForElement('css', '.ck-editor__nested-editable .ck-table-bogus-paragraph');
    
$this->drupalLogin($this->drupalCreateUser([
      'administer entity_test content',
    ]));
  }

  /** * @dataProvider linkFieldFormStatesData */
  public function testLinkFieldFormStates(string $uri, string $title) {
    $this->drupalGet('entity_test/add');
    $session = $this->assertSession();
    $session->elementNotExists('css', '#edit-links-0-uri[required]');
    $session->elementNotExists('css', '#edit-links-0-title[required]');

    $page = $this->getSession()->getPage();

    if ($uri !== '') {
      $page->fillField('links[0][uri]', $uri);
      $session->elementNotExists('css', '#edit-links-0-uri[required]');
      $session->elementExists('css', '#edit-links-0-title[required]');
    }
    else {
      $page->fillField('links[0][title]', $title);
      
$this->clickLink('Disable');

    // Confirm that the block is now listed as disabled.     $this->assertSession()->statusMessageContains('The block settings have been updated.', 'status');

    // Confirm that the block instance title and markup are not displayed.     $this->drupalGet('node');
    $this->assertSession()->pageTextNotContains($block['settings[label]']);
    // Check for <div id="block-my-block-instance-name"> if the machine name     // is my_block_instance_name.     $xpath = $this->assertSession()->buildXPathQuery('//div[@id=:id]/*', [':id' => 'block-' . str_replace('_', '-', strtolower($block['id']))]);
    $this->assertSession()->elementNotExists('xpath', $xpath);

    $pages = [
      '',
      '<front>',
      '/valid-page',
      'user/login',
    ];
    // Test error when not including forward slash.     $this->drupalGet('admin/structure/block/manage/' . $block['id']);
    $this->submitForm(['visibility[request_path][pages]' => implode("\n", $pages)], 'Save block');
    $this->assertSession()->pageTextContains('The path user/login requires a leading forward slash when used with the Pages setting.');

    
$session = $this->getSession();
    $page = $session->getPage();
    $assert_session = $this->assertSession();

    $media_type = $this->createMediaType('test', [
      'queue_thumbnail_downloads' => FALSE,
    ]);

    $this->drupalGet('media/add');
    $assert_session->statusCodeEquals(200);
    $assert_session->addressEquals('media/add/' . $media_type->id());
    $assert_session->elementNotExists('css', '#edit-revision');

    // Tests media add form.     $media_name = $this->randomMachineName();
    $page->fillField('name[0][value]', $media_name);
    $revision_log_message = $this->randomString();
    $page->fillField('revision_log_message[0][value]', $revision_log_message);
    $source_field = $this->randomString();
    $page->fillField('field_media_test[0][value]', $source_field);
    $page->pressButton('Save');
    $media_id = $this->container->get('entity_type.manager')
      ->getStorage('media')
      
/** * Enables a disabled CKEditor 5 toolbar item. * * @param string $toolbar_item_id * The toolbar item to enable. */
  protected function enableDisabledToolbarItem(string $toolbar_item_id): void {
    $assert_session = $this->assertSession();
    $assert_session->elementExists('css', ".ckeditor5-toolbar-disabled .ckeditor5-toolbar-item-$toolbar_item_id");
    $this->triggerKeyUp(".ckeditor5-toolbar-item-$toolbar_item_id", 'ArrowDown');
    $assert_session->elementNotExists('css', ".ckeditor5-toolbar-disabled .ckeditor5-toolbar-item-$toolbar_item_id");
    $assert_session->elementExists('css', ".ckeditor5-toolbar-active .ckeditor5-toolbar-item-$toolbar_item_id");
  }

  /** * Confirms active tab status is intact after AJAX refresh. */
  public function testActiveTabsMaintained() {
    $page = $this->getSession()->getPage();
    $assert_session = $this->assertSession();

    $this->createNewTextFormat($page$assert_session);
    
$page->pressButton('Remove');
    $assert_session->assertWaitOnAjaxRequest();

    $assert_session->pageTextNotContains('This is the block content');
    $assert_session->linkNotExists('Add block');
    $this->assertPageNotReloaded();

    $page->pressButton('Save layout');

    // Removing all sections results in no layout being used.     $assert_session->addressEquals($node_url);
    $assert_session->elementNotExists('css', '.layout');
    $assert_session->pageTextNotContains('The node body');
  }

  /** * Tests configurable layouts. */
  public function testConfigurableLayoutSections() {
    $layout_url = 'node/1/layout';

    \Drupal::entityTypeManager()
      ->getStorage('entity_view_display')
      
$this->drupalGet('admin/structure/views/view/test_taxonomy_term_name/edit/default');
    $this->submitForm([], 'Save');
    $this->submitForm([], 'Update preview');
    $this->assertSession()->pageTextNotContains($node1->getTitle());
    $this->assertSession()->linkByHrefNotExists($node1->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node2->getTitle());
    $this->assertSession()->linkByHrefNotExists($node2->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node3->getTitle());
    $this->assertSession()->linkByHrefNotExists($node3->toUrl()->toString());
    $this->assertSession()->pageTextNotContains($node4->getTitle());
    $this->assertSession()->linkByHrefNotExists($node4->toUrl()->toString());
    $this->assertSession()->elementNotExists('xpath', "//div[@class='views-row']");
  }

  /** * Tests exposed grouped taxonomy filters. */
  public function testExposedGroupedFilter() {
    // Create a content type with a taxonomy field.     $this->drupalCreateContentType(['type' => 'article']);
    $field_name = 'field_views_testing_tags';
    $this->createEntityReferenceField('node', 'article', $field_name, NULL, 'taxonomy_term');

    
->setRevisionLogMessage('third revision log')
      ->setRevisionUser($this->drupalCreateUser(name: 'third author'))
      ->setNewRevision();
    $entity->save();

    $this->drupalGet($entity->toUrl('version-history'));
    $this->assertSession()->elementsCount('css', 'table tbody tr', 3);

    // Order is newest to oldest revision by creation order.     $row1 = $this->assertSession()->elementExists('css', 'table tbody tr:nth-child(1)');
    // Latest revision does not have revert or delete revision operation.     $this->assertSession()->elementNotExists('named', ['link', 'Revert']$row1);
    $this->assertSession()->elementNotExists('named', ['link', 'Delete']$row1);
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'Current revision');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', 'third revision log');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(1)', '06/03/2020 - 09:00 by third author');

    $row2 = $this->assertSession()->elementExists('css', 'table tbody tr:nth-child(2)');
    $this->assertSession()->elementExists('named', ['link', 'Revert']$row2);
    $this->assertSession()->elementExists('named', ['link', 'Delete']$row2);
    $this->assertSession()->elementTextNotContains('css', 'table tbody tr:nth-child(2)', 'Current revision');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(2)', 'second revision log');
    $this->assertSession()->elementTextContains('css', 'table tbody tr:nth-child(2)', '06/02/2020 - 08:00 by second author');

    
/** * Tests adding an existing field in another content type. */
  public function addExistingField() {
    // Check "Re-use existing field" appears.     $this->drupalGet('admin/structure/types/manage/page/fields');
    $this->assertSession()->pageTextContains('Re-use an existing field');
    $this->clickLink('Re-use an existing field');
    // Check that fields of other entity types (here, the 'comment_body' field)     // do not show up in the "Re-use existing field" list.     $this->assertSession()->elementNotExists('css', '.js-reuse-table [data-field-id="comment_body"]');
    // Validate the FALSE assertion above by also testing a valid one.     $this->assertSession()->elementExists('css', ".js-reuse-table [data-field-id='{$this->fieldName}']");
    $new_label = $this->fieldLabel . '_2';
    // Add a new field based on an existing field.     $this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->fieldName, $new_label);
  }

  /** * Tests the cardinality settings of a field. * * We do not test if the number can be submitted with anything else than a * numeric value. That is tested already in FormTest::testNumber(). */
$this->submitForm([], 'Delete');

    // Check that the language is no longer stored in the configuration after     // it is deleted.     $block = Block::load($block->id());
    $visibility = $block->getVisibility();
    $this->assertArrayNotHasKey('language', $visibility, 'Language is no longer not set in the block configuration after deleting the block.');

    // Ensure that the block visibility for language is gone from the UI.     $this->drupalGet('admin/structure/block');
    $this->clickLink('Configure');
    $this->assertSession()->elementNotExists('xpath', '//details[@id="edit-visibility-language"]');
  }

  /** * Tests block language visibility with different language types. */
  public function testMultipleLanguageTypes() {
    // Customize content language detection to be different from interface     // language detection.     $edit = [
      // Interface language detection: only using session.       'language_interface[enabled][language-url]' => FALSE,
      
Home | Imprint | This part of the site doesn't use cookies.