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

OPENEUROPA-1500: Create configuration UI for Webtools Analytics module #24

Merged
merged 11 commits into from
Jan 11, 2019
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 CONFIGNAME = 'oe_webtools_analytics.settings';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this into WebtoolsAnalyticsSettingsForm::CONFIG_NAME.


/**
* {@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::CONFIGNAME)->get('siteID'),
'#description' => $this->t('The site unique numeric identifier.'),
];
$form['sitePath'] = [
'#type' => 'textfield',
'#title' => $this->t('Site path'),
'#default_value' => $this->config(static::CONFIGNAME)->get('sitePath'),
'#description' => $this->t('The domain + root path without protocol.'),
];
$form['instance'] = [
'#type' => 'textfield',
'#title' => $this->t('Instance'),
'#default_value' => $this->config(static::CONFIGNAME)->get('instance'),
'#description' => $this->t('The server instance. e.g. testing, ec.europa.eu or europa.eu.'),
];
drupol marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config(static::CONFIGNAME)
->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
nagyad marked this conversation as resolved.
Show resolved Hide resolved
Given I am logged in as a user with the "administer webtools analytics" permission
And I am on "admin/config/system/oe_webtools_analytics"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the transformation context to turn this path into a business readable string, such as:

    And I am on "the Webtools Analytics configuration page"

And then in the behat.yml.dist:

      - OpenEuropa\Behat\TransformationContext:
          pages:
            Webtools Analytics configuration: "/admin/config/system/oe_webtools_analytics"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work for me.

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"