$this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), t('Mapping for uid is sioc:has_creator and dc:creator, and type is rel.'));
$this->assertTrue(rdf_mapping_save($mapping) === SAVED_NEW, t('Mapping was saved.'));
// Read the raw record from the {rdf_mapping} table.
$result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
$this->assertTrue(rdf_mapping_save($mapping) === SAVED_UPDATED, t('Mapping was updated.'));
// Read the raw record from the {rdf_mapping} table.
$result = db_query('SELECT * FROM {rdf_mapping} WHERE type = :type AND bundle = :bundle', array(':type' => $mapping['type'], ':bundle' => $mapping['bundle']));
$blog_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
$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']");
$this->assertTrue(!empty($blog_title), t('Property dc:title is present in meta tag.'));
$this->assertTrue(!empty($blog_meta), t('RDF type is present on post. Properties dc:date and dc:created are present on post date.'));
// Ensure the mapping defined in rdf_module.test is used.
$test_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
$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']");
$this->assertTrue(!empty($test_bundle_title), t('Property dc:title is present in meta tag.'));
$this->assertTrue(!empty($test_bundle_meta), t('RDF type is present on post. Properties dc:date and dc:created are present on post date.'));
$random_bundle_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
$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']");
$this->assertTrue(!empty($random_bundle_title), t('Property dc:title is present in meta tag.'));
$this->assertTrue(!empty($random_bundle_meta), t('RDF type is present on post. Properties dc:date and dc:created are present on post date.'));
$user_account_holder = $this->xpath('//meta[contains(@typeof, "foaf:Person") and @about=:person-uri and @resource=:account-uri and contains(@rel, "foaf:account")]', array(
$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(
$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));
$this->assertTrue(!empty($comment_count_teaser), t('RDFa markup for the number of comments found on full node view.'));
// Tests the RDFa markup for the homepage (specific to anonymous comments).
$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 @href="http://example.org/" and contains(@rel, "foaf:page")]');
$this->assertTrue(!empty($comment_homepage), t('RDFa markup for the homepage of anonymous user found.'));
// There should be no about attribute on anonymous comments.
$comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
$this->assertTrue(empty($comment_homepage), t('No about attribute is present on anonymous user comment.'));
// Tests the RDFa markup for the homepage (specific to anonymous comments).
$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 @href="http://example.org/" and contains(@rel, "foaf:page")]');
$this->assertTrue(!empty($comment_homepage), t("RDFa markup for the homepage of anonymous user found."));
// There should be no about attribute on anonymous comments.
$comment_homepage = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//span[@rel="sioc:has_creator"]/a[@about]');
$this->assertTrue(empty($comment_homepage), t("No about attribute is present on anonymous user comment."));
// Tests the reply_of relationship of a first level comment.
$result = $this->xpath("id('comments')//div[@class='comment' and position()=0]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
$this->assertEqual(1, count($result), t('RDFa markup referring to the node is present.'));
$result = $this->xpath("id('comments')//div[@class='comment' and position()=0]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
$this->assertFalse($result, t('No RDFa markup referring to the comment itself is present.'));
// Tests the reply_of relationship of a second level comment.
$result = $this->xpath("id('comments')//div[@class='comment' and position()=1]//span[@rel='sioc:reply_of' and @resource=:node]", array(':node' => url("node/{$this->node1->nid}")));
$this->assertEqual(1, count($result), t('RDFa markup referring to the node is present.'));
$result = $this->xpath("id('comments')//div[@class='comment' and position()=1]//span[@rel='sioc:reply_of' and @resource=:comment]", array(':comment' => url('comment/1#comment-1')));
$this->assertEqual(1, count($result), t('RDFa markup referring to the parent comment is present.'));
}
/**
* Helper function for testCommentRdfaMarkup().
*
* Tests the current page for basic comment RDFa markup.
*
* @param $comment
* Comment object.
* @param $account
* An array containing information about an anonymous user.
*/
function _testBasicCommentRdfaMarkup($comment, $account = array()) {
$comment_container = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]');
$this->assertTrue(!empty($comment_container), t("Comment RDF type for comment found."));
$comment_title = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//h3[@property="dc:title"]');
$this->assertEqual((string)$comment_title[0]->a, $comment->subject, t("RDFa markup for the comment title found."));
$comment_date = $this->xpath('//div[contains(@class, "comment") and contains(@typeof, "sioct:Comment")]//*[contains(@property, "dc:date") and contains(@property, "dc:created")]');
$this->assertTrue(!empty($comment_date), t("RDFa markup for the date of the comment found."));
// The author tag can be either a or span
$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"]');
$this->assertTrue(!empty($tracker_activity), t('Latest activity date and changed properties found when there are no comments on @user content. Latest activity date content is correct.', array('@user'=> $user)));
// Tests that the appropriate RDFa markup to annotate the latest activity
// date has been added to the tracker output after a comment is posted.
$this->assertTrue(!empty($tracker_activity), t('Latest activity date found when there are comments on @user content. Latest activity date content is correct.', array('@user'=> $user)));
* Tests for RDF namespaces declaration with hook_rdf_namespaces().
*/
class RdfGetRdfNamespacesTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'RDF namespaces',
'description' => 'Test hook_rdf_namespaces() and ensure only "safe" namespaces are returned.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Test getting RDF namesapces.
*/
function testGetRdfNamespaces() {
// Get all RDF namespaces.
$ns = rdf_get_namespaces();
$this->assertEqual($ns['owl'], 'http://www.w3.org/2002/07/owl#', t('A prefix declared once is included.'));
$this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', t('The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'));
$this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', t('Two prefixes can be assigned the same namespace.'));
$this->assertTrue(!isset($ns['dc']), t('A prefix with conflicting namespaces is discarded.'));