Commit e008d3a5 authored by webchick's avatar webchick
Browse files

Issue #2030165 by Berdir, tim.plunkett, vijaycs85, tkuldeep17 | rteijeiro:...

Issue #2030165 by Berdir, tim.plunkett, vijaycs85, tkuldeep17 | rteijeiro: Convert form_test_* functions to classes.
parent b96e8232
......@@ -32,7 +32,7 @@ function testFormCheckbox() {
// #return_value, with the exception of integer 0, which is not supported.
// @see form_process_checkbox().
foreach (array('0', '', 1, '1', 'foobar', '1foobar') as $return_value) {
$form_array = \Drupal::formBuilder()->getForm('form_test_checkbox_type_juggling', $default_value, $return_value);
$form_array = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestCheckboxTypeJugglingForm', $default_value, $return_value);
$form = drupal_render($form_array);
if ($default_value === TRUE) {
$checked = TRUE;
......
......@@ -10,6 +10,7 @@
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\String;
use Drupal\Core\Render\Element;
use Drupal\form_test\Form\FormTestDisabledElementsForm;
use Drupal\simpletest\WebTestBase;
/**
......@@ -158,11 +159,10 @@ function testRequiredFields() {
* is submitted twice, first without values for required fields and then
* with values. Each submission is checked for relevant error messages.
*
* @see form_test_validate_required_form()
* @see \Drupal\form_test\Form\FormTestValidateRequiredForm
*/
function testRequiredCheckboxesRadio() {
$form = $form_state = array();
$form = form_test_validate_required_form($form, $form_state);
$form = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestValidateRequiredForm');
// Attempt to submit the form with no required fields set.
$edit = array();
......@@ -235,7 +235,7 @@ function testRequiredCheckboxesRadio() {
* and then with value. Each submission is checked for relevant error
* messages.
*
* @see form_test_validate_required_form_no_title()
* @see \Drupal\form_test\Form\FormTestValidateRequiredNoTitleForm
*/
function testRequiredTextfieldNoTitle() {
// Attempt to submit the form with no required field set.
......@@ -293,8 +293,7 @@ function testCheckboxProcessing() {
* Tests validation of #type 'select' elements.
*/
function testSelect() {
$form = $form_state = array();
$form = form_test_select($form, $form_state);
$form = \Drupal::formBuilder()->getForm('Drupal\form_test\Form\FormTestSelectForm');
$error = '!name field is required.';
$this->drupalGet('form-test/select');
......@@ -366,8 +365,7 @@ function testEmptySelect() {
* Tests validation of #type 'number' and 'range' elements.
*/
function testNumber() {
$form = $form_state = array();
$form = form_test_number($form, $form_state);
$form = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestNumberForm');
// Array with all the error messages to be checked.
$error_messages = array(
......@@ -484,7 +482,7 @@ function testColorValidation() {
function testDisabledElements() {
// Get the raw form in its original state.
$form_state = array();
$form = _form_test_disabled_elements(array(), $form_state);
$form = (new FormTestDisabledElementsForm())->buildForm(array(), $form_state);
// Build a submission that tries to hijack the form by submitting input for
// elements that are disabled.
......@@ -568,8 +566,7 @@ function assertFormValuesDefault($values, $form) {
*/
function testDisabledMarkup() {
$this->drupalGet('form-test/disabled-elements');
$form_state = array();
$form = _form_test_disabled_elements(array(), $form_state);
$form = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestDisabledElementsForm');
$type_map = array(
'textarea' => 'textarea',
'select' => 'select',
......
......@@ -72,7 +72,7 @@ function testSubmissionWorkflow() {
private function submitForm($values, $valid_input) {
// Programmatically submit the given values.
$form_state = array('values' => $values);
drupal_form_submit('form_test_programmatic_form', $form_state);
\Drupal::formBuilder()->submitForm('\Drupal\form_test\Form\FormTestProgrammaticForm', $form_state);
// Check that the form returns an error when expected, and vice versa.
$errors = form_get_errors($form_state);
......@@ -106,7 +106,7 @@ public function testProgrammaticAccessBypass() {
// Programmatically submit the form with a value for the restricted field.
// Since programmed_bypass_access_check is set to TRUE by default, the
// field is accessible and can be set.
\Drupal::formBuilder()->submitForm('form_test_programmatic_form', $form_state);
\Drupal::formBuilder()->submitForm('\Drupal\form_test\Form\FormTestProgrammaticForm', $form_state);
$values = $form_state['storage']['programmatic_form_submit'];
$this->assertEqual($values['field_restricted'], 'dummy value', 'The value for the restricted field is stored correctly.');
......@@ -115,7 +115,7 @@ public function testProgrammaticAccessBypass() {
// restrictions apply, the restricted field is inaccessible, and the value
// should not be stored.
$form_state['programmed_bypass_access_check'] = FALSE;
\Drupal::formBuilder()->submitForm('form_test_programmatic_form', $form_state);
\Drupal::formBuilder()->submitForm('\Drupal\form_test\Form\FormTestProgrammaticForm', $form_state);
$values = $form_state['storage']['programmatic_form_submit'];
$this->assertNotEqual($values['field_restricted'], 'dummy value', 'The value for the restricted field is not stored.');
......
......@@ -197,11 +197,10 @@ function testPatternValidation() {
/**
* Tests #required with custom validation errors.
*
* @see form_test_validate_required_form()
* @see \Drupal\form_test\Form\FormTestValidateRequiredForm
*/
function testCustomRequiredError() {
$form = $form_state = array();
$form = form_test_validate_required_form($form, $form_state);
$form = \Drupal::formBuilder()->getForm('\Drupal\form_test\Form\FormTestValidateRequiredForm');
// Verify that a custom #required error can be set.
$edit = array();
......
......@@ -71,7 +71,7 @@ form_test.autocomplete_2:
form_test.alter_form:
path: '/form-test/alter'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::alterForm'
_form: '\Drupal\form_test\Form\FormTestAlterForm'
_title: 'Form altering test'
requirements:
_access: 'TRUE'
......@@ -79,7 +79,7 @@ form_test.alter_form:
form_test.validate_form:
path: '/form-test/validate'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::validateForm'
_form: '\Drupal\form_test\Form\FormTestValidateForm'
_title: 'Form validation handlers test'
requirements:
_access: 'TRUE'
......@@ -87,7 +87,7 @@ form_test.validate_form:
form_test.validate_required:
path: '/form-test/validate-required'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::validateRequiredForm'
_form: '\Drupal\form_test\Form\FormTestValidateRequiredForm'
_title: 'Form #required validation'
requirements:
_access: 'TRUE'
......@@ -95,7 +95,7 @@ form_test.validate_required:
form_test.validate_required_no_title:
path: '/form-test/validate-required-no-title'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::validateRequiredFormNoTitle'
_form: '\Drupal\form_test\Form\FormTestValidateRequiredNoTitleForm'
_title: 'Form #required validation without #title'
requirements:
_access: 'TRUE'
......@@ -103,7 +103,7 @@ form_test.validate_required_no_title:
form_test.validate_with_error_suppresion:
path: '/form-test/limit-validation-errors'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::validateFormWithErrorSuppression'
_form: '\Drupal\form_test\Form\FormTestLimitValidationErrorsForm'
_title: 'Form validation with some error suppression'
requirements:
_access: 'TRUE'
......@@ -111,7 +111,7 @@ form_test.validate_with_error_suppresion:
form_test.pattern:
path: '/form-test/pattern'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::validatePattern'
_form: '\Drupal\form_test\Form\FormTestPatternForm'
_title: 'Pattern validation'
requirements:
_access: 'TRUE'
......@@ -167,7 +167,7 @@ form_test.vertical_tabs:
form_test.storage:
path: '/form_test/form-storage'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testStorage'
_form: '\Drupal\form_test\Form\FormTestStorageForm'
_title: 'Form storage test'
requirements:
_access: 'TRUE'
......@@ -175,7 +175,7 @@ form_test.storage:
form_test.state_clean:
path: '/form_test/form-state-values-clean'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testFormStateClean'
_form: '\Drupal\form_test\Form\FormTestFormStateValuesCleanForm'
_title: 'Form state values clearance test'
requirements:
_access: 'TRUE'
......@@ -183,7 +183,7 @@ form_test.state_clean:
form_test.state_clean_advanced:
path: '/form_test/form-state-values-clean-advanced'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testFormStateCleanAdvanced'
_form: '\Drupal\form_test\Form\FormTestFormStateValuesCleanAdvancedForm'
_title: 'Form state values clearance advanced test'
requirements:
_access: 'TRUE'
......@@ -199,7 +199,7 @@ form_test.checkbox:
form_test.select:
path: '/form-test/select'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testSelect'
_form: '\Drupal\form_test\Form\FormTestSelectForm'
_title: 'Select'
requirements:
_access: 'TRUE'
......@@ -207,7 +207,7 @@ form_test.select:
form_test.empty_select:
path: '/form-test/empty-select'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testEmptySelect'
_form: '\Drupal\form_test\Form\FormTestEmptySelectForm'
_title: 'Empty Select Element'
requirements:
_access: 'TRUE'
......@@ -215,7 +215,7 @@ form_test.empty_select:
form_test.language_select:
path: '/form-test/language_select'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testLanguageSelect'
_form: '\Drupal\form_test\Form\FormTestLanguageSelectForm'
_title: 'Language Select'
requirements:
_access: 'TRUE'
......@@ -223,7 +223,7 @@ form_test.language_select:
form_test.placeholder:
path: '/form-test/placeholder-text'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testPlaceholder'
_form: '\Drupal\form_test\Form\FormTestPlaceholderForm'
_title: 'Placeholder'
requirements:
_access: 'TRUE'
......@@ -231,7 +231,7 @@ form_test.placeholder:
form_test.number:
path: '/form-test/number'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testNumber'
_form: '\Drupal\form_test\Form\FormTestNumberForm'
_title: 'Number'
requirements:
_access: 'TRUE'
......@@ -239,15 +239,16 @@ form_test.number:
form_test.number_range:
path: '/form-test/number/range'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testNumberRange'
_form: '\Drupal\form_test\Form\FormTestNumberForm'
_title: 'Range'
element: 'range'
requirements:
_access: 'TRUE'
form_test.range:
path: '/form-test/range'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testRange'
_form: '\Drupal\form_test\Form\FormTestRangeForm'
_title: 'Range'
requirements:
_access: 'TRUE'
......@@ -255,7 +256,7 @@ form_test.range:
form_test.range_invalid:
path: '/form-test/range/invalid'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testRangeInvalid'
_form: '\Drupal\form_test\Form\FormTestRangeInvalidForm'
_title: 'Invalid range'
requirements:
_access: 'TRUE'
......@@ -263,7 +264,7 @@ form_test.range_invalid:
form_test.color:
path: '/form-test/color'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testColor'
_form: '\Drupal\form_test\Form\FormTestColorForm'
_title: 'Color'
requirements:
_access: 'TRUE'
......@@ -271,7 +272,7 @@ form_test.color:
form_test.checkboxes_radios:
path: '/form-test/checkboxes-radios/{customize}'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testCheckboxesRadios'
_form: '\Drupal\form_test\Form\FormTestCheckboxesRadiosForm'
_title: 'Checkboxes, Radios'
customize: FALSE
requirements:
......@@ -280,7 +281,7 @@ form_test.checkboxes_radios:
form_test.email:
path: '/form-test/email'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testEmail'
_form: '\Drupal\form_test\Form\FormTestEmailForm'
_title: 'Email fields'
requirements:
_access: 'TRUE'
......@@ -288,7 +289,7 @@ form_test.email:
form_test.url:
path: '/form-test/url'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testUrl'
_form: '\Drupal\form_test\Form\FormTestUrlForm'
_title: 'URL'
requirements:
_access: 'TRUE'
......@@ -296,7 +297,7 @@ form_test.url:
form_test.disabled_elements:
path: '/form-test/disabled-elements'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testDisabledElements'
_form: '\Drupal\form_test\Form\FormTestDisabledElementsForm'
_title: 'Form test'
requirements:
_access: 'TRUE'
......@@ -312,7 +313,7 @@ form_test.input_forgery:
form_test.rebuild_preservation:
path: '/form-test/form-rebuild-preserve-values'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testRebuildPreservation'
_form: '\Drupal\form_test\Form\FormTestRebuildPreserveValuesForm'
_title: 'Form values preservation during rebuild test'
requirements:
_access: 'TRUE'
......@@ -320,7 +321,7 @@ form_test.rebuild_preservation:
form_test.redirect:
path: '/form-test/redirect'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testRedirect'
_form: '\Drupal\form_test\Form\FormTestRedirectForm'
_title: 'Redirect test'
requirements:
_access: 'TRUE'
......@@ -328,7 +329,7 @@ form_test.redirect:
form_test.label:
path: '/form_test/form-labels'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testLabel'
_form: '\Drupal\form_test\Form\FormTestLabelForm'
_title: 'Form label test'
requirements:
_access: 'TRUE'
......@@ -336,7 +337,7 @@ form_test.label:
form_test.state_persistence:
path: '/form-test/state-persist'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testStatePersistence'
_form: '\Drupal\form_test\Form\FormTestStatePersistForm'
_title: 'Form state persistence without storage'
requirements:
_access: 'TRUE'
......@@ -344,7 +345,7 @@ form_test.state_persistence:
form_test.clicked_button:
path: '/form-test/clicked-button/{first}/{second}/{third}'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testClickedButton'
_form: '\Drupal\form_test\Form\FormTestClickedButtonForm'
_title: 'Clicked button test'
first: NULL
second: NULL
......@@ -355,7 +356,7 @@ form_test.clicked_button:
form_test.checkboxes_zero:
path: '/form-test/checkboxes-zero/{json}'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testCheckboxesZero'
_form: '\Drupal\form_test\Form\FormTestCheckboxesZeroForm'
_title: 'FAPI test involving checkboxes and zero'
json: TRUE
requirements:
......@@ -364,7 +365,7 @@ form_test.checkboxes_zero:
form_test.required:
path: '/form-test/required-attribute'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testRequired'
_form: '\Drupal\form_test\Form\FormTestRequiredAttributeForm'
_title: 'Required'
requirements:
_access: 'TRUE'
......@@ -372,7 +373,7 @@ form_test.required:
form_test.button_class:
path: '/form-test/button-class'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testButtonClass'
_form: '\Drupal\form_test\Form\FormTestButtonClassForm'
_title: 'Button class testing'
requirements:
_access: 'TRUE'
......@@ -380,7 +381,7 @@ form_test.button_class:
form_test.group_details:
path: '/form-test/group-details'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testGroupDetails'
_form: '\Drupal\form_test\Form\FormTestGroupDetailsForm'
_title: 'Group details testing'
requirements:
_access: 'TRUE'
......@@ -388,7 +389,7 @@ form_test.group_details:
form_test.group_container:
path: '/form-test/group-container'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testGroupContainer'
_form: '\Drupal\form_test\Form\FormTestGroupContainerForm'
_title: 'Group container testing'
requirements:
_access: 'TRUE'
......@@ -396,7 +397,7 @@ form_test.group_container:
form_test.group_fieldset:
path: '/form-test/group-fieldset'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testGroupFieldset'
_form: '\Drupal\form_test\Form\FormTestGroupFieldsetForm'
_title: 'Group fieldset testing'
requirements:
_access: 'TRUE'
......@@ -404,7 +405,7 @@ form_test.group_fieldset:
form_test.group_vertical_tabs:
path: '/form-test/group-vertical-tabs'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testGroupVerticalTabs'
_form: '\Drupal\form_test\Form\FormTestGroupVerticalTabsForm'
_title: 'Group vertical tabs testing'
requirements:
_access: 'TRUE'
......@@ -412,7 +413,7 @@ form_test.group_vertical_tabs:
form_test.form_state_database:
path: '/form-test/form_state-database'
defaults:
_content: '\Drupal\form_test\Form\FormTestForm::testFormStateDatabase'
_form: '\Drupal\form_test\Form\FormTestFormStateDatabaseForm'
_title: 'Form state with a database connection'
requirements:
_access: 'TRUE'
......
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestAlterForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
/**
* Form builder for testing hook_form_alter() and hook_form_FORM_ID_alter().
*/
class FormTestAlterForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_alter_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
// Elements can be added as needed for future testing needs, but for now,
// we're only testing alter hooks that do not require any elements added by
// this function.
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestButtonClassForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
/**
* Builds a simple form to test form button classes.
*/
class FormTestButtonClassForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_button_class';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state) {
$form['button'] = array(
'#type' => 'button',
'#value' => 'test',
'#button_type' => 'foo',
);
$form['delete'] = array(
'#type' => 'button',
'#value' => 'Delete',
'#button_type' => 'danger',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
......@@ -91,10 +91,7 @@ public function buildForm(array $form, array &$form_state) {
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$response = new JsonResponse($form_state['values']);
// @todo remove once converted to new routing system.
$response->send();
exit;
$form_state['response'] = new JsonResponse($form_state['values']);
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestCheckboxTypeJugglingForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
/**
* Builds a form to test return values for checkboxes.
*/
class FormTestCheckboxTypeJugglingForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_checkbox_type_juggling';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, $default_value = NULL, $return_value = NULL) {
$form['checkbox'] = array(
'#title' => t('Checkbox'),
'#type' => 'checkbox',
'#return_value' => $return_value,
'#default_value' => $default_value,
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
}
}
<?php
/**
* @file
* Contains \Drupal\form_test\Form\FormTestCheckboxesRadiosForm.
*/
namespace Drupal\form_test\Form;
use Drupal\Core\Form\FormBase;
use Symfony\Component\HttpFoundation\JsonResponse;
/**
* Form constructor to test expansion of #type checkboxes and radios.
*/
class FormTestCheckboxesRadiosForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'form_test_checkboxes_radios';
}
/**
* {@inheritdoc}