function ApiDataTest::setUp in Views (for Drupal 7) 8.3
Sets up a Drupal site for running functional and integration tests.
Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.
Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.
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.
Overrides ViewTestBase::setUp
File
- lib/
Drupal/ views/ Tests/ Field/ ApiDataTest.php, line 28 - Definition of Drupal\views\Test\Field\ApiDataTest.
Class
- ApiDataTest
- Test the produced views_data.
Namespace
Drupal\views\Tests\FieldCode
function setUp() {
parent::setUp();
$langcode = LANGUAGE_NOT_SPECIFIED;
$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);
}
// Reset views data cache.
$this
->clearViewsCaches();
}