Commit e81c0f12 authored by webchick's avatar webchick

Issue #2102653 by tim.plunkett, disasm: Convert test form callbacks to new form controller.

parent ad5810ed
......@@ -43,6 +43,8 @@ function field_test_entity_info_translatable($entity_type = NULL, $translatable
/**
* Form combining two separate entities.
*
* @deprecated Use \Drupal\field_test\Form\FieldTestForm::testEntityNestedForm()
*/
function field_test_entity_nested_form($form, &$form_state, $entity_1, $entity_2) {
// First entity.
......
......@@ -43,10 +43,7 @@ function field_test_menu() {
$items = array();
$items['test-entity/nested/%entity_test/%entity_test'] = array(
'title' => 'Nested entity form',
'page callback' => 'drupal_get_form',
'page arguments' => array('field_test_entity_nested_form', 2, 3),
'access arguments' => array('administer entity_test content'),
'type' => MENU_NORMAL_ITEM,
'route_name' => 'field_test.entity_nested_form',
);
return $items;
......
field_test.entity_nested_form:
path: '/test-entity/nested/{entity_1}/{entity_2}'
defaults:
_title: 'Nested entity form'
_content: '\Drupal\field_test\Form\FieldTestForm::testEntityNestedForm'
options:
parameters:
entity_1:
type: 'entity:entity_test'
entity_2:
type: 'entity:entity_test'
requirements:
_permission: 'administer entity_test content'
<?php
/**
* @file
* Contains \Drupal\field_test\Form\FieldTestForm.
*/
namespace Drupal\field_test\Form;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a form for field_test routes.
*/
class FieldTestForm {
/**
* @todo Remove field_test_entity_nested_form().
*/
public function testEntityNestedForm(EntityInterface $entity_1, EntityInterface $entity_2) {
module_load_include('entity.inc', 'field_test');
return drupal_get_form('field_test_entity_nested_form', $entity_1, $entity_2);
}
}
......@@ -9,28 +9,14 @@
use Drupal\file\Entity\File;
use Drupal\field\FieldInterface;
/**
* Implements hook_menu().
*/
function file_module_test_menu() {
$items = array();
$items['file/test'] = array(
'title' => 'Managed file test',
'page callback' => 'drupal_get_form',
'page arguments' => array('file_module_test_form'),
'access arguments' => array('access content'),
);
return $items;
}
/**
* Form constructor for testing a 'managed_file' element.
*
* @see file_module_test_menu()
* @see file_module_test_form_submit()
* @ingroup forms
*
* @deprecated Use \Drupal\file_module_test\Form\FileModuleTestForm::managedFileTest()
*/
function file_module_test_form($form, &$form_state, $tree = TRUE, $extended = TRUE, $multiple = FALSE, $default_fids = NULL) {
$form['#tree'] = (bool) $tree;
......
file_module_test.managed_test:
path: '/file/test/{tree}/{extended}/{multiple}/{default_fids}'
defaults:
_content: '\Drupal\file_module_test\Form\FileModuleTestForm::managedFileTest'
tree: TRUE
extended: TRUE
multiple: FALSE
default_fids: NULL
requirements:
_permission: 'access content'
<?php
/**
* @file
* Contains \Drupal\file_module_test\Form\FileModuleTestForm.
*/
namespace Drupal\file_module_test\Form;
/**
* Temporary form controller for file_module_test module.
*/
class FileModuleTestForm {
/**
* @todo Remove file_module_test_form().
*/
public function managedFileTest($tree, $extended, $multiple, $default_fids) {
return drupal_get_form('file_module_test_form', $tree, $extended, $multiple, $default_fids);
}
}
......@@ -5,27 +5,6 @@
* Mock module for language form elements test.
*/
/**
* Implements hook_menu().
*/
function language_elements_test_menu() {
$items['language-tests/language_configuration_element'] = array(
'title' => 'Language configuration form element',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array('language_elements_configuration_element'),
);
$items['language-tests/language_configuration_element_test'] = array(
'title' => 'Language configuration form element',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
'page callback' => 'drupal_get_form',
'page arguments' => array('language_elements_configuration_element_test'),
);
return $items;
}
/**
* A form containing a language configuration element.
*/
......
language_elements_test.config_element:
path: '/language-tests/language_configuration_element'
defaults:
_content: '\Drupal\language_elements_test\Form\LanguageElementsTestForm::configFormElement'
_title: 'Language configuration form element'
requirements:
_access: 'TRUE'
language_elements_test.config_element_test:
path: '/language-tests/language_configuration_element_test'
defaults:
_content: '\Drupal\language_elements_test\Form\LanguageElementsTestForm::configFormElementTest'
_title: 'Language configuration form element'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\language_elements_test\Form\LanguageElementsTestForm.
*/
namespace Drupal\language_elements_test\Form;
/**
* Controller routines for language_elements_test routes.
*/
class LanguageElementsTestForm {
/**
* Wraps language_elements_configuration_element().
*
* @todo Remove language_elements_configuration_element().
*/
public function configFormElement() {
return drupal_get_form('language_elements_configuration_element');
}
/**
* Wraps language_element_tests_configuration_element_test().
*
* @todo Remove language_element_tests_configuration_element_test().
*/
public function configFormElementTest() {
return drupal_get_form('language_elements_configuration_element_test');
}
}
<?php
/**
* @file
* Contains \Drupal\search_embedded_form\Form\SearchEmbeddedForm.
*/
namespace Drupal\search_embedded_form\Form;
/**
* Temporary form controller for search_embedded_form module.
*/
class SearchEmbeddedForm {
/**
* @todo Remove search_embedded_form_form().
*/
public function testEmbeddedForm() {
return drupal_get_form('search_embedded_form_form');
}
}
......@@ -9,25 +9,12 @@
* individual product (node) listed in the search results.
*/
/**
* Implements hook_menu().
*/
function search_embedded_form_menu() {
$items['search_embedded_form'] = array(
'title' => 'Search_Embed_Form',
'page callback' => 'drupal_get_form',
'page arguments' => array('search_embedded_form_form'),
'access arguments' => array('search content'),
'type' => MENU_CALLBACK,
);
return $items;
}
/**
* Form constructor for embedding search results for testing.
*
* @see search_embedded_form_form_submit().
*
* @deprecated Use \Drupal\search_embedded_form\Form\SearchEmbeddedForm::testEmbeddedForm()
*/
function search_embedded_form_form($form, &$form_state) {
$count = \Drupal::config('search_embedded_form.settings')->get('submitted');
......
search_embedded_form.test_embedded_form:
path: '/search_embedded_form'
defaults:
_title: 'Search_Embed_Form'
_content: '\Drupal\search_embedded_form\Form\SearchEmbeddedForm::testEmbeddedForm'
requirements:
_permission: 'search content'
......@@ -46,34 +46,34 @@ function testBatchNoForm() {
function testBatchForm() {
// Batch 0: no operation.
$edit = array('batch' => 'batch_0');
$this->drupalPostForm('batch-test/simple', $edit, 'Submit');
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_0'), 'Batch with no operation performed successfully.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
// Batch 1: several simple operations.
$edit = array('batch' => 'batch_1');
$this->drupalPostForm('batch-test/simple', $edit, 'Submit');
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_1'), 'Batch with simple operations performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_1'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
// Batch 2: one multistep operation.
$edit = array('batch' => 'batch_2');
$this->drupalPostForm('batch-test/simple', $edit, 'Submit');
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_2'), 'Batch with multistep operation performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_2'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
// Batch 3: simple + multistep combined.
$edit = array('batch' => 'batch_3');
$this->drupalPostForm('batch-test/simple', $edit, 'Submit');
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_3'), 'Batch with simple and multistep operations performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_3'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
// Batch 4: nested batch.
$edit = array('batch' => 'batch_4');
$this->drupalPostForm('batch-test/simple', $edit, 'Submit');
$this->drupalPostForm('batch-test', $edit, 'Submit');
$this->assertBatchMessages($this->_resultMessages('batch_4'), 'Nested batch performed successfully.');
$this->assertEqual(batch_test_stack(), $this->_resultStack('batch_4'), 'Execution order was correct.');
$this->assertText('Redirection successful.', 'Redirection after batch execution is correct.');
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Form\FileInclusionTest.
*/
namespace Drupal\system\Tests\Form;
use Drupal\simpletest\WebTestBase;
/**
* Tests form API file inclusion.
*/
class FileInclusionTest extends WebTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('form_test');
public static function getInfo() {
return array(
'name' => 'Form API file inclusion',
'description' => 'Tests form API file inclusion.',
'group' => 'Form API',
);
}
/**
* Tests loading an include specified in hook_menu().
*/
function testLoadMenuInclude() {
$this->drupalPostAjaxForm('form-test/load-include-menu', array(), array('op' => t('Save')), 'system/ajax', array(), array(), 'form-test-load-include-menu');
$this->assertText('Submit callback called.');
}
/**
* Tests loading a custom specified include.
*/
function testLoadCustomInclude() {
$this->drupalPostForm('form-test/load-include-custom', array(), t('Save'));
$this->assertText('Submit callback called.');
}
}
......@@ -9,40 +9,10 @@
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\ajax_forms_test\Callbacks;
/**
* Implements hook_menu().
*/
function ajax_forms_test_menu() {
$items = array();
$items['ajax_forms_test_get_form'] = array(
'title' => 'AJAX forms simple form test',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_forms_test_simple_form'),
'access callback' => TRUE,
);
$items['ajax_forms_test_ajax_commands_form'] = array(
'title' => 'AJAX forms AJAX commands test',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_forms_test_ajax_commands_form'),
'access callback' => TRUE,
);
$items['ajax_validation_test'] = array(
'title' => 'AJAX Validation Test',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_forms_test_validation_form'),
'access callback' => TRUE,
);
$items['ajax_forms_test_lazy_load_form'] = array(
'title' => 'AJAX forms lazy load test',
'page callback' => 'drupal_get_form',
'page arguments' => array('ajax_forms_test_lazy_load_form'),
'access callback' => TRUE,
);
return $items;
}
/**
* Tests form_state['values'] during callback.
*
* @deprecated Use \Drupal\ajax_forms_test\Form\AjaxFormsTestForm::getForm()
*/
function ajax_forms_test_simple_form($form, &$form_state) {
$object = new Callbacks();
......@@ -95,6 +65,8 @@ function ajax_forms_test_simple_form($form, &$form_state) {
/**
* Form constructor for the Ajax Command display form.
*
* @deprecated Use \Drupal\ajax_forms_test\Form\AjaxFormsTestForm::commandsForm()
*/
function ajax_forms_test_ajax_commands_form($form, &$form_state) {
$form = array();
......@@ -462,6 +434,8 @@ function ajax_forms_test_advanced_commands_settings_with_merging_callback($form,
* be able to trigger without causing validation of the "required_field".
*
* @see ajax_forms_test_validation_form_submit()
*
* @deprecated Use \Drupal\ajax_forms_test\Form\AjaxFormsTestForm::validationForm()
*/
function ajax_forms_test_validation_form($form, &$form_state) {
......@@ -534,6 +508,8 @@ function ajax_forms_test_validation_number_form_callback($form, $form_state) {
/**
* Form builder: Builds a form that triggers a simple AJAX callback.
*
* @deprecated Use \Drupal\ajax_forms_test\Form\AjaxFormsTestForm::lazyLoadForm()
*/
function ajax_forms_test_lazy_load_form($form, &$form_state) {
// We attach a JavaScript setting, so that one of the generated AJAX commands
......
ajax_forms_test.get_form:
path: '/ajax_forms_test_get_form'
defaults:
_title: 'AJAX forms simple form test'
_content: '\Drupal\ajax_forms_test\Form\AjaxFormsTestForm::getForm'
requirements:
_access: 'TRUE'
ajax_forms_test.commands_form:
path: '/ajax_forms_test_ajax_commands_form'
defaults:
_title: 'AJAX forms AJAX commands test'
_content: '\Drupal\ajax_forms_test\Form\AjaxFormsTestForm::commandsForm'
requirements:
_access: 'TRUE'
ajax_forms_test.validation_test:
path: '/ajax_validation_test'
defaults:
_title: 'AJAX Validation Test'
_content: '\Drupal\ajax_forms_test\Form\AjaxFormsTestForm::validationForm'
requirements:
_access: 'TRUE'
ajax_forms_test.lazy_load_form:
path: '/ajax_forms_test_lazy_load_form'
defaults:
_title: 'AJAX forms lazy load test'
_content: '\Drupal\ajax_forms_test\Form\AjaxFormsTestForm::lazyLoadForm'
requirements:
_access: 'TRUE'
<?php
/**
* @file
* Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestForm.
*/
namespace Drupal\ajax_forms_test\Form;
/**
* Temporary form controller for ajax_forms_test module.
*/
class AjaxFormsTestForm {
/**
* @todo Remove ajax_forms_test_simple_form().
*/
public function getForm() {
return drupal_get_form('ajax_forms_test_simple_form');
}
/**
* @todo Remove ajax_forms_test_ajax_commands_form().
*/
public function commandsForm() {
return drupal_get_form('ajax_forms_test_ajax_commands_form');
}
/**
* @todo Remove ajax_forms_test_validation_form().
*/
public function validationForm() {
return drupal_get_form('ajax_forms_test_validation_form');
}
/**
* @todo Remove ajax_forms_test_lazy_load_form().
*/
public function lazyLoadForm() {
return drupal_get_form('ajax_forms_test_lazy_load_form');
}
}
......@@ -13,9 +13,7 @@ function batch_test_menu() {
$items['batch-test'] = array(
'title' => 'Batch test',
'page callback' => 'drupal_get_form',
'page arguments' => array('batch_test_simple_form'),
'access callback' => TRUE,
'route_name' => 'batch_test.test_form',
);
// Simple form: one submit handler, setting a batch.
$items['batch-test/simple'] = array(
......@@ -26,18 +24,14 @@ function batch_test_menu() {
// Multistep form: two steps, each setting a batch.
$items['batch-test/multistep'] = array(
'title' => 'Multistep',
'page callback' => 'drupal_get_form',
'page arguments' => array('batch_test_multistep_form'),
'access callback' => TRUE,
'route_name' => 'batch_test.multistep',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
// Chained form: four submit handlers, several of which set a batch.
$items['batch-test/chained'] = array(
'title' => 'Chained',
'page callback' => 'drupal_get_form',
'page arguments' => array('batch_test_chained_form'),
'access callback' => TRUE,
'route_name' => 'batch_test.chained',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
......@@ -80,6 +74,8 @@ function batch_test_menu() {
* Form constructor for a batch selection form.
*
* @see batch_test_simple_form_submit()
*
* @deprecated Use \Drupal\batch_test\Form\BatchTestForm::testForm()
*/
function batch_test_simple_form() {
$form['batch'] = array(
......@@ -120,6 +116,8 @@ function batch_test_simple_form_submit($form, &$form_state) {
* Form constructor for a multistep form.
*
* @see batch_test_multistep_form_submit()
*
* @deprecated Use \Drupal\batch_test\Form\BatchTestForm::testMultistepForm()
*/
function batch_test_multistep_form($form, &$form_state) {
if (empty($form_state['storage']['step'])) {
......@@ -170,6 +168,8 @@ function batch_test_multistep_form_submit($form, &$form_state) {
* @see batch_test_chained_form_submit_3()
* @see batch_test_chained_form_submit_3()
* @see batch_test_chained_form_submit_4()
*
* @deprecated Use \Drupal\batch_test\Form\BatchTestForm::testChainedForm()
*/
function batch_test_chained_form() {
// This value is used to test that $form_state persists through batched
......
......@@ -31,6 +31,30 @@ batch_test.no_form:
requirements:
_access: 'TRUE'
batch_test.test_form:
path: '/batch-test'
defaults:
_content: '\Drupal\batch_test\Form\BatchTestForm::testForm'
_title: 'Batch test'
requirements:
_access: 'TRUE'