function viewsFieldApiDataTest::setUp

Overrides ViewsSqlTest::setUp

File

tests/field/views_fieldapi.test, line 134

Class

viewsFieldApiDataTest
Test the produced views_data.

Code

public function setUp(array $modules = array()) {
    parent::setUp($modules);
    $langcode = LANGUAGE_NONE;
    $field_names = $this->setUpFields();
    // The first one will be attached to nodes only.
    $instance = array(
        'field_name' => $field_names[0],
        'entity_type' => 'node',
        'bundle' => 'page',
    );
    field_create_instance($instance);
    // The second one will be attached to users only.
    $instance = array(
        'field_name' => $field_names[1],
        'entity_type' => 'user',
        'bundle' => 'user',
    );
    field_create_instance($instance);
    // The third will be attached to both nodes and users.
    $instance = array(
        'field_name' => $field_names[2],
        'entity_type' => 'node',
        'bundle' => 'page',
    );
    field_create_instance($instance);
    $instance = array(
        'field_name' => $field_names[2],
        'entity_type' => 'user',
        'bundle' => 'user',
    );
    field_create_instance($instance);
    // Now create some example nodes/users for the view result.
    for ($i = 0; $i < 5; $i++) {
        $edit = array(
            // @todo Write a helper method to create such values.
'field_name_0' => array(
                $langcode => array(
                    array(
                        'value' => $this->randomName(),
                    ),
                ),
            ),
            'field_name_2' => array(
                $langcode => array(
                    array(
                        'value' => $this->randomName(),
                    ),
                ),
            ),
        );
        $this->nodes[] = $this->drupalCreateNode($edit);
    }
    for ($i = 0; $i < 5; $i++) {
        $edit = array(
            'field_name_1' => array(
                $langcode => array(
                    array(
                        'value' => $this->randomName(),
                    ),
                ),
            ),
            'field_name_2' => array(
                $langcode => array(
                    array(
                        'value' => $this->randomName(),
                    ),
                ),
            ),
        );
        $this->users[] = $this->createUser($edit);
    }
    // Reset views data cache.
    $this->clearViewsCaches();
}