Chris@0: container->get('entity.manager')->getStorage('node'); Chris@0: $this->fieldName = strtolower($this->randomMachineName()); Chris@0: Chris@0: $type_name = 'article'; Chris@0: $this->createFileField($this->fieldName, 'node', $type_name); Chris@0: Chris@0: // Set the teaser display to show this field. Chris@0: entity_get_display('node', 'article', 'teaser') Chris@0: ->setComponent($this->fieldName, ['type' => 'file_default']) Chris@0: ->save(); Chris@0: Chris@0: // Set the RDF mapping for the new field. Chris@0: $mapping = rdf_get_mapping('node', 'article'); Chris@0: $mapping->setFieldMapping($this->fieldName, ['properties' => ['rdfs:seeAlso'], 'mapping_type' => 'rel'])->save(); Chris@0: Chris@0: $test_file = $this->getTestFile('text'); Chris@0: Chris@0: // Create a new node with the uploaded file. Chris@0: $nid = $this->uploadNodeFile($test_file, $this->fieldName, $type_name); Chris@0: Chris@0: $node_storage->resetCache([$nid]); Chris@0: $this->node = $node_storage->load($nid); Chris@0: $this->file = File::load($this->node->{$this->fieldName}->target_id); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests if file fields in teasers have correct resources. Chris@0: * Chris@0: * Ensure that file fields have the correct resource as the object in RDFa Chris@0: * when displayed as a teaser. Chris@0: */ Chris@0: public function testNodeTeaser() { Chris@0: // Render the teaser. Chris@0: $node_render_array = entity_view_multiple([$this->node], 'teaser'); Chris@0: $html = \Drupal::service('renderer')->renderRoot($node_render_array); Chris@0: Chris@0: // Parses front page where the node is displayed in its teaser form. Chris@0: $parser = new \EasyRdf_Parser_Rdfa(); Chris@0: $graph = new \EasyRdf_Graph(); Chris@18: $base_uri = Url::fromRoute('', [], ['absolute' => TRUE])->toString(); Chris@0: $parser->parse($graph, $html, 'rdfa', $base_uri); Chris@0: Chris@18: $node_uri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString(); Chris@0: $file_uri = file_create_url($this->file->getFileUri()); Chris@0: Chris@0: // Node relation to attached file. Chris@0: $expected_value = [ Chris@0: 'type' => 'uri', Chris@0: 'value' => $file_uri, Chris@0: ]; Chris@0: $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).'); Chris@0: $this->drupalGet('node'); Chris@0: } Chris@0: Chris@0: }