X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fentity_embed%2Fsrc%2FTests%2FEntityEmbedFilterTest.php;fp=web%2Fmodules%2Fcontrib%2Fentity_embed%2Fsrc%2FTests%2FEntityEmbedFilterTest.php;h=594ff953bfe3513793176a4d0e05efb2a89b9dae;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/modules/contrib/entity_embed/src/Tests/EntityEmbedFilterTest.php b/web/modules/contrib/entity_embed/src/Tests/EntityEmbedFilterTest.php new file mode 100644 index 000000000..594ff953b --- /dev/null +++ b/web/modules/contrib/entity_embed/src/Tests/EntityEmbedFilterTest.php @@ -0,0 +1,198 @@ +node->id() . '" data-view-mode="teaser">This placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test entity embed with entity-id and view-mode'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertText($this->node->body->value, 'Embedded node exists in page'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
', 'Embed container found.'); + + // Tests that embedded entity is not rendered if not accessible. + $this->node->setPublished(FALSE)->save(); + $settings = []; + $settings['type'] = 'page'; + $settings['title'] = 'Test un-accessible entity embed with entity-id and view-mode'; + $settings['body'] = [['value' => $content, 'format' => 'custom_format']]; + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertNoText($this->node->body->value, 'Embedded node does not exist in the page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + // Tests that embedded entity is displayed to the user who has the view + // unpublished content permission. + $this->createRole(['view own unpublished content'], 'access_unpublished'); + $this->webUser->addRole('access_unpublished'); + $this->webUser->save(); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertText($this->node->body->value, 'Embedded node exists in the page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
', 'Embed container found.'); + $this->webUser->removeRole('access_unpublished'); + $this->webUser->save(); + $this->node->setPublished(TRUE)->save(); + + // Tests entity embed using entity UUID and view mode. + $content = 'This placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test entity embed with entity-uuid and view-mode'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertText($this->node->body->value, 'Embedded node exists in page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
', 'Embed container found.'); + $this->assertCacheTag('foo:' . $this->node->id()); + + // Ensure that placeholder is not replaced when embed is unsuccessful. + $content = 'This placeholder should be rendered since specified entity does not exists.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test that placeholder is retained when specified entity does not exists'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is unsuccessful.'); + + // Ensure that UUID is preferred over ID when both attributes are present. + $sample_node = $this->drupalCreateNode(); + $content = 'This placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test that entity-uuid is preferred over entity-id when both attributes are present'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertNoRaw('assertText($this->node->body->value, 'Entity specifed with UUID exists in the page.'); + $this->assertNoText($sample_node->body->value, 'Entity specifed with ID does not exists in the page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
node->uuid() . '" data-entity-embed-display="default" data-entity-embed-display-settings=\'{"view_mode":"teaser"}\'>This placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test entity embed with entity-embed-display and data-entity-embed-display-settings'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertText($this->node->body->value, 'Embedded node exists in page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
node->uuid() . '" data-entity-embed-display="default" data-entity-embed-display-settings=\'{"view_mode":"full"}\' data-view-mode="some-invalid-view-mode" data-align="left" data-caption="test caption">This placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'Test entity embed with entity-embed-display and data-entity-embed-display-settings'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertText($this->node->body->value, 'Embedded node exists in page with the view mode specified by entity-embed-settings.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('
drupalGet('node/' . $this->node->id()); + $this->assertNoRaw('data-align="left"', 'Align data attribute not found.'); + $this->assertNoRaw('data-caption="test caption"', 'Caption data attribute not found.'); + + // Test that tag of container element is not replaced when it's not + // . + $content = 'this placeholder should not be rendered.'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'test entity embed with entity-id and view-mode'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalget('node/' . $node->id()); + $this->assertNoText($this->node->body->value, 'embedded node exists in page'); + $this->assertRaw(''); + $content = '
this placeholder should not be rendered.
'; + $settings = array(); + $settings['type'] = 'page'; + $settings['title'] = 'test entity embed with entity-id and view-mode'; + $settings['body'] = array(array('value' => $content, 'format' => 'custom_format')); + $node = $this->drupalCreateNode($settings); + $this->drupalget('node/' . $node->id()); + $this->assertNoText($this->node->body->value, 'embedded node exists in page'); + $this->assertRaw('
getTestFile('image'); + $image->setPermanent(); + $image->save(); + $content = 'This placeholder should not be rendered.'; + $settings = []; + $settings['type'] = 'page'; + $settings['title'] = 'test entity image formatter'; + $settings['body'] = [['value' => $content, 'format' => 'custom_format']]; + $node = $this->drupalCreateNode($settings); + $this->drupalget('node/' . $node->id()); + $this->assertRaw('assertRaw('data-caption="test caption"', 'Caption found.'); + $this->assertRaw('data-align="left"', 'Alignment information found.'); + $this->assertTrue((bool) $this->xpath("//img[@alt='This is alt text']"), 'Alt text found'); + $this->assertTrue((bool) $this->xpath("//img[@title='This is title text']"), 'Title text found'); + $this->assertRaw('
node->uuid() . '" data-entity-embed-display="entity_reference:entity_reference_label" data-entity-embed-settings=\'{"link":"0"}\' data-align="left" data-caption="test caption">This placeholder should not be rendered.'; + $settings = []; + $settings['type'] = 'page'; + $settings['title'] = 'Test entity embed with data-entity-embed-settings'; + $settings['body'] = [['value' => $content, 'format' => 'custom_format']]; + $node = $this->drupalCreateNode($settings); + $this->drupalGet('node/' . $node->id()); + $this->assertText($this->node->getTitle(), 'Embeded node title is displayed.'); + $this->assertNoLink($this->node->getTitle(), 'Embed settings are respected.'); + $this->assertNoText($this->node->body->value, 'Embedded node exists in page.'); + $this->assertNoText(strip_tags($content), 'Placeholder does not appear in the output when embed is successful.'); + $this->assertRaw('