function ViewsHandlerManyToOneTest::setUp

Overrides ViewsSqlTest::setUp

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);
}