Skip to content

Commit

Permalink
MDL-69092 behat: Repeated generator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols authored and andrewmadden committed Nov 15, 2021
1 parent c69c33b commit e11332c
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/tests/behat/behat_data_generators.php
Expand Up @@ -92,6 +92,34 @@ public function the_following_entities_exist($entitytype, TableNode $data) {
$this->get_instance_for_component($component)->generate_items($entity, $data);
}

/**
* Create multiple entities of one entity type.
*
* @Given :count :entitytype exist with the following data:
*
* @param string $entitytype The name of the type entity to add
* @param int $count
* @param TableNode $data
*/
public function the_following_repeated_entities_exist(string $entitytype, int $count, TableNode $data): void {
$rows = $data->getRowsHash();

$tabledata = [array_keys($rows)];
for ($current = 1; $current < $count + 1; $current++) {
$rowdata = [];
foreach ($rows as $fieldname => $fieldtemplate) {
$rowdata[$fieldname] = str_replace('[count]', $current, $fieldtemplate);
}
$tabledata[] = $rowdata;
}

if (isset($this->movedentitytypes[$entitytype])) {
$entitytype = $this->movedentitytypes[$entitytype];
}
list($component, $entity) = $this->parse_entity_type($entitytype);
$this->get_instance_for_component($component)->generate_items($entity, new TableNode($tabledata), false);
}

/**
* Creates the specified element.
*
Expand Down

0 comments on commit e11332c

Please sign in to comment.