You are here

public function AETRecursionWebTest::testSingleEmbedding in Advanced Entity Tokens 2.x

Test normal operation - embed content from one node into another.

Throws

\Behat\Mink\Exception\ResponseTextException

\Drupal\Core\Entity\EntityStorageException

File

tests/src/Functional/AETRecursionWebTest.php, line 70

Class

AETRecursionWebTest
Tests for Advanced Entity Tokens.

Namespace

Drupal\Tests\aet\Functional

Code

public function testSingleEmbedding() {
  $this
    ->drupalLogin($this->editor_user);

  // Set up the target first.
  $embedded_text = 'I can be embedded.';
  $embedded_node_data = [
    'type' => 'page',
    'title' => 'Embed me',
    'body' => [
      [
        'value' => $embedded_text,
        'format' => 'simple_tokens',
      ],
    ],
  ];
  $embedded_node = $this
    ->drupalCreateNode($embedded_node_data);

  // Build a node that embeds the target.
  $token = "[aet:node:{$embedded_node->id()}:body]";
  $embedder_node_data = [
    'type' => 'page',
    'title' => 'I contain an embed',
    'body' => [
      [
        'value' => "I am a wrapper around <blockquote>{$token}</blockquote>",
        'format' => 'simple_tokens',
      ],
    ],
  ];
  $embedder_node = $this
    ->drupalCreateNode($embedder_node_data);
  $this
    ->drupalGet("node/" . $embedder_node
    ->id());

  // Content from the token pulling body data from the target was found in the
  // wrapper page when using token $token.
  $this
    ->assertSession()
    ->pageTextContains($embedded_text);

  // Using token $token did not trigger a recursive token warning.
  $this
    ->assertSession()
    ->pageTextNotContains("Recursive token use");

  // Test embedding full view of a node, not just a field.
  $token = "[aet:node:{$embedded_node->id()}]";
  $embedder_node->body = "I am embedding the whole node. <blockquote>{$token}</blockquote>";
  $embedder_node
    ->save();
  $this
    ->drupalGet("node/" . $embedder_node
    ->id());

  // Using token $token did not trigger a recursive token warning.
  $this
    ->assertSession()
    ->pageTextNotContains("Recursive token use");

  // Embedded nodes title was found when embedding token $token.
  $this
    ->assertSession()
    ->pageTextContains($embedded_node_data['title']);

  // Embedded nodes body was found when embedding token $token.
  $this
    ->assertSession()
    ->pageTextContains($embedded_text);

  // Test embedding a user.
  $token = "[aet:user:{$this->editor_user->id()}]";
  $embedder_node->body = "I am embedding a display of my user. <blockquote>{$token}</blockquote>";
  $embedder_node
    ->save();
  $this
    ->drupalGet("node/" . $embedder_node
    ->id());

  // Using token $token did not trigger a recursive token warning.
  $this
    ->assertSession()
    ->pageTextNotContains("Recursive token use");

  // User history name was found when embedding token $token.
  $this
    ->assertSession()
    ->pageTextContains("Member for");
}