Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add file and chart test #99

Open
wants to merge 2 commits into
base: 2.x-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<img src="https://github.com/govCMS/dvf/wiki/images/dvf-logo.png" width="460"/>

The Data Visualisation Framework (DVF for short) is a Drupal 8/9 module that
The Data Visualisation Framework (DVF for short) is a Drupal 8/9/10 module that
allows you to turn boring data sources (Eg CSV or JSON file) into interactive
visualisation. This allows content authors to provide more meaning to raw data,
illustrate trends and engage users.
Expand Down
11 changes: 11 additions & 0 deletions src/Plugin/Visualisation/Style/PieChart.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Drupal\dvf\Plugin\Visualisation\Style;

use Drupal\Core\Form\FormStateInterface;
use Drupal\dvf\FormElementAttributesTrait;

/**
Expand All @@ -25,6 +26,16 @@ public function defaultConfiguration() {
] + parent::defaultConfiguration();
}

/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['chart']['#title'] = $this->t('Pie chart settings');

return $form;
}

/**
* {@inheritdoc}
*/
Expand Down
77 changes: 66 additions & 11 deletions tests/src/Functional/DvfFieldBasicConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,51 @@
class DvfFieldBasicConfigTest extends DvfFieldTestBase {

/**
* Tests the configuration of a visualisation file with csv source.
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Core\Entity\EntityStorageException
* Tests the configuration of a visualisation files.
*/
public function testConfigureFieldVisualisationFileCsv() {
public function testConfigureFieldVisualisationFiles() {
$fileTypes = [
'csv',
'json',
];

foreach ($fileTypes as $fileType) {
$this->configureFieldVisualisationFile($fileType);
}
}

/**
* Test that the visualisation style config properties are correct.
*/
public function testVisualisationStyleProperties() {
$visualisation_styles = [
'bar_chart',
'bubble_chart',
'donut_chart',
'gauge_chart',
'line_chart',
'pie_chart',
'radar_chart',
'scatter_plot_chart',
'spline_chart',
'table',
];

foreach ($visualisation_styles as $visualisation_style) {
$settingsText = ucfirst(str_replace('_', ' ', $visualisation_style)) . ' settings';
$this->configureVisualisationStyle('csv', "dvf_$visualisation_style", $settingsText);
}
}

/**
* Configure the visualisation style dropdown properties.
*/
public function configureVisualisationStyle($fileType = 'csv', $style = 'dvf_bar_chart', $settingsText = '') {
$assert_session = $this->assertSession();
// Create a new file field csv and attach to page bundle.
$field_name = 'testing_field_vis_file_csv';
// Create a new file field json and attach to page bundle.
$field_name = "field_{$fileType}_{$style}";
$field_settings = [
'visualisation_source' => 'dvf_csv_file',
'visualisation_source' => "dvf_{$fileType}_file",
];
$this->createDvfFileField($field_name, $field_settings);

Expand All @@ -42,17 +75,39 @@ public function testConfigureFieldVisualisationFileCsv() {
$this->visitAndAssertText($edit_page_path, $field_name);

// Upload a csv sample file to node page.
$csv_sample_filename = 'fruits.csv';
$csv_sample_filename = "fruits.$fileType";
$this->uploadSampleFileToNode($csv_sample_filename, $field_name);

// Confirm that file name is displayed on page.
$assert_session->pageTextNotContains('could not be uploaded');

// Select a visualisation style.
$assert_session->fieldExists($field_name . '[0][options][visualisation_style]')
->setValue($this->defaultVisualisationStyle);
->setValue($style);
$this->submitForm([], $this->t('Save'));
$this->drupalGet($edit_page_path);
$assert_session->pageTextContains($settingsText);

return [
'field_name' => $field_name,
'assert_session' => $assert_session,
'nid' => $nid,
];
}

/**
* Common test for the configuration of a visualisation file.
*
* @throws \Behat\Mink\Exception\ElementNotFoundException
* @throws \Behat\Mink\Exception\ResponseTextException
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function configureFieldVisualisationFile($fileType = 'csv') {
$response = $this->configureVisualisationStyle($fileType,'dvf_bar_chart', 'Bar chart settings');

$field_name = $response['field_name'];
$nid = $response['nid'];
$assert_session = $response['assert_session'];

// Select visualisation style options.
// @codingStandardsIgnoreStart - ignore line exceed warning.
Expand Down