You are here

public function ViewsHandlerManyToOneTest::setUp in Views (for Drupal 7) 7.3

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 ViewsSqlTest::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/handlers/views_handler_manytoone.test, line 86

Class

ViewsHandlerManyToOneTest
Tests the many to one helper handler class.

Code

public function setUp(array $modules = array()) {
  parent::setUp($modules);

  // Create boolean field.
  $this->fields[0] = array(
    'field_name' => 'field_bool',
    'type' => 'list_boolean',
    'cardinality' => 1,
    'settings' => array(
      'allowed_values' => array(
        0 => '',
        1 => '',
      ),
    ),
  );
  $this->fields[0] = field_create_field($this->fields[0]);

  // Create text list field.
  $this->fields[1] = array(
    'field_name' => 'field_list',
    'type' => 'list_text',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        1 => '1',
        2 => '2',
        3 => '3',
      ),
    ),
  );
  $this->fields[1] = field_create_field($this->fields[1]);

  // Create boolean field instance for article nodes.
  $instance = array(
    'field_name' => $this->fields[0]['field_name'],
    'entity_type' => 'node',
    'bundle' => 'article',
    'widget' => array(
      'type' => 'options_onoff',
    ),
  );
  $this->instances[0][] = field_create_instance($instance);

  // Create text list field instance for article nodes.
  $instance = array(
    'field_name' => $this->fields[1]['field_name'],
    'entity_type' => 'node',
    'bundle' => 'article',
    'widget' => array(
      'type' => 'options_buttons',
    ),
  );
  $this->instances[1][] = field_create_instance($instance);

  // Create boolean field instance for users.
  $instance = array(
    'field_name' => $this->fields[0]['field_name'],
    'entity_type' => 'user',
    'bundle' => 'user',
    'widget' => array(
      'type' => 'options_onoff',
    ),
  );
  $this->instances[0][] = field_create_instance($instance);

  // Create text list field instance for users.
  $instance = array(
    'field_name' => $this->fields[1]['field_name'],
    'entity_type' => 'user',
    'bundle' => 'user',
    'widget' => array(
      'type' => 'options_buttons',
    ),
  );
  $this->instances[1][] = field_create_instance($instance);

  // Create tags field instance for users.
  $instance = array(
    'field_name' => 'field_tags',
    'entity_type' => 'user',
    'bundle' => 'user',
  );
  $this->instances[2][] = field_create_instance($instance);

  // Clear views data cache.
  $this
    ->clearViewsDataCache();

  // Create 62 tags.
  $vocabulary = taxonomy_vocabulary_machine_name_load('tags');
  for ($i = 0; $i < 62; $i++) {
    $this->terms[] = $this
      ->createTerm($vocabulary);
  }

  // Create a node where the field_bool is checked, field_list is '1' and
  // tag is term 2.
  $node = array();
  $node['type'] = 'article';
  $node[$this->fields[0]['field_name']][LANGUAGE_NONE][]['value'] = '1';
  $node[$this->fields[1]['field_name']][LANGUAGE_NONE][]['value'] = '1';
  $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[1]->tid;
  $this->nodes[0] = $this
    ->drupalCreateNode($node);

  // Create a node where the field_bool is not checked, field_list is empty
  // and tag is term 1.
  $node = array();
  $node['type'] = 'article';
  $node[$this->fields[0]['field_name']] = array();
  $node[$this->fields[1]['field_name']] = array();
  $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid;
  $this->nodes[1] = $this
    ->drupalCreateNode($node);

  // Create a node where the field_bool is not checked, field_list is empty
  // and tag is term 1 and 2.
  $node = array();
  $node['type'] = 'article';
  $node[$this->fields[0]['field_name']] = array();
  $node[$this->fields[1]['field_name']] = array();
  $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid;
  $node['field_tags'][LANGUAGE_NONE][]['tid'] = $this->terms[1]->tid;
  $this->nodes[2] = $this
    ->drupalCreateNode($node);

  // Create a user where field_bool is checked, field_list is '1' and tag is
  // term 1.
  $permissions = array(
    'access content',
  );
  $account = $this
    ->drupalCreateUser($permissions);
  $account->{$this->fields[0]['field_name']}[LANGUAGE_NONE][]['value'] = '1';
  $account->{$this->fields[1]['field_name']}[LANGUAGE_NONE][]['value'] = '1';
  $account->field_tags[LANGUAGE_NONE][]['tid'] = $this->terms[0]->tid;
  $this->accounts[0] = user_save($account);
}