Commit 1af32393 authored by Dries's avatar Dries

Issue #1869914 by scor: Refactor RdfMappingDefinitionTestCase and split it in dedicated test cases.

parent 71364b1a
<?php
/**
* @file
* Contains Drupal\rdf\Tests\NodeAttributesTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\node\Tests\NodeTestBase;
/**
* Tests the RDFa markup of Nodes.
*/
class NodeAttributesTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf');
public static function getInfo() {
return array(
'name' => 'RDFa markup for nodes',
'description' => 'Tests the RDFa markup of nodes.',
'group' => 'RDF',
);
}
/**
* Creates a node of type article and tests its RDFa markup.
*/
function testNodeAttributes() {
$node = $this->drupalCreateNode(array('type' => 'article'));
$node_uri = url('node/' . $node->nid, array('absolute' => TRUE));
$base_uri = url('<front>', array('absolute' => TRUE));
// 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->nid), 'rdfa', $base_uri);
// Inspects RDF graph output.
// Node type.
$expected_value = array(
'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).');
// Node type.
$expected_value = array(
'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).');
// Node title.
$expected_value = array(
'type' => 'literal',
'value' => $node->title,
'lang' => 'en',
);
$this->assertTrue($graph->hasProperty($node_uri, 'http://purl.org/dc/terms/title', $expected_value), 'Node title found in RDF output (dc:title).');
// Node date.
$expected_value = array(
'type' => 'literal',
'value' => date('c', $node->created),
'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).');
// Node date.
$expected_value = array(
'type' => 'literal',
'value' => date('c', $node->created),
'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).');
}
}
<?php
/**
* @file
* Contains Drupal\rdf\Tests\TaxonomyAttributesTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
/**
* Tests the RDFa markup of Taxonomy terms.
*/
class TaxonomyAttributesTest extends TaxonomyTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('rdf');
public static function getInfo() {
return array(
'name' => 'RDFa markup for taxonomy terms',
'description' => 'Tests the RDFa markup of taxonomy terms.',
'group' => 'RDF',
);
}
/**
* Creates a random term and ensures the RDF output is correct.
*/
function testTaxonomyTermRdfaAttributes() {
$vocabulary = $this->createVocabulary();
$term = $this->createTerm($vocabulary);
$term_uri = url('taxonomy/term/' . $term->tid, array('absolute' => TRUE));
// 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('<front>', array('absolute' => TRUE));
$parser->parse($graph, $this->drupalGet('taxonomy/term/' . $term->tid), 'rdfa', $base_uri);
// Inspects RDF graph output.
// Term type.
$expected_value = array(
'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).');
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->label(),
'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).');
// Term label.
$expected_value = array(
'type' => 'literal',
'value' => $term->label(),
'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).');
}
}
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