UserEntityCallbacksTest.php 1.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * @file
 * Definition of Drupal\user\Tests\UserEntityCallbacksTest.
 */

namespace Drupal\user\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Test user entity callbacks.
 */
class UserEntityCallbacksTest extends WebTestBase {
16 17 18 19 20 21 22 23

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('user');

24 25 26 27 28 29 30 31 32
  public static function getInfo() {
    return array(
      'name' => 'User entity callback tests',
      'description' => 'Tests specific parts of the user entity like the URI callback and the label callback.',
      'group' => 'User'
    );
  }

  function setUp() {
33
    parent::setUp();
34 35

    $this->account = $this->drupalCreateUser();
36
    $this->anonymous = entity_create('user', (array) drupal_anonymous_user());
37 38 39 40 41 42
  }

  /**
   * Test label callback.
   */
  function testLabelCallback() {
43
    $this->assertEqual($this->account->label(), $this->account->name, t('The username should be used as label'));
44 45 46

    // Setup a random anonymous name to be sure the name is used.
    $name = $this->randomName();
47
    config('user.settings')->set('anonymous', $name)->save();
48
    $this->assertEqual($this->anonymous->label(), $name, t('The variable anonymous should be used for name of uid 0'));
49 50 51 52 53 54
  }

  /**
   * Test URI callback.
   */
  function testUriCallback() {
55
    $uri = $this->account->uri();
56 57 58
    $this->assertEqual('user/' . $this->account->uid, $uri['path'], t('Correct user URI.'));
  }
}