summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMariano Carballal2015-07-01 19:52:14 (GMT)
committerMariano Carballal2015-07-01 19:52:14 (GMT)
commitdad1fd4b1acafe6a6f0dc7e480009ae56d92c4ad (patch)
tree9e9d978e516a94477ebb47ddb50d066949caa796
parentaa7a554513ad57d1bf45e7ec9d4b21baab38a5fd (diff)
parentaac37248645b0b9d7a75cc0e71bf326faf12edbc (diff)
Merge pull request #537 from NuCivic/670_data_dashboard_tests
NuCivic/internal#670: Added tests for Data Dashboards.
-rw-r--r--.travis.yml1
-rw-r--r--test/behat.yml4
-rw-r--r--test/features/bootstrap/FeatureContext.php53
-rw-r--r--test/features/data_dashboard.feature50
4 files changed, 108 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml
index 28eb77f..15d76ef 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 e9d3d44..e847713 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 e4781aa..bd1ab53 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 0000000..bc5a246
--- /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