/** * Tests if file fields in teasers have correct resources. * * Ensure that file fields have the correct resource as the object in RDFa * when displayed as a teaser. */ function testNodeTeaser() { // Render the teaser. $node_render_array = entity_view_multiple(array($this->node), 'teaser'); $html = \Drupal::service('renderer')->renderRoot($node_render_array); // Parses front page where the node is displayed in its teaser form. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); $parser->parse($graph, $html, 'rdfa', $base_uri); $node_uri = $this->node->url('canonical', ['absolute' => TRUE]); $file_uri = file_create_url($this->file->getFileUri()); // Node relation to attached file. $expected_value = array('type' => 'uri', 'value' => $file_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $expected_value), 'Node to file relation found in RDF output (rdfs:seeAlso).'); $this->drupalGet('node'); }
/** * Tests that image fields in teasers have correct resources. */ function testNodeTeaser() { // Set the display options for the teaser. $display_options = array('type' => 'image', 'settings' => array('image_style' => 'medium', 'image_link' => 'content')); $display = entity_get_display('node', 'article', 'teaser'); $display->setComponent($this->fieldName, $display_options)->save(); // Render the teaser. $node_render_array = node_view($this->node, 'teaser'); $html = \Drupal::service('renderer')->renderRoot($node_render_array); // Parse the teaser. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = \Drupal::url('<front>', [], ['absolute' => TRUE]); $parser->parse($graph, $html, 'rdfa', $base_uri); // Construct the node and image URIs for testing. $node_uri = $this->node->url('canonical', ['absolute' => TRUE]); $image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri()); // Test relations from node to image. $expected_value = array('type' => 'uri', 'value' => $image_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).'); // Test image type. $expected_value = array('type' => 'uri', 'value' => 'http://xmlns.com/foaf/0.1/Image'); $this->assertTrue($graph->hasProperty($image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Image type found in RDF output (foaf:Image).'); }
/** * Tests output for properties held in common between articles and pages. * * @param \EasyRdf_Graph $graph * The EasyRDF graph object. * @param \Drupal\node\NodeInterface $node * The node being displayed. * @param string $message_prefix * The word to use in the test assertion message. */ protected function assertRdfaCommonNodeProperties($graph, NodeInterface $node, $message_prefix) { $uri = $node->url('canonical', array('absolute' => TRUE)); // Title. $expected_value = array('type' => 'literal', 'value' => $node->get('title')->value, 'lang' => 'en'); $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/name', $expected_value), "{$message_prefix} title was found (schema:name)."); // Created date. $expected_value = array('type' => 'literal', 'value' => format_date($node->get('created')->value, 'custom', 'c', 'UTC'), 'lang' => 'en'); $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/dateCreated', $expected_value), "{$message_prefix} created date was found (schema:dateCreated) in teaser."); // Body. $expected_value = array('type' => 'literal', 'value' => $node->get('body')->value, 'lang' => 'en'); $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/text', $expected_value), "{$message_prefix} body was found (schema:text) in teaser."); // Author. $expected_value = array('type' => 'uri', 'value' => $this->authorUri); $this->assertTrue($graph->hasProperty($uri, 'http://schema.org/author', $expected_value), "{$message_prefix} author was found (schema:author) in teaser."); // Author type. $this->assertEqual($graph->type($this->authorUri), 'schema:Person', "{$message_prefix} author type was found (schema:Person)."); // Author name. $expected_value = array('type' => 'literal', 'value' => $this->adminUser->label()); $this->assertTrue($graph->hasProperty($this->authorUri, 'http://schema.org/name', $expected_value), "{$message_prefix} author name was found (schema:name)."); }