public function ResponsivePreviewToolbarTest::testToolbarIntegration in Responsive Theme Preview 8
Tests that the toolbar integration works properly.
File
- tests/
src/ Functional/ ResponsivePreviewToolbarTest.php, line 39
Class
- ResponsivePreviewToolbarTest
- Tests the toolbar integration.
Namespace
Drupal\Tests\responsive_preview\FunctionalCode
public function testToolbarIntegration() {
$toolbar_xpath = '//div[@id="toolbar-administration"]/nav[@id="toolbar-bar"]';
$tab_xpath = '//nav[@id="toolbar-bar"]//div[contains(@class, "toolbar-tab-responsive-preview")]';
$devices = array_keys($this
->getDefaultDevices(TRUE));
// Anonymous user by default cannot use the preview so the module library
// and the cache tags and contexts should not be present.
$this
->drupalGet('');
$this
->assertNoResponsivePreviewLibrary();
$this
->assertNoResponsivePreviewCachesTagAndContexts();
// Users with 'access toolbar' permission can use the toolbar but cannot use
// the preview so the module library should not be included but the cache
// tags and contexts should be present.
$toolbar_user = $this
->drupalCreateUser([
'access toolbar',
]);
$this
->drupalLogin($toolbar_user);
$this
->assertSession()
->elementExists('xpath', $toolbar_xpath);
$this
->assertSession()
->elementNotExists('xpath', $tab_xpath);
$this
->assertNoResponsivePreviewLibrary();
// Users with 'access responsive preview' permission can use the toolbar
// and the preview so the module library and the cache tags and contexts
// should be included.
$this
->drupalLogin($this->previewUser);
$this
->assertSession()
->elementExists('xpath', $toolbar_xpath);
$this
->assertSession()
->elementExists('xpath', $tab_xpath);
$this
->assertResponsivePreviewLibrary();
$this
->assertResponsivePreviewCachesTagAndContexts();
$this
->assertDeviceListEquals($devices);
// Login as user with 'administer responsive preview' permission so you
// can check the preview behaviour on administrative page. The preview on
// the admin pages sould not be enabled so the module library should not be
// included but the cache tags and contexts should be present.
$admin_user = $this
->drupalCreateUser([
'access responsive preview',
'access toolbar',
'administer responsive preview',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/user-interface/responsive-preview');
$this
->assertSession()
->elementExists('xpath', $toolbar_xpath);
$this
->assertSession()
->elementNotExists('xpath', $tab_xpath);
$this
->assertNoResponsivePreviewLibrary();
$this
->assertResponsivePreviewCachesTagAndContexts();
$this
->drupalGet('');
$this
->assertSession()
->elementExists('xpath', $toolbar_xpath);
$this
->assertSession()
->elementExists('xpath', $tab_xpath);
$this
->assertResponsivePreviewLibrary();
$this
->assertResponsivePreviewCachesTagAndContexts();
$this
->assertDeviceListEquals($devices);
}