You are here

realname_entity.test in Real Name 7

Test file for Realname module.

File

tests/realname_entity.test
View source
<?php

/**
 * @file
 * Test file for Realname module.
 */

/**
 * Test entity related functionality.
 */
class RealnameEntityTest extends DrupalWebTestCase {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Realname entity tests',
      'description' => 'Test entity related functionality.',
      'group' => 'Realname',
      'dependencies' => array(
        'entity',
      ),
    );
  }

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp('entity', 'realname');
    $permissions = array(
      'change own username',
    );
    $this->user = $this
      ->drupalCreateUser($permissions);
  }

  /**
   * Test realname user update hook.
   */
  public function testRealnameUserUpdate() {
    variable_set('realname_pattern', '[user:name-raw]');
    $uid = $this->user->uid;
    $wrapper1 = entity_metadata_wrapper('user', $uid);
    $realname1 = $wrapper1
      ->label();

    // Update user name via entity_metadata_wrapper.
    $wrapper1->name = $this
      ->randomName();
    $wrapper1
      ->save();

    // Reload the user via entity_metadata_wrapper.
    $wrapper2 = entity_metadata_wrapper('user', $uid);
    $realname2 = $wrapper2
      ->label();

    // Check if realname changed via entity_metadata_wrapper.
    $this
      ->assertTrue($realname1);
    $this
      ->assertTrue($realname2);
    $this
      ->assertNotEqual($realname1, $realname2, '[testRealnameUserUpdate]: Real name changed via entity_metadata_wrapper.');
  }

}

Classes

Namesort descending Description
RealnameEntityTest Test entity related functionality.