Commit 33ef742c authored by webchick's avatar webchick

Issue #1593450 by aspilicious: Convert rdf tests to PSR-0.

parent b8352532
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\CrudTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the RDF mapping CRUD functions.
*/
class CrudTest extends WebTestBase {
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() {
// Verify loading of a default mapping.
$mapping = _rdf_mapping_load('test_entity', 'test_bundle');
$this->assertTrue(count($mapping), t('Default mapping was found.'));
// Verify saving a mapping.
$mapping = array(
'type' => 'crud_test_entity',
'bundle' => 'crud_test_bundle',
'mapping' => array(
'rdftype' => array('sioc:Post'),
'title' => array(
'predicates' => array('dc:title'),
),
'uid' => array(
'predicates' => array('sioc:has_creator', 'dc:creator'),
'type' => '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']));
$stored_mapping = $result->fetchAssoc();
$stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
$this->assertEqual($mapping, $stored_mapping, t('Mapping was stored properly in the {rdf_mapping} table.'));
// Verify loading of saved mapping.
$this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Saved mapping loaded successfully.'));
// Verify updating of mapping.
$mapping['mapping']['title'] = array(
'predicates' => array('dc2:bar2'),
);
$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']));
$stored_mapping = $result->fetchAssoc();
$stored_mapping['mapping'] = unserialize($stored_mapping['mapping']);
$this->assertEqual($mapping, $stored_mapping, t('Updated mapping was stored properly in the {rdf_mapping} table.'));
// Verify loading of saved mapping.
$this->assertEqual($mapping['mapping'], _rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Saved mapping loaded successfully.'));
// Verify deleting of mapping.
$this->assertTrue(rdf_mapping_delete($mapping['type'], $mapping['bundle']), t('Mapping was deleted.'));
$this->assertFalse(_rdf_mapping_load($mapping['type'], $mapping['bundle']), t('Deleted mapping is no longer found in the database.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\GetNamespacesTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests for RDF namespaces XML serialization.
*/
class GetNamespacesTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'RDF namespaces serialization test',
'description' => 'Confirm that the serialization of RDF namespaces in present in the HTML markup.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Test RDF namespaces.
*/
function testGetRdfNamespaces() {
// Fetches the front page and extracts RDFa 1.1 prefixes.
$this->drupalGet('');
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'rdfs: http://www.w3.org/2000/01/rdf-schema#',
));
$this->assertTrue(!empty($element), t('A prefix declared once is displayed.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'foaf: http://xmlns.com/foaf/0.1/',
));
$this->assertTrue(!empty($element), t('The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'foaf1: http://xmlns.com/foaf/0.1/',
));
$this->assertTrue(!empty($element), t('Two prefixes can be assigned the same namespace.'));
$element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', array(
':prefix_binding' => 'dc: ',
));
$this->assertTrue(empty($element), t('A prefix with conflicting namespaces is discarded.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\GetRdfNamespacesTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests for RDF namespaces declaration with hook_rdf_namespaces().
*/
class GetRdfNamespacesTest extends WebTestBase {
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['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 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.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\MappingDefinitionTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\taxonomy\Tests\TaxonomyTestBase;
/**
* Test the RDF mapping definition functionality.
*/
class MappingDefinitionTest extends TaxonomyTestBase {
protected $profile = 'standard';
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 nodes and user profile pages.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test');
}
/**
* Create a node of type article 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' => 'article'));
$isoDate = date('c', $node->changed);
$url = url('node/' . $node->nid);
$this->drupalGet('node/' . $node->nid);
// Ensure the default bundle mapping for node is used. These attributes come
// from the node default bundle definition.
$node_title = $this->xpath("//meta[@property='dc:title' and @content='$node->title']");
$node_meta = $this->xpath("//div[(@about='$url')]//span[contains(@property, 'dc:date') and contains(@property, 'dc:created') and @datatype='xsd:dateTime' and @content='$isoDate']");
$this->assertTrue(!empty($node_title), t('Property dc:title is present in meta tag.'));
$this->assertTrue(!empty($node_meta), t('RDF type is present on post. Properties dc:date and dc:created are present on post date.'));
}
/**
* 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'));
$isoDate = date('c', $node->changed);
$url = url('node/' . $node->nid);
$this->drupalGet('node/' . $node->nid);
// 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.'));
}
/**
* 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));
$isoDate = date('c', $node->changed);
$url = url('node/' . $node->nid);
$this->drupalGet('node/' . $node->nid);
// Ensure the default bundle mapping for node is used. These attributes come
// from the node default bundle definition.
$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.'));
}
/**
* Create a random user and ensure the default mapping for user is used.
*/
function testUserAttributesInMarkup() {
// Create two users, one with access to user profiles.
$user1 = $this->drupalCreateUser(array('access user profiles'));
$user2 = $this->drupalCreateUser();
$username = $user2->name;
$this->drupalLogin($user1);
// Browse to the user profile page.
$this->drupalGet('user/' . $user2->uid);
// Ensure the default bundle mapping for user is used on the user profile
// page. These attributes come from the user default bundle definition.
$account_uri = url('user/' . $user2->uid);
$person_uri = url('user/' . $user2->uid, array('fragment' => 'me'));
$user2_profile_about = $this->xpath('//article[@class="profile" and @typeof="sioc:UserAccount" and @about=:account-uri]', array(
':account-uri' => $account_uri,
));
$this->assertTrue(!empty($user2_profile_about), t('RDFa markup found on user profile page'));
$user_account_holder = $this->xpath('//meta[contains(@typeof, "foaf:Person") and @about=:person-uri and @resource=:account-uri and contains(@rel, "foaf:account")]', array(
':person-uri' => $person_uri,
':account-uri' => $account_uri,
));
$this->assertTrue(!empty($user_account_holder), t('URI created for account holder and username set on sioc:UserAccount.'));
$user_username = $this->xpath('//meta[@about=:account-uri and contains(@property, "foaf:name") and @content=:username]', array(
':account-uri' => $account_uri,
':username' => $username,
));
$this->assertTrue(!empty($user_username), t('foaf:name set on username.'));
// User 2 creates node.
$this->drupalLogin($user2);
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$this->drupalLogin($user1);
$this->drupalGet('node/' . $node->nid);
// Ensures the default bundle mapping for user is used on the Authored By
// information on the node.
$author_about = $this->xpath('//a[@typeof="sioc:UserAccount" and @about=:account-uri and @property="foaf:name" and contains(@lang, "")]', array(
':account-uri' => $account_uri,
));
$this->assertTrue(!empty($author_about), t('RDFa markup found on author information on post. The lang attribute on username is set to empty string.'));
}
/**
* Creates a random term and ensures the right RDFa markup is used.
*/
function testTaxonomyTermRdfaAttributes() {
$vocabulary = $this->createVocabulary();
$term = $this->createTerm($vocabulary);
// Views the term and checks that the RDFa markup is correct.
$this->drupalGet('taxonomy/term/' . $term->tid);
$term_url = url('taxonomy/term/' . $term->tid);
$term_name = $term->name;
$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(
':term-url' => $term_url,
':term-name' => $term_name,
));
$this->assertTrue(!empty($term_rdfa_meta), t('RDFa markup found on term page.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\MappingHookTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests the RDF mapping hook.
*/
class MappingHookTest extends WebTestBase {
public static function getInfo() {
return array(
'name' => 'RDF mapping hook',
'description' => 'Test hook_rdf_mapping().',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test', 'field_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'), 'type' => 'rel'), t('Mapping for uid is sioc:has_creator and dc:creator, and type is rel.'));
$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.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\RdfaMarkupTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Tests RDFa markup generation.
*/
class RdfaMarkupTest extends WebTestBase {
protected $profile = 'standard';
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');
}
/**
* Test rdf_rdfa_attributes().
*/
function testDrupalRdfaAttributes() {
// Same value as the one in the HTML tag (no callback function).
$expected_attributes = array(
'property' => array('dc:title'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['title']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Value different from the one in the HTML tag (callback function).
$date = 1252750327;
$isoDate = date('c', $date);
$expected_attributes = array(
'datatype' => 'xsd:dateTime',
'property' => array('dc:created'),
'content' => $isoDate,
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['created'], $date);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Same value as the one in the HTML tag with datatype.
$expected_attributes = array(
'datatype' => 'foo:bar1type',
'property' => array('foo:bar1'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar1']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// ObjectProperty mapping (rel).
$expected_attributes = array(
'rel' => array('sioc:has_creator', 'dc:creator'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
// Inverse ObjectProperty mapping (rev).
$expected_attributes = array(
'rev' => array('sioc:reply_of'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']);
ksort($expected_attributes);
ksort($attributes);
$this->assertEqual($expected_attributes, $attributes);
}
/**
* Ensure that file fields have the correct resource as the object in RDFa
* when displayed as a teaser.
*/
function testAttributesInMarkupFile() {
// Create a user to post the image.
$admin_user = $this->drupalCreateUser(array('edit own article content', 'revert revisions', 'administer content types'));
$this->drupalLogin($admin_user);
$langcode = LANGUAGE_NOT_SPECIFIED;
$bundle_name = "article";
$field_name = 'file_test';
$field = array(
'field_name' => $field_name,
'type' => 'file',
);
field_create_field($field);
$instance = array(
'field_name' => $field_name,
'entity_type' => 'node',
'bundle' => $bundle_name,
'display' => array(
'teaser' => array(
'type' => 'file_default',
),
),
);
field_create_instance($instance);
// Set the RDF mapping for the new field.
$rdf_mapping = rdf_mapping_load('node', $bundle_name);
$rdf_mapping += array($field_name => array('predicates' => array('rdfs:seeAlso'), 'type' => 'rel'));
$rdf_mapping_save = array('mapping' => $rdf_mapping, 'type' => 'node', 'bundle' => $bundle_name);
rdf_mapping_save($rdf_mapping_save);
// Get the test file that simpletest provides.
$file = current($this->drupalGetTestFiles('text'));
// Prepare image variables.
$image_field = "field_image";
// Get the test image that simpletest provides.
$image = current($this->drupalGetTestFiles('image'));
// Create an array for drupalPost with the field names as the keys and
// the uris for the test files as the values.
$edit = array("files[" . $field_name . "_" . $langcode . "_0]" => drupal_realpath($file->uri),
"files[" . $image_field . "_" . $langcode . "_0]" => drupal_realpath($image->uri));
// Create node and save, then edit node to upload files.
$node = $this->drupalCreateNode(array('type' => 'article', 'promote' => 1));
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Get filenames and nid for comparison with HTML output.
$file_filename = $file->filename;
$image_filename = $image->filename;
$nid = $node->nid;
// Navigate to front page, where node is displayed in teaser form.
$this->drupalGet('node');
// We only check to make sure that the resource attribute contains '.txt'
// instead of the full file name because the filename is altered on upload.
$file_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, ".txt")]', array(
':node-uri' => 'node/' . $nid,
));
$this->assertTrue(!empty($file_rel), t('Attribute \'rel\' set on file field. Attribute \'resource\' is also set.'));
$image_rel = $this->xpath('//div[contains(@about, :node-uri)]//div[contains(@rel, "rdfs:seeAlso") and contains(@resource, :image)]//img[contains(@typeof, "foaf:Image")]', array(
':node-uri' => 'node/' . $nid,
':image' => $image_filename,
));
$this->assertTrue(!empty($image_rel), t('Attribute \'rel\' set on image field. Attribute \'resource\' is also set.'));
// Edits the node to add tags.
$tag1 = $this->randomName(8);
$tag2 = $this->randomName(8);
$edit = array();
$edit['field_tags[' . LANGUAGE_NOT_SPECIFIED . ']'] = "$tag1, $tag2";
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Ensures the RDFa markup for the relationship between the node and its
// tags is correct.
$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 text()=:term-name]', array(
':node-url' => url('node/' . $node->nid),
':term-name' => $tag1,
));
$this->assertTrue(!empty($term_rdfa_meta), t('Property dc:subject is present for the tag1 field item.'));
$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 text()=:term-name]', array(
':node-url' => url('node/' . $node->nid),
':term-name' => $tag2,
));
$this->assertTrue(!empty($term_rdfa_meta), t('Property dc:subject is present for the tag2 field item.'));
}
}
<?php
/**
* @file
* Definition of Drupal\rdf\Tests\TrackerAttributesTest.
*/
namespace Drupal\rdf\Tests;
use Drupal\node\Node;
use Drupal\simpletest\WebTestBase;
/**
* Tests the RDF tracker page mapping.
*/
class TrackerAttributesTest extends WebTestBase {
protected $profile = 'standard';
public static function getInfo() {
return array(
'name' => 'RDF tracker page mapping',
'description' => 'Test the mapping for the tracker page and ensure the proper RDFa markup in included.',
'group' => 'RDF',
);
}
function setUp() {
parent::setUp('rdf', 'rdf_test', 'tracker');
// Enable anonymous posting of content.
user_role_change_permissions(DRUPAL_ANONYMOUS_RID, array(
'create article content' => TRUE,
'access comments' => TRUE,
'post comments' => TRUE,
'skip comment approval' => TRUE,
));
}
/**
* Create nodes as both admin and anonymous user and test for correct RDFa
* markup on the tracker page for those nodes and their comments.
*/
function testAttributesInTracker() {
// Create node as anonymous user.
$node_anon = $this->drupalCreateNode(array('type' => 'article', 'uid' => 0));
// Create node as admin user.
$node_admin = $this->drupalCreateNode(array('type' => 'article', 'uid' => 1));
// Pass both the anonymously posted node and the administrator posted node
// through to test for the RDF attributes.
$this->_testBasicTrackerRdfaMarkup($node_anon);
$this->_testBasicTrackerRdfaMarkup($node_admin);
}
/**
* Helper function for testAttributesInTracker().
*
* Tests the tracker page for RDFa markup.
*
* @param Node $node
* The node just created.
*/
function _testBasicTrackerRdfaMarkup(Node $node) {
$url = url('node/' . $node->nid);
$user = ($node->uid == 0) ? 'Anonymous user' : 'Registered user';
// Navigate to tracker page.
$this->drupalGet('tracker');
// Tests whether the about property is applied. This is implicit in the
// success of the following tests, but making it explicit will make
// debugging easier in case of failure.
$tracker_about = $this->xpath('//tr[@about=:url]', array(':url' => $url));
$this->assertTrue(!empty($tracker_about), t('About attribute found on table row for @user content.', array('@user'=> $user)));
// Tests whether the title has the correct property attribute.
$tracker_title = $this->xpath('//tr[@about=:url]/td[@property="dc:title" and @datatype=""]', array(':url' => $url));
$this->assertTrue(!empty($tracker_title), t('Title property attribute found on @user content.', array('@user'=> $user)));
// Tests whether the relationship between the content and user has been set.
$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));
$this->assertTrue(!empty($tracker_user), t('Typeof and name property attributes found on @user.', array('@user'=> $user)));
// There should be an about attribute on logged in users and no about
// attribute for anonymous users.
$tracker_user = $this->xpath('//tr[@about=:url]//td[@rel="sioc:has_creator"]/*[@about]', array(':url' => $url));
if ($node->uid == 0) {
$this->assertTrue(empty($tracker_user), t('No about attribute is present on @user.', array('@user'=> $user)));
}
elseif ($node->uid > 0) {
$this->assertTrue(!empty($tracker_user), t('About attribute is present on @user.', array('@user'=> $user)));
}
// Tests whether the property has been set for number of comments.
$tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "0") and @datatype="xsd:integer"]', array(':url' => $url));
$this->assertTrue($tracker_replies, t('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
// Tests that the appropriate RDFa markup to annotate the latest activity
// date has been added to the tracker output before comments have been
// posted, meaning the latest activity reflects changes to the node itself.
$isoDate = date('c', $node->changed);
$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));
$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.
$comment = array(
'subject' => $this->randomName(),
'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(),
);
$this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save'));
$this->drupalGet('tracker');
// Tests whether the property has been set for number of comments.
$tracker_replies = $this->xpath('//tr[@about=:url]//td[contains(@property, "sioc:num_replies") and contains(@content, "1") and @datatype="xsd:integer"]', array(':url' => $url));
$this->assertTrue($tracker_replies, t('Num replies property and content attributes found on @user content.', array('@user'=> $user)));
// Need to query database directly to obtain last_activity_date because
// it cannot be accessed via node_load().
$result = db_query('SELECT t.changed FROM {tracker_node} t WHERE t.nid = (:nid)', array(':nid' => $node->nid));
foreach ($result as $node) {
$expected_last_activity_date = $node->changed;
}
$isoDate = date('c', $expected_last_activity_date);
$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));
$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)));
}
}
......@@ -3,4 +3,3 @@ description = Enriches your content with metadata to let other applications (e.g
package = Core
version = VERSION