Skip to content

Commit

Permalink
OPENEUROPA-1500: Add validation for Site ID input field.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagyad committed Jan 7, 2019
1 parent ca8df1f commit cec4035
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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
Expand Up @@ -39,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textfield',
'#title' => $this->t('Site ID'),
'#default_value' => $this->config(static::CONFIGNAME)->get('siteID'),
'#description' => $this->t('The site unique identifier.'),
'#description' => $this->t('The site unique numeric identifier.'),
];
$form['sitePath'] = [
'#type' => 'textfield',
Expand All @@ -56,6 +56,18 @@ public function buildForm(array $form, FormStateInterface $form_state) {
return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {

This comment has been minimized.

Copy link
@drupol

drupol Jan 7, 2019

Contributor

I would definitely remove this logic and use

'#type' => 'number'

instead of

'#type' => 'textfield'

for the site ID.

parent::validateForm($form, $form_state);

$site_id = $form_state->getValue('siteID');
if (!is_numeric($site_id)) {
$form_state->setErrorByName('siteID', $this->t('The value must be numeric.'));
}
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 7 additions & 2 deletions tests/features/analytics.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ Feature: Webtools Analytics
Given I am logged in as a user with the "administer site configuration" permission

Scenario: Create Webtools Analytics settings
Given I am on "admin/config/regional/oe_webtools_analytics"
Given I am on "admin/config/system/oe_webtools_analytics"
Then I should see "Webtools Analytics settings"
When I fill in "Site ID" with "INFO"
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 value must be numeric."
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 "INFO"
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 cec4035

Please sign in to comment.