findLink example


  protected function assertHelpLink(NodeElement $element, string $text, array $attributes = []): void {
    // Find all the links inside the element.     $link = $element->findLink($text);

    $this->assertNotEmpty($link);
    foreach ($attributes as $attribute => $value) {
      $this->assertSame($link->getAttribute($attribute)$value);
    }
  }

  /** * Asserts that a given link is not present. * * @param \Behat\Mink\Element\NodeElement $element * The element to search. * @param string $text * The link text. * * @internal */

    $this->drupalLogin($this->adminUser);
  }

  /** * Tests that the search form block can be placed and works. */
  public function testSearchFormBlock() {

    // Test availability of the search block in the admin "Place blocks" list.     $this->drupalGet('admin/structure/block');
    $this->getSession()->getPage()->findLink('Place block')->click();
    $this->assertSession()->linkByHrefExists('/admin/structure/block/add/search_form_block/stark', 0,
      'Did not find the search block in block candidate list.');

    $block = $this->drupalPlaceBlock('search_form_block');

    $this->drupalGet('');
    $this->assertSession()->pageTextContains($block->label());

    // Check that name attribute is not empty.     $this->assertSession()->elementNotExists('xpath', "//input[@type='submit' and @name='']");

    
$page = $this->getSession()->getPage();
    $page->waitFor(10, function D) use ($page$selector) {
      return $page->find('css', "$selector .contextual-links");
    });

    if ($force_visible) {
      $this->toggleContextualTriggerVisibility($selector);
    }

    $element = $this->getSession()->getPage()->find('css', $selector);
    $element->find('css', '.contextual button')->press();
    $element->findLink($link_locator)->click();

    if ($force_visible) {
      $this->toggleContextualTriggerVisibility($selector);
    }
  }

  /** * Toggles the visibility of a contextual trigger. * * @param string $selector * The selector for the element that contains the contextual link. */
$page->waitFor(10, function D) use ($page$selector) {
      return $page->find('css', "$selector .contextual-links");
    });
    if (count($page->findAll('css', "$selector .contextual-links")) > 1) {
      throw new \Exception('More than one contextual links found by selector');
    }

    if ($force_visible && $page->find('css', "$selector .contextual .trigger.visually-hidden")) {
      $this->toggleContextualTriggerVisibility($selector);
    }

    $link = $assert_session->elementExists('css', $selector)->findLink($link_locator);
    $this->assertNotEmpty($link);

    if (!$link->isVisible()) {
      $button = $assert_session->waitForElementVisible('css', "$selector .contextual button");
      $this->assertNotEmpty($button);
      $button->press();
      $link = $page->waitFor(10, function D) use ($link) {
        return $link->isVisible() ? $link : FALSE;
      });
    }

    
// Test field UI and field integration.     $this->drupalGet('admin/structure/contact');

    // Test contact listing links to contact form.     $this->assertSession()->elementExists('xpath', $this->assertSession()->buildXPathQuery('//table/tbody/tr/td/a[contains(@href, :href) and text()=:text]', [
      ':href' => Url::fromRoute('entity.contact_form.canonical', ['contact_form' => $contact_form])->toString(),
      ':text' => $label,
    ]));

    // Find out in which row the form we want to add a field to is.     foreach ($this->xpath('//table/tbody/tr') as $row) {
      if ($row->findLink($label)) {
        $row->clickLink('Manage fields');
        break;
      }
    }

    $this->assertSession()->statusCodeEquals(200);
    $this->clickLink('Create a new field');
    $this->assertSession()->statusCodeEquals(200);

    // Create a simple textfield.     $field_name = mb_strtolower($this->randomMachineName());
    
/** * Test to ensure that remove contextual link is present in the block. */
  public function testBlockContextualRemoveLinks() {
    // Ensure that contextual filter links are visible on the page.     $this->drupalLogin($this->rootUser);
    $this->drupalGet('<front>');
    $contextual_id = "[data-contextual-id^='block:block=$this->blockId:langcode=en']";
    $this->assertSession()->waitForElement('css', "$contextual_id .contextual-links");

    $expected_configure_block_link = base_path() . 'admin/structure/block/manage/' . $this->blockId;
    $actual_configure_block_link = parse_url($this->getSession()->getPage()->findLink('Configure block')->getAttribute('href'));
    $this->assertEquals($expected_configure_block_link$actual_configure_block_link['path']);

    $expected_remove_block_link = base_path() . 'admin/structure/block/manage/' . $this->blockId . '/delete';
    $actual_remove_block_link = parse_url($this->getSession()->getPage()->findLink('Remove block')->getAttribute('href'));
    $this->assertEquals($expected_remove_block_link$actual_remove_block_link['path']);
  }

}
// @todo Work out why this fixes random fails in this test.     // https://www.drupal.org/project/drupal/issues/3055982     $this->getSession()->resizeWindow(800, 1000);
    $assert_session = $this->assertSession();
    $page = $this->getSession()->getPage();

    $this->drupalLogin($this->drupalCreateUser([
      'access contextual links',
      'configure any layout',
    ]));
    $this->drupalGet('node/1/layout');
    $page->findLink('Add block')->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
    $page->findLink('Powered by Drupal')->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
    $page->findField('Title')->setValue('');
    $page->findButton('Add block')->click();
    $this->assertMessagesDisplayed();
    $page->findField('Title')->setValue('New title');
    $page->pressButton('Add block');
    $block_css_locator = '#layout-builder .block-system-powered-by-block';
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));

    
    \Drupal::configFactory()->getEditable('views.settings')->set('ui.always_live_preview', FALSE)->save();
    $this->drupalLogin($admin_user);
  }

  /** * Tests dialog for filter criteria. */
  public function testFilterCriteriaDialog() {
    // Checks that the admin summary is not double escaped.     $this->drupalGet('admin/structure/views/view/who_s_online');
    $page = $this->getSession()->getPage();
    $this->assertNotNull($page->findLink('User: Last access (>= -15 minutes)'));

    $this->drupalGet('admin/structure/views/view/content_recent');
    $assert_session = $this->assertSession();
    $session = $this->getSession();
    $page = $session->getPage();

    $this->openFilterDialog();

    // Add a new filter group.     $create_new_filter_group = $page->findById('views-add-group-link');
    $this->assertTrue($create_new_filter_group->isVisible(), 'Add group link found.');
    
    // confirmation page.     $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "messages--status")]');
    $this->submitForm([], 'Delete');
    $this->assertSession()->pageTextContains('Deleted 5 content items.');
    // Check if we got redirected to the original page.     $this->assertSession()->addressEquals('test_bulk_form');

    // Test that the bulk form works when a node gets deleted by another user     // before the loaded bulk form can be used.     $this->drupalGet('test_bulk_form');
    // Now delete the node we want to delete with the bulk form.     $link = $this->getSession()->getPage()->findLink($nodes[6]->label());
    $checkbox = $link->getParent()->getParent()->find('css', 'input');
    $nodes[6]->delete();
    $edit = [
      $checkbox->getAttribute('name') => TRUE,
      'action' => 'node_delete_action',
    ];
    $this->submitForm($edit, 'Apply to selected items');
    // Make sure we just return to the bulk view with no warnings.     $this->assertSession()->addressEquals('test_bulk_form');
    $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "messages--status")]');

    
$this->drupalLogin($admin_user);

    // Set size for horizontal toolbar.     $this->getSession()->resizeWindow(1200, 600);
    $this->drupalGet('<front>');
    $this->assertNotEmpty($this->assertSession()->waitForElement('css', 'body.toolbar-horizontal'));
    $this->assertNotEmpty($this->assertSession()->waitForElementVisible('css', '.toolbar-tray'));

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

    // Test that it is possible to toggle the toolbar tray.     $content = $page->findLink('Content');
    $this->assertTrue($content->isVisible(), 'Toolbar tray is open by default.');
    $page->clickLink('Manage');
    $this->assertFalse($content->isVisible(), 'Toolbar tray is closed after clicking the "Manage" link.');
    $page->clickLink('Manage');
    $this->assertTrue($content->isVisible(), 'Toolbar tray is visible again after clicking the "Manage" button a second time.');

    // Test toggling the toolbar tray between horizontal and vertical.     $tray = $page->findById('toolbar-item-administration-tray');
    $this->assertFalse($tray->hasClass('toolbar-tray-vertical'), 'Toolbar tray is not vertically oriented by default.');
    $page->pressButton('Vertical orientation');
    $this->assertTrue($tray->hasClass('toolbar-tray-vertical'), 'After toggling the orientation the toolbar tray is now displayed vertically.');

    
$this->drupalGet('admin/structure/views/view/test_content_ajax');
    $page = $this->getSession()->getPage();

    $page->find('css', '#views-display-menu-tabs .add')->click();

    // Wait for the animation to complete.     $this->assertSession()->assertWaitOnAjaxRequest();

    // Add the display.     $page->find('css', '#edit-displays-top-add-display-block')->click();

    $element = $page->findById('views-display-menu-tabs')->findLink('Block');
    $this->assertNotEmpty($element);
  }

  /** * Tests setting the administrative title. */
  public function testRenameDisplayAdminName() {
    $titles = ['New admin title', '</title><script>alert("alert!")</script>'];
    foreach ($titles as $new_title) {
      $this->drupalGet('admin/structure/views/view/test_content_ajax');
      $page = $this->getSession()->getPage();

      
$machine_name = $assert_session->waitForElementVisible('css', '[name="label"] + * .machine-name-value');
    $this->assertNotEmpty($machine_name);
    $page->findButton('Edit')->press();

    $field_field_name = $page->findField('field_name');
    $this->assertTrue($field_field_name->isVisible());
    $field_field_name->setValue($field_name);

    $page->findButton('Save and continue')->click();

    $assert_session->pageTextContains("These settings apply to the $label field everywhere it is used.");
    $breadcrumb_link = $page->findLink($label);

    // Test breadcrumb.     $this->assertTrue($breadcrumb_link->isVisible());

    // Second step: 'Storage settings' form.     $page->findButton('Save field settings')->click();
    $assert_session->pageTextContains("Updated field $label field settings.");

    // Third step: 'Field settings' form.     $page->findButton('Save settings')->click();
    $assert_session->pageTextContains("Saved $label configuration.");

    
$test_wait_on_element_visible = $page->findButton('Test waitForElementVisible');

    // Test the wait...() methods by first checking the fields aren't available     // and then are available after the wait method.     $result = $page->findButton('Added button');
    $this->assertEmpty($result);
    $test_button->click();
    $result = $assert_session->waitForButton('Added button');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findLink('Added link');
    $this->assertEmpty($result);
    $test_link->click();
    $result = $assert_session->waitForLink('Added link');
    $this->assertNotEmpty($result);
    $this->assertInstanceOf(NodeElement::class$result);

    $result = $page->findField('added_field');
    $this->assertEmpty($result);
    $test_field->click();
    $result = $assert_session->waitForField('added_field');
    $this->assertNotEmpty($result);
    
    // links are used.     /** @var \Behat\Mink\Element\NodeElement[] $rows */
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(5, $rows);
    $this->assertStringContainsString('Node 1 content default_value', $rows[0]->getHtml());

    $this->clickLink('Go to page 2');
    $session_assert->assertWaitOnAjaxRequest();
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(5, $rows);
    $this->assertStringContainsString('Node 6 content default_value', $rows[0]->getHtml());
    $link = $page->findLink('Go to page 3');
    $this->assertNoDuplicateAssetsOnPage();

    // Test that no unwanted parameters are added to the URL.     $this->assertEquals('?status=All&type=All&title=&langcode=All&items_per_page=5&order=changed&sort=asc&page=2', $link->getAttribute('href'));

    $this->clickLink('Go to page 3');
    $session_assert->assertWaitOnAjaxRequest();
    $rows = $page->findAll('css', 'tbody tr');
    $this->assertCount(1, $rows);
    $this->assertStringContainsString('Node 11 content', $rows[0]->getHtml());

    
$disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
    $disabled_rows = $this->filterVisibleElements($disabled_rows);

    $this->assertCount($enabled_views_count$enabled_rows);
    $this->assertCount($disabled_views_count$disabled_rows);

    // Disable a View and see if it moves to the disabled listing.     $enabled_view = $page->find('css', 'tr.views-ui-list-enabled');
    $view_description = $enabled_view->find('css', '.views-ui-view-name strong')->getText();
    // Open the dropdown with additional actions.     $enabled_view->find('css', 'li.dropbutton-toggle button')->click();
    $disable_button = $enabled_view->findLink('Disable');
    // Check that the disable button is visible now.     $this->assertTrue($disable_button->isVisible());
    $disable_button->click();

    $session->assertWaitOnAjaxRequest();

    $enabled_rows = $page->findAll('css', 'tr.views-ui-list-enabled');
    $enabled_rows = $this->filterVisibleElements($enabled_rows);
    $disabled_rows = $page->findAll('css', 'tr.views-ui-list-disabled');
    $disabled_rows = $this->filterVisibleElements($disabled_rows);

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