ResponsivePreviewTestBase.php in Responsive Theme Preview 8
File
tests/src/Functional/ResponsivePreviewTestBase.php
View source
<?php
namespace Drupal\Tests\responsive_preview\Functional;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Tests\BrowserTestBase;
abstract class ResponsivePreviewTestBase extends BrowserTestBase {
protected static $modules = [
'responsive_preview',
];
protected $defaultTheme = 'classy';
protected function getDefaultDevices($enabled_only = FALSE) {
$devices = [
'galaxy_s9' => 'Galaxy S9',
'galaxy_tab_s4' => 'Galaxy Tab S4',
'ipad_pro' => 'iPad Pro',
'iphone_xs' => 'iPhone XS',
'iphone_xs_max' => 'iPhone XS Max',
];
if ($enabled_only) {
return $devices;
}
$devices += [
'large' => 'Typical desktop',
'medium' => 'Tablet',
'small' => 'Smart phone',
];
return $devices;
}
protected function assertDeviceListEquals(array $devices) {
$device_buttons = $this
->xpath('//button[@data-responsive-preview-name]');
$this
->assertTrue(count($devices) === count($device_buttons));
foreach ($device_buttons as $button) {
$name = $button
->getAttribute('data-responsive-preview-name');
$this
->assertTrue(!empty($name) && in_array($name, $devices), new FormattableMarkup('%name device shown', [
'%name' => $name,
]));
}
}
protected function assertResponsivePreviewCachesTagAndContexts() {
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'config:responsive_preview_device_list');
}
protected function assertNoResponsivePreviewCachesTagAndContexts() {
$this
->assertSession()
->responseHeaderNotContains('X-Drupal-Cache-Tags', 'config:responsive_preview_device_list');
}
protected function assertResponsivePreviewLibrary() {
$this
->assertSession()
->responseContains('responsive_preview/js/responsive-preview.js');
$this
->assertSession()
->responseContains('responsive_preview/css/responsive-preview.icons.css');
$this
->assertSession()
->responseContains('responsive_preview/css/responsive-preview.module.css');
$this
->assertSession()
->responseContains('responsive_preview/css/responsive-preview.theme.css');
}
protected function assertNoResponsivePreviewLibrary() {
$this
->assertSession()
->responseNotContains('responsive_preview/js/responsive-preview.js');
$this
->assertSession()
->responseNotContains('responsive_preview/css/responsive-preview.icons.css');
$this
->assertSession()
->responseNotContains('responsive_preview/css/responsive-preview.module.css');
$this
->assertSession()
->responseNotContains('responsive_preview/css/responsive-preview.theme.css');
}
}