3 namespace Drupal\batch_test\Controller;
5 use Drupal\Core\Form\FormState;
8 * Controller routines for batch tests.
10 class BatchTestController {
13 * Redirects successfully.
16 * Render array containing success message.
18 public function testRedirect() {
21 '#markup' => 'Redirection successful.',
27 * Fires a batch process without a form submission.
29 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
30 * A redirect response if the batch is progressive. No return value otherwise.
32 public function testLargePercentage() {
33 batch_test_stack(NULL, TRUE);
35 batch_set(_batch_test_batch_5());
36 return batch_process('batch-test/redirect');
40 * Submits a form within a batch programmatically.
43 * Some value passed to a custom batch callback.
45 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
46 * A redirect response if the batch is progressive. No return value otherwise.
48 public function testNestedDrupalFormSubmit($value = 1) {
49 // Set the batch and process it.
50 $batch['operations'] = [
51 ['_batch_test_nested_drupal_form_submit_callback', [$value]],
54 return batch_process('batch-test/redirect');
58 * Fires a batch process without a form submission.
60 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
61 * A redirect response if the batch is progressive. No return value otherwise.
63 public function testNoForm() {
64 batch_test_stack(NULL, TRUE);
66 batch_set(_batch_test_batch_1());
67 return batch_process('batch-test/redirect');
72 * Fires a batch process without a form submission and a finish redirect.
74 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
75 * A redirect response if the batch is progressive. No return value otherwise.
77 public function testFinishRedirect() {
78 batch_test_stack(NULL, TRUE);
80 $batch = _batch_test_batch_1();
81 $batch['finished'] = '_batch_test_finished_1_finished';
83 return batch_process('batch-test/redirect');
87 * Submits the 'Chained' form programmatically.
89 * Programmatic form: the page submits the 'Chained' form through
90 * \Drupal::formBuilder()->submitForm().
93 * Some value passed to a the chained form.
96 * Render array containing markup.
98 public function testProgrammatic($value = 1) {
99 $form_state = (new FormState())->setValues([
102 \Drupal::formBuilder()->submitForm('Drupal\batch_test\Form\BatchTestChainedForm', $form_state);
105 '#markup' => 'Got out of a programmatic batched form.',
111 * Runs a batch for testing theme used on the progress page.
113 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
114 * A redirect response if the batch is progressive. No return value otherwise.
116 public function testThemeBatch() {
117 batch_test_stack(NULL, TRUE);
120 ['_batch_test_theme_callback', []],
124 return batch_process('batch-test/redirect');
128 * Runs a batch for testing the title shown on the progress page.
130 * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
131 * A redirect response if the batch is progressive. No return value otherwise.
133 public function testTitleBatch() {
134 batch_test_stack(NULL, TRUE);
136 'title' => 'Batch Test',
138 ['_batch_test_title_callback', []],
142 return batch_process('batch-test/redirect');