View source
<?php
class RdfxNodeSerializationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF serialization for Nodes',
'description' => 'Create a node and test its RDF serialization.',
'group' => 'RDFx',
);
}
function setUp() {
parent::setUp('rdfx');
variable_set('field_storage_default', 'field_sql_storage');
$web_user = $this
->drupalCreateUser(array(
'create article content',
'create page content',
));
$this
->drupalLogin($web_user);
}
function testRdfxNodeCreation() {
$edit = array();
$langcode = LANGUAGE_NONE;
$edit["title"] = $this
->randomName(8);
$edit["body[{$langcode}][0][value]"] = $this
->randomName(16);
$this
->drupalPost('node/add/article', $edit, t('Save'));
$this
->assertRaw(t('!post %title has been created.', array(
'!post' => 'Article',
'%title' => $edit["title"],
)), t('Article created.'));
$node = $this
->drupalGetNodeByTitle($edit["title"]);
$this
->assertTrue($node, t('Node found in database.'));
$base_uri = url('', array(
'absolute' => TRUE,
));
$uri = url('node/' . $node->nid, array(
'absolute' => TRUE,
));
$g = rdfx_get_rdf_model('node', $node->nid);
$this
->assertTrue(get_class($g) == 'ARC2_Resource', t('Object is of type ARC2_Resource.'));
$this
->assertTrue($g->base == $base_uri, t('Base uri set properly by ARC2.'));
$this
->assertTrue($g->uri == $uri, t('Graph uri set properly by ARC2.'));
$erroneous_core_ns = FALSE;
foreach (rdf_rdf_namespaces() as $prefix => $ns) {
if (!isset($g->ns[$prefix]) || $g->ns[$prefix] != $ns) {
$erroneous_core_ns = TRUE;
}
}
$this
->assertFalse($erroneous_core_ns, t('Core RDF namespaces set properly by ARC2.'));
$o = array(
'value' => 'http://rdfs.org/sioc/ns#Item',
'type' => 'uri',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']), t('sioc:Item type found in ARC2 index.'));
$o = array(
'value' => 'http://xmlns.com/foaf/0.1/Document',
'type' => 'uri',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://www.w3.org/1999/02/22-rdf-syntax-ns#type']), t('foaf:Document type found in ARC2 index.'));
$o = array(
'value' => $node->title,
'type' => 'literal',
'datatype' => '',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/title']), t('dc:title value found in ARC2 index.'));
$o = array(
'value' => date_iso8601($node->created),
'type' => 'literal',
'datatype' => 'xsd:dateTime',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/date']), t('dc:date value found in ARC2 index.'));
$o = array(
'value' => date_iso8601($node->created),
'type' => 'literal',
'datatype' => 'xsd:dateTime',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://purl.org/dc/terms/created']), t('dc:created value found in ARC2 index.'));
$o = array(
'value' => $node->comment_count,
'type' => 'literal',
'datatype' => 'xsd:integer',
);
$this
->assertTrue(in_array($o, $g->index[$uri]['http://rdfs.org/sioc/ns#num_replies']), t('sioc:num_replies value found in ARC2 index.'));
}
}
class RdfxFeaturesIntegrationTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF Features integration',
'description' => 'Enables a feature and check whether the RDF mappings defined by the feature have been saved. (REQUIRES FEATURES)',
'group' => 'RDFx',
);
}
function setUp() {
parent::setUp('rdfx', 'features');
}
function testFeaturesEnable() {
$mappings = rdf_mapping_load('node', 'article');
$this
->assertTrue($mappings['rdftype'] == array(
'sioc:Item',
'foaf:Document',
), t('Initial RDF type set properly.'));
$this
->assertTrue($mappings['title']['predicates'] == array(
'dc:title',
), t('Initial property for title set properly.'));
$this
->assertTrue($mappings['field_tags']['predicates'] == array(
'dc:subject',
), t('Initial property for tags field set properly.'));
module_enable(array(
'rdfx_test',
));
features_revert(array(
'rdfx_test' => array(
'rdf_mappings',
),
));
$mappings = rdf_mapping_load('node', 'article');
$this
->assertTrue($mappings['rdftype'] == array(
'sioc:Post',
), t('sioc:num_replies value found in ARC2 index.'));
$this
->assertTrue($mappings['title']['predicates'] == array(
'rdfs:label',
), t('sioc:num_replies value found in ARC2 index.'));
$this
->assertTrue($mappings['field_tags']['predicates'] == array(
'dc:subject',
), t('Initial property for tags field set properly.'));
}
}