View source
<?php
namespace Drupal\Tests\aet\Functional;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Tests\BrowserTestBase;
class AETRecursionWebTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'node',
'aet',
'token_filter',
];
protected $editor_user;
public function setUp() {
parent::setUp();
$this->profile = 'testing';
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
$permissions = [
'create page content',
'edit any page content',
];
$this->editor_user = $this
->drupalCreateUser($permissions);
FilterFormat::create([
'format' => 'simple_tokens',
'name' => 'Simple Tokens',
'filters' => [
'token_filter' => [
'status' => 1,
],
],
])
->save();
}
public function testSingleEmbedding() {
$this
->drupalLogin($this->editor_user);
$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);
$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());
$this
->assertSession()
->pageTextContains($embedded_text);
$this
->assertSession()
->pageTextNotContains("Recursive token use");
$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());
$this
->assertSession()
->pageTextNotContains("Recursive token use");
$this
->assertSession()
->pageTextContains($embedded_node_data['title']);
$this
->assertSession()
->pageTextContains($embedded_text);
$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());
$this
->assertSession()
->pageTextNotContains("Recursive token use");
$this
->assertSession()
->pageTextContains("Member for");
}
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',
],
],
);
$embedder_node = $this
->drupalCreateNode($embedder_node_data);
$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());
$this
->assertSession()
->pageTextContains("My title is '" . $embedder_node
->label() . "'");
$this
->assertSession()
->pageTextNotContains("Recursive token use");
$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());
$this
->assertSession()
->pageTextContains("Recursive token use");
$this
->assertSession()
->responseNotContains('<blockquote>I am embedding');
}
public function testCyclicEmbedding() {
$this
->drupalLogin($this->editor_user);
$alpha_node_data = [
'type' => 'page',
'title' => 'I am the alpha',
'body' => [
[
'value' => "I will try to embed data from the beta node into my body.",
'format' => 'simple_tokens',
],
],
];
$alpha_node = $this
->drupalCreateNode($alpha_node_data);
$beta_node_data = [
'type' => 'page',
'title' => 'I am the beta',
'body' => [
[
'value' => "This is the beta content. I will try to embed data from the alpha node named '[aet:node:{$alpha_node->id()}:title]' into my body. <blockquote>[aet:node:{$alpha_node->id()}:body]</blockquote>",
'format' => 'simple_tokens',
],
],
];
$beta_node = $this
->drupalCreateNode($beta_node_data);
$alpha_node->body = "This is the alpha content. I will try to embed data from the beta node named '[aet:node:{$beta_node->id()}:title]' into my body. <blockquote>[aet:node:{$beta_node->id()}:body]</blockquote>";
$alpha_node
->save();
$this
->drupalGet("node/" . $alpha_node
->id());
$this
->assertSession()
->pageTextContains("'I am the beta'");
$this
->assertSession()
->pageTextContains("Recursive token use");
$this
->assertSession()
->pageTextNotContains("This is the beta content");
}
}