ResponsiveMenuAdminTest.php in Responsive and off-canvas menu 4.1.x
File
tests/src/Functional/ResponsiveMenuAdminTest.php
View source
<?php
namespace Drupal\Tests\responsive_menu\Functional;
use Drupal\Tests\BrowserTestBase;
class ResponsiveMenuAdminTest extends BrowserTestBase {
public static $modules = [
'responsive_menu_test',
];
protected $profile = 'minimal';
protected $defaultTheme = 'stark';
protected static $userPermissions = [
'access content',
'administer site configuration',
];
protected function setUp() {
parent::setUp();
$account = $this
->drupalCreateUser(static::$userPermissions);
$this
->drupalLogin($account);
}
public function testAccessAdminPage() {
$this
->drupalGet('/admin/config/user-interface/responsive-menu');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testMenuDepthSetting() {
$this
->drupalGet('/admin/config/user-interface/responsive-menu');
$this
->getSession()
->getPage()
->selectFieldOption('horizontal_depth', '1');
$this
->getSession()
->getPage()
->pressButton('Save configuration');
$this
->drupalGet('/node/1');
$horizontal_menu = $this
->getSession()
->getPage()
->findById('horizontal-menu');
$link = $horizontal_menu
->findLink('A sibling on the second level');
$this
->assertTrue(empty($link), 'A second level link was found even though the menu depth was set to 1.');
}
public function testLibrariesStatus() {
$this
->drupalGet('/admin/reports/status');
$this
->assertSession()
->pageTextNotContains('The mmenu library must be installed at');
$this
->assertSession()
->pageTextContains('Responsive menu: mmenu library');
}
public function testWarningWithNoBreakpoints() {
\Drupal::service('theme_installer')
->install([
'responsive_menu_theme_test_nobp',
]);
\Drupal::configFactory()
->getEditable('system.theme')
->set('default', 'responsive_menu_theme_test_nobp')
->save();
$this
->drupalGet('/admin/config/user-interface/responsive-menu');
$this
->assertSession()
->pageTextNotContains('Warning: htmlspecialchars() expects parameter 1 to be string, object given');
}
public function testPolyfillsInclusion() {
$this
->drupalGet('/admin/config/user-interface/responsive-menu');
$this
->getSession()
->getPage()
->checkField('use_polyfills');
$this
->getSession()
->getPage()
->pressButton('Save configuration');
$this
->drupalGet('/node/1');
$this
->assertSession()
->elementContains('css', 'body', 'mmenu.polyfills.js');
}
}