You are here

protected function DuplicatesTermMergeWebTestCase::createTerms in Term Merge 7

Supportive method.

Create taxonomy terms with similar names.

Parameters

array $groups: Key should be a name of the group (terms' names in this group may only differ in case, but will always use this string as their names), while corresponding value to that key should denote how many terms in each group should be created

Return value

array Array of fully loaded taxonomy terms objects of the just created terms, grouped by their group name

1 call to DuplicatesTermMergeWebTestCase::createTerms()
DuplicatesTermMergeWebTestCase::testDuplicates in ./term_merge.test
Test merging duplicates feature of Term Merge module.

File

./term_merge.test, line 991
Test the Term Merge module.

Class

DuplicatesTermMergeWebTestCase
Test the Merge Duplicate Terms feature of the Term Merge module.

Code

protected function createTerms($groups) {
  foreach ($groups as $name => $quantity) {
    $groups[$name] = array();
    $description = $this
      ->randomName();
    for ($i = 0; $i < $quantity; $i++) {
      $term_name = '';
      $term_description = '';

      // Randomizing case of the group name.
      foreach (str_split($name) as $symbol) {
        $symbol = rand(0, 1) ? drupal_strtoupper($symbol) : drupal_strtolower($symbol);
        $term_name .= $symbol;
      }

      // Getting description in different cases.
      foreach (str_split($description) as $symbol) {
        $symbol = rand(0, 1) ? drupal_strtoupper($symbol) : drupal_strtolower($symbol);
        $term_description .= $symbol;
      }
      $term = (object) array(
        'vid' => $this->vocabulary->vid,
        'name' => $term_name,
        'description' => $description,
      );
      taxonomy_term_save($term);
      $groups[$name][] = $this
        ->getLastTerm($this->vocabulary);
    }
  }
  return $groups;
}