danielebarchiesi@0: 'RDF mapping hook', danielebarchiesi@0: 'description' => 'Test hook_rdf_mapping().', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'rdf_test', 'field_test'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test that hook_rdf_mapping() correctly returns and processes mapping. danielebarchiesi@0: */ danielebarchiesi@0: function testMapping() { danielebarchiesi@0: // Test that the mapping is returned correctly by the hook. danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $this->assertIdentical($mapping['rdftype'], array('sioc:Post'), 'Mapping for rdftype is sioc:Post.'); danielebarchiesi@0: $this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), 'Mapping for title is dc:title.'); danielebarchiesi@0: $this->assertIdentical($mapping['created'], array( danielebarchiesi@0: 'predicates' => array('dc:created'), danielebarchiesi@0: 'datatype' => 'xsd:dateTime', danielebarchiesi@0: 'callback' => 'date_iso8601', danielebarchiesi@0: ), t('Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.')); danielebarchiesi@0: $this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), 'Mapping for uid is sioc:has_creator and dc:creator, and type is rel.'); danielebarchiesi@0: danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping'); danielebarchiesi@0: $this->assertEqual($mapping, array(), 'Empty array returned when an entity type, bundle pair has no mapping.'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test RDFa markup generation. danielebarchiesi@0: */ danielebarchiesi@0: class RdfRdfaMarkupTestCase extends DrupalWebTestCase { danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDFa markup', danielebarchiesi@0: 'description' => 'Test RDFa markup generation.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'field_test', 'rdf_test'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test rdf_rdfa_attributes(). danielebarchiesi@0: */ danielebarchiesi@0: function testDrupalRdfaAttributes() { danielebarchiesi@0: // Same value as the one in the HTML tag (no callback function). danielebarchiesi@0: $expected_attributes = array( danielebarchiesi@0: 'property' => array('dc:title'), danielebarchiesi@0: ); danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $attributes = rdf_rdfa_attributes($mapping['title']); danielebarchiesi@0: ksort($expected_attributes); danielebarchiesi@0: ksort($attributes); danielebarchiesi@0: $this->assertEqual($expected_attributes, $attributes); danielebarchiesi@0: danielebarchiesi@0: // Value different from the one in the HTML tag (callback function). danielebarchiesi@0: $date = 1252750327; danielebarchiesi@0: $isoDate = date('c', $date); danielebarchiesi@0: $expected_attributes = array( danielebarchiesi@0: 'datatype' => 'xsd:dateTime', danielebarchiesi@0: 'property' => array('dc:created'), danielebarchiesi@0: 'content' => $isoDate, danielebarchiesi@0: ); danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $attributes = rdf_rdfa_attributes($mapping['created'], $date); danielebarchiesi@0: ksort($expected_attributes); danielebarchiesi@0: ksort($attributes); danielebarchiesi@0: $this->assertEqual($expected_attributes, $attributes); danielebarchiesi@0: danielebarchiesi@0: // Same value as the one in the HTML tag with datatype. danielebarchiesi@0: $expected_attributes = array( danielebarchiesi@0: 'datatype' => 'foo:bar1type', danielebarchiesi@0: 'property' => array('foo:bar1'), danielebarchiesi@0: ); danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $attributes = rdf_rdfa_attributes($mapping['foobar1']); danielebarchiesi@0: ksort($expected_attributes); danielebarchiesi@0: ksort($attributes); danielebarchiesi@0: $this->assertEqual($expected_attributes, $attributes); danielebarchiesi@0: danielebarchiesi@0: // ObjectProperty mapping (rel). danielebarchiesi@0: $expected_attributes = array( danielebarchiesi@0: 'rel' => array('sioc:has_creator', 'dc:creator'), danielebarchiesi@0: ); danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']); danielebarchiesi@0: ksort($expected_attributes); danielebarchiesi@0: ksort($attributes); danielebarchiesi@0: $this->assertEqual($expected_attributes, $attributes); danielebarchiesi@0: danielebarchiesi@0: // Inverse ObjectProperty mapping (rev). danielebarchiesi@0: $expected_attributes = array( danielebarchiesi@0: 'rev' => array('sioc:reply_of'), danielebarchiesi@0: ); danielebarchiesi@0: $mapping = rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']); danielebarchiesi@0: ksort($expected_attributes); danielebarchiesi@0: ksort($attributes); danielebarchiesi@0: $this->assertEqual($expected_attributes, $attributes); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Ensure that file fields have the correct resource as the object in RDFa danielebarchiesi@0: * when displayed as a teaser. danielebarchiesi@0: */ danielebarchiesi@0: function testAttributesInMarkupFile() { danielebarchiesi@0: // Create a user to post the image. danielebarchiesi@0: $admin_user = $this->drupalCreateUser(array('edit own article content', 'revert revisions', 'administer content types')); danielebarchiesi@0: $this->drupalLogin($admin_user); danielebarchiesi@0: danielebarchiesi@0: $langcode = LANGUAGE_NONE; danielebarchiesi@0: $bundle_name = "article"; danielebarchiesi@0: danielebarchiesi@0: $field_name = 'file_test'; danielebarchiesi@0: $field = array( danielebarchiesi@0: 'field_name' => $field_name, danielebarchiesi@0: 'type' => 'file', danielebarchiesi@0: ); danielebarchiesi@0: field_create_field($field); danielebarchiesi@0: $instance = array( danielebarchiesi@0: 'field_name' => $field_name, danielebarchiesi@0: 'entity_type' => 'node', danielebarchiesi@0: 'bundle' => $bundle_name, danielebarchiesi@0: 'display' => array( danielebarchiesi@0: 'teaser' => array( danielebarchiesi@0: 'type' => 'file_default', danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: field_create_instance($instance); danielebarchiesi@0: danielebarchiesi@0: // Set the RDF mapping for the new field. danielebarchiesi@0: $rdf_mapping = rdf_mapping_load('node', $bundle_name); danielebarchiesi@0: $rdf_mapping += array($field_name => array('predicates' => array('rdfs:seeAlso'), 'type' => 'rel')); danielebarchiesi@0: $rdf_mapping_save = array('mapping' => $rdf_mapping, 'type' => 'node', 'bundle' => $bundle_name); danielebarchiesi@0: rdf_mapping_save($rdf_mapping_save); danielebarchiesi@0: danielebarchiesi@0: // Get the test file that simpletest provides. danielebarchiesi@0: $file = current($this->drupalGetTestFiles('text')); danielebarchiesi@0: danielebarchiesi@0: // Prepare image variables. danielebarchiesi@0: $image_field = "field_image"; danielebarchiesi@0: // Get the test image that simpletest provides. danielebarchiesi@0: $image = current($this->drupalGetTestFiles('image')); danielebarchiesi@0: danielebarchiesi@0: // Create an array for drupalPost with the field names as the keys and danielebarchiesi@0: // the URIs for the test files as the values. danielebarchiesi@0: $edit = array("files[" . $field_name . "_" . $langcode . "_0]" => drupal_realpath($file->uri), danielebarchiesi@0: "files[" . $image_field . "_" . $langcode . "_0]" => drupal_realpath($image->uri)); danielebarchiesi@0: danielebarchiesi@0: // Create node and save, then edit node to upload files. danielebarchiesi@0: $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); danielebarchiesi@0: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@0: danielebarchiesi@0: // Get filenames and nid for comparison with HTML output. danielebarchiesi@0: $file_filename = $file->filename; danielebarchiesi@0: $image_filename = $image->filename; danielebarchiesi@0: $nid = $node->nid; danielebarchiesi@0: // Navigate to front page, where node is displayed in teaser form. danielebarchiesi@0: $this->drupalGet('node'); danielebarchiesi@0: danielebarchiesi@0: // We only check to make sure that the resource attribute contains '.txt' danielebarchiesi@0: // instead of the full file name because the filename is altered on upload. danielebarchiesi@0: $file_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, ".txt")]', array( danielebarchiesi@0: ':node-uri' => 'node/' . $nid, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($file_rel), "Attribute 'rel' set on file field. Attribute 'resource' is also set."); danielebarchiesi@0: $image_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, :image)]//img[contains(@typeof, "foaf:Image")]', array( danielebarchiesi@0: ':node-uri' => 'node/' . $nid, danielebarchiesi@0: ':image' => $image_filename, danielebarchiesi@0: )); danielebarchiesi@0: danielebarchiesi@0: $this->assertTrue(!empty($image_rel), "Attribute 'rel' set on image field. Attribute 'resource' is also set."); danielebarchiesi@0: danielebarchiesi@0: // Edits the node to add tags. danielebarchiesi@0: $tag1 = $this->randomName(8); danielebarchiesi@0: $tag2 = $this->randomName(8); danielebarchiesi@0: $edit = array(); danielebarchiesi@0: $edit['field_tags[' . LANGUAGE_NONE . ']'] = "$tag1, $tag2"; danielebarchiesi@0: $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); danielebarchiesi@0: // Ensures the RDFa markup for the relationship between the node and its danielebarchiesi@0: // tags is correct. danielebarchiesi@0: $term_rdfa_meta = $this->xpath('//div[@about=:node-url and contains(@typeof, "sioc:Item") and contains(@typeof, "foaf:Document")]//ul[@class="links"]/li[@rel="dc:subject"]/a[@typeof="skos:Concept" and @datatype="" and text()=:term-name]', array( danielebarchiesi@0: ':node-url' => url('node/' . $node->nid), danielebarchiesi@0: ':term-name' => $tag1, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag1 field item.'); danielebarchiesi@0: $term_rdfa_meta = $this->xpath('//div[@about=:node-url and contains(@typeof, "sioc:Item") and contains(@typeof, "foaf:Document")]//ul[@class="links"]/li[@rel="dc:subject"]/a[@typeof="skos:Concept" and @datatype="" and text()=:term-name]', array( danielebarchiesi@0: ':node-url' => url('node/' . $node->nid), danielebarchiesi@0: ':term-name' => $tag2, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($term_rdfa_meta), 'Property dc:subject is present for the tag2 field item.'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: class RdfCrudTestCase extends DrupalWebTestCase { danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDF mapping CRUD functions', danielebarchiesi@0: 'description' => 'Test the RDF mapping CRUD functions.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'rdf_test'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test inserting, loading, updating, and deleting RDF mappings. danielebarchiesi@0: */ danielebarchiesi@0: function testCRUD() { danielebarchiesi@0: // Verify loading of a default mapping. danielebarchiesi@0: $mapping = _rdf_mapping_load('test_entity', 'test_bundle'); danielebarchiesi@0: $this->assertTrue(count($mapping), 'Default mapping was found.'); danielebarchiesi@0: danielebarchiesi@0: // Verify saving a mapping. danielebarchiesi@0: $mapping = array( danielebarchiesi@0: 'type' => 'crud_test_entity', danielebarchiesi@0: 'bundle' => 'crud_test_bundle', danielebarchiesi@0: 'mapping' => array( danielebarchiesi@0: 'rdftype' => array('sioc:Post'), danielebarchiesi@0: 'title' => array( danielebarchiesi@0: 'predicates' => array('dc:title'), danielebarchiesi@0: ), danielebarchiesi@0: 'uid' => array( danielebarchiesi@0: 'predicates' => array('sioc:has_creator', 'dc:creator'), danielebarchiesi@0: 'type' => 'rel', danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: $this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, 'Mapping was saved.'); danielebarchiesi@0: danielebarchiesi@0: // Read the raw record from the {rdf_mapping} table. danielebarchiesi@0: $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle'])); danielebarchiesi@0: $stored_mapping = $result->fetchAssoc(); danielebarchiesi@0: $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']); danielebarchiesi@0: $this->assertEqual($mapping, $stored_mapping, 'Mapping was stored properly in the {rdf_mapping} table.'); danielebarchiesi@0: danielebarchiesi@0: // Verify loading of saved mapping. danielebarchiesi@0: $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.'); danielebarchiesi@0: danielebarchiesi@0: // Verify updating of mapping. danielebarchiesi@0: $mapping['mapping']['title'] = array( danielebarchiesi@0: 'predicates' => array('dc2:bar2'), danielebarchiesi@0: ); danielebarchiesi@0: $this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, 'Mapping was updated.'); danielebarchiesi@0: danielebarchiesi@0: // Read the raw record from the {rdf_mapping} table. danielebarchiesi@0: $result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle'])); danielebarchiesi@0: $stored_mapping = $result->fetchAssoc(); danielebarchiesi@0: $stored_mapping['mapping'] = unserialize($stored_mapping['mapping']); danielebarchiesi@0: $this->assertEqual($mapping, $stored_mapping, 'Updated mapping was stored properly in the {rdf_mapping} table.'); danielebarchiesi@0: danielebarchiesi@0: // Verify loading of saved mapping. danielebarchiesi@0: $this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Saved mapping loaded successfully.'); danielebarchiesi@0: danielebarchiesi@0: // Verify deleting of mapping. danielebarchiesi@0: $this->assertTrue(rdf_mapping_delete($mapping['type'], $mapping['bundle']), 'Mapping was deleted.'); danielebarchiesi@0: $this->assertFalse(_rdf_mapping_load($mapping['type'], $mapping['bundle']), 'Deleted mapping is no longer found in the database.'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: class RdfMappingDefinitionTestCase extends TaxonomyWebTestCase { danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDF mapping definition functionality', danielebarchiesi@0: 'description' => 'Test the different types of RDF mappings and ensure the proper RDFa markup in included in nodes and user profile pages.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'rdf_test', 'blog'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create a node of type blog and test whether the RDF mapping defined for danielebarchiesi@0: * this node type in rdf_test.module is used in the node page. danielebarchiesi@0: */ danielebarchiesi@0: function testAttributesInMarkup1() { danielebarchiesi@0: $node = $this->drupalCreateNode(array('type' => 'blog')); danielebarchiesi@0: $isoDate = date('c', $node->changed); danielebarchiesi@0: $url = url('node/' . $node->nid); danielebarchiesi@0: $this->drupalGet('node/' . $node->nid); danielebarchiesi@0: danielebarchiesi@0: // Ensure the default bundle mapping for node is used. These attributes come danielebarchiesi@0: // from the node default bundle definition. danielebarchiesi@0: $blog_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']"); danielebarchiesi@0: $blog_meta = $this->xpath("//div[(@about='$url') and (@typeof='sioct:Weblog')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']"); danielebarchiesi@0: $this->assertTrue(!empty($blog_title), 'Property dc:title is present in meta tag.'); danielebarchiesi@0: $this->assertTrue(!empty($blog_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create a content type and a node of type test_bundle_hook_install and test danielebarchiesi@0: * whether the RDF mapping defined in rdf_test.install is used. danielebarchiesi@0: */ danielebarchiesi@0: function testAttributesInMarkup2() { danielebarchiesi@0: $type = $this->drupalCreateContentType(array('type' => 'test_bundle_hook_install')); danielebarchiesi@0: $node = $this->drupalCreateNode(array('type' => 'test_bundle_hook_install')); danielebarchiesi@0: $isoDate = date('c', $node->changed); danielebarchiesi@0: $url = url('node/' . $node->nid); danielebarchiesi@0: $this->drupalGet('node/' . $node->nid); danielebarchiesi@0: danielebarchiesi@0: // Ensure the mapping defined in rdf_module.test is used. danielebarchiesi@0: $test_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']"); danielebarchiesi@0: $test_bundle_meta = $this->xpath("//div[(@about='$url') and contains(@typeof, 'foo:mapping_install1') and contains(@typeof, 'bar:mapping_install2')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']"); danielebarchiesi@0: $this->assertTrue(!empty($test_bundle_title), 'Property dc:title is present in meta tag.'); danielebarchiesi@0: $this->assertTrue(!empty($test_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create a random content type and node and ensure the default mapping for danielebarchiesi@0: * node is used. danielebarchiesi@0: */ danielebarchiesi@0: function testAttributesInMarkup3() { danielebarchiesi@0: $type = $this->drupalCreateContentType(); danielebarchiesi@0: $node = $this->drupalCreateNode(array('type' => $type->type)); danielebarchiesi@0: $isoDate = date('c', $node->changed); danielebarchiesi@0: $url = url('node/' . $node->nid); danielebarchiesi@0: $this->drupalGet('node/' . $node->nid); danielebarchiesi@0: danielebarchiesi@0: // Ensure the default bundle mapping for node is used. These attributes come danielebarchiesi@0: // from the node default bundle definition. danielebarchiesi@0: $random_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']"); danielebarchiesi@0: $random_bundle_meta = $this->xpath("//div[(@about='$url') and contains(@typeof, 'sioc:Item') and contains(@typeof, 'foaf:Document')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']"); danielebarchiesi@0: $this->assertTrue(!empty($random_bundle_title), 'Property dc:title is present in meta tag.'); danielebarchiesi@0: $this->assertTrue(!empty($random_bundle_meta), 'RDF type is present on post. Properties dc:date and dc:created are present on post date.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create a random user and ensure the default mapping for user is used. danielebarchiesi@0: */ danielebarchiesi@0: function testUserAttributesInMarkup() { danielebarchiesi@0: // Create two users, one with access to user profiles. danielebarchiesi@0: $user1 = $this->drupalCreateUser(array('access user profiles')); danielebarchiesi@0: $user2 = $this->drupalCreateUser(); danielebarchiesi@0: $username = $user2->name; danielebarchiesi@0: $this->drupalLogin($user1); danielebarchiesi@0: // Browse to the user profile page. danielebarchiesi@0: $this->drupalGet('user/' . $user2->uid); danielebarchiesi@0: // Ensure the default bundle mapping for user is used on the user profile danielebarchiesi@0: // page. These attributes come from the user default bundle definition. danielebarchiesi@0: $account_uri = url('user/' . $user2->uid); danielebarchiesi@0: $person_uri = url('user/' . $user2->uid, array('fragment' => 'me')); danielebarchiesi@0: danielebarchiesi@0: $user2_profile_about = $this->xpath('//div[@class="profile" and @typeof="sioc:UserAccount" and @about=:account-uri]', array( danielebarchiesi@0: ':account-uri' => $account_uri, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($user2_profile_about), 'RDFa markup found on user profile page'); danielebarchiesi@0: danielebarchiesi@0: $user_account_holder = $this->xpath('//meta[contains(@typeof, "foaf:Person") and @about=:person-uri and @resource=:account-uri and contains(@rel, "foaf:account")]', array( danielebarchiesi@0: ':person-uri' => $person_uri, danielebarchiesi@0: ':account-uri' => $account_uri, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($user_account_holder), 'URI created for account holder and username set on sioc:UserAccount.'); danielebarchiesi@0: danielebarchiesi@0: $user_username = $this->xpath('//meta[@about=:account-uri and contains(@property, "foaf:name") and @content=:username]', array( danielebarchiesi@0: ':account-uri' => $account_uri, danielebarchiesi@0: ':username' => $username, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($user_username), 'foaf:name set on username.'); danielebarchiesi@0: danielebarchiesi@0: // User 2 creates node. danielebarchiesi@0: $this->drupalLogin($user2); danielebarchiesi@0: $node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); danielebarchiesi@0: $this->drupalLogin($user1); danielebarchiesi@0: $this->drupalGet('node/' . $node->nid); danielebarchiesi@0: // Ensures the default bundle mapping for user is used on the Authored By danielebarchiesi@0: // information on the node. danielebarchiesi@0: $author_about = $this->xpath('//a[@typeof="sioc:UserAccount" and @about=:account-uri and @property="foaf:name" and @datatype="" and contains(@xml:lang, "")]', array( danielebarchiesi@0: ':account-uri' => $account_uri, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($author_about), 'RDFa markup found on author information on post. xml:lang on username is set to empty string.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Creates a random term and ensures the right RDFa markup is used. danielebarchiesi@0: */ danielebarchiesi@0: function testTaxonomyTermRdfaAttributes() { danielebarchiesi@0: $vocabulary = $this->createVocabulary(); danielebarchiesi@0: $term = $this->createTerm($vocabulary); danielebarchiesi@0: danielebarchiesi@0: // Views the term and checks that the RDFa markup is correct. danielebarchiesi@0: $this->drupalGet('taxonomy/term/' . $term->tid); danielebarchiesi@0: $term_url = url('taxonomy/term/' . $term->tid); danielebarchiesi@0: $term_name = $term->name; danielebarchiesi@0: $term_rdfa_meta = $this->xpath('//meta[@typeof="skos:Concept" and @about=:term-url and contains(@property, "rdfs:label") and contains(@property, "skos:prefLabel") and @content=:term-name]', array( danielebarchiesi@0: ':term-url' => $term_url, danielebarchiesi@0: ':term-name' => $term_name, danielebarchiesi@0: )); danielebarchiesi@0: $this->assertTrue(!empty($term_rdfa_meta), 'RDFa markup found on term page.'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: class RdfCommentAttributesTestCase extends CommentHelperCase { danielebarchiesi@0: danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDF comment mapping', danielebarchiesi@0: 'description' => 'Tests the RDFa markup of comments.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: public function setUp() { danielebarchiesi@0: parent::setUp('comment', 'rdf', 'rdf_test'); danielebarchiesi@0: danielebarchiesi@0: $this->admin_user = $this->drupalCreateUser(array('administer content types', 'administer comments', 'administer permissions', 'administer blocks')); danielebarchiesi@0: $this->web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'create article content', 'access user profiles')); danielebarchiesi@0: danielebarchiesi@0: // Enables anonymous user comments. danielebarchiesi@0: user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( danielebarchiesi@0: 'access comments' => TRUE, danielebarchiesi@0: 'post comments' => TRUE, danielebarchiesi@0: 'skip comment approval' => TRUE, danielebarchiesi@0: )); danielebarchiesi@0: // Allows anonymous to leave their contact information. danielebarchiesi@0: $this->setCommentAnonymous(COMMENT_ANONYMOUS_MAY_CONTACT); danielebarchiesi@0: $this->setCommentPreview(DRUPAL_OPTIONAL); danielebarchiesi@0: $this->setCommentForm(TRUE); danielebarchiesi@0: $this->setCommentSubject(TRUE); danielebarchiesi@0: $this->setCommentSettings('comment_default_mode', COMMENT_MODE_THREADED, t('Comment paging changed.')); danielebarchiesi@0: danielebarchiesi@0: // Creates the nodes on which the test comments will be posted. danielebarchiesi@0: $this->drupalLogin($this->web_user); danielebarchiesi@0: $this->node1 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); danielebarchiesi@0: $this->node2 = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1)); danielebarchiesi@0: $this->drupalLogout(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Tests the presence of the RDFa markup for the number of comments. danielebarchiesi@0: */ danielebarchiesi@0: public function testNumberOfCommentsRdfaMarkup() { danielebarchiesi@0: // Posts 2 comments as a registered user. danielebarchiesi@0: $this->drupalLogin($this->web_user); danielebarchiesi@0: $this->postComment($this->node1, $this->randomName(), $this->randomName()); danielebarchiesi@0: $this->postComment($this->node1, $this->randomName(), $this->randomName()); danielebarchiesi@0: danielebarchiesi@0: // Tests number of comments in teaser view. danielebarchiesi@0: $this->drupalGet('node'); danielebarchiesi@0: $comment_count_teaser = $this->xpath('//div[contains(@typeof, "sioc:Item")]//li[contains(@class, "comment-comments")]/a[contains(@property, "sioc:num_replies") and contains(@content, "2") and @datatype="xsd:integer"]'); danielebarchiesi@0: $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on teaser view.'); danielebarchiesi@0: $comment_count_link = $this->xpath('//div[@about=:url]//a[contains(@property, "sioc:num_replies") and @rel=""]', array(':url' => url("node/{$this->node1->nid}"))); danielebarchiesi@0: $this->assertTrue(!empty($comment_count_link), 'Empty rel attribute found in comment count link.'); danielebarchiesi@0: danielebarchiesi@0: // Tests number of comments in full node view. danielebarchiesi@0: $this->drupalGet('node/' . $this->node1->nid); danielebarchiesi@0: $node_url = url('node/' . $this->node1->nid); danielebarchiesi@0: $comment_count_teaser = $this->xpath('/html/head/meta[@about=:node-url and @property="sioc:num_replies" and @content="2" and @datatype="xsd:integer"]', array(':node-url' => $node_url)); danielebarchiesi@0: $this->assertTrue(!empty($comment_count_teaser), 'RDFa markup for the number of comments found on full node view.'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Tests the presence of the RDFa markup for the title, date and author and danielebarchiesi@0: * homepage on registered users and anonymous comments. danielebarchiesi@0: */ danielebarchiesi@0: public function testCommentRdfaMarkup() { danielebarchiesi@0: danielebarchiesi@0: // Posts comment #1 as a registered user. danielebarchiesi@0: $this->drupalLogin($this->web_user); danielebarchiesi@0: $comment1_subject = $this->randomName(); danielebarchiesi@0: $comment1_body = $this->randomName(); danielebarchiesi@0: $comment1 = $this->postComment($this->node1, $comment1_body, $comment1_subject); danielebarchiesi@0: danielebarchiesi@0: // Tests comment #1 with access to the user profile. danielebarchiesi@0: $this->drupalGet('node/' . $this->node1->nid); danielebarchiesi@0: $this->_testBasicCommentRdfaMarkup($comment1); danielebarchiesi@0: danielebarchiesi@0: // Tests comment #1 with no access to the user profile (as anonymous user). danielebarchiesi@0: $this->drupalLogout(); danielebarchiesi@0: $this->drupalGet('node/' . $this->node1->nid); danielebarchiesi@0: $this->_testBasicCommentRdfaMarkup($comment1); danielebarchiesi@0: danielebarchiesi@0: // Posts comment #2 as anonymous user. danielebarchiesi@0: $comment2_subject = $this->randomName(); danielebarchiesi@0: $comment2_body = $this->randomName(); danielebarchiesi@0: $anonymous_user = array(); danielebarchiesi@0: $anonymous_user['name'] = $this->randomName(); danielebarchiesi@0: $anonymous_user['mail'] = 'tester@simpletest.org'; danielebarchiesi@0: $anonymous_user['homepage'] = 'http://example.org/'; danielebarchiesi@0: $comment2 = $this->postComment($this->node2, $comment2_body, $comment2_subject, $anonymous_user); danielebarchiesi@0: $this->drupalGet('node/' . $this->node2->nid); danielebarchiesi@0: danielebarchiesi@0: // Tests comment #2 as anonymous user. danielebarchiesi@0: $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user); danielebarchiesi@0: // Tests the RDFa markup for the homepage (specific to anonymous comments). danielebarchiesi@0: $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype="" and @href="http://example.org/" and contains(@rel, "foaf:page")]'); danielebarchiesi@0: $this->assertTrue(!empty($comment_homepage), 'RDFa markup for the homepage of anonymous user found.'); danielebarchiesi@0: // There should be no about attribute on anonymous comments. danielebarchiesi@0: $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]'); danielebarchiesi@0: $this->assertTrue(empty($comment_homepage), 'No about attribute is present on anonymous user comment.'); danielebarchiesi@0: danielebarchiesi@0: // Tests comment #2 as logged in user. danielebarchiesi@0: $this->drupalLogin($this->web_user); danielebarchiesi@0: $this->drupalGet('node/' . $this->node2->nid); danielebarchiesi@0: $this->_testBasicCommentRdfaMarkup($comment2, $anonymous_user); danielebarchiesi@0: // Tests the RDFa markup for the homepage (specific to anonymous comments). danielebarchiesi@0: $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype="" and @href="http://example.org/" and contains(@rel, "foaf:page")]'); danielebarchiesi@0: $this->assertTrue(!empty($comment_homepage), "RDFa markup for the homepage of anonymous user found."); danielebarchiesi@0: // There should be no about attribute on anonymous comments. danielebarchiesi@0: $comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]'); danielebarchiesi@0: $this->assertTrue(empty($comment_homepage), "No about attribute is present on anonymous user comment."); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test RDF comment replies. danielebarchiesi@0: */ danielebarchiesi@0: public function testCommentReplyOfRdfaMarkup() { danielebarchiesi@0: // Posts comment #1 as a registered user. danielebarchiesi@0: $this->drupalLogin($this->web_user); danielebarchiesi@0: $comments[] = $this->postComment($this->node1, $this->randomName(), $this->randomName()); danielebarchiesi@0: danielebarchiesi@0: // Tests the reply_of relationship of a first level comment. danielebarchiesi@0: $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}"))); danielebarchiesi@0: $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.'); danielebarchiesi@0: $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=1]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1'))); danielebarchiesi@0: $this->assertFalse($result, 'No RDFa markup referring to the comment itself is present.'); danielebarchiesi@0: danielebarchiesi@0: // Posts a reply to the first comment. danielebarchiesi@0: $this->drupalGet('comment/reply/' . $this->node1->nid . '/' . $comments[0]->id); danielebarchiesi@0: $comments[] = $this->postComment(NULL, $this->randomName(), $this->randomName(), TRUE); danielebarchiesi@0: danielebarchiesi@0: // Tests the reply_of relationship of a second level comment. danielebarchiesi@0: $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}"))); danielebarchiesi@0: $this->assertEqual(1, count($result), 'RDFa markup referring to the node is present.'); danielebarchiesi@0: $result = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1', array('fragment' => 'comment-1')))); danielebarchiesi@0: $this->assertEqual(1, count($result), 'RDFa markup referring to the parent comment is present.'); danielebarchiesi@0: $comments = $this->xpath("(id('comments')//div[contains(@class,'comment ')])[position()=2]"); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Helper function for testCommentRdfaMarkup(). danielebarchiesi@0: * danielebarchiesi@0: * Tests the current page for basic comment RDFa markup. danielebarchiesi@0: * danielebarchiesi@0: * @param $comment danielebarchiesi@0: * Comment object. danielebarchiesi@0: * @param $account danielebarchiesi@0: * An array containing information about an anonymous user. danielebarchiesi@0: */ danielebarchiesi@0: function _testBasicCommentRdfaMarkup($comment, $account = array()) { danielebarchiesi@0: $comment_container = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]'); danielebarchiesi@0: $this->assertTrue(!empty($comment_container), "Comment RDF type for comment found."); danielebarchiesi@0: $comment_title = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//h3[@property="dc:title"]'); danielebarchiesi@0: $this->assertEqual((string)$comment_title[0]->a, $comment->subject, "RDFa markup for the comment title found."); danielebarchiesi@0: $comment_date = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//*[contains(@property, "dc:date") and contains(@property, "dc:created")]'); danielebarchiesi@0: $this->assertTrue(!empty($comment_date), "RDFa markup for the date of the comment found."); danielebarchiesi@0: // The author tag can be either a or span danielebarchiesi@0: $comment_author = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/*[contains(@class, "username") and @typeof="sioc:UserAccount" and @property="foaf:name" and @datatype=""]'); danielebarchiesi@0: $name = empty($account["name"]) ? $this->web_user->name : $account["name"] . " (not verified)"; danielebarchiesi@0: $this->assertEqual((string)$comment_author[0], $name, "RDFa markup for the comment author found."); danielebarchiesi@0: $comment_body = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//div[@class="content"]//div[contains(@class, "comment-body")]//div[@property="content:encoded"]'); danielebarchiesi@0: $this->assertEqual((string)$comment_body[0]->p, $comment->comment, "RDFa markup for the comment body found."); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: class RdfTrackerAttributesTestCase extends DrupalWebTestCase { danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDF tracker page mapping', danielebarchiesi@0: 'description' => 'Test the mapping for the tracker page and ensure the proper RDFa markup in included.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'rdf_test', 'tracker'); danielebarchiesi@0: // Enable anonymous posting of content. danielebarchiesi@0: user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array( danielebarchiesi@0: 'create article content' => TRUE, danielebarchiesi@0: 'access comments' => TRUE, danielebarchiesi@0: 'post comments' => TRUE, danielebarchiesi@0: 'skip comment approval' => TRUE, danielebarchiesi@0: )); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Create nodes as both admin and anonymous user and test for correct RDFa danielebarchiesi@0: * markup on the tracker page for those nodes and their comments. danielebarchiesi@0: */ danielebarchiesi@0: function testAttributesInTracker() { danielebarchiesi@0: // Create node as anonymous user. danielebarchiesi@0: $node_anon = $this->drupalCreateNode(array('type' => 'article', 'uid' => 0)); danielebarchiesi@0: // Create node as admin user. danielebarchiesi@0: $node_admin = $this->drupalCreateNode(array('type' => 'article', 'uid' => 1)); danielebarchiesi@0: danielebarchiesi@0: // Pass both the anonymously posted node and the administrator posted node danielebarchiesi@0: // through to test for the RDF attributes. danielebarchiesi@0: $this->_testBasicTrackerRdfaMarkup($node_anon); danielebarchiesi@0: $this->_testBasicTrackerRdfaMarkup($node_admin); danielebarchiesi@0: danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Helper function for testAttributesInTracker(). danielebarchiesi@0: * danielebarchiesi@0: * Tests the tracker page for RDFa markup. danielebarchiesi@0: * danielebarchiesi@0: * @param $node danielebarchiesi@0: * The node just created. danielebarchiesi@0: */ danielebarchiesi@0: function _testBasicTrackerRdfaMarkup($node) { danielebarchiesi@0: $url = url('node/' . $node->nid); danielebarchiesi@0: danielebarchiesi@0: $user = ($node->uid == 0) ? 'Anonymous user' : 'Registered user'; danielebarchiesi@0: danielebarchiesi@0: // Navigate to tracker page. danielebarchiesi@0: $this->drupalGet('tracker'); danielebarchiesi@0: danielebarchiesi@0: // Tests whether the about property is applied. This is implicit in the danielebarchiesi@0: // success of the following tests, but making it explicit will make danielebarchiesi@0: // debugging easier in case of failure. danielebarchiesi@0: $tracker_about = $this->xpath('//tr[@about=:url]', array(':url' => $url)); danielebarchiesi@0: $this->assertTrue(!empty($tracker_about), format_string('About attribute found on table row for @user content.', array('@user'=> $user))); danielebarchiesi@0: danielebarchiesi@0: // Tests whether the title has the correct property attribute. danielebarchiesi@0: $tracker_title = $this->xpath('//tr[@about=:url]/td[@property="dc:title" and @datatype=""]', array(':url' => $url)); danielebarchiesi@0: $this->assertTrue(!empty($tracker_title), format_string('Title property attribute found on @user content.', array('@user'=> $user))); danielebarchiesi@0: danielebarchiesi@0: // Tests whether the relationship between the content and user has been set. danielebarchiesi@0: $tracker_user = $this->xpath('//tr[@about=:url]//td[contains(@rel, "sioc:has_creator")]//*[contains(@typeof, "sioc:UserAccount") and contains(@property, "foaf:name")]', array(':url' => $url)); danielebarchiesi@0: $this->assertTrue(!empty($tracker_user), format_string('Typeof and name property attributes found on @user.', array('@user'=> $user))); danielebarchiesi@0: // There should be an about attribute on logged in users and no about danielebarchiesi@0: // attribute for anonymous users. danielebarchiesi@0: $tracker_user = $this->xpath('//tr[@about=:url]//td[@rel="sioc:has_creator"]/*[@about]', array(':url' => $url)); danielebarchiesi@0: if ($node->uid == 0) { danielebarchiesi@0: $this->assertTrue(empty($tracker_user), format_string('No about attribute is present on @user.', array('@user'=> $user))); danielebarchiesi@0: } danielebarchiesi@0: elseif ($node->uid > 0) { danielebarchiesi@0: $this->assertTrue(!empty($tracker_user), format_string('About attribute is present on @user.', array('@user'=> $user))); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Tests whether the property has been set for number of comments. danielebarchiesi@0: $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "0") and @datatype="xsd:integer"]', array(':url' => $url)); danielebarchiesi@0: $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user))); danielebarchiesi@0: danielebarchiesi@0: // Tests that the appropriate RDFa markup to annotate the latest activity danielebarchiesi@0: // date has been added to the tracker output before comments have been danielebarchiesi@0: // posted, meaning the latest activity reflects changes to the node itself. danielebarchiesi@0: $isoDate = date('c', $node->changed); danielebarchiesi@0: $tracker_activity = $this->xpath('//tr[@about=:url]//td[contains(@property, "dc:modified") and contains(@property, "sioc:last_activity_date") and contains(@datatype, "xsd:dateTime") and @content=:date]', array(':url' => $url, ':date' => $isoDate)); danielebarchiesi@0: $this->assertTrue(!empty($tracker_activity), format_string('Latest activity date and changed properties found when there are no comments on @user content. Latest activity date content is correct.', array('@user'=> $user))); danielebarchiesi@0: danielebarchiesi@0: // Tests that the appropriate RDFa markup to annotate the latest activity danielebarchiesi@0: // date has been added to the tracker output after a comment is posted. danielebarchiesi@0: $comment = array( danielebarchiesi@0: 'subject' => $this->randomName(), danielebarchiesi@0: 'comment_body[' . LANGUAGE_NONE . '][0][value]' => $this->randomName(), danielebarchiesi@0: ); danielebarchiesi@0: $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); danielebarchiesi@0: $this->drupalGet('tracker'); danielebarchiesi@0: danielebarchiesi@0: // Tests whether the property has been set for number of comments. danielebarchiesi@0: $tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "1") and @datatype="xsd:integer"]', array(':url' => $url)); danielebarchiesi@0: $this->assertTrue($tracker_replies, format_string('Num replies property and content attributes found on @user content.', array('@user'=> $user))); danielebarchiesi@0: danielebarchiesi@0: // Need to query database directly to obtain last_activity_date because danielebarchiesi@0: // it cannot be accessed via node_load(). danielebarchiesi@0: $result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid)); danielebarchiesi@0: foreach ($result as $node) { danielebarchiesi@0: $expected_last_activity_date = $node->changed; danielebarchiesi@0: } danielebarchiesi@0: $isoDate = date('c', $expected_last_activity_date); danielebarchiesi@0: $tracker_activity = $this->xpath('//tr[@about=:url]//td[@property="sioc:last_activity_date" and @datatype="xsd:dateTime" and @content=:date]', array(':url' => $url, ':date' => $isoDate)); danielebarchiesi@0: $this->assertTrue(!empty($tracker_activity), format_string('Latest activity date found when there are comments on @user content. Latest activity date content is correct.', array('@user'=> $user))); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Tests for RDF namespaces declaration with hook_rdf_namespaces(). danielebarchiesi@0: */ danielebarchiesi@0: class RdfGetRdfNamespacesTestCase extends DrupalWebTestCase { danielebarchiesi@0: public static function getInfo() { danielebarchiesi@0: return array( danielebarchiesi@0: 'name' => 'RDF namespaces', danielebarchiesi@0: 'description' => 'Test hook_rdf_namespaces() and ensure only "safe" namespaces are returned.', danielebarchiesi@0: 'group' => 'RDF', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function setUp() { danielebarchiesi@0: parent::setUp('rdf', 'rdf_test'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Test getting RDF namesapces. danielebarchiesi@0: */ danielebarchiesi@0: function testGetRdfNamespaces() { danielebarchiesi@0: // Get all RDF namespaces. danielebarchiesi@0: $ns = rdf_get_namespaces(); danielebarchiesi@0: danielebarchiesi@0: $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.'); danielebarchiesi@0: $this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'); danielebarchiesi@0: $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.'); danielebarchiesi@0: $this->assertTrue(!isset($ns['dc']), 'A prefix with conflicting namespaces is discarded.'); danielebarchiesi@0: } danielebarchiesi@0: }