You are here

public function ModuleIntegrationTest::testAmpIntegration in Thunder 8.4

Same name and namespace in other branches
  1. 8.5 tests/src/FunctionalJavascript/ModuleIntegrationTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModuleIntegrationTest::testAmpIntegration()
  2. 8.2 tests/src/FunctionalJavascript/ModuleIntegrationTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModuleIntegrationTest::testAmpIntegration()
  3. 8.3 tests/src/FunctionalJavascript/ModuleIntegrationTest.php \Drupal\Tests\thunder\FunctionalJavascript\ModuleIntegrationTest::testAmpIntegration()

Testing integration of "AMP" module and theme.

File

tests/src/FunctionalJavascript/ModuleIntegrationTest.php, line 203

Class

ModuleIntegrationTest
Testing of module integrations.

Namespace

Drupal\Tests\thunder\FunctionalJavascript

Code

public function testAmpIntegration() {
  if (!\Drupal::service('theme_installer')
    ->install([
    'thunder_amp',
  ])) {
    $this
      ->fail("thunder_amp theme couldn't be installed.");
    return;
  }
  $this
    ->drupalGet('/node/6', [
    'query' => [
      'amp' => 1,
    ],
  ]);

  // Text paragraph.
  $this
    ->assertSession()
    ->pageTextContains('Board Member Philipp Welte explains');

  // Image paragraph.
  $this
    ->assertSession()
    ->elementExists('css', '.paragraph--type--image amp-img');
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.paragraph--type--image amp-img img');
  $this
    ->drupalGet('/node/7', [
    'query' => [
      'amp' => 1,
    ],
    'fragment' => 'development=1',
  ]);

  // Gallery paragraph.
  $this
    ->assertSession()
    ->elementExists('css', '.paragraph--type--gallery amp-carousel');

  // Images in gallery paragraph.
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.paragraph--type--gallery amp-carousel amp-img');
  $this
    ->assertSession()
    ->elementsCount('css', '.paragraph--type--gallery amp-carousel amp-img', 5);

  // Video Paragraph.
  $this
    ->assertSession()
    ->elementExists('css', '.paragraph--type--video amp-youtube[data-videoid="Ksp5JVFryEg"]');
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.paragraph--type--video amp-youtube[data-videoid="Ksp5JVFryEg"] iframe');

  // Twitter Paragraph.
  $this
    ->assertSession()
    ->elementExists('css', '.paragraph--type--twitter amp-twitter[data-tweetid="731057647877787648"]');
  $this
    ->assertSession()
    ->waitForElementVisible('css', '.paragraph--type--twitter amp-twitter[data-tweetid="731057647877787648"] iframe');
  $this
    ->getSession()
    ->executeScript('AMPValidationSuccess = false; console.info = function(message) { if (message === "AMP validation successful.") { AMPValidationSuccess = true } }; amp.validator.validateUrlAndLog(document.location.href, document);');
  $this
    ->assertJsCondition('AMPValidationSuccess === true', 10000, 'AMP validation successful.');
  $this
    ->drupalLogout();
  $this
    ->drupalLogin($this->rootUser);

  // Verify that the Site branding block is in the header region.
  $this
    ->drupalGet('admin/structure/block/list/thunder_amp');
  $element = $this
    ->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]", [
    ':block' => 'edit-blocks-thunder-amp-branding',
    ':status' => 'block-enabled',
    ':region' => 'header',
  ]);
  $this
    ->assertNotEmpty($element);

  // Verify that the Title block is in the content region.
  $this
    ->drupalGet('admin/structure/block/list/thunder_amp');
  $element = $this
    ->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]", [
    ':block' => 'edit-blocks-thunder-amp-page-title',
    ':status' => 'block-enabled',
    ':region' => 'content',
  ]);
  $this
    ->assertNotEmpty($element);

  // Verify that the Content block is in the content region.
  $this
    ->drupalGet('admin/structure/block/list/thunder_amp');
  $element = $this
    ->xpath("//tr[contains(@data-drupal-selector, :block) and contains(@class, :status)]//select/option[@selected and @value=:region]", [
    ':block' => 'edit-blocks-thunder-amp-content',
    ':status' => 'block-enabled',
    ':region' => 'content',
  ]);
  $this
    ->assertNotEmpty($element);
}