You are here

public function StyleJumpMenuTest::testJumpMenuOutput in Views Jump Menu 8

Tests jump menu output.

File

tests/src/Functional/Plugin/StyleJumpMenuTest.php, line 83

Class

StyleJumpMenuTest
Tests the Jump Menu style views plugin.

Namespace

Drupal\Tests\views_jump_menu\Functional\Plugin

Code

public function testJumpMenuOutput() {

  // Navigate to the test view.
  $this
    ->drupalGet('test-style-jump-menu');

  // Check that the jump menu wrapper has the custom class configured in the
  // view.
  $wrapper = $this
    ->xpath('//div[contains(concat(" ", @class, " "), " test-wrapper-class ")]');
  $this
    ->assertGreaterThan(0, count($wrapper), 'Ensure there is a div with the class test-wrapper-class');

  // Check that the jump menu select list has the custom class configured in
  // the view.
  $select = $this
    ->xpath('//select[contains(concat(" ", @class, " "), " test-select-class ")]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the class test-select-class');

  // Check that the jump menu select list has the ViewsJumpMenu class.
  $select = $this
    ->xpath('//select[contains(concat(" ", @class, " "), " ViewsJumpMenu ")]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the class ViewsJumpMenu');

  // Check that the jump menu select list has the js-viewsJumpMenu class
  // required for the JavaScript to function.
  $select = $this
    ->xpath('//select[contains(concat(" ", @class, " "), " js-viewsJumpMenu ")]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the class js-viewsJumpMenu');

  // Check that the jump menu select list has a title attribute which matches
  // the prompt option.
  $select = $this
    ->xpath('//select[@title="-- Select --"]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the title -- Select --');

  // Check that the jump menu select list has the custom label configured in
  // the view.
  $select = $this
    ->xpath('//select[@aria-label="test-select-label"]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the aria-label test-select-label');

  // Check that the jump menu select list has an ID.
  $select = $this
    ->xpath('//select[@id="test-style-jump-menu-page-test-jump-menu-jump-menu"]');
  $this
    ->assertGreaterThan(0, count($select), 'Ensure there is a select list with the HTML ID test-style-jump-menu-page-test-jump-menu-jump-menu');

  // Assert that there is a drupalSetting for this particular select list, and
  // by default, it is not set to open in a new window.
  $this
    ->assertRaw('viewsJumpMenu":{"test-style-jump-menu-page-test-jump-menu-jump-menu":{"new_window":false}}');

  // Check that the jump menu has a prompt option.
  $testUserOption = $this
    ->xpath('//option[. = "-- Select --"]');
  $this
    ->assertGreaterThan(0, count($testUserOption), 'Ensure there is an option with the text -- Select --');

  // Check that the jump menu has an option whose title matches the test user
  // name.
  $testUserOption = $this
    ->xpath('//option[. = "' . $this->viewsJumpMenuTestUserName . '"]');
  $this
    ->assertGreaterThan(0, count($testUserOption), 'Ensure there is an option with the text ' . $this->viewsJumpMenuTestUserName);

  // Check that the second jump menu option's URL matches the test user view
  // URL.
  $testUserOption = $this
    ->xpath('//option[@data-url]');
  $this
    ->assertGreaterThan(0, count($testUserOption), 'Ensure there options with the data-url attribute');
  $this
    ->assertEqual($testUserOption[1]
    ->getAttribute('data-url'), $this->viewsJumpMenuTestUserUrlString, 'Ensure there is an option with the data-url ' . $this->viewsJumpMenuTestUserUrlString);
}