You are here

function DefaultViewsTest::clickViewsOperationLink in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views_ui/src/Tests/DefaultViewsTest.php \Drupal\views_ui\Tests\DefaultViewsTest::clickViewsOperationLink()

Click a link to perform an operation on a view.

In general, we expect lots of links titled "enable" or "disable" on the various views listing pages, and they might have tokens in them. So we need special code to find the correct one to click.

Parameters

$label: Text between the anchor tags of the desired link.

$unique_href_part: A unique string that is expected to occur within the href of the desired link. For example, if the link URL is expected to look like "admin/structure/views/view/glossary/*", then "/glossary/" could be passed as the expected unique string.

Return value

The page content that results from clicking on the link, or FALSE on failure. Failure also results in a failed assertion.

2 calls to DefaultViewsTest::clickViewsOperationLink()
DefaultViewsTest::testDefaultViews in core/modules/views_ui/src/Tests/DefaultViewsTest.php
Tests default views.
DefaultViewsTest::testSplitListing in core/modules/views_ui/src/Tests/DefaultViewsTest.php
Tests that enabling views moves them to the correct table.

File

core/modules/views_ui/src/Tests/DefaultViewsTest.php, line 217
Contains \Drupal\views_ui\Tests\DefaultViewsTest.

Class

DefaultViewsTest
Tests enabling, disabling, and reverting default views via the listing page.

Namespace

Drupal\views_ui\Tests

Code

function clickViewsOperationLink($label, $unique_href_part) {
  $links = $this
    ->xpath('//a[normalize-space(text())=:label]', array(
    ':label' => $label,
  ));
  foreach ($links as $link_index => $link) {
    $position = strpos($link['href'], $unique_href_part);
    if ($position !== FALSE) {
      $index = $link_index;
      break;
    }
  }
  $this
    ->assertTrue(isset($index), format_string('Link to "@label" containing @part found.', array(
    '@label' => $label,
    '@part' => $unique_href_part,
  )));
  if (isset($index)) {
    return $this
      ->clickLink($label, $index);
  }
  else {
    return FALSE;
  }
}