1 views_handler_manytoone.test protected ViewsHandlerManyToOneTest::setUp(array $modules = array())

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

Generates a random database prefix and installs Backdrop with the specified installation profile in BackdropWebTestCase::$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.

Return value

bool: TRUE if set up completes, FALSE if an error occurred.

Overrides ViewsSqlTest::setUp

See also

BackdropWebTestCase::prepareDatabasePrefix()

BackdropWebTestCase::changeDatabasePrefix()

BackdropWebTestCase::prepareEnvironment()

File

core/modules/views/tests/handlers/views_handler_manytoone.test, line 81
Definition of ViewsHandlerManyToOneTest.

Class

ViewsHandlerManyToOneTest
Tests the many to one helper handler class.

Code

protected 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 post nodes.
  $instance = array(
    'field_name' => $this->fields[0]['field_name'],
    'entity_type' => 'node',
    'bundle' => 'post',
    'widget' => array(
      'type' => 'options_onoff',
    ),
  );
  $this->instances[0][] = field_create_instance($instance);

  // Create text list field instance for post nodes.
  $instance = array(
    'field_name' => $this->fields[1]['field_name'],
    'entity_type' => 'node',
    'bundle' => 'post',
    '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 two tags.
  $vocabulary = taxonomy_vocabulary_load('tags');
  $this->terms[] = $this->createTerm($vocabulary);
  $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'] = 'post';
  $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->backdropCreateNode($node);

  // Create a node where the field_bool is not checked, field_list is empty
  // and tag is term 1.
  $node = array();
  $node['type'] = 'post';
  $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->backdropCreateNode($node);

  // Create a number new users to get UIDs equal to the highest NID. We'll
  // do all our testing with the last created account.
  $permissions = array('access content');
  $highest_nid = db_query("SELECT MAX(nid) from {node}")->fetchField();
  for ($i = 0; $i <= $highest_nid; $i++) {
    // Each user: field_bool is checked, field_list is '1', and tag is term 2.
    $account = $this->backdropCreateUser($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;
    user_save($account);
    $this->accounts[$i] = $account;
    if ($account->uid == $highest_nid) {
      break;
    }
  }
}