public function AETRecursionWebTest::testSelfEmbedding in Advanced Entity Tokens 2.x
Test that it's OK to embed a different field from myself into myself.
Throws
\Behat\Mink\Exception\ExpectationException
\Behat\Mink\Exception\ResponseTextException
\Drupal\Core\Entity\EntityStorageException
File
- tests/
src/ Functional/ AETRecursionWebTest.php, line 137
Class
- AETRecursionWebTest
- Tests for Advanced Entity Tokens.
Namespace
Drupal\Tests\aet\FunctionalCode
public function testSelfEmbedding() {
$this
->drupalLogin($this->editor_user);
$embedder_node_data = array(
'type' => 'page',
'title' => 'I contain an embed',
'body' => [
[
'value' => "I will try to embed data from myself into my body",
'format' => 'simple_tokens',
],
],
);
// Save once so I know what my nid is.
$embedder_node = $this
->drupalCreateNode($embedder_node_data);
// I should be able to use a field from myself.
$token = "[aet:node:{$embedder_node->id()}:title]";
$embedder_node->body = "I am embedding a token from myself. My title is '{$token}'.";
$embedder_node
->save();
$this
->drupalGet("node/" . $embedder_node
->id());
// Node was able to embed its own title using a token $token.
$this
->assertSession()
->pageTextContains("My title is '" . $embedder_node
->label() . "'");
// Using token $token did not trigger a recursive token warning.
$this
->assertSession()
->pageTextNotContains("Recursive token use");
// But if we tried to embed a token to the same field,
// that would be illegal recursion.
$token = "[aet:node:{$embedder_node->id()}:body]";
$embedder_node->body = "I am embedding my own body into my body. <blockquote>{$token}</blockquote> This should fail.";
$embedder_node
->save();
$this
->drupalGet("node/" . $embedder_node
->id());
// Recursive token use was accurately detected.
$this
->assertSession()
->pageTextContains("Recursive token use");
// Attempting to embed the body inside itself failed correctly when using
// token $token.
$this
->assertSession()
->responseNotContains('<blockquote>I am embedding');
}