You are here

public function UuidReferenceTest::setUp in UUID reference field 7

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

./uuidreference.test, line 56
Test classes for uuidreference.

Class

UuidReferenceTest
Tests the uuidreference field.

Code

public function setUp() {
  parent::setUp('uuid', 'uuidreference');

  // Create test content type.
  $this->contentType = $this
    ->drupalCreateContentType();

  // Create field.
  $this->field = array(
    'field_name' => 'uuidreference_test',
    'type' => 'uuidreference',
    'cardinality' => -1,
    'settings' => array(
      'target_type' => 'user',
    ),
  );
  field_create_field($this->field);

  // Create field instance for test content type.
  $this->fieldInstance = array(
    'field_name' => $this->field['field_name'],
    'entity_type' => 'node',
    'bundle' => $this->contentType->type,
    'label' => $this
      ->randomName(),
    'description' => '',
    'widget' => array(
      'type' => 'uuidreference_textfield',
    ),
  );
  field_create_instance($this->fieldInstance);

  // Create our users.
  for ($i = 0; $i < 2; $i++) {
    $this->users[] = $this
      ->drupalCreateUser();
  }

  // Create the field structure to save.
  $refs = array();
  foreach ($this->users as $user) {
    $refs[] = array(
      'target_type' => 'user',
      'target_uuid' => $user->uuid,
    );
  }

  // Create a node with values in the uuidreference field.
  $params = array(
    'type' => $this->contentType->type,
    'uuidreference_test' => array(
      LANGUAGE_NONE => $refs,
    ),
  );
  $this->node = $this
    ->drupalCreateNode($params);

  // Log in an admin user.
  // We just need this permission for the get AJAX call.
  $this->adminUser = $this
    ->drupalCreateUser(array(
    'access content',
    'bypass node access',
  ));
  $this
    ->drupalLogin($this->adminUser);
}