Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fillpdf
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal.org
fillpdf
Commits
44c27c7d
Commit
44c27c7d
authored
6 years ago
by
Bernd Oliver Suenderhauf
Browse files
Options
Downloads
Patches
Plain Diff
Issue #3044868 by Pancho: Don't save unvalidated backend configuration if another backend is chosen
parent
63f2c1dc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Form/FillPdfSettingsForm.php
+23
-9
23 additions, 9 deletions
src/Form/FillPdfSettingsForm.php
tests/src/Functional/FillPdfSettingsFormTest.php
+33
-5
33 additions, 5 deletions
tests/src/Functional/FillPdfSettingsFormTest.php
with
56 additions
and
14 deletions
src/Form/FillPdfSettingsForm.php
+
23
−
9
View file @
44c27c7d
...
@@ -286,15 +286,29 @@ class FillPdfSettingsForm extends ConfigFormBase {
...
@@ -286,15 +286,29 @@ class FillPdfSettingsForm extends ConfigFormBase {
*/
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// Save form values.
// Save form values.
$this
->
config
(
'fillpdf.settings'
)
$values
=
$form_state
->
getValues
();
->
set
(
'backend'
,
$form_state
->
getValue
(
'backend'
))
$config
=
$this
->
config
(
'fillpdf.settings'
);
->
set
(
'remote_endpoint'
,
$form_state
->
getValue
(
'remote_endpoint'
))
->
set
(
'fillpdf_service_api_key'
,
$form_state
->
getValue
(
'fillpdf_service_api_key'
))
$config
->
set
(
'scheme'
,
$values
[
'scheme'
])
->
set
(
'remote_protocol'
,
$form_state
->
getValue
(
'remote_protocol'
))
->
set
(
'backend'
,
$values
[
'backend'
]);
->
set
(
'pdftk_path'
,
$form_state
->
getValue
(
'pdftk_path'
))
->
set
(
'scheme'
,
$form_state
->
getValue
(
'scheme'
))
switch
(
$values
[
'backend'
])
{
->
set
(
'local_service_endpoint'
,
$form_state
->
getValue
(
'local_service_endpoint'
))
case
'fillpdf_service'
:
->
save
();
$config
->
set
(
'remote_endpoint'
,
$values
[
'remote_endpoint'
])
->
set
(
'fillpdf_service_api_key'
,
$values
[
'fillpdf_service_api_key'
])
->
set
(
'remote_protocol'
,
$values
[
'remote_protocol'
]);
break
;
case
'local_service'
:
$config
->
set
(
'local_service_endpoint'
,
$values
[
'local_service_endpoint'
]);
break
;
case
'pdftk'
:
$config
->
set
(
'pdftk_path'
,
$form_state
->
getValue
(
'pdftk_path'
));
break
;
}
$config
->
save
();
parent
::
submitForm
(
$form
,
$form_state
);
parent
::
submitForm
(
$form
,
$form_state
);
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/FillPdfSettingsFormTest.php
+
33
−
5
View file @
44c27c7d
...
@@ -120,6 +120,30 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
...
@@ -120,6 +120,30 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
'scheme'
),
'private'
);
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
'scheme'
),
'private'
);
}
}
/**
* Tests the backend settings with the 'fillpdf_service' backend.
*/
public
function
testSettingsFormBackendFillPdfService
()
{
// FillPDF is not yet configured. The settings form is however initialized
// with the 'fillpdf_service' backend. Save that configuration.
$this
->
drupalPostForm
(
Url
::
fromRoute
(
'fillpdf.settings'
),
NULL
,
'Save configuration'
);
// There's currently no validation, so the 'backend' setting should be
// both submitted and stored.
$this
->
assertSession
()
->
pageTextContains
(
'The configuration options have been saved.'
);
$this
->
assertSession
()
->
fieldValueEquals
(
'backend'
,
'fillpdf_service'
);
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
'backend'
),
'fillpdf_service'
);
// Now add an API key and save again.
$this
->
drupalPostForm
(
NULL
,
[
'fillpdf_service_api_key'
=>
'Invalid, just playing around.'
],
'Save configuration'
);
// There's currently no validation, so the obviously invalid
// 'fillpdf_service_api_key' should be both submitted and stored.
$this
->
assertSession
()
->
pageTextContains
(
'The configuration options have been saved.'
);
$this
->
assertSession
()
->
fieldValueEquals
(
'fillpdf_service_api_key'
,
'Invalid, just playing around.'
);
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
'fillpdf_service_api_key'
),
'Invalid, just playing around.'
);
}
/**
/**
* Tests the backend settings with the 'pdftk' backend.
* Tests the backend settings with the 'pdftk' backend.
*/
*/
...
@@ -155,12 +179,14 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
...
@@ -155,12 +179,14 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
$this
->
assertSession
()
->
pageTextContainsOnce
(
'plugin for testing'
);
$this
->
assertSession
()
->
pageTextContainsOnce
(
'plugin for testing'
);
$this
->
assertSession
()
->
pageTextContains
(
'Form-altered pass-through plugin for testing'
);
$this
->
assertSession
()
->
pageTextContains
(
'Form-altered pass-through plugin for testing'
);
// Try configuring FillPDF with the 'test' backend, yet an invalid value
// Try configuring FillPDF with the 'test' backend, yet with invalid values
// for the form-altered configuration setting.
// for the form-altered 'example_setting' and the unrelated
// 'fillpdf_service_api_key'.
$edit
=
[
$edit
=
[
'scheme'
=>
'private'
,
'scheme'
=>
'private'
,
'backend'
=>
'test'
,
'backend'
=>
'test'
,
'example_setting'
=>
'x'
,
'example_setting'
=>
'x'
,
'fillpdf_service_api_key'
=>
'Invalid, just playing around.'
,
];
];
$this
->
drupalPostForm
(
NULL
,
$edit
,
'Save configuration'
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
'Save configuration'
);
...
@@ -182,10 +208,12 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
...
@@ -182,10 +208,12 @@ class FillPdfSettingsFormTest extends BrowserTestBase {
// This time, our custom validation handler passes.
// This time, our custom validation handler passes.
$this
->
assertSession
()
->
pageTextNotContains
(
'Not a valid value.'
);
$this
->
assertSession
()
->
pageTextNotContains
(
'Not a valid value.'
);
$this
->
assertSession
()
->
pageTextContains
(
'The configuration options have been saved.'
);
$this
->
assertSession
()
->
pageTextContains
(
'The configuration options have been saved.'
);
// So the new values should be submitted *and* saved this time.
// So the new values should be submitted *and* saved this time, except for
foreach
(
$edit
as
$field
=>
$value
)
{
// the unrelated 'fillpdf_service_api_key' which should be dismissed.
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
$field
),
$value
);
$expected
=
[
'fillpdf_service_api_key'
=>
NULL
]
+
$edit
;
foreach
(
$expected
as
$field
=>
$value
)
{
$this
->
assertSession
()
->
fieldValueEquals
(
$field
,
$value
);
$this
->
assertSession
()
->
fieldValueEquals
(
$field
,
$value
);
$this
->
assertEqual
(
$this
->
config
(
'fillpdf.settings'
)
->
get
(
$field
),
$value
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment