You are here

public function VarbaseSeoJavascriptSnippetsTest::testCheckVarbaseSeoJavascriptSnippetsFunctionality in Varbase SEO 9.0.x

Check Varbase SEO Javascript Snippets Functionality.

After integration with number of modules. Enabled under the same system.

File

tests/src/FunctionalJavascript/VarbaseSeoJavascriptSnippetsTest.php, line 100

Class

VarbaseSeoJavascriptSnippetsTest
Tests Varbase SEO test the Javascript Snippets functionality.

Namespace

Drupal\Tests\varbase_seo\FunctionalJavascript

Code

public function testCheckVarbaseSeoJavascriptSnippetsFunctionality() {

  // Given that SEO admin user was logged in to the site.
  $this
    ->drupalLogin($this->seoAdminUser);

  // Navigate to the Scripts admin page.
  $this
    ->drupalGet('admin/structure/scripts');
  $this
    ->assertSession()
    ->pageTextContains('Scripts');
  $this
    ->assertSession()
    ->pageTextContains('There are no script entities yet.');

  // Add Script.
  $this
    ->drupalGet('admin/structure/scripts/add');
  $this
    ->assertSession()
    ->pageTextContains('Add script');
  $this->testScript = Script::create([
    'id' => 'test_script',
    'label' => $this
      ->t('Test Script'),
    'snippet' => '<script> document.getElementById("main-wrapper").innerHTML = "Hello JavaScript!"; </script>',
    'position' => ScriptInterface::POSITION_BOTTOM,
  ]);
  $this->testScript
    ->save();
  $this->testScript
    ->set('visibility', [
    'request_path' => [
      'id' => 'request_path',
      'pages' => '<front>',
      'negate' => FALSE,
      'context_mapping' => [],
    ],
  ])
    ->save();

  // Navigate to the Scripts admin page.
  $this
    ->drupalGet('admin/structure/scripts');
  $this
    ->assertSession()
    ->pageTextContains('Scripts');
  $this
    ->assertSession()
    ->pageTextContains('Test Script');

  // Got to the homepage.
  $this
    ->drupalGet('<front>');
  $this
    ->assertSession()
    ->pageTextContains('Hello JavaScript!');

  // Got to the use page.
  $this
    ->drupalGet('/user');
  $this
    ->assertSession()
    ->pageTextNotContains('Hello JavaScript!');
}