Skip to content

Commit

Permalink
Merge pull request #24 from openeuropa/OPENEUROPA-1500
Browse files Browse the repository at this point in the history
OPENEUROPA-1500: Create configuration UI for Webtools Analytics module
  • Loading branch information
nagyad committed Jan 11, 2019
2 parents 454c121 + 04f742d commit d580d2b
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 1 deletion.
3 changes: 3 additions & 0 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ default:
- Drupal\DrupalExtension\Context\MessageContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsAnalyticsMinkContext
- Drupal\Tests\oe_webtools\Behat\WebtoolsConfigContext
- OpenEuropa\Behat\TransformationContext:
pages:
Webtools Analytics configuration: '/admin/config/system/oe_webtools_analytics'
extensions:
Behat\MinkExtension:
goutte: ~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ oe_webtools_analytics.settings:
instance:
type: string
label: 'Instance'
description: 'The test server instance. e.g. testing, ec.europa.eu or europa.eu.'
description: 'The server instance. e.g. testing, ec.europa.eu or europa.eu.'
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ package: OpenEuropa Webtools
type: module
version: 1.0
core: 8.x
configure: oe_webtools_analytics.settings
dependencies:
- oe_webtools
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
oe_webtools_analytics.settings:
title: Webtools Analytics
description: 'Configure Webtools Analytics.'
route_name: oe_webtools_analytics.settings
parent: system.admin_config_system
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
administer webtools analytics:
title: 'Administer Webtools Analytics'
restrict access: false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
oe_webtools_analytics.settings:
path: '/admin/config/system/oe_webtools_analytics'
defaults:
_form: 'Drupal\oe_webtools_analytics\Form\WebtoolsAnalyticsSettingsForm'
_title: 'Webtools Analytics settings'
requirements:
_permission: 'administer webtools analytics'
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_webtools_analytics\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* Settings form for module.
*/
class WebtoolsAnalyticsSettingsForm extends ConfigFormBase {

/**
* Name of the config being edited.
*/
const CONFIG_NAME = 'oe_webtools_analytics.settings';

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'oe_webtools_analytics_settings';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['siteID'] = [
'#type' => 'number',
'#title' => $this->t('Site ID'),
'#default_value' => $this->config(static::CONFIG_NAME)->get('siteID'),
'#description' => $this->t('The site unique numeric identifier.'),
];
$form['sitePath'] = [
'#type' => 'textfield',
'#title' => $this->t('Site path'),
'#default_value' => $this->config(static::CONFIG_NAME)->get('sitePath'),
'#description' => $this->t('The domain + root path without protocol.'),
];
$form['instance'] = [
'#type' => 'textfield',
'#title' => $this->t('Instance'),
'#default_value' => $this->config(static::CONFIG_NAME)->get('instance'),
'#description' => $this->t('The server instance. e.g. testing, ec.europa.eu or europa.eu.'),
];

return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config(static::CONFIG_NAME)
->set('siteID', $form_state->getValue('siteID'))
->set('sitePath', $form_state->getValue('sitePath'))
->set('instance', $form_state->getValue('instance'))
->save();
parent::submitForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['oe_webtools_analytics.settings'];
}

}
13 changes: 13 additions & 0 deletions tests/Behat/WebtoolsConfigContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,17 @@ public function backupLacoConfigs() {
}
}

/**
* Backup configs that need to be reverted in AfterScenario by ConfigContext.
*
* @BeforeScenario @BackupAnalyticsConfigs
*/
public function backupAnalyticsConfigs() {
$name = 'oe_webtools_analytics.settings';
$configs = $this->getDriver()->getCore()->configGet($name);
foreach ($configs as $key => $value) {
$this->configContext->setConfig($name, $key, $value);
}
}

}
19 changes: 19 additions & 0 deletions tests/features/analytics.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@api
Feature: Webtools Analytics
In order to provide analytics
As the site manager
I need to be able to configure the settings

@BackupAnalyticsConfigs
Scenario: Create Webtools Analytics settings
Given I am logged in as a user with the "administer webtools analytics" permission
And I am on "the Webtools Analytics configuration page"
Then I should see "Webtools Analytics settings"
When I fill in "Site ID" with "123456"
And I fill in "Site path" with "ec.europa.eu/info"
And I fill in "Instance" with "ec.europa.eu"
And I press "Save configuration"
Then I should see the message "The configuration options have been saved."
And the "Site ID" field should contain "123456"
And the "Site path" field should contain "ec.europa.eu/info"
And the "Instance" field should contain "ec.europa.eu"

0 comments on commit d580d2b

Please sign in to comment.