You are here

public function ProcessingTest::_resultStack in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Batch/ProcessingTest.php \Drupal\Tests\system\Functional\Batch\ProcessingTest::_resultStack()

Returns expected execution stacks for the test batches.

7 calls to ProcessingTest::_resultStack()
ProcessingTest::testBatchForm in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
Tests batches defined in a form submit handler.
ProcessingTest::testBatchFormMultipleBatches in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
Tests batches defined in different submit handlers on the same form.
ProcessingTest::testBatchFormMultistep in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
Tests batches defined in a multistep form.
ProcessingTest::testBatchFormProgrammatic in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
Tests batches defined in a programmatically submitted form.
ProcessingTest::testBatchLargePercentage in core/modules/system/tests/src/Functional/Batch/ProcessingTest.php
Tests batches that return $context['finished'] > 1 do in fact complete.

... See full list

File

core/modules/system/tests/src/Functional/Batch/ProcessingTest.php, line 239

Class

ProcessingTest
Tests batch processing in form and non-form workflow.

Namespace

Drupal\Tests\system\Functional\Batch

Code

public function _resultStack($id, $value = 0) {
  $stack = [];
  switch ($id) {
    case 'batch_1':
      for ($i = 1; $i <= 10; $i++) {
        $stack[] = "op 1 id {$i}";
      }
      break;
    case 'batch_2':
      for ($i = 1; $i <= 10; $i++) {
        $stack[] = "op 2 id {$i}";
      }
      break;
    case 'batch_3':
      for ($i = 1; $i <= 5; $i++) {
        $stack[] = "op 1 id {$i}";
      }
      for ($i = 1; $i <= 5; $i++) {
        $stack[] = "op 2 id {$i}";
      }
      for ($i = 6; $i <= 10; $i++) {
        $stack[] = "op 1 id {$i}";
      }
      for ($i = 6; $i <= 10; $i++) {
        $stack[] = "op 2 id {$i}";
      }
      break;
    case 'batch_4':
      for ($i = 1; $i <= 5; $i++) {
        $stack[] = "op 1 id {$i}";
      }
      $stack[] = 'setting up batch 2';
      for ($i = 6; $i <= 10; $i++) {
        $stack[] = "op 1 id {$i}";
      }
      $stack = array_merge($stack, $this
        ->_resultStack('batch_2'));
      break;
    case 'batch_5':
      for ($i = 1; $i <= 10; $i++) {
        $stack[] = "op 5 id {$i}";
      }
      break;
    case 'batch_6':
      for ($i = 1; $i <= 10; $i++) {
        $stack[] = "op 6 id {$i}";
      }
      break;
    case 'batch_7':
      for ($i = 1; $i <= 5; $i++) {
        $stack[] = "op 7 id {$i}";
      }
      $stack[] = 'setting up batch 6';
      $stack[] = 'setting up batch 5';
      for ($i = 6; $i <= 10; $i++) {
        $stack[] = "op 7 id {$i}";
      }
      $stack = array_merge($stack, $this
        ->_resultStack('batch_6'));
      $stack = array_merge($stack, $this
        ->_resultStack('batch_5'));
      break;
    case 'chained':
      $stack[] = 'submit handler 1';
      $stack[] = 'value = ' . $value;
      $stack = array_merge($stack, $this
        ->_resultStack('batch_1'));
      $stack[] = 'submit handler 2';
      $stack[] = 'value = ' . ($value + 1);
      $stack = array_merge($stack, $this
        ->_resultStack('batch_2'));
      $stack[] = 'submit handler 3';
      $stack[] = 'value = ' . ($value + 2);
      $stack[] = 'submit handler 4';
      $stack[] = 'value = ' . ($value + 3);
      $stack = array_merge($stack, $this
        ->_resultStack('batch_3'));
      break;
  }
  return $stack;
}