'RDF mapping hook', 'description' => 'Test hook_rdf_mapping().', 'group' => 'RDF', ); } function setUp() { parent::setUp('rdf', 'rdf_test', 'field_test'); // We need to trigger rdf_modules_installed() because // hook_modules_installed() is not automatically invoked during testing. rdf_modules_installed(array('rdf_test')); } /** * Test that hook_rdf_mapping() correctly returns and processes mapping. */ function testMapping() { // Test that the mapping is returned correctly by the hook. $mapping = rdf_mapping_load('test_entity', 'test_bundle'); $this->assertIdentical($mapping['rdftype'], array('sioc:Post'), t('Mapping for rdftype is sioc:Post.')); $this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), t('Mapping for title is dc:title.')); $this->assertIdentical($mapping['created'], array( 'predicates' => array('dc:created'), 'datatype' => 'xsd:dateTime', 'callback' => 'date_iso8601', ), t('Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.')); $this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator')), t('Mapping for uid is sioc:has_creator and dc:creator.')); $mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping'); $this->assertEqual($mapping, array(), t('Empty array returned when an entity type, bundle pair has no mapping.')); } } class RdfMarkupTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'RDFa markup', 'description' => 'Test RDFa markup generation.', 'group' => 'RDF', ); } function setUp() { parent::setUp('rdf', 'field_test', 'rdf_test'); rdf_modules_installed(array('field_test', 'rdf_test')); } /** * Test rdf_rdfa_attributes(). */ function testDrupalRdfaAtributes() { $date = 1252750327; $isoDate = date('c', $date); $expected_type = 'xsd:dateTime'; $expected_property = array('dc:created'); $expected_value = $isoDate; $mapping = rdf_mapping_load('test_entity', 'test_bundle'); $attributes = rdf_rdfa_attributes($mapping['created'], $date); $this->assertEqual($expected_type, $attributes['datatype']); $this->assertEqual($expected_property, $attributes['property']); $this->assertEqual($expected_value, $attributes['content']); } } class RdfCrudTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'RDF mapping CRUD functions', 'description' => 'Test the RDF mapping CRUD functions.', 'group' => 'RDF', ); } function setUp() { parent::setUp('rdf', 'rdf_test'); } /** * Test inserting, loading, updating, and deleting RDF mappings. */ function testCRUD() { $test_mapping = rdf_test_rdf_mapping(); // Verify loading of a default mapping. $this->assertFalse(count(_rdf_mapping_load('test_entity', 'test_bundle')), t('Default mapping was found.')); // Verify saving a mapping. $mapping = (array) $test_mapping; rdf_mapping_save($mapping[0]); $this->assertEqual($mapping[0]['mapping'], $test_mapping[0]['mapping'], t('Saved mapping equals default mapping.')); $this->assertTrue(rdf_mapping_save($mapping[1]) === SAVED_NEW, t('Second mapping was inserted.')); $this->assertEqual($mapping[1]['mapping'], _rdf_mapping_load($test_mapping[1]['type'], $test_mapping[1]['bundle']), t('Second mapping equals default mapping.')); // Verify loading of saved mapping. $this->assertEqual($mapping[0]['mapping'], _rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Saved mapping equals loaded default mapping.')); // Verify updating of mapping. $mapping[0]['mapping']['boofar'] = array( 'predicates' => array('foo:bar'), ); $this->assertTrue(rdf_mapping_save($mapping[0]) === SAVED_UPDATED, t('Mapping was updated.')); $this->assertEqual($mapping[0]['mapping'], _rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Updated and loaded mapping are equal.')); // Verify deleting of mapping. $this->assertTrue(rdf_mapping_delete($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Mapping was deleted.')); $this->assertFalse(_rdf_mapping_load($test_mapping[0]['type'], $test_mapping[0]['bundle']), t('Deleted mapping is no longer found.')); } } class RdfMappingDefinitionTestCase extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'RDF mapping definition functionality', 'description' => 'Test the different types of RDF mappings and ensure the proper RDFa markup in included in node pages.', 'group' => 'RDF', ); } function setUp() { parent::setUp('rdf', 'rdf_test', 'blog'); // We need to trigger rdf_modules_installed() because // hook_modules_installed() is not automatically invoked during testing. rdf_modules_installed(array('rdf_test', 'node')); // entity_info caches must be cleared during testing. This is done // automatically during the manual installation. entity_info_cache_clear(); } /** * Create a node of type blog and test whether the RDF mapping defined for * this node type in rdf_test.module is used in the node page. */ function testAttributesInMarkup1() { $node = $this->drupalCreateNode(array('type' => 'blog')); $this->drupalGet('node/' . $node->nid); $this->assertRaw('typeof="sioct:Weblog"'); // Ensure the default bundle mapping for node is used. These attributes come // from the node default bundle definition. $this->assertRaw('property="dc:title"'); $this->assertRaw('property="dc:date dc:created"'); } /** * Create a content type and a node of type test_bundle_hook_install and test * whether the RDF mapping defined in rdf_test.install is used. */ function testAttributesInMarkup2() { $type = $this->drupalCreateContentType(array('type' => 'test_bundle_hook_install')); $node = $this->drupalCreateNode(array('type' => 'test_bundle_hook_install')); $this->drupalGet('node/' . $node->nid); $this->assertRaw('typeof="foo:mapping_install1 bar:mapping_install2"'); // Ensure the default bundle mapping for node is used. These attributes come // from the node default bundle definition. $this->assertRaw('property="dc:title"'); $this->assertRaw('property="dc:date dc:created"'); } /** * Create a random content type and node and ensure the default mapping for * node is used. */ function testAttributesInMarkup3() { $type = $this->drupalCreateContentType(); $node = $this->drupalCreateNode(array('type' => $type->type)); $this->drupalGet('node/' . $node->nid); $this->assertRaw('typeof="sioc:Item foaf:Document"'); // Ensure the default bundle mapping for node is used. These attributes come // from the node default bundle definition. $this->assertRaw('property="dc:title"'); $this->assertRaw('property="dc:date dc:created"'); } }