class BatchTestController

Same name in other branches
  1. 9 core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php \Drupal\batch_test\Controller\BatchTestController
  2. 8.9.x core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php \Drupal\batch_test\Controller\BatchTestController
  3. 10 core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php \Drupal\batch_test\Controller\BatchTestController

Controller routines for batch tests.

Hierarchy

Expanded class hierarchy of BatchTestController

File

core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php, line 13

Namespace

Drupal\batch_test\Controller
View source
class BatchTestController {
    
    /**
     * Redirects successfully.
     *
     * @return array
     *   Render array containing success message.
     */
    public function testRedirect() {
        return [
            'success' => [
                '#markup' => 'Redirection successful.',
            ],
        ];
    }
    
    /**
     * Fires a batch process without a form submission.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testLargePercentage() {
        batch_test_stack(NULL, TRUE);
        batch_set(_batch_test_batch_5());
        return batch_process('batch-test/redirect');
    }
    
    /**
     * Submits a form within a batch programmatically.
     *
     * @param int $value
     *   Some value passed to a custom batch callback.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testNestedDrupalFormSubmit($value = 1) {
        // Set the batch and process it.
        $batch_builder = (new BatchBuilder())->addOperation('_batch_test_nested_drupal_form_submit_callback', [
            $value,
        ]);
        batch_set($batch_builder->toArray());
        return batch_process('batch-test/redirect');
    }
    
    /**
     * Fires a batch process without a form submission.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testNoForm() {
        batch_test_stack(NULL, TRUE);
        batch_set(_batch_test_batch_1());
        return batch_process('batch-test/redirect');
    }
    
    /**
     * Fires a batch process without a form submission and a finish redirect.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testFinishRedirect() {
        batch_test_stack(NULL, TRUE);
        $batch = _batch_test_batch_1();
        $batch['finished'] = '_batch_test_finished_1_finished';
        batch_set($batch);
        return batch_process('batch-test/redirect');
    }
    
    /**
     * Submits the 'Chained' form programmatically.
     *
     * Programmatic form: the page submits the 'Chained' form through
     * \Drupal::formBuilder()->submitForm().
     *
     * @param int $value
     *   Some value passed to a the chained form.
     *
     * @return array
     *   Render array containing markup.
     */
    public function testProgrammatic($value = 1) {
        $form_state = (new FormState())->setValues([
            'value' => $value,
        ]);
        \Drupal::formBuilder()->submitForm('Drupal\\batch_test\\Form\\BatchTestChainedForm', $form_state);
        return [
            'success' => [
                '#markup' => 'Got out of a programmatic batched form.',
            ],
        ];
    }
    
    /**
     * Runs a batch for testing theme used on the progress page.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testThemeBatch() {
        batch_test_stack(NULL, TRUE);
        $batch = [
            'operations' => [
                [
                    '_batch_test_theme_callback',
                    [],
                ],
            ],
        ];
        batch_set($batch);
        return batch_process('batch-test/redirect');
    }
    
    /**
     * Runs a batch for testing the title shown on the progress page.
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|null
     *   A redirect response if the batch is progressive. No return value otherwise.
     */
    public function testTitleBatch() {
        batch_test_stack(NULL, TRUE);
        $batch = [
            'title' => 'Batch Test',
            'operations' => [
                [
                    '_batch_test_title_callback',
                    [],
                ],
            ],
        ];
        batch_set($batch);
        return batch_process('batch-test/redirect');
    }

}

Members

Title Sort descending Modifiers Object type Summary
BatchTestController::testFinishRedirect public function Fires a batch process without a form submission and a finish redirect.
BatchTestController::testLargePercentage public function Fires a batch process without a form submission.
BatchTestController::testNestedDrupalFormSubmit public function Submits a form within a batch programmatically.
BatchTestController::testNoForm public function Fires a batch process without a form submission.
BatchTestController::testProgrammatic public function Submits the 'Chained' form programmatically.
BatchTestController::testRedirect public function Redirects successfully.
BatchTestController::testThemeBatch public function Runs a batch for testing theme used on the progress page.
BatchTestController::testTitleBatch public function Runs a batch for testing the title shown on the progress page.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.