diff --git a/.travis.yml b/.travis.yml index 28eb77f65db4317a641112e7d53d84bf2eca3836..15d76effa8aa36126ee8e61fe8ea733d28e3a311 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,6 +60,7 @@ script: - bin/behat features/search.feature - bin/behat features/recline.feature - bin/behat features/widgets.feature + - bin/behat features/data_dashboard.feature notifications: slack: diff --git a/test/behat.yml b/test/behat.yml index e9d3d442a3573127dd6506d727caf3e0ef336f40..e847713b87e53f7e0ae109362eb742f1e66cd8b0 100644 --- a/test/behat.yml +++ b/test/behat.yml @@ -9,8 +9,11 @@ default: files_path: "files" Drupal\DrupalExtension\Extension: blackbox: ~ + drupal: + drupal_root: "drupal" drush: root: "drupal" + api_driver: "drupal" region_map: content: ".region-content" toolbar: ".tabs--primary" @@ -20,3 +23,4 @@ default: left header: "#header-left" right header: "#header-right" right sidebar: "#column-right" + dashboards: ".view-data-dashboards table tbody" diff --git a/test/features/bootstrap/FeatureContext.php b/test/features/bootstrap/FeatureContext.php index e4781aa2c424c99ceee3a5f7a68aa6898bff1af6..bd1ab53e367c4d270b929ffca85c27ab2c9f727a 100644 --- a/test/features/bootstrap/FeatureContext.php +++ b/test/features/bootstrap/FeatureContext.php @@ -2,12 +2,16 @@ use Drupal\DrupalExtension\Context\DrupalContext; use Behat\Behat\Context\Step\Given; +use Behat\Behat\Context\BehatContext; use Symfony\Component\Process\Process; +use Behat\Gherkin\Node\TableNode; require 'vendor/autoload.php'; class FeatureContext extends DrupalContext { + // Keep track of created data dashboards so they can be cleaned up. + protected $data_dashboards = array(); /** * @Given /^I scroll to the top$/ @@ -252,4 +256,53 @@ class FeatureContext extends DrupalContext $element = $session->getPage(); return $element->findLink($this->getDrupalText('log_out')); } + + /************************************/ + /* DATA DASHBOARDS */ + /************************************/ + + /** + * @Given data_dashboards: + */ + public function addDataDashboard(TableNode $data_dashboards_table) { + + // Map readable field names to drupal field names. + $field_map = array( + 'title' => 'title', + ); + + foreach ($data_dashboards_table->getHash() as $data_dashboards_hash) { + + $node = new stdClass(); + $node->type = 'data_dashboard'; + + foreach($data_dashboards_hash as $field => $value) { + + if(isset($field_map[$field])) { + $drupal_field = $field_map[$field]; + $node->$drupal_field = $value; + } + else { + throw new Exception(sprintf("Data Dashboard field %s doesn't exist, or hasn't been mapped. See FeatureContext::addDataDashboard for mappings.", $field)); + } + } + $created_node = $this->getDriver()->createNode($node); + // Add the created node to the data dashboards array. + $this->data_dashboards[$created_node->nid] = $created_node; + } + } + + /** + * Clean up generated content. + */ + public function afterScenario($event) { + + parent::afterScenario($event); + + if (!empty($this->data_dashboards)) { + foreach ($this->data_dashboards as $data_dashboard_id => $data_dashboard) { + $this->getDriver()->nodeDelete($data_dashboard); + } + } + } } diff --git a/test/features/data_dashboard.feature b/test/features/data_dashboard.feature new file mode 100644 index 0000000000000000000000000000000000000000..bc5a2467161734408b1c5283e6c49b07b9d2b229 --- /dev/null +++ b/test/features/data_dashboard.feature @@ -0,0 +1,50 @@ +Feature: Data Dashboard + + Background: + Given data_dashboards: + | title | + | Dashboard 01 | + | Dashboard 02 | + + @api + Scenario: See the list of data dashboards + Given I am logged in as a user with the "administrator" role + When I am on "admin/dkan/data-dashboards" + Then I should see the text "Dashboard 01" in the "dashboards" region + And I should see the text "Dashboard 02" in the "dashboards" region + + @api + Scenario: Creation of data dashboard + Given I am logged in as a user with the "administrator" role + And I am on "admin/dkan/data-dashboards" + And I click "Create Dashboard" + Then I should see "Create Data Dashboard" + When I fill in "title" with "My new dashboard" + And I select the radio button "Radix Boxton" with the id "edit-layout-radix-boxton" + And I press "Save" + Then I should see "Your Data Dashboard 'My new dashboard' has been created" + And I should see "Start adding content by clicking on the + sign on each panel" + + @api + Scenario: Edition of data dashboard + Given I am logged in as a user with the "administrator" role + And I am on "/dashboard-01" + When I click "Edit" + And I fill in "title" with "Edited Dashboard" + And I press "Save" + Then I should see "Data Dashboard Edited Dashboard has been updated" + When I am on "admin/dkan/data-dashboards" + Then I should see the text "Edited Dashboard" in the "dashboards" region + And I should not see the text "Dashboard 01" in the "dashboards" region + + @api + Scenario: Deletion of data dashboard + Given I am logged in as a user with the "administrator" role + And I am on "/dashboard-01" + When I click "Edit" + And I press "Delete" + Then I should see "Are you sure you want to delete Dashboard 01?" + When I press "Delete" + Then I should see "Data Dashboard Dashboard 01 has been deleted" + When I am on "admin/dkan/data-dashboards" + Then I should not see the text "Dashboard 01" in the "dashboards" region