Commit 1fa5a193 authored by catch's avatar catch

Issue #3090017 by amjad1233, larowlan, alexpott, mondrake, andypost: Isolate...

Issue #3090017 by amjad1233, larowlan, alexpott, mondrake, andypost: Isolate test dependency on easyrdf/easyrdf to a single trait
parent f1abfd2d
......@@ -4,6 +4,7 @@
use Drupal\Core\Url;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
/**
......@@ -13,6 +14,8 @@
*/
class EntityReferenceFieldAttributesTest extends TaxonomyTestBase {
use RdfParsingTrait;
/**
* Modules to enable.
*
......@@ -25,6 +28,13 @@ class EntityReferenceFieldAttributesTest extends TaxonomyTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
/**
* The name of the taxonomy term reference field used in the test.
*
......@@ -78,6 +88,9 @@ protected function setUp() {
->setBundleMapping(['types' => ['skos:Concept']])
->setFieldMapping('name', ['properties' => ['rdfs:label']])
->save();
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -112,24 +125,18 @@ public function testNodeTeaser() {
->view($node, 'teaser');
$html = \Drupal::service('renderer')->renderRoot($node_render_array);
// Parse the teaser.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $html, 'rdfa', $base_uri);
// Node relations to taxonomy terms.
$node_uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString();
$expected_value = [
'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).');
$this->assertTrue($this->hasRdfProperty($html, $this->baseUri, $node_uri, 'http://purl.org/dc/terms/subject', $expected_value), 'Node to term relation found in RDF output (dc:subject).');
$expected_value = [
'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).');
$this->assertTrue($this->hasRdfProperty($html, $this->baseUri, $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 = [
......
......@@ -5,6 +5,7 @@
use Drupal\Core\Url;
use Drupal\Tests\file\Functional\FileFieldTestBase;
use Drupal\file\Entity\File;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
/**
* Tests the RDFa markup of filefields.
......@@ -13,6 +14,8 @@
*/
class FileFieldAttributesTest extends FileFieldTestBase {
use RdfParsingTrait;
/**
* Modules to enable.
*
......@@ -25,6 +28,13 @@ class FileFieldAttributesTest extends FileFieldTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
/**
* The name of the file field used in the test.
*
......@@ -72,6 +82,9 @@ protected function setUp() {
$node_storage->resetCache([$nid]);
$this->node = $node_storage->load($nid);
$this->file = File::load($this->node->{$this->fieldName}->target_id);
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -87,12 +100,6 @@ public function testNodeTeaser() {
->view($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 = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $html, 'rdfa', $base_uri);
$node_uri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString();
$file_uri = file_create_url($this->file->getFileUri());
......@@ -101,7 +108,7 @@ public function testNodeTeaser() {
'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->assertTrue($this->hasRdfProperty($html, $this->baseUri, $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');
}
......
......@@ -7,6 +7,7 @@
use Drupal\Tests\image\Functional\ImageFieldTestBase;
use Drupal\node\Entity\Node;
use Drupal\file\Entity\File;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
use Drupal\Tests\TestFileCreationTrait;
/**
......@@ -16,6 +17,8 @@
*/
class ImageFieldAttributesTest extends ImageFieldTestBase {
use RdfParsingTrait;
use TestFileCreationTrait {
getTestFiles as drupalGetTestFiles;
}
......@@ -32,6 +35,13 @@ class ImageFieldAttributesTest extends ImageFieldTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
/**
* The name of the image field used in the test.
*
......@@ -77,6 +87,9 @@ protected function setUp() {
$nid = $this->uploadNodeImage($image, $this->fieldName, 'article', $this->randomMachineName());
$this->node = Node::load($nid);
$this->file = File::load($this->node->{$this->fieldName}->target_id);
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -99,12 +112,6 @@ public function testNodeTeaser() {
->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 = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $html, 'rdfa', $base_uri);
// Construct the node and image URIs for testing.
$node_uri = $this->node->toUrl('canonical', ['absolute' => TRUE])->toString();
$image_uri = ImageStyle::load('medium')->buildUrl($this->file->getFileUri());
......@@ -114,14 +121,14 @@ public function testNodeTeaser() {
'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).');
$this->assertTrue($this->hasRdfProperty($html, $this->baseUri, $node_uri, 'http://ogp.me/ns#image', $expected_value), 'Node to file relation found in RDF output (og:image).');
// Test image type.
$expected_value = [
'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).');
$this->assertTrue($this->hasRdfProperty($html, $this->baseUri, $image_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
}
}
......@@ -4,6 +4,7 @@
use Drupal\Core\Url;
use Drupal\Tests\node\Functional\NodeTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
/**
* Tests the RDFa markup of Nodes.
......@@ -12,6 +13,8 @@
*/
class NodeAttributesTest extends NodeTestBase {
use RdfParsingTrait;
/**
* Modules to enable.
*
......@@ -24,6 +27,13 @@ class NodeAttributesTest extends NodeTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
protected function setUp() {
parent::setUp();
......@@ -40,6 +50,8 @@ protected function setUp() {
'datatype_callback' => ['callable' => 'Drupal\rdf\CommonDataConverter::dateIso8601Value'],
])
->save();
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -52,49 +64,43 @@ public function testNodeAttributes() {
'type' => 'article',
'title' => $this->randomMachineName(8) . "'",
]);
$node_uri = $node->toUrl('canonical', ['absolute' => TRUE])->toString();
$base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
// Parses front page where the node is displayed in its teaser form.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
$this->drupalGet($node->toUrl());
// Inspects RDF graph output.
// Node type.
$expected_value = [
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#Item',
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (sioc:Item).');
// Node type.
$expected_value = [
'type' => 'uri',
'value' => 'http://xmlns.com/foaf/0.1/Document',
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $node_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Node type found in RDF output (foaf:Document).');
// Node title.
$expected_value = [
'type' => 'literal',
'value' => $node->getTitle(),
'lang' => 'en',
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
// Node date (date format must be UTC).
$expected_value = [
'type' => 'literal',
'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $node_uri, 'http://purl.org/dc/terms/date', $expected_value), 'Node date found in RDF output (dc:date).');
// Node date (date format must be UTC).
$expected_value = [
'type' => 'literal',
'value' => \Drupal::service('date.formatter')->format($node->getCreatedTime(), 'custom', 'c', 'UTC'),
'datatype' => 'http://www.w3.org/2001/XMLSchema#dateTime',
];
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $node_uri, 'http://purl.org/dc/terms/created', $expected_value), 'Node date found in RDF output (dc:created).');
}
}
......@@ -4,6 +4,7 @@
use Drupal\Core\Url;
use Drupal\Tests\taxonomy\Functional\TaxonomyTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
/**
* Tests the RDFa markup of Taxonomy terms.
......@@ -12,6 +13,8 @@
*/
class TaxonomyAttributesTest extends TaxonomyTestBase {
use RdfParsingTrait;
/**
* Modules to enable.
*
......@@ -24,6 +27,13 @@ class TaxonomyAttributesTest extends TaxonomyTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
/**
* Vocabulary created for testing purposes.
*
......@@ -43,6 +53,9 @@ protected function setUp() {
'properties' => ['rdfs:label', 'skos:prefLabel'],
])
->save();
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -52,11 +65,8 @@ public function testTaxonomyTermRdfaAttributes() {
$term = $this->createTerm($this->vocabulary);
$term_uri = $term->toUrl('canonical', ['absolute' => TRUE])->toString();
// Parses the term's page and checks that the RDF output is correct.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->id()), 'rdfa', $base_uri);
$this->drupalGet('taxonomy/term/' . $term->id());
$this->drupalGet($term->toUrl());
// Inspects RDF graph output.
// Term type.
......@@ -64,21 +74,22 @@ public function testTaxonomyTermRdfaAttributes() {
'type' => 'uri',
'value' => 'http://www.w3.org/2004/02/skos/core#Concept',
];
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'Term type found in RDF output (skos:Concept).');
// Term label.
$expected_value = [
'type' => 'literal',
'value' => $term->getName(),
'lang' => 'en',
];
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/2000/01/rdf-schema#label', $expected_value), 'Term label found in RDF output (rdfs:label).');
// Term label.
$expected_value = [
'type' => 'literal',
'value' => $term->getName(),
'lang' => 'en',
];
$this->assertTrue($graph->hasProperty($term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $term_uri, 'http://www.w3.org/2004/02/skos/core#prefLabel', $expected_value), 'Term label found in RDF output (skos:prefLabel).');
// @todo Add test for term description once it is a field:
// https://www.drupal.org/node/569434.
......
......@@ -4,6 +4,7 @@
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
/**
* Tests the RDFa markup of Users.
......@@ -12,6 +13,8 @@
*/
class UserAttributesTest extends BrowserTestBase {
use RdfParsingTrait;
/**
* Modules to enable.
*
......@@ -24,6 +27,13 @@ class UserAttributesTest extends BrowserTestBase {
*/
protected $defaultTheme = 'stark';
/**
* URI of the front page of the Drupal site.
*
* @var string
*/
protected $baseUri;
protected function setUp() {
parent::setUp();
rdf_get_mapping('user', 'user')
......@@ -34,6 +44,9 @@ protected function setUp() {
'properties' => ['foaf:name'],
])
->save();
// Prepares commonly used URIs.
$this->baseUri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
}
/**
......@@ -61,13 +74,7 @@ public function testUserAttributesInMarkup() {
/** @var \Drupal\user\UserInterface[] $authors */
foreach ($authors as $author) {
$account_uri = $author->toUrl('canonical', ['absolute' => TRUE])->toString();
// Parses the user profile page where the default bundle mapping for user
// should be used.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $this->drupalGet('user/' . $author->id()), 'rdfa', $base_uri);
$this->drupalGet('user/' . $author->id());
// Inspects RDF graph output.
// User type.
......@@ -75,24 +82,20 @@ public function testUserAttributesInMarkup() {
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
// User name.
$expected_value = [
'type' => 'literal',
'value' => $author->getAccountName(),
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
// User creates a node.
$this->drupalLogin($author);
$node = $this->drupalCreateNode(['type' => 'article', 'promote' => 1]);
$this->drupalLogin($user1);
// Parses the node created by the user.
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$base_uri = Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString();
$parser->parse($graph, $this->drupalGet('node/' . $node->id()), 'rdfa', $base_uri);
$this->drupalGet('node/' . $node->id());
// Ensures the default bundle mapping for user is used on the Authored By
// information on the node.
......@@ -100,14 +103,14 @@ public function testUserAttributesInMarkup() {
'type' => 'uri',
'value' => 'http://rdfs.org/sioc/ns#UserAccount',
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', $expected_value), 'User type found in RDF output (sioc:UserAccount).');
// User name.
$expected_value = [
'type' => 'literal',
'value' => $author->getAccountName(),
];
$this->assertTrue($graph->hasProperty($account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
$this->assertTrue($this->hasRdfProperty($this->getSession()->getPage()->getContent(), $this->baseUri, $account_uri, 'http://xmlns.com/foaf/0.1/name', $expected_value), 'User name found in RDF output (foaf:name).');
}
}
......
......@@ -5,9 +5,12 @@
use Drupal\field\Entity\FieldConfig;
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Tests\rdf\Traits\RdfParsingTrait;
abstract class FieldRdfaTestBase extends FieldKernelTestBase {
use RdfParsingTrait;
/**
* The machine name of the field type to test.
*
......@@ -95,17 +98,8 @@ protected function assertFormatterRdfa($formatter, $property, $expected_rdf_valu
->getViewBuilder($this->entity->getEntityTypeId())
->view($this->entity, 'default');
$output = \Drupal::service('renderer')->renderRoot($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
$this->setRawContent($output);
// If verbose debugging is turned on, display the HTML and parsed RDF
// in the results.
if ($this->debug) {
print_r($output);
print_r($graph->toRdfPhp());
}
$this->assertTrue($graph->hasProperty($this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
$this->assertTrue($this->hasRdfProperty($output, $this->uri, $this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
}
/**
......
<?php
namespace Drupal\Tests\rdf\Traits;
use Drupal\Core\Url;
/**
* Defines a trait for parsing RDF properties from HTML.
*/
trait RdfParsingTrait {
/**
* Checks if a html document contains a resource with a given property value.
*
* @param string $html
* The HTML to parse.
* @param string $base_uri
* The base URI for the html being parsed.
* @param string $resource
* The URI of the resource which should have the given property.
* @param string $property
* The property being tested.
* @param array $value
* The expected value. This should include the following keys:
* - type: one of literal, uri and bnode
* - value: the expected value
* - datatype: the expected datatype in URI format - e.g.
* - http://www.w3.org/2001/XMLSchema#integer
* - http://www.w3.org/2001/XMLSchema#dateTime
* - lang: language code of the property.
*
* @return bool
* TRUE if the property exists with the given value.
*/
protected function hasRdfProperty($html, $base_uri, $resource, $property, array $value) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $html, 'rdfa', $base_uri);
return $graph->hasProperty($resource, $property, $value);
}
/**
* Checks if a html document contains a resource with a given property value.
*
* @param string $html
* The HTML to parse.
* @param string $base_uri
* The base URI for the html being parsed.
* @param string $resource
* The URI of the resource which should have the given property.
* @param string $parent_property
* The parent property being tested.
* @param string $child_property
* The child property being tested.
* @param array $value
* The expected value. This should include the following keys:
* - type: one of literal, uri and bnode
* - value: the expected value
* - datatype: the expected datatype in URI format - e.g.
* - http://www.w3.org/2001/XMLSchema#integer
* - http://www.w3.org/2001/XMLSchema#dateTime
* - lang: language code of the property.
*
* @return bool
* TRUE if the property exists with the given value.
*/
protected function hasRdfChildProperty($html, $base_uri, $resource, $parent_property, string $child_property, array $value) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $html, 'rdfa', $base_uri);
$node = $graph->get($resource, $parent_property);
return $graph->hasProperty($node, $child_property, $value);
}
/**
* Counts the number of resources of the provided type.
*
* @param \Drupal\Core\Url $url
* URL of the document.
* @param string $base_uri
* The base URI for the html being parsed.
* @param string $type
* Type of resource to count.
*
* @return int
* The number of resources of the provided type.
*/
protected function getElementByRdfTypeCount(Url $url, $base_uri, $type) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $this->drupalGet($url), 'rdfa', $base_uri);
return count($graph->allOfType($type));
}
/**
* Gets type of RDF Element.
*
* @param \Drupal\Core\Url $url
* URL of the document.
* @param string $base_uri
* The base URI for the html being parsed.
* @param string $resource_uri
* The URI of the resource from where to get element.
*
* @return string|null
* The type of resource or NULL if the resource has no type.
*/
protected function getElementRdfType(Url $url, $base_uri, $resource_uri) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $this->drupalGet($url), 'rdfa', $base_uri);
return $graph->type($resource_uri);
}
/**
* Checks if RDF Node property is blank.
*
* @param string $html
* The HTML to parse.
* @param string $base_uri
* The base URI for the html being parsed.
* @param string $resource_uri
* The URI of the resource which should have the given property.
* @param string $property
* The property being tested.
*
* @return bool
* TRUE if the given property is blank.
*/
protected function rdfElementIsBlankNode($html, $base_uri, $resource_uri, $property) {
$parser = new \EasyRdf_Parser_Rdfa();
$graph = new \EasyRdf_Graph();
$parser->parse($graph, $html, 'rdfa', $base_uri);
return $graph->get($resource_uri, $property)->isBnode();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment