You are here

public function ModuleIntegrationTest::testAmpIntegration in Thunder 8.3

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.4 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.');
}