schemadotorg_experimental-1.0.x-dev/modules/schemadotorg_embedded_content/tests/src/Kernel/SchemaDotOrgEmbeddedContentJsonLdKernelTest.php
modules/schemadotorg_embedded_content/tests/src/Kernel/SchemaDotOrgEmbeddedContentJsonLdKernelTest.php
<?php
declare(strict_types=1);
namespace Drupal\Tests\schemadotorg_embedded_content\Kernel;
use Drupal\node\Entity\Node;
use Drupal\Tests\schemadotorg_jsonld\Kernel\SchemaDotOrgJsonLdKernelTestBase;
/**
* Tests the functionality of the Schema.org Embedded Content JSON-LD.
*
* @covers \Drupal\schemadotorg_embedded_content\Plugin\SchemaDotOrgEmbeddedContentBase
*
* @group schemadotorg
*/
class SchemaDotOrgEmbeddedContentJsonLdKernelTest extends SchemaDotOrgJsonLdKernelTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'sdc',
'embedded_content',
'schemadotorg_embedded_content',
'schemadotorg_embedded_content_test',
];
/**
* Test Schema.org Blueprints embedded content JSON-LD.
*/
public function testJsonLd(): void {
$this->createSchemaEntity('node', 'WebPage');
$node = Node::create([
'type' => 'page',
'title' => 'page',
'body' => [
'value' => '<embedded-content data-plugin-id="schemadotorg_thing" data-plugin-config="{"name":"Drupal.org","description":"Drupal is an open source platform for building amazing digital experiences. It\\\u0027s made by a dedicated community. Anyone can use it, and it will always be free.","url":"https:\/\/drupal.org"}"> </embedded-content>',
],
]);
$node->save();
/* ********************************************************************** */
// Check Thing JSON-LD.
$expected_result = [
'@context' => 'https://schema.org',
'@type' => 'Thing',
'name' => 'Drupal.org',
'description' => 'Drupal is an open source platform for building amazing digital experiences. It\\u0027s made by a dedicated community. Anyone can use it, and it will always be free.',
'url' => 'https://drupal.org',
];
$route_match = $this->manager->getEntityRouteMatch($node);
$this->assertEquals($expected_result, $this->builder->build($route_match));
// Check subtype Event JSON-LD.
$node->body->value = '<embedded-content data-plugin-id="schemadotorg_thing" data-plugin-config="{"subtype":"Event","name":"Drupal.org","description":"Drupal is an open source platform for building amazing digital experiences. It\\\u0027s made by a dedicated community. Anyone can use it, and it will always be free.","url":"https:\/\/drupal.org"}"> </embedded-content>';
$node->save();
$expected_result = [
'@context' => 'https://schema.org',
'@type' => 'Event',
'name' => 'Drupal.org',
'description' => 'Drupal is an open source platform for building amazing digital experiences. It\\u0027s made by a dedicated community. Anyone can use it, and it will always be free.',
'url' => 'https://drupal.org',
];
$route_match = $this->manager->getEntityRouteMatch($node);
$this->assertEquals($expected_result, $this->builder->build($route_match));
}
}
