Chris@16: fieldName = 'field_image'; Chris@16: Chris@16: // Create the image field. Chris@16: $this->createImageField($this->fieldName, 'article'); Chris@16: Chris@16: // Set the RDF mapping for the new field. Chris@16: rdf_get_mapping('node', 'article') Chris@16: ->setFieldMapping($this->fieldName, [ Chris@16: 'properties' => ['og:image'], Chris@16: 'mapping_type' => 'rel', Chris@16: ]) Chris@16: ->setBundleMapping(['types' => []]) Chris@16: ->save(); Chris@16: Chris@16: // Get the test image that simpletest provides. Chris@16: $image = current($this->drupalGetTestFiles('image')); Chris@16: Chris@16: // Save a node with the image. Chris@16: $nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName()); Chris@16: $this->node = Node::load($nid); Chris@16: $this->file = File::load($this->node->{$this->fieldName}->target_id); Chris@16: } Chris@16: Chris@16: /** Chris@16: * Tests that image fields in teasers have correct resources. Chris@16: */ Chris@16: public function testNodeTeaser() { Chris@16: // Set the display options for the teaser. Chris@16: $display_options = [ Chris@16: 'type' => 'image', Chris@16: 'settings' => ['image_style' => 'medium', 'image_link' => 'content'], Chris@16: ]; Chris@16: $display = entity_get_display('node', 'article', 'teaser'); Chris@16: $display->setComponent($this->fieldName, $display_options) Chris@16: ->save(); Chris@16: Chris@16: // Render the teaser. Chris@16: $node_render_array = node_view($this->node, 'teaser'); Chris@16: $html = \Drupal::service('renderer')->renderRoot($node_render_array); Chris@16: Chris@16: // Parse the teaser. Chris@16: $parser = new \EasyRdf_Parser_Rdfa(); Chris@16: $graph = new \EasyRdf_Graph(); Chris@18: $base_uri = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); Chris@16: $parser->parse($graph, $html, 'rdfa', $base_uri); Chris@16: Chris@16: // Construct the node and image URIs for testing. Chris@18: $node_uri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString(); Chris@16: $image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri()); Chris@16: Chris@16: // Test relations from node to image. Chris@16: $expected_value = [ Chris@16: 'type' => 'uri', Chris@16: 'value' => $image_uri, Chris@16: ]; Chris@16: $this->assertTrue($graph->hasProperty($node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).'); Chris@16: Chris@16: // Test image type. Chris@16: $expected_value = [ Chris@16: 'type' => 'uri', Chris@16: 'value' => 'http://xmlns.com/foaf/0.1/Image', Chris@16: ]; Chris@16: $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).'); Chris@16: } Chris@16: Chris@16: }