You are here

public function NodeRevisionDeleteTest::providerGetRevisionDeletionBatch in Node Revision Delete 8

Data provider for testGetRevisionDeletionBatch().

Return value

array An array of arrays, each containing:

  • 'expected' - Expected return from ::getRevisionDeletionBatch().
  • 'revisions' - An array of revisions.
  • 'dry_run' - An option to know if we should delete or not the revisions.

See also

testGetRevisionDeletionBatch()

File

tests/src/Unit/NodeRevisionDeleteTest.php, line 320

Class

NodeRevisionDeleteTest
Tests the NodeRevisionDelete class methods.

Namespace

Drupal\Tests\node_revision_delete\Unit

Code

public function providerGetRevisionDeletionBatch() {

  // Sets of revisions.
  $revision_sets = [
    [],
    [
      12,
    ],
    [
      32,
      4,
    ],
    [
      45,
      23,
      72,
    ],
    [
      76,
      97,
      34,
      53,
    ],
  ];

  // Set for the dry run option.
  $dry_run_set = [
    TRUE,
    TRUE,
    TRUE,
    FALSE,
    FALSE,
  ];

  // The batch.
  $batch_template = [
    'title' => $this
      ->getStringTranslationStub()
      ->translate('Deleting revisions'),
    'init_message' => $this
      ->getStringTranslationStub()
      ->translate('Starting to delete revisions.'),
    'progress_message' => $this
      ->getStringTranslationStub()
      ->translate('Deleted @current out of @total (@percentage%). Estimated time: @estimate.'),
    'error_message' => $this
      ->getStringTranslationStub()
      ->translate('Error deleting revisions.'),
    'operations' => [],
    'finished' => [
      NodeRevisionDeleteBatch::class,
      'finish',
    ],
    'file' => NULL,
    'library' => [],
    'url_options' => [],
    'progressive' => TRUE,
  ];
  $expected = [];

  // Creating the expected arrays.
  foreach ($revision_sets as $set => $revisions) {
    $expected[$set] = $batch_template;
    foreach ($revisions as $revision) {
      $expected[$set]['operations'][] = [
        [
          NodeRevisionDeleteBatch::class,
          'deleteRevision',
        ],
        [
          $revision,
          $dry_run_set[$set],
        ],
      ];
    }
  }
  $tests[] = [
    $expected[0],
    $revision_sets[0],
    $dry_run_set[0],
  ];
  $tests[] = [
    $expected[1],
    $revision_sets[1],
    $dry_run_set[1],
  ];
  $tests[] = [
    $expected[2],
    $revision_sets[2],
    $dry_run_set[2],
  ];
  $tests[] = [
    $expected[3],
    $revision_sets[3],
    $dry_run_set[3],
  ];
  $tests[] = [
    $expected[4],
    $revision_sets[4],
    $dry_run_set[4],
  ];
  return $tests;
}