You are here

function RdfxNodeSerializationTestCase::testRdfxNodeCreation in RDF Extensions 7.2

Create a "Article" node and ensure it serialized properly.

File

./rdfx.test, line 52

Class

RdfxNodeSerializationTestCase
Test the RDF serialization functionality for nodes.

Code

function testRdfxNodeCreation() {

  // Create a node.
  $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'));

  // Check that the Article has been created.
  $this
    ->assertRaw(t('!post %title has been created.', array(
    '!post' => 'Article',
    '%title' => $edit["title"],
  )), t('Article created.'));

  // Check that the node exists in the database.
  $node = $this
    ->drupalGetNodeByTitle($edit["title"]);
  $this
    ->assertTrue($node, t('Node found in database.'));

  // Expected base URI and graph URI.
  $base_uri = url('', array(
    'absolute' => TRUE,
  ));
  $uri = url('node/' . $node->nid, array(
    'absolute' => TRUE,
  ));

  // Get the node as RDF.
  $g = rdfx_get_rdf_model('node', $node->nid);

  // Inspect the PHP object returned by ARC2.
  // Test object class.
  $this
    ->assertTrue(get_class($g) == 'ARC2_Resource', t('Object is of type ARC2_Resource.'));

  // Test base uri.
  $this
    ->assertTrue($g->base == $base_uri, t('Base uri set properly by ARC2.'));

  // Test graph uri.
  $this
    ->assertTrue($g->uri == $uri, t('Graph uri set properly by ARC2.'));

  // Test if core rdf namespaces are present.
  // @todo move this into a dedicate test for namespaces.
  $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.'));

  // Test RDF types in ARC2 RDF index.
  $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.'));

  // Test title in ARC2 RDF 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.'));

  // Test date in ARC2 RDF 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.'));

  // Test comment_count in ARC2 RDF 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.'));
}