class NoJavaScriptAnonymousTest
Tests that anonymous users are not served any JavaScript.
This is tested with the core modules that are enabled in the 'standard' profile.
@group Common
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Common\NoJavaScriptAnonymousTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of NoJavaScriptAnonymousTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Common/ NoJavaScriptAnonymousTest.php, line 16
Namespace
Drupal\Tests\system\Functional\CommonView source
class NoJavaScriptAnonymousTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected $profile = 'standard';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Grant the anonymous user the permission to look at user profiles.
user_role_grant_permissions('anonymous', [
'access user profiles',
]);
}
/**
* Tests that anonymous users are not served any JavaScript.
*/
public function testNoJavaScript() {
// Create a node of content type 'article' that is listed on the frontpage.
$this->drupalCreateNode([
'type' => 'article',
'promote' => NodeInterface::PROMOTED,
]);
// Test frontpage.
$this->drupalGet('');
$this->assertNoJavaScript();
// Test node page.
$this->drupalGet('node/1');
$this->assertNoJavaScript();
// Test user profile page.
$user = $this->drupalCreateUser();
$this->drupalGet('user/' . $user->id());
$this->assertNoJavaScript();
}
/**
* Passes if no JavaScript is found on the page.
*
* @internal
*/
protected function assertNoJavaScript() : void {
// Ensure drupalSettings is not set.
$settings = $this->getDrupalSettings();
$this->assertEmpty($settings, 'drupalSettings is not set.');
$this->assertSession()
->responseNotMatches('/\\.js/');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.