View source
<?php
namespace Drupal\Tests\views_jump_menu\Functional\Plugin;
use Drupal\Tests\views\Functional\ViewTestBase;
class StyleJumpMenuTest extends ViewTestBase {
public static $testViews = [
'test_style_jump_menu',
];
public static $modules = [
'views',
'views_jump_menu_test_config',
];
protected $defaultTheme = 'stark';
protected $viewsJumpMenuTestUserName;
protected $viewsJumpMenuTestUserUrlString;
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->enableViewsTestModule();
$this->viewsJumpMenuTestUserName = $this
->randomMachineName();
$testUser = $this
->drupalCreateUser([], $this->viewsJumpMenuTestUserName);
$this->viewsJumpMenuTestUserUrlString = $testUser
->toUrl('canonical', [
'absolute' => FALSE,
])
->toString();
$this
->drupalLogin($this
->drupalCreateUser([
'access user profiles',
]));
}
public function testJumpMenuLibrary() {
$viewsJumpMenuModulePath = drupal_get_path('module', 'views_jump_menu');
$this
->drupalGet('test-style-jump-menu');
$this
->assertRaw($viewsJumpMenuModulePath . '/js/views-jump-menu.js');
}
public function testJumpMenuOutput() {
$this
->drupalGet('test-style-jump-menu');
$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');
$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');
$select = $this
->xpath('//select[contains(concat(" ", @class, " "), " ViewsJumpMenu ")]');
$this
->assertGreaterThan(0, count($select), 'Ensure there is a select list with the class ViewsJumpMenu');
$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');
$select = $this
->xpath('//select[@title="-- Select --"]');
$this
->assertGreaterThan(0, count($select), 'Ensure there is a select list with the title -- Select --');
$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');
$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');
$this
->assertRaw('viewsJumpMenu":{"test-style-jump-menu-page-test-jump-menu-jump-menu":{"new_window":false}}');
$testUserOption = $this
->xpath('//option[. = "-- Select --"]');
$this
->assertGreaterThan(0, count($testUserOption), 'Ensure there is an option with the text -- Select --');
$testUserOption = $this
->xpath('//option[. = "' . $this->viewsJumpMenuTestUserName . '"]');
$this
->assertGreaterThan(0, count($testUserOption), 'Ensure there is an option with the text ' . $this->viewsJumpMenuTestUserName);
$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);
}
public function testJumpMenuCanBeConfiguredToOpenInNewWindow() {
$testViewConfig = \Drupal::configFactory()
->getEditable('views.view.test_style_jump_menu');
$testViewConfigArray = $testViewConfig
->getOriginal();
$testViewConfigArray['display']['default']['display_options']['style']['options']['new_window'] = TRUE;
$testViewConfig
->setData($testViewConfigArray);
$testViewConfig
->save();
$this
->drupalGet('test-style-jump-menu');
$this
->assertRaw('viewsJumpMenu":{"test-style-jump-menu-page-test-jump-menu-jump-menu":{"new_window":true}}');
}
}