class AttachedAssetsTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Common/AttachedAssetsTest.php \Drupal\system\Tests\Common\AttachedAssetsTest
Tests #attached assets: attached asset libraries and JavaScript settings.
i.e. tests:
$build['#attached']['library'] = …
$build['#attached']['drupalSettings'] = …
@group Common @group Asset
Hierarchy
- class \Drupal\simpletest\TestBase uses AssertHelperTrait, RandomGeneratorTrait, SessionTestTrait
- class \Drupal\simpletest\KernelTestBase uses AssertContentTrait
- class \Drupal\system\Tests\Common\AttachedAssetsTest
- class \Drupal\simpletest\KernelTestBase uses AssertContentTrait
Expanded class hierarchy of AttachedAssetsTest
File
- core/
modules/ system/ src/ Tests/ Common/ AttachedAssetsTest.php, line 28 - Contains \Drupal\system\Tests\Common\AttachedAssetsTest.
Namespace
Drupal\system\Tests\CommonView source
class AttachedAssetsTest extends KernelTestBase {
/**
* The asset resolver service.
*
* @var \Drupal\Core\Asset\AssetResolverInterface
*/
protected $assetResolver;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* {@inheritdoc}
*/
public static $modules = array(
'language',
'simpletest',
'common_test',
'system',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this
->installSchema('system', array(
'router',
));
$this->container
->get('router.builder')
->rebuild();
$this->assetResolver = $this->container
->get('asset.resolver');
$this->renderer = $this->container
->get('renderer');
}
/**
* Tests that default CSS and JavaScript is empty.
*/
function testDefault() {
$assets = new AttachedAssets();
$this
->assertEqual(array(), $this->assetResolver
->getCssAssets($assets, FALSE), 'Default CSS is empty.');
list($js_assets_header, $js_assets_footer) = $this->assetResolver
->getJsAssets($assets, FALSE);
$this
->assertEqual(array(), $js_assets_header, 'Default header JavaScript is empty.');
$this
->assertEqual(array(), $js_assets_footer, 'Default footer JavaScript is empty.');
}
/**
* Tests non-existing libraries.
*/
function testLibraryUnknown() {
$build['#attached']['library'][] = 'core/unknown';
$assets = AttachedAssets::createFromRenderArray($build);
$this
->assertIdentical([], $this->assetResolver
->getJsAssets($assets, FALSE)[0], 'Unknown library was not added to the page.');
}
/**
* Tests adding a CSS and a JavaScript file.
*/
function testAddFiles() {
$build['#attached']['library'][] = 'common_test/files';
$assets = AttachedAssets::createFromRenderArray($build);
$css = $this->assetResolver
->getCssAssets($assets, FALSE);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/bar.css', $css), 'CSS files are correctly added.');
$this
->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/foo.js', $js), 'JavaScript files are correctly added.');
$css_render_array = \Drupal::service('asset.css.collection_renderer')
->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_css = $this->renderer
->renderPlain($css_render_array);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$query_string = $this->container
->get('state')
->get('system.css_js_query_string') ?: '0';
$this
->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" href="' . file_create_url('core/modules/system/tests/modules/common_test/bar.css') . '?' . $query_string . '" media="all" />'), FALSE, 'Rendering an external CSS file.');
$this
->assertNotIdentical(strpos($rendered_js, '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/foo.js') . '?' . $query_string . '"></script>'), FALSE, 'Rendering an external JavaScript file.');
}
/**
* Tests adding JavaScript settings.
*/
function testAddJsSettings() {
// Add a file in order to test default settings.
$build['#attached']['library'][] = 'core/drupalSettings';
$assets = AttachedAssets::createFromRenderArray($build);
$this
->assertEqual([], $assets
->getSettings(), 'JavaScript settings on $assets are empty.');
$javascript = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertTrue(array_key_exists('currentPath', $javascript['drupalSettings']['data']['path']), 'The current path JavaScript setting is set correctly.');
$this
->assertTrue(array_key_exists('currentPath', $assets
->getSettings()['path']), 'JavaScript settings on $assets are resolved after retrieving JavaScript assets, and are equal to the returned JavaScript settings.');
$assets
->setSettings([
'drupal' => 'rocks',
'dries' => 280342800,
]);
$javascript = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertEqual(280342800, $javascript['drupalSettings']['data']['dries'], 'JavaScript setting is set correctly.');
$this
->assertEqual('rocks', $javascript['drupalSettings']['data']['drupal'], 'The other JavaScript setting is set correctly.');
}
/**
* Tests adding external CSS and JavaScript files.
*/
function testAddExternalFiles() {
$build['#attached']['library'][] = 'common_test/external';
$assets = AttachedAssets::createFromRenderArray($build);
$css = $this->assetResolver
->getCssAssets($assets, FALSE);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertTrue(array_key_exists('http://example.com/stylesheet.css', $css), 'External CSS files are correctly added.');
$this
->assertTrue(array_key_exists('http://example.com/script.js', $js), 'External JavaScript files are correctly added.');
$css_render_array = \Drupal::service('asset.css.collection_renderer')
->render($css);
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_css = $this->renderer
->renderPlain($css_render_array);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$this
->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" href="http://example.com/stylesheet.css" media="all" />'), FALSE, 'Rendering an external CSS file.');
$this
->assertNotIdentical(strpos($rendered_js, '<script src="http://example.com/script.js"></script>'), FALSE, 'Rendering an external JavaScript file.');
}
/**
* Tests adding JavaScript files with additional attributes.
*/
function testAttributes() {
$build['#attached']['library'][] = 'common_test/js-attributes';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>';
$this
->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
$this
->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered internal JavaScript with correct defer and random attributes.');
}
/**
* Tests that attributes are maintained when JS aggregation is enabled.
*/
function testAggregatedAttributes() {
$build['#attached']['library'][] = 'common_test/js-attributes';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, TRUE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$expected_1 = '<script src="http://example.com/deferred-external.js" foo="bar" defer></script>';
$expected_2 = '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/deferred-internal.js') . '?v=1" defer bar="foo"></script>';
$this
->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered external JavaScript with correct defer and random attributes.');
$this
->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered internal JavaScript with correct defer and random attributes.');
}
/**
* Integration test for CSS/JS aggregation.
*/
function testAggregation() {
$build['#attached']['library'][] = 'core/drupal.timezone';
$build['#attached']['library'][] = 'core/drupal.vertical-tabs';
$assets = AttachedAssets::createFromRenderArray($build);
$this
->assertEqual(1, count($this->assetResolver
->getCssAssets($assets, TRUE)), 'There is a sole aggregated CSS asset.');
list($header_js, $footer_js) = $this->assetResolver
->getJsAssets($assets, TRUE);
$this
->assertEqual([], \Drupal::service('asset.js.collection_renderer')
->render($header_js), 'There are 0 JavaScript assets in the header.');
$rendered_footer_js = \Drupal::service('asset.js.collection_renderer')
->render($footer_js);
$this
->assertEqual(2, count($rendered_footer_js), 'There are 2 JavaScript assets in the footer.');
$this
->assertEqual('drupal-settings-json', $rendered_footer_js[0]['#attributes']['data-drupal-selector'], 'The first of the two JavaScript assets in the footer has drupal settings.');
$this
->assertEqual('http://', substr($rendered_footer_js[1]['#attributes']['src'], 0, 7), 'The second of the two JavaScript assets in the footer has the sole aggregated JavaScript asset.');
}
/**
* Tests JavaScript settings.
*/
function testSettings() {
$build = array();
$build['#attached']['library'][] = 'core/drupalSettings';
// Nonsensical value to verify if it's possible to override path settings.
$build['#attached']['drupalSettings']['path']['pathPrefix'] = 'yarhar';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
// Parse the generated drupalSettings <script> back to a PHP representation.
$startToken = '{';
$endToken = '}';
$start = strpos($rendered_js, $startToken);
$end = strrpos($rendered_js, $endToken);
$json = Unicode::substr($rendered_js, $start, $end - $start + 1);
$parsed_settings = Json::decode($json);
// Test whether the settings for core/drupalSettings are available.
$this
->assertTrue(isset($parsed_settings['path']['baseUrl']), 'drupalSettings.path.baseUrl is present.');
$this
->assertIdentical($parsed_settings['path']['pathPrefix'], 'yarhar', 'drupalSettings.path.pathPrefix is present and has the correct (overridden) value.');
$this
->assertIdentical($parsed_settings['path']['currentPath'], '', 'drupalSettings.path.currentPath is present and has the correct value.');
$this
->assertIdentical($parsed_settings['path']['currentPathIsAdmin'], FALSE, 'drupalSettings.path.currentPathIsAdmin is present and has the correct value.');
$this
->assertIdentical($parsed_settings['path']['isFront'], FALSE, 'drupalSettings.path.isFront is present and has the correct value.');
$this
->assertIdentical($parsed_settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is present and has the correct value.');
// Tests whether altering JavaScript settings via hook_js_settings_alter()
// is working as expected.
// @see common_test_js_settings_alter()
$this
->assertIdentical($parsed_settings['pluralDelimiter'], '☃');
$this
->assertIdentical($parsed_settings['foo'], 'bar');
}
/**
* Tests JS assets depending on the 'core/<head>' virtual library.
*/
function testHeaderHTML() {
$build['#attached']['library'][] = 'common_test/js-header';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[0];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$query_string = $this->container
->get('state')
->get('system.css_js_query_string') ?: '0';
$this
->assertNotIdentical(strpos($rendered_js, '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/header.js') . '?' . $query_string . '"></script>'), FALSE, 'The JS asset in common_test/js-header appears in the header.');
$this
->assertNotIdentical(strpos($rendered_js, '<script src="' . file_create_url('core/misc/drupal.js')), FALSE, 'The JS asset of the direct dependency (core/drupal) of common_test/js-header appears in the header.');
$this
->assertNotIdentical(strpos($rendered_js, '<script src="' . file_create_url('core/assets/vendor/domready/ready.min.js')), FALSE, 'The JS asset of the indirect dependency (core/domready) of common_test/js-header appears in the header.');
}
/**
* Tests that for assets with cache = FALSE, Drupal sets preprocess = FALSE.
*/
function testNoCache() {
$build['#attached']['library'][] = 'common_test/no-cache';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertFalse($js['core/modules/system/tests/modules/common_test/nocache.js']['preprocess'], 'Setting cache to FALSE sets preprocess to FALSE when adding JavaScript.');
}
/**
* Tests adding JavaScript within conditional comments.
*
* @see \Drupal\Core\Render\Element\HtmlTag::preRenderConditionalComments()
*/
function testBrowserConditionalComments() {
$default_query_string = $this->container
->get('state')
->get('system.css_js_query_string') ?: '0';
$build['#attached']['library'][] = 'common_test/browsers';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$expected_1 = "<!--[if lte IE 8]>\n" . '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/old-ie.js') . '?' . $default_query_string . '"></script>' . "\n<![endif]-->";
$expected_2 = "<!--[if !IE]><!-->\n" . '<script src="' . file_create_url('core/modules/system/tests/modules/common_test/no-ie.js') . '?' . $default_query_string . '"></script>' . "\n<!--<![endif]-->";
$this
->assertNotIdentical(strpos($rendered_js, $expected_1), FALSE, 'Rendered JavaScript within downlevel-hidden conditional comments.');
$this
->assertNotIdentical(strpos($rendered_js, $expected_2), FALSE, 'Rendered JavaScript within downlevel-revealed conditional comments.');
}
/**
* Tests JavaScript versioning.
*/
function testVersionQueryString() {
$build['#attached']['library'][] = 'core/backbone';
$build['#attached']['library'][] = 'core/domready';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$this
->assertTrue(strpos($rendered_js, 'core/assets/vendor/backbone/backbone-min.js?v=1.2.3') > 0 && strpos($rendered_js, 'core/assets/vendor/domready/ready.min.js?v=1.0.8') > 0, 'JavaScript version identifiers correctly appended to URLs');
}
/**
* Tests JavaScript and CSS asset ordering.
*/
function testRenderOrder() {
$build['#attached']['library'][] = 'common_test/order';
$assets = AttachedAssets::createFromRenderArray($build);
// Construct the expected result from the regex.
$expected_order_js = [
"-8_1",
"-8_2",
"-8_3",
"-8_4",
"-5_1",
// The external script.
"-3_1",
"-3_2",
"0_1",
"0_2",
"0_3",
];
// Retrieve the rendered JavaScript and test against the regex.
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$matches = array();
if (preg_match_all('/weight_([-0-9]+_[0-9]+)/', $rendered_js, $matches)) {
$result = $matches[1];
}
else {
$result = array();
}
$this
->assertIdentical($result, $expected_order_js, 'JavaScript is added in the expected weight order.');
// Construct the expected result from the regex.
$expected_order_css = [
// Base.
'base_weight_-101_1',
'base_weight_-8_1',
'layout_weight_-101_1',
'base_weight_0_1',
'base_weight_0_2',
// Layout.
'layout_weight_-8_1',
'component_weight_-101_1',
'layout_weight_0_1',
'layout_weight_0_2',
// Component.
'component_weight_-8_1',
'state_weight_-101_1',
'component_weight_0_1',
'component_weight_0_2',
// State.
'state_weight_-8_1',
'theme_weight_-101_1',
'state_weight_0_1',
'state_weight_0_2',
// Theme.
'theme_weight_-8_1',
'theme_weight_0_1',
'theme_weight_0_2',
];
// Retrieve the rendered CSS and test against the regex.
$css = $this->assetResolver
->getCssAssets($assets, FALSE);
$css_render_array = \Drupal::service('asset.css.collection_renderer')
->render($css);
$rendered_css = $this->renderer
->renderPlain($css_render_array);
$matches = array();
if (preg_match_all('/([a-z]+)_weight_([-0-9]+_[0-9]+)/', $rendered_css, $matches)) {
$result = $matches[0];
}
else {
$result = array();
}
$this
->assertIdentical($result, $expected_order_css, 'CSS is added in the expected weight order.');
}
/**
* Tests rendering the JavaScript with a file's weight above jQuery's.
*/
function testRenderDifferentWeight() {
// If a library contains assets A and B, and A is listed first, then B can
// still make itself appear first by defining a lower weight.
$build['#attached']['library'][] = 'core/jquery';
$build['#attached']['library'][] = 'common_test/weight';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$this
->assertTrue(strpos($rendered_js, 'lighter.css') < strpos($rendered_js, 'first.js'), 'Lighter CSS assets are rendered first.');
$this
->assertTrue(strpos($rendered_js, 'lighter.js') < strpos($rendered_js, 'first.js'), 'Lighter JavaScript assets are rendered first.');
$this
->assertTrue(strpos($rendered_js, 'before-jquery.js') < strpos($rendered_js, 'core/assets/vendor/jquery/jquery.min.js'), 'Rendering a JavaScript file above jQuery.');
}
/**
* Tests altering a JavaScript's weight via hook_js_alter().
*
* @see simpletest_js_alter()
*/
function testAlter() {
// Add both tableselect.js and simpletest.js.
$build['#attached']['library'][] = 'core/drupal.tableselect';
$build['#attached']['library'][] = 'simpletest/drupal.simpletest';
$assets = AttachedAssets::createFromRenderArray($build);
// Render the JavaScript, testing if simpletest.js was altered to be before
// tableselect.js. See simpletest_js_alter() to see where this alteration
// takes place.
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$this
->assertTrue(strpos($rendered_js, 'simpletest.js') < strpos($rendered_js, 'core/misc/tableselect.js'), 'Altering JavaScript weight through the alter hook.');
}
/**
* Adds a JavaScript library to the page and alters it.
*
* @see common_test_library_info_alter()
*/
function testLibraryAlter() {
// Verify that common_test altered the title of Farbtastic.
/** @var \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery */
$library_discovery = \Drupal::service('library.discovery');
$library = $library_discovery
->getLibraryByName('core', 'jquery.farbtastic');
$this
->assertEqual($library['version'], '0.0', 'Registered libraries were altered.');
// common_test_library_info_alter() also added a dependency on jQuery Form.
$build['#attached']['library'][] = 'core/jquery.farbtastic';
$assets = AttachedAssets::createFromRenderArray($build);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$this
->assertTrue(strpos($rendered_js, 'core/assets/vendor/jquery-form/jquery.form.min.js'), 'Altered library dependencies are added to the page.');
}
/**
* Dynamically defines an asset library and alters it.
*/
function testDynamicLibrary() {
/** @var \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery */
$library_discovery = \Drupal::service('library.discovery');
// Retrieve a dynamic library definition.
// @see common_test_library_info_build()
\Drupal::state()
->set('common_test.library_info_build_test', TRUE);
$library_discovery
->clearCachedDefinitions();
$dynamic_library = $library_discovery
->getLibraryByName('common_test', 'dynamic_library');
$this
->assertTrue(is_array($dynamic_library));
if ($this
->assertTrue(isset($dynamic_library['version']))) {
$this
->assertIdentical('1.0', $dynamic_library['version']);
}
// Make sure the dynamic library definition could be altered.
// @see common_test_library_info_alter()
if ($this
->assertTrue(isset($dynamic_library['dependencies']))) {
$this
->assertIdentical([
'core/jquery',
], $dynamic_library['dependencies']);
}
}
/**
* Tests that multiple modules can implement libraries with the same name.
*
* @see common_test.library.yml
*/
function testLibraryNameConflicts() {
/** @var \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery */
$library_discovery = \Drupal::service('library.discovery');
$farbtastic = $library_discovery
->getLibraryByName('common_test', 'jquery.farbtastic');
$this
->assertEqual($farbtastic['version'], '0.1', 'Alternative libraries can be added to the page.');
}
/**
* Tests JavaScript files that have querystrings attached get added right.
*/
function testAddJsFileWithQueryString() {
$build['#attached']['library'][] = 'common_test/querystring';
$assets = AttachedAssets::createFromRenderArray($build);
$css = $this->assetResolver
->getCssAssets($assets, FALSE);
$js = $this->assetResolver
->getJsAssets($assets, FALSE)[1];
$this
->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2', $css), 'CSS file with query string is correctly added.');
$this
->assertTrue(array_key_exists('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2', $js), 'JavaScript file with query string is correctly added.');
$css_render_array = \Drupal::service('asset.css.collection_renderer')
->render($css);
$rendered_css = $this->renderer
->renderPlain($css_render_array);
$js_render_array = \Drupal::service('asset.js.collection_renderer')
->render($js);
$rendered_js = $this->renderer
->renderPlain($js_render_array);
$query_string = $this->container
->get('state')
->get('system.css_js_query_string') ?: '0';
$this
->assertNotIdentical(strpos($rendered_css, '<link rel="stylesheet" href="' . str_replace('&', '&', file_create_url('core/modules/system/tests/modules/common_test/querystring.css?arg1=value1&arg2=value2')) . '&' . $query_string . '" media="all" />'), FALSE, 'CSS file with query string gets version query string correctly appended..');
$this
->assertNotIdentical(strpos($rendered_js, '<script src="' . str_replace('&', '&', file_create_url('core/modules/system/tests/modules/common_test/querystring.js?arg1=value1&arg2=value2')) . '&' . $query_string . '"></script>'), FALSE, 'JavaScript file with query string gets version query string correctly appended.');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertContentTrait:: |
protected | property | The current raw content. | |
AssertContentTrait:: |
protected | property | The drupalSettings value from the current raw $content. | |
AssertContentTrait:: |
protected | property | The XML structure parsed from the current raw $content. | 2 |
AssertContentTrait:: |
protected | property | The plain-text content of raw $content (text nodes). | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertContentTrait:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href is not found in the main region. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page does not exist. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text is NOT found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | |
AssertContentTrait:: |
protected | function | Pass if the page title is not the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | |
AssertContentTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertContentTrait:: |
protected | function | Asserts that a Perl regex pattern is found in the plain-text content. | |
AssertContentTrait:: |
protected | function | Asserts themed output. | |
AssertContentTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
AssertContentTrait:: |
protected | function | Builds an XPath query. | |
AssertContentTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertContentTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
AssertContentTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertContentTrait:: |
protected | function | Gets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Gets the current raw content. | |
AssertContentTrait:: |
protected | function | Get the selected value from a select field. | |
AssertContentTrait:: |
protected | function | Retrieves the plain-text content from the current raw content. | |
AssertContentTrait:: |
protected | function | Get the current URL from the cURL handler. | 1 |
AssertContentTrait:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
AssertContentTrait:: |
protected | function | Removes all white-space between HTML tags from the raw content. | |
AssertContentTrait:: |
protected | function | Sets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Sets the raw content (e.g. HTML). | |
AssertContentTrait:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
AssertHelperTrait:: |
protected | function | Casts MarkupInterface objects into strings. | |
AttachedAssetsTest:: |
protected | property | The asset resolver service. | |
AttachedAssetsTest:: |
public static | property |
Modules to enable. Overrides KernelTestBase:: |
|
AttachedAssetsTest:: |
protected | property | The renderer service. | |
AttachedAssetsTest:: |
protected | function |
Performs setup tasks before each individual test method is run. Overrides KernelTestBase:: |
|
AttachedAssetsTest:: |
function | Tests adding external CSS and JavaScript files. | ||
AttachedAssetsTest:: |
function | Tests adding a CSS and a JavaScript file. | ||
AttachedAssetsTest:: |
function | Tests JavaScript files that have querystrings attached get added right. | ||
AttachedAssetsTest:: |
function | Tests adding JavaScript settings. | ||
AttachedAssetsTest:: |
function | Tests that attributes are maintained when JS aggregation is enabled. | ||
AttachedAssetsTest:: |
function | Integration test for CSS/JS aggregation. | ||
AttachedAssetsTest:: |
function | Tests altering a JavaScript's weight via hook_js_alter(). | ||
AttachedAssetsTest:: |
function | Tests adding JavaScript files with additional attributes. | ||
AttachedAssetsTest:: |
function | Tests adding JavaScript within conditional comments. | ||
AttachedAssetsTest:: |
function | Tests that default CSS and JavaScript is empty. | ||
AttachedAssetsTest:: |
function | Dynamically defines an asset library and alters it. | ||
AttachedAssetsTest:: |
function | Tests JS assets depending on the 'core/<head>' virtual library. | ||
AttachedAssetsTest:: |
function | Adds a JavaScript library to the page and alters it. | ||
AttachedAssetsTest:: |
function | Tests that multiple modules can implement libraries with the same name. | ||
AttachedAssetsTest:: |
function | Tests non-existing libraries. | ||
AttachedAssetsTest:: |
function | Tests that for assets with cache = FALSE, Drupal sets preprocess = FALSE. | ||
AttachedAssetsTest:: |
function | Tests rendering the JavaScript with a file's weight above jQuery's. | ||
AttachedAssetsTest:: |
function | Tests JavaScript and CSS asset ordering. | ||
AttachedAssetsTest:: |
function | Tests JavaScript settings. | ||
AttachedAssetsTest:: |
function | Tests JavaScript versioning. | ||
KernelTestBase:: |
protected | property | The configuration directories for this test run. | |
KernelTestBase:: |
protected | property | A KeyValueMemoryFactory instance to use when building the container. | |
KernelTestBase:: |
private | property | ||
KernelTestBase:: |
protected | property | Array of registered stream wrappers. | |
KernelTestBase:: |
private | property | ||
KernelTestBase:: |
protected | function |
Act on global state information before the environment is altered for a test. Overrides TestBase:: |
|
KernelTestBase:: |
public | function | Sets up the base service container for this test. | 12 |
KernelTestBase:: |
protected | function | Provides the data for setting the default language on the container. | 1 |
KernelTestBase:: |
protected | function | Disables modules for this test. | |
KernelTestBase:: |
protected | function | Enables modules for this test. | |
KernelTestBase:: |
protected | function | Installs default configuration for a given list of modules. | |
KernelTestBase:: |
protected | function | Installs the storage schema for a specific entity type. | |
KernelTestBase:: |
protected | function | Installs a specific table from a module schema definition. | |
KernelTestBase:: |
protected | function | Create and set new configuration directories. | 1 |
KernelTestBase:: |
protected | function | Registers a stream wrapper for this test. | |
KernelTestBase:: |
protected | function | Renders a render array. | |
KernelTestBase:: |
protected | function |
Performs cleanup tasks after each individual test method has been run. Overrides TestBase:: |
|
KernelTestBase:: |
function |
Constructor for Test. Overrides TestBase:: |
||
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
SessionTestTrait:: |
protected | property | The name of the session cookie. | |
SessionTestTrait:: |
protected | function | Generates a session cookie name. | |
SessionTestTrait:: |
protected | function | Returns the session name in use on the child site. | |
TestBase:: |
protected | property | Assertions thrown in that test case. | |
TestBase:: |
protected | property | The config importer that can used in a test. | 5 |
TestBase:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
TestBase:: |
protected | property | The dependency injection container used in the test. | |
TestBase:: |
protected | property | The database prefix of this test run. | |
TestBase:: |
public | property | Whether to die in case any test assertion fails. | |
TestBase:: |
protected | property | HTTP authentication credentials (<username>:<password>). | |
TestBase:: |
protected | property | HTTP authentication method (specified as a CURLAUTH_* constant). | |
TestBase:: |
protected | property | The DrupalKernel instance used in the test. | 1 |
TestBase:: |
protected | property | The original configuration (variables), if available. | |
TestBase:: |
protected | property | The original configuration (variables). | |
TestBase:: |
protected | property | The original configuration directories. | |
TestBase:: |
protected | property | The original container. | |
TestBase:: |
protected | property | The original file directory, before it was changed for testing purposes. | |
TestBase:: |
protected | property | The original language. | |
TestBase:: |
protected | property | The original database prefix when running inside Simpletest. | |
TestBase:: |
protected | property | The original installation profile. | |
TestBase:: |
protected | property | The name of the session cookie of the test-runner. | |
TestBase:: |
protected | property | The settings array. | |
TestBase:: |
protected | property | The original array of shutdown function callbacks. | 1 |
TestBase:: |
protected | property | The site directory of the original parent site. | |
TestBase:: |
protected | property | The original user, before testing began. | 1 |
TestBase:: |
protected | property | The private file directory for the test environment. | |
TestBase:: |
protected | property | The public file directory for the test environment. | |
TestBase:: |
public | property | Current results of this test case. | |
TestBase:: |
protected | property | The site directory of this test run. | |
TestBase:: |
protected | property | This class is skipped when looking for the source of an assertion. | |
TestBase:: |
protected | property | Set to TRUE to strict check all configuration saved. | 4 |
TestBase:: |
protected | property | The temporary file directory for the test environment. | |
TestBase:: |
protected | property | The test run ID. | |
TestBase:: |
protected | property | Time limit for the test. | |
TestBase:: |
protected | property | The translation file directory for the test environment. | |
TestBase:: |
public | property | TRUE if verbose debugging is enabled. | |
TestBase:: |
protected | property | Safe class name for use in verbose output filenames. | |
TestBase:: |
protected | property | Directory where verbose output files are put. | |
TestBase:: |
protected | property | URL to the verbose output file directory. | |
TestBase:: |
protected | property | Incrementing identifier for verbose output filenames. | |
TestBase:: |
protected | function | Internal helper: stores the assert. | |
TestBase:: |
protected | function | Check to see if two values are equal. | |
TestBase:: |
protected | function | Asserts that a specific error has been logged to the PHP error log. | |
TestBase:: |
protected | function | Check to see if a value is false. | |
TestBase:: |
protected | function | Check to see if two values are identical. | |
TestBase:: |
protected | function | Checks to see if two objects are identical. | |
TestBase:: |
protected | function | Asserts that no errors have been logged to the PHP error.log thus far. | |
TestBase:: |
protected | function | Check to see if two values are not equal. | |
TestBase:: |
protected | function | Check to see if two values are not identical. | |
TestBase:: |
protected | function | Check to see if a value is not NULL. | |
TestBase:: |
protected | function | Check to see if a value is NULL. | |
TestBase:: |
protected | function | Check to see if a value is not false. | |
TestBase:: |
private | function | Changes the database connection to the prefixed one. | |
TestBase:: |
protected | function | Checks the matching requirements for Test. | 2 |
TestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
TestBase:: |
public | function | Returns a ConfigImporter object to import test importing of configuration. | 5 |
TestBase:: |
public | function | Copies configuration objects from source storage to target storage. | |
TestBase:: |
public static | function | Delete an assertion record by message ID. | |
TestBase:: |
protected | function | Fire an error assertion. | 3 |
TestBase:: |
public | function | Handle errors during test runs. | |
TestBase:: |
protected | function | Handle exceptions. | |
TestBase:: |
protected | function | Fire an assertion that is always negative. | |
TestBase:: |
public static | function | Ensures test files are deletable within file_unmanaged_delete_recursive(). | |
TestBase:: |
public static | function | Converts a list of possible parameters into a stack of permutations. | |
TestBase:: |
protected | function | Cycles through backtrace until the first non-assertion method is found. | |
TestBase:: |
protected | function | Gets the config schema exclusions for this test. | |
TestBase:: |
public static | function | Returns the database connection to the site running Simpletest. | |
TestBase:: |
public | function | Gets the database prefix. | |
TestBase:: |
public | function | Gets the temporary files directory. | |
TestBase:: |
public static | function | Store an assertion from outside the testing context. | |
TestBase:: |
protected | function | Fire an assertion that is always positive. | |
TestBase:: |
private | function | Generates a database prefix for running tests. | |
TestBase:: |
private | function | Prepares the current environment for running the test. | |
TestBase:: |
private | function | Cleans up the test environment and restores the original environment. | |
TestBase:: |
public | function | Run all tests in this class. | 1 |
TestBase:: |
protected | function | Changes in memory settings. | |
TestBase:: |
protected | function | Helper method to store an assertion record in the configured database. | |
TestBase:: |
protected | function | Logs a verbose message in a text file. |