public function NodeRevisionGenerateTest::providerGetRevisionCreationBatch in Node Revision Delete 8
Data provider for testGetRevisionCreationBatch().
Return value
array An array of arrays, each containing:
- 'expected' - Expected return from ::getRevisionCreationBatch().
- 'nodes_for_revisions' - The nodes for revisions array.
- 'revisions_number' - Number of revisions to generate.
- 'revisions_age' - Time to add to the last revision date of the node.
See also
testGetRevisionCreationBatch()
File
- modules/
node_revision_generate/ tests/ src/ Unit/ NodeRevisionGenerateTest.php, line 98
Class
- NodeRevisionGenerateTest
- Tests the NodeRevisionGenerate class methods.
Namespace
Drupal\Tests\node_revision_generate\UnitCode
public function providerGetRevisionCreationBatch() {
// Sets of revisions.
$revisions = $this
->getRevisions();
// The number of revisions to generate.
$number = [
1,
5,
2,
7,
3,
];
// Set for the revisions age option.
$revisions_age = $this
->getRevisionAge();
// The batch.
$batch_template = [
'title' => $this
->getStringTranslationStub()
->translate('Generating revisions'),
'init_message' => $this
->getStringTranslationStub()
->translate('Starting to create revisions.'),
'progress_message' => $this
->getStringTranslationStub()
->translate('Processed @current out of @total (@percentage%). Estimated time: @estimate.'),
'error_message' => $this
->getStringTranslationStub()
->translate('The revision creation process has encountered an error.'),
'operations' => [],
'finished' => [
NodeRevisionGenerateBatch::class,
'finish',
],
'file' => NULL,
'library' => [],
'url_options' => [],
'progressive' => TRUE,
];
$expected = [];
// Creating the expected arrays.
foreach ($revisions as $set => $nodes_for_revisions) {
$expected[$set] = $batch_template;
// Building batch operations, one per revision.
foreach ($nodes_for_revisions as $node) {
$revision_timestamp = $node->revision_timestamp;
// Initializing variables.
$i = 0;
$revision_timestamp += $revisions_age[$set];
// Adding operations.
while ($i < $number[$set] && $revision_timestamp <= $this
->getRequestTime()) {
// Adding the operation.
$expected[$set]['operations'][] = [
[
NodeRevisionGenerateBatch::class,
'generateRevisions',
],
[
$node->nid,
$revision_timestamp,
],
];
$revision_timestamp += $revisions_age[$set];
$i++;
}
}
}
$tests = [];
$tests['t1'] = [
$expected[0],
$revisions[0],
$number[0],
$revisions_age[0],
];
$tests['t2'] = [
$expected[1],
$revisions[1],
$number[1],
$revisions_age[1],
];
$tests['t3'] = [
$expected[2],
$revisions[2],
$number[2],
$revisions_age[2],
];
$tests['t4'] = [
$expected[3],
$revisions[3],
$number[3],
$revisions_age[3],
];
$tests['t5'] = [
$expected[4],
$revisions[4],
$number[4],
$revisions_age[4],
];
return $tests;
}