diff --git a/tests/src/Functional/AmpFormatterTest.php b/tests/src/Functional/AmpFormatterTest.php new file mode 100644 index 0000000..a8b6dc0 --- /dev/null +++ b/tests/src/Functional/AmpFormatterTest.php @@ -0,0 +1,114 @@ +install(array('amptheme')); + + // Create Article node type. + $this->createContentType([ + 'type' => 'article', + 'name' => 'Article' + ]); + } + + /** + * Test the AMP view mode. + */ + public function testAmpViewMode() { + + // Login as an admin user. + $this->adminUser = $this->drupalCreateUser($this->permissions); + $this->drupalLogin($this->adminUser); + + // Create a node to test AMP field formatters. + $node = Node::create([ + 'type' => 'article', + 'title' => $this->randomMachineName(), + 'body' => 'AMP test body', + ]); + $node->save(); + + // Check that the AMP view mode is available. + $view_modes_url = Url::fromRoute('entity.entity_view_mode.collection')->toString(); + $this->drupalGet($view_modes_url); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('AMP'); + + // Enable AMP display on article content. + $article_url = Url::fromRoute("entity.entity_view_display.node.default", ['node_type' => 'article'])->toString(); + $this->drupalGet($article_url); + $this->assertSession()->statusCodeEquals(200); + $edit = ['display_modes_custom[amp]' => 'amp']; + $this->submitForm($edit, t('Save')); + + // Check the metadata of the full display mode. + $node_url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()])->toString(); + $this->drupalGet($node_url); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('AMP test body'); + $this->assertSession()->responseContains('data-quickedit-field-id="node/1/body/en/full"'); + $this->assertSession()->responseContains('link rel="amphtml" href="/node/1?amp"'); + + // Check the metadata of the AMP display mode. + $this->drupalGet('node/1', ['query' => ['amp' => TRUE]]); + $this->assertSession()->statusCodeEquals(200); + $this->assertSession()->pageTextContains('AMP test body'); + $this->assertSession()->responseContains('data-quickedit-field-id="node/1/body/en/amp"'); + $this->assertSession()->responseContains('link rel="canonical" href="/node/1"'); + } +}