Chris@0: set('views_test_data_schema', $this->schemaDefinition()); Chris@0: \Drupal::state()->set('views_test_data_views_data', $this->viewsData()); Chris@0: Chris@0: \Drupal::service('module_installer')->install(['views_test_data']); Chris@0: $this->resetAll(); Chris@0: $this->rebuildContainer(); Chris@0: $this->container->get('module_handler')->reload(); Chris@0: Chris@0: // Load the test dataset. Chris@0: $data_set = $this->dataSet(); Chris@18: $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: * Asserts the existence of a button with a certain ID and label. Chris@0: * Chris@0: * @param string $id Chris@0: * The HTML ID of the button Chris@0: * @param string $expected_label Chris@0: * The expected label for the button. Chris@0: * @param string $message Chris@0: * (optional) A custom message to display with the assertion. If no custom Chris@0: * message is provided, the message will indicate the button label. Chris@0: * Chris@0: * @return bool Chris@0: * TRUE if the assertion was successful, or FALSE on failure. Chris@0: */ Chris@0: protected function helperButtonHasLabel($id, $expected_label, $message = 'Label has the expected value: %label.') { Chris@0: return $this->assertFieldById($id, $expected_label, t($message, ['%label' => $expected_label])); 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(ViewExecutable $view, $args = []) { Chris@0: // A view does not really work outside of a request scope, due to many Chris@0: // dependencies like the current user. 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: }