elementTextEquals example

// Hides the field and check whether the hidden label is appended.     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
    $this->drupalGet($edit_handler_url);
    $this->submitForm(['options[exclude]' => TRUE], 'Apply');

    $this->assertSession()->pageTextContains('Views test: Name [hidden]');

    // Ensure that the expected tokens appear in the UI.     $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/age';
    $this->drupalGet($edit_handler_url);
    $xpath = '//details[@id="edit-options-alter-help"]/ul/li';
    $this->assertSession()->elementTextEquals('xpath', $xpath, '{{ age }} == Age');

    $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/id';
    $this->drupalGet($edit_handler_url);
    $this->assertSession()->elementTextEquals('xpath', "{$xpath}[1]", '{{ age }} == Age');
    $this->assertSession()->elementTextEquals('xpath', "{$xpath}[2]", '{{ id }} == ID');

    $edit_handler_url = 'admin/structure/views/nojs/handler/test_view/default/field/name';
    $this->drupalGet($edit_handler_url);
    $this->assertSession()->elementTextEquals('xpath', "{$xpath}[1]", '{{ age }} == Age');
    $this->assertSession()->elementTextEquals('xpath', "{$xpath}[2]", '{{ id }} == ID');
    $this->assertSession()->elementTextEquals('xpath', "{$xpath}[3]", '{{ name }} == Name');

    


  /** * Test language attribute "lang" for the search results. */
  public function testLanguageAttributes() {
    $this->drupalGet('search/node');
    $this->submitForm(['keys' => 'the Spanish title'], 'Search');

    $node = $this->searchableNodes[1]->getTranslation('es');
    $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "es")]/a', $node->getTitle());
    $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "es")]');

    // Visit the search form in Spanish language.     $this->drupalGet('es/search/node');
    $this->submitForm(['keys' => 'First node'], 'Search');
    $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]');
    $node = $this->searchableNodes[0]->getTranslation('en');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//ol/li/h3[contains(@lang, "en")]/a', $node->getTitle());
    $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//ol/li/p[contains(@lang, "en")]');
  }

}
// Test for the page title.     $this->assertSession()->titleEquals('Test configuration | Drupal');

    // Test for the table.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table', 1);

    // Test the table header.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 3);

    // Test the contents of each th cell.     $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Label');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Machine name');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Operations');

    // Check the number of table row cells.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/tbody/tr[1]/td', 3);

    // Check the contents of each row cell. The first cell contains the label,     // the second contains the machine name, and the third contains the     // operations list.     $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr[1]/td[1]', 'Default');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/tbody/tr[1]/td[2]', 'dotted.default');
    
$this->drupalGet('admin/structure/views/view/test_display/edit/display_no_area_test_1');

    $areas = [
      'header',
      'footer',
      'empty',
    ];

    // Assert that the expected text is found in each area category.     foreach ($areas as $type) {
      $this->assertSession()->elementTextEquals('xpath', "//div[contains(@class, '$type')]/div", "The selected display type does not use $type plugins");
    }
  }

  /** * Tests the link-display setting. */
  public function testLinkDisplay() {
    // Test setting the link display in the UI form.     $path = 'admin/structure/views/view/test_display/edit/block_1';
    $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display';

    
->save();

    // Create an entity and save test value in field_test_text.     $test_value = $this->randomMachineName();
    $entity = EntityTest::create();
    $entity->field_test_text = $test_value;
    $entity->save();

    // Browse to the entity and verify that the attribute is rendered in the     // field item HTML markup.     $this->drupalGet('entity_test/' . $entity->id());
    $this->assertSession()->elementTextEquals('xpath', '//div[@data-field-item-attr="foobar" and @property="schema:text"]/p', $test_value);
  }

  /** * Tests that a view builder can successfully override the view builder. */
  public function testEntityViewControllerViewBuilder() {
    $entity_test = $this->createTestEntity('entity_test_view_builder');
    $entity_test->save();
    $this->drupalGet('entity_test_view_builder/' . $entity_test->id());
    $this->assertSession()->pageTextContains($entity_test->label());
  }

  
'modules[language][enable]' => TRUE,
    ];
    $this->drupalGet('admin/modules');
    $this->submitForm($edit, 'Install');

    // Status messages are shown.     $this->assertSession()->statusMessageContains('This site has only a single language enabled. Add at least one more language in order to translate content.', 'warning');
    $this->assertSession()->statusMessageContains('Enable translation for content types, taxonomy vocabularies, accounts, or any other element you wish to translate.', 'warning');

    // No pending updates should be available.     $this->drupalGet('admin/reports/status');
    $this->assertSession()->elementTextEquals('css', "details.system-status-report__entry summary:contains('Entity/field definitions') + div", 'Up to date');

    $this->drupalGet('admin/config/regional/content-language');
    // The node entity type should not be an option because it has no bundles.     $this->assertSession()->responseNotContains('entity_types[node]');
    // Enable content translation on entity types that have will have a     // content_translation_uid.     $edit = [
      'entity_types[menu_link_content]' => TRUE,
      'settings[menu_link_content][menu_link_content][translatable]' => TRUE,
      'entity_types[entity_test_mul]' => TRUE,
      'settings[entity_test_mul][entity_test_mul][translatable]' => TRUE,
    ];
$this->drupalGet(Url::fromRoute('block.admin_library', ['theme' => $default_theme]$options));

      $block_name = 'system_powered_by_block';
      $add_url = Url::fromRoute('block.admin_add', [
        'plugin_id' => $block_name,
        'theme' => $default_theme,
      ]);

      // Verify that one link is found, with the expected link text.       $xpath = $this->assertSession()->buildXPathQuery('//a[contains(@href, :href)]', [':href' => $add_url->toString()]);
      $this->assertSession()->elementsCount('xpath', $xpath, 1);
      $this->assertSession()->elementTextEquals('xpath', $xpath, 'Place block');

      $link = $this->getSession()->getPage()->find('xpath', $xpath);
      [$path$query_string] = explode('?', $link->getAttribute('href'), 2);
      parse_str($query_string$query_parts);
      $this->assertEquals($weight$query_parts['weight'], 'Found the expected weight query string.');

      // Create a random title for the block.       $title = $this->randomMachineName(8);
      $block_id = strtolower($this->randomMachineName(8));
      $edit = [
        'id' => $block_id,
        
// Test for the page title.     $this->assertSession()->titleEquals('List links | Drupal');

    // Test for the table.     $this->assertSession()->elementExists('xpath', '//div[@class="layout-content"]//table');

    // Test the table header.     $this->assertSession()->elementsCount('xpath', '//div[@class="layout-content"]//table/thead/tr/th', 3);

    // Test the contents of each th cell.     $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[1]', 'Name');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[2]', 'Weight');
    $this->assertSession()->elementTextEquals('xpath', '//div[@class="layout-content"]//table/thead/tr/th[3]', 'Operations');

    // Look for test shortcuts in the table.     $weight = count($shortcuts);
    $edit = [];
    foreach ($shortcuts as $shortcut) {
      $title = $shortcut->getTitle();

      // Confirm that a link to the shortcut is found within the table.       $this->assertSession()->linkExists($title);

      
// Test that the preview shows the alt value from the media field's     // alt text.     $this->assertNotEmpty($assert_session->waitForElementVisible('css', '.ck-widget.drupal-media img[alt*="default alt"]'));
    // Test that clicking the media widget triggers a CKEditor balloon panel     // with a single button to override the alt text.     $this->click('.ck-widget.drupal-media');
    $this->assertVisibleBalloon('[aria-label="Drupal Media toolbar"]');
    // Click the "Override media image alternative text" button.     $this->getBalloonButton('Override media image alternative text')->click();
    $this->assertVisibleBalloon('.ck-media-alternative-text-form');
    // Assert that the default alt text is visible in the UI.     $assert_session->elementTextEquals('css', '.ck-media-alternative-text-form__default-alt-text-value', 'default alt');
    // Assert that the value is currently empty.     $alt_override_input = $page->find('css', '.ck-balloon-panel .ck-media-alternative-text-form input[type=text]');
    $this->assertSame('', $alt_override_input->getValue());

    // Fill in the alt field and submit.     // cSpell:disable-next-line     $who_is_zartan = 'Zartan is the leader of the Dreadnoks.';
    $alt_override_input->setValue($who_is_zartan);
    $this->getBalloonButton('Save')->click();

    // Assert that the img within the media embed within the CKEditor contains
/** * Tests that we store and retrieve multi-byte UTF-8 characters correctly. */
  public function testMultiByteUtf8() {
    $title = '🐝';
    // To ensure that the title has multi-byte characters, we compare the byte     // length to the character length.     $this->assertLessThan(strlen($title)mb_strlen($title, 'utf-8'));
    $node = $this->drupalCreateNode(['title' => $title]);
    $this->drupalGet($node->toUrl());
    // Verify that the passed title was returned.     $this->assertSession()->elementTextEquals('xpath', '//h1/span', $title);
  }

}
/** * {@inheritdoc} */
  protected function setUpSettings() {
    $driver = Database::getConnection()->driver();
    if (!in_array($driver['mysql', 'pgsql'])) {
      $this->markTestSkipped("This test does not support the {$driver} database driver.");
    }
    $this->testDriverName = 'Drivertest' . ucfirst($driver);

    // Assert that we are using the database drivers from the driver_test module.     $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestmysql"]', 'MySQL by the driver_test module');
    $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-driver-drivertestpgsql"]', 'PostgreSQL by the driver_test module');

    $settings = $this->parameters['forms']['install_settings_form'];

    $settings['driver'] = $this->testDriverName;
    $settings[$this->testDriverName] = $settings[$driver];
    unset($settings[$driver]);
    $edit = $this->translatePostValues($settings);
    $this->submitForm($edit$this->translations['Save and continue']);
  }

  
// Place a custom local translation in the translations directory.     mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
    file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.ar.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Arabic\"");

    parent::setUpLanguage();
    // After selecting a different language than English, all following screens     // should be translated already.     $this->assertSession()->buttonExists('Save and continue Arabic');
    $this->translations['Save and continue'] = 'Save and continue Arabic';

    // Verify that language direction is right-to-left.     $this->assertSession()->elementTextEquals('xpath', '/@dir', 'rtl');
  }

  /** * Confirms that the installation succeeded. */
  public function testInstalled() {
    $this->assertSession()->addressEquals('user/1');
    $this->assertSession()->statusCodeEquals(200);
  }

}
    $display_ids = ['attachment_1', 'block_1', 'embed_1', 'feed_1', 'page_2'];

    $this->drupalCreateContentType(['type' => 'page']);
    $this->drupalCreateNode();

    // Load the test view and initialize its displays.     $view = $this->container->get('entity_type.manager')->getStorage('view')->load('test_disabled_display');
    $view->getExecutable()->setDisplay();

    // Enabled page display should return content.     $this->drupalGet('test-disabled-display');
    $this->assertSession()->elementTextEquals('xpath', '//h1[@class="page-title"]', 'test_disabled_display');

    // Disabled page view should 404.     $this->drupalGet('test-disabled-display-2');
    $this->assertSession()->statusCodeEquals(404);

    // Enable each disabled display and save the view.     foreach ($display_ids as $display_id) {
      $view->getExecutable()->displayHandlers->get($display_id)->setOption('enabled', TRUE);
      $view->save();
      $enabled = $view->getExecutable()->displayHandlers->get($display_id)->isEnabled();
      $this->assertTrue($enabled, 'Display ' . $display_id . ' is now enabled');
    }
// Create "Basic page" content with title.     // Add the node to the frontpage so we can test if teaser links are     // clickable.     $settings = [
      'title' => $this->randomMachineName(8),
      'promote' => 1,
    ];
    $node = $this->drupalCreateNode($settings);

    // Test <title> tag.     $this->drupalGet('node/' . $node->id());
    $this->assertSession()->elementTextEquals('xpath', '//title', $node->label() . ' | Drupal');

    // Test breadcrumb in comment preview.     $this->assertBreadcrumb('comment/reply/node/' . $node->id() . '/comment', [
      '' => 'Home',
      'node/' . $node->id() => $node->label(),
    ]);

    // Verify that node preview title is equal to node title.     $this->assertSession()->elementTextEquals('xpath', "//article/h2/a/span", $node->label());

    // Test node title is clickable on teaser list (/node).
    $view = Views::getView('test_bulk_form');
    $display = &$view->storage->getDisplay('default');
    $display['display_options']['fields']['node_bulk_form']['include_exclude'] = 'exclude';
    $view->save();

    $this->drupalGet('test_bulk_form');
    $this->assertSession()->optionNotExists('edit-action', 'node_make_sticky_action');
    $this->assertSession()->optionNotExists('edit-action', 'node_make_unsticky_action');

    // Check the default title.     $this->drupalGet('test_bulk_form');
    $this->assertSession()->elementTextEquals('xpath', '//label[@for="edit-action"]', 'Action');

    // There should be an error message if no action is selected.     $edit = ['node_bulk_form[0]' => TRUE, 'action' => ''];
    $this->submitForm($edit, 'Apply to selected items');
    $this->assertSession()->pageTextContains('No Action option selected.');

    // Setup up a different bulk form title.     $view = Views::getView('test_bulk_form');
    $display = &$view->storage->getDisplay('default');
    $display['display_options']['fields']['node_bulk_form']['action_title'] = 'Test title';
    $view->save();

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