AmpViewModeTest.php in Accelerated Mobile Pages (AMP) 8.2
File
tests/src/Functional/AmpViewModeTest.php
View source
<?php
namespace Drupal\Tests\amp\Functional;
use Drupal\Core\Url;
use Drupal\node\Entity\Node;
use Drupal\simpletest\ContentTypeCreationTrait;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\amp\Functional\AmpTestBase;
class AmpViewModeTest extends AmpTestBase {
public function testAmpViewMode() {
$node = Node::create([
'type' => 'article',
'title' => $this
->randomMachineName(),
'body' => 'AMP test body',
]);
$node
->save();
$amp_context = \Drupal::service('router.amp_context');
$view_modes_url = Url::fromRoute('entity.entity_view_mode.collection')
->toString();
$this
->drupalGet($view_modes_url);
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('AMP');
$node_url = Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
], [
'absolute' => TRUE,
])
->toString();
$amp_node_url = Url::fromRoute('entity.node.canonical', [
'node' => $node
->id(),
], [
'absolute' => TRUE,
'query' => [
'amp' => NULL,
],
])
->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="' . $amp_node_url . '"');
$this
->assertSession()
->responseHeaderEquals('Link', '<' . $amp_node_url . '> rel="amphtml"');
$this
->drupalGet($amp_node_url);
$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_url . '"');
$this
->drupalGet($amp_node_url . "&warnfix");
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains('AMP test body');
$this
->assertSession()
->pageTextContains('AMP-HTML Validation Issues and Fixes');
$this
->assertSession()
->pageTextContains('-------------------------------------');
$this
->assertSession()
->pageTextContains('PASS');
}
}