/** * {@inheritdoc} */ public function preRender(&$values) { // Render all nodes, so you can grep the comment links. $entities = array(); foreach ($values as $row) { $entity = $row->_entity; $entities[$entity->id()] = $entity; } if ($entities) { $this->build = entity_view_multiple($entities, $this->options['teaser'] ? 'teaser' : 'full'); } }
/** * 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 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() { // Set the teaser display to show this field. entity_get_display('node', 'article', 'teaser')->setComponent($this->fieldName, array('type' => 'taxonomy_term_reference_link'))->save(); // Create a term in each vocabulary. $term1 = $this->createTerm($this->vocabulary); $term2 = $this->createTerm($this->vocabulary); $taxonomy_term_1_uri = url('taxonomy/term/' . $term1->id(), array('absolute' => TRUE)); $taxonomy_term_2_uri = url('taxonomy/term/' . $term2->id(), array('absolute' => TRUE)); // Create the node. $node = $this->drupalCreateNode(array('type' => 'article')); $node->set($this->fieldName, array(array('target_id' => $term1->id()), array('target_id' => $term2->id()))); // Render the node. $node_render_array = entity_view_multiple(array($node), 'teaser'); $html = drupal_render($node_render_array); // Parse the teaser. $parser = new \EasyRdf_Parser_Rdfa(); $graph = new \EasyRdf_Graph(); $base_uri = url('<front>', array('absolute' => TRUE)); $parser->parse($graph, $html, 'rdfa', $base_uri); // Node relations to taxonomy terms. $node_uri = url('node/' . $node->id(), array('absolute' => TRUE)); $expected_value = array('type' => 'uri', 'value' => $taxonomy_term_1_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/subject', $expected_value), 'Node to term relation found in RDF output (dc:subject).'); $expected_value = array('type' => 'uri', 'value' => $taxonomy_term_2_uri); $this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/subject', $expected_value), 'Node to term relation found in RDF output (dc:subject).'); // Taxonomy terms triples. // Term 1. $expected_value = array('type' => 'uri', 'value' => 'http://www.w3.org/2004/02/skos/core#Concept'); // @todo enable with https://drupal.org/node/2072791 //$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).'); $expected_value = array('type' => 'literal', 'value' => $term1->getName()); //$this->assertTrue($graph->hasProperty($taxonomy_term_1_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).'); // Term 2. $expected_value = array('type' => 'uri', 'value' => 'http://www.w3.org/2004/02/skos/core#Concept'); //$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Taxonomy term type found in RDF output (skos:Concept).'); $expected_value = array('type' => 'literal', 'value' => $term2->getName()); //$this->assertTrue($graph->hasProperty($taxonomy_term_2_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Taxonomy term name found in RDF output (rdfs:label).'); }