NoJavaScriptAnonymousTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Common;
use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
class NoJavaScriptAnonymousTest extends BrowserTestBase {
protected $profile = 'standard';
protected function setUp() : void {
parent::setUp();
user_role_grant_permissions('anonymous', [
'access user profiles',
]);
}
public function testNoJavaScript() {
$this
->drupalCreateNode([
'promote' => NodeInterface::PROMOTED,
]);
$user = $this
->drupalCreateUser();
$this
->drupalGet('');
$this
->assertNoJavaScript();
$this
->drupalGet('node/1');
$this
->assertNoJavaScript();
$this
->drupalGet('user/' . $user
->id());
$this
->assertNoJavaScript();
}
protected function assertNoJavaScript() {
$settings = $this
->getDrupalSettings();
$this
->assertTrue(empty($settings), 'drupalSettings is not set.');
$this
->assertSession()
->responseNotMatches('/\\.js/');
}
}