Chris@0: installSchema('system', ['sequences', 'key_value_expire']); Chris@0: $this->setUpFixtures(); Chris@0: Chris@0: if ($import_test_views) { Chris@0: ViewTestData::createTestViews(get_class($this), ['views_test_config']); Chris@0: } Chris@0: } Chris@17: Chris@0: /** Chris@0: * Sets up the configuration and schema of views and views_test_data modules. Chris@0: * Chris@0: * Because the schema of views_test_data.module is dependent on the test Chris@0: * using it, it cannot be enabled normally. Chris@0: */ Chris@0: protected function setUpFixtures() { Chris@0: // First install the system module. Many Views have Page displays have menu Chris@0: // links, and for those to work, the system menus must already be present. Chris@0: $this->installConfig(['system']); Chris@0: Chris@0: /** @var \Drupal\Core\State\StateInterface $state */ Chris@0: $state = $this->container->get('state'); Chris@0: // Define the schema and views data variable before enabling the test module. Chris@0: $state->set('views_test_data_schema', $this->schemaDefinition()); Chris@0: $state->set('views_test_data_views_data', $this->viewsData()); Chris@17: $this->container->get('views.views_data')->clear(); Chris@0: Chris@0: $this->installConfig(['views', 'views_test_config', 'views_test_data']); Chris@0: foreach ($this->schemaDefinition() as $table => $schema) { Chris@0: $this->installSchema('views_test_data', $table); Chris@0: } Chris@0: Chris@0: $this->container->get('router.builder')->rebuild(); Chris@0: Chris@0: // Load the test dataset. Chris@0: $data_set = $this->dataSet(); Chris@0: $query = Database::getConnection()->insert('views_test_data') Chris@0: ->fields(array_keys($data_set[0])); Chris@0: foreach ($data_set as $record) { Chris@0: $query->values($record); Chris@0: } Chris@0: $query->execute(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Orders a nested array containing a result set based on a given column. Chris@0: * Chris@0: * @param array $result_set Chris@0: * An array of rows from a result set, with each row as an associative Chris@0: * array keyed by column name. Chris@0: * @param string $column Chris@0: * The column name by which to sort the result set. Chris@0: * @param bool $reverse Chris@0: * (optional) Boolean indicating whether to sort the result set in reverse Chris@0: * order. Defaults to FALSE. Chris@0: * Chris@0: * @return array Chris@0: * The sorted result set. Chris@0: */ Chris@0: protected function orderResultSet($result_set, $column, $reverse = FALSE) { Chris@0: $order = $reverse ? -1 : 1; Chris@0: usort($result_set, function ($a, $b) use ($column, $order) { Chris@0: if ($a[$column] == $b[$column]) { Chris@0: return 0; Chris@0: } Chris@0: return $order * (($a[$column] < $b[$column]) ? -1 : 1); Chris@0: }); Chris@0: return $result_set; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Executes a view with debugging. Chris@0: * Chris@0: * @param \Drupal\views\ViewExecutable $view Chris@0: * The view object. Chris@0: * @param array $args Chris@0: * (optional) An array of the view arguments to use for the view. Chris@0: */ Chris@0: protected function executeView($view, array $args = []) { Chris@0: $view->setDisplay(); Chris@0: $view->preExecute($args); Chris@0: $view->execute(); Chris@0: $verbose_message = '
Executed view: ' . ((string) $view->build_info['query']) . ''; Chris@0: if ($view->build_info['query'] instanceof SelectInterface) { Chris@0: $verbose_message .= '
Arguments: ' . print_r($view->build_info['query']->getArguments(), TRUE) . ''; Chris@0: } Chris@0: $this->verbose($verbose_message); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the schema definition. Chris@0: * Chris@0: * @internal Chris@0: */ Chris@0: protected function schemaDefinition() { Chris@0: return ViewTestData::schemaDefinition(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the views data definition. Chris@0: */ Chris@0: protected function viewsData() { Chris@0: return ViewTestData::viewsData(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns a very simple test dataset. Chris@0: */ Chris@0: protected function dataSet() { Chris@0: return ViewTestData::dataSet(); Chris@0: } Chris@0: Chris@0: }