set('views_test_data_schema', $this->schemaDefinition()); \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); \Drupal::service('module_installer')->install(array('views_test_data')); $this->resetAll(); $this->rebuildContainer(); $this->container->get('module_handler')->reload(); // Load the test dataset. $data_set = $this->dataSet(); $query = db_insert('views_test_data') ->fields(array_keys($data_set[0])); foreach ($data_set as $record) { $query->values($record); } $query->execute(); } /** * Orders a nested array containing a result set based on a given column. * * @param array $result_set * An array of rows from a result set, with each row as an associative * array keyed by column name. * @param string $column * The column name by which to sort the result set. * @param bool $reverse * (optional) Boolean indicating whether to sort the result set in reverse * order. Defaults to FALSE. * * @return array * The sorted result set. */ protected function orderResultSet($result_set, $column, $reverse = FALSE) { $order = $reverse ? -1 : 1; usort($result_set, function ($a, $b) use ($column, $order) { if ($a[$column] == $b[$column]) { return 0; } return $order * (($a[$column] < $b[$column]) ? -1 : 1); }); return $result_set; } /** * Asserts the existence of a button with a certain ID and label. * * @param string $id * The HTML ID of the button * @param string $label. * The expected label for the button. * @param string $message * (optional) A custom message to display with the assertion. If no custom * message is provided, the message will indicate the button label. * * @return bool * TRUE if the assertion was successful, or FALSE on failure. */ protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { return $this->assertFieldById($id, $expected_label, t($message, array('%label' => $expected_label))); } /** * Executes a view with debugging. * * @param \Drupal\views\ViewExecutable $view * The view object. * @param array $args * (optional) An array of the view arguments to use for the view. */ protected function executeView(ViewExecutable $view, $args = array()) { // A view does not really work outside of a request scope, due to many // dependencies like the current user. $view->setDisplay(); $view->preExecute($args); $view->execute(); $verbose_message = '
Executed view: ' . ((string) $view->build_info['query']). '
'; if ($view->build_info['query'] instanceof SelectInterface) { $verbose_message .= '
Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . '
'; } $this->verbose($verbose_message); } /** * Returns the schema definition. */ protected function schemaDefinition() { return ViewTestData::schemaDefinition(); } /** * Returns the views data definition. */ protected function viewsData() { return ViewTestData::viewsData(); } /** * Returns a very simple test dataset. */ protected function dataSet() { return ViewTestData::dataSet(); } }