src/Plugin/Filter/EntityEmbedFilter.php | 4 ++-- tests/src/Functional/RecursionProtectionTest.php | 26 ++++++++++++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Plugin/Filter/EntityEmbedFilter.php b/src/Plugin/Filter/EntityEmbedFilter.php index 2a03d2d..3cc1320 100644 --- a/src/Plugin/Filter/EntityEmbedFilter.php +++ b/src/Plugin/Filter/EntityEmbedFilter.php @@ -73,9 +73,9 @@ class EntityEmbedFilter extends FilterBase implements ContainerFactoryPluginInte * Each counter takes into account all the relevant information about the * field and the referenced entity that is being rendered. * - * @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter::$recursiveRenderDepth - * * @var array + * + * @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\EntityReferenceEntityFormatter::$recursiveRenderDepth */ protected static $recursiveRenderDepth = []; diff --git a/tests/src/Functional/RecursionProtectionTest.php b/tests/src/Functional/RecursionProtectionTest.php index 7134401..d722901 100644 --- a/tests/src/Functional/RecursionProtectionTest.php +++ b/tests/src/Functional/RecursionProtectionTest.php @@ -2,17 +2,21 @@ namespace Drupal\Tests\entity_embed\Functional; +use Drupal\entity_embed\Plugin\Filter\EntityEmbedFilter; + /** * Tests recursive rendering protection. * * @group entity_embed + * + * @see \Drupal\Tests\entity_embed\Kernel\EntityEmbedFilterTest::testRecursionProtection */ class RecursionProtectionTest extends EntityEmbedTestBase { /** - * Tests node embedding itself is rendered no more than 21 times. + * Tests self embedding. */ - public function testNodeEmbeddingItself() { + public function testSelfEmbedding() { $node = $this->drupalCreateNode([ 'type' => 'article', 'title' => "Pirate Chinchilla LLama", @@ -29,13 +33,13 @@ class RecursionProtectionTest extends EntityEmbedTestBase { ]); $node->save(); $this->drupalGet('node/' . $node->id()); - $this->assertEquals(21, count($this->getSession()->getPage()->findAll('xpath', '//div[@class="pirate"]'))); + $this->assertCount(EntityEmbedFilter::RECURSIVE_RENDER_LIMIT + 1, $this->getSession()->getPage()->findAll('xpath', '//div[@class="pirate"]')); } /** - * Tests node embedding node embedding original node. + * Tests circular embedding. */ - public function testEmbeddingParentAsChild() { + public function testCircularEmbedding() { $node1 = $this->drupalCreateNode([ 'type' => 'article', 'title' => "Grandpa", @@ -54,13 +58,13 @@ class RecursionProtectionTest extends EntityEmbedTestBase { ], ]); $node2->save(); - $content = '
Embedded Son
'; + $content = '
Embedded Son
'; $node1->set('body', [ 'value' => $content, 'format' => 'custom_format', ]); $node1->save(); - $content = '
Embedded Son who is own grandpa
'; + $content = '
Embedded Son who is own grandpa
'; $node2->set('body', [ 'value' => $content, 'format' => 'custom_format', @@ -68,13 +72,13 @@ class RecursionProtectionTest extends EntityEmbedTestBase { $node2->save(); $this->drupalGet('node/' . $node1->id()); $page = $this->getSession()->getPage(); - $this->assertEquals(20, count($page->findAll('xpath', '//div[@class="node-1-embed"]'))); - $this->assertEquals(21, count($page->findAll('xpath', '//div[@class="node-2-embed"]'))); + $this->assertCount(EntityEmbedFilter::RECURSIVE_RENDER_LIMIT, $page->findAll('xpath', '//div[@class="node-1-embed"]')); + $this->assertCount(EntityEmbedFilter::RECURSIVE_RENDER_LIMIT + 1, $page->findAll('xpath', '//div[@class="node-2-embed"]')); $this->drupalGet('node/' . $node2->id()); $page = $this->getSession()->getPage(); - $this->assertEquals(21, count($page->findAll('xpath', '//div[@class="node-1-embed"]'))); - $this->assertEquals(20, count($page->findAll('xpath', '//div[@class="node-2-embed"]'))); + $this->assertCount(EntityEmbedFilter::RECURSIVE_RENDER_LIMIT + 1, $page->findAll('xpath', '//div[@class="node-1-embed"]')); + $this->assertCount(EntityEmbedFilter::RECURSIVE_RENDER_LIMIT, $page->findAll('xpath', '//div[@class="node-2-embed"]')); } }