function MappingDefinitionTest::testUserAttributesInMarkup

Tests if default mapping for user is being used.

Creates a random user and ensures the default mapping for the user is being used.

File

drupal/core/modules/rdf/lib/Drupal/rdf/Tests/MappingDefinitionTest.php, line 99
Definition of Drupal\rdf\Tests\MappingDefinitionTest.

Class

MappingDefinitionTest
Tests the RDF mapping definition functionality.

Namespace

Drupal\rdf\Tests

Code

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), '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), '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), '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), 'RDFa markup found on author information on post. The lang attribute on username is set to empty string.');
}