You are here

public function TermMergeTermMergeWebTestCase::testTermMergeResistance in Term Merge 7

Test all cases for potentially "buggy" input.

Test the functionality of the action "Term Merge" with various suspicious input arguments, and testing the web UI of the module with suspicious input.

File

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

Class

TermMergeTermMergeWebTestCase
Test the functionality of Term Merge module.

Code

public function testTermMergeResistance() {
  drupal_static_reset();

  // Trying to merge 2 terms from 2 different vocabularies.
  $this
    ->drupalPost('admin/structure/taxonomy/add', array(
    'name' => $this
      ->randomName(),
    'machine_name' => 'vocabulary2',
  ), 'Save');
  $terms = array(
    'vocabulary' => FALSE,
    'vocabulary2' => FALSE,
  );
  foreach ($terms as $term_type => $tmp) {
    $url = 'admin/structure/taxonomy/' . $term_type . '/add';
    $edit = array(
      'name' => $this
        ->randomName(),
    );
    $this
      ->drupalPost($url, $edit, 'Save');
    $terms[$term_type] = $this
      ->getLastTerm(taxonomy_vocabulary_machine_name_load($term_type));
  }
  actions_do('term_merge_action', $terms['vocabulary'], array(
    'term_trunk' => $terms['vocabulary2']->tid,
    'term_branch_keep' => FALSE,
  ));
  $this
    ->termMergeResistanceAssert($terms, 'Testing merging 2 terms from 2 different vocabularies.');

  // Trying to merge a parent into its child.
  $terms = array(
    'parent' => FALSE,
    'child' => FALSE,
  );
  drupal_static_reset();
  foreach ($terms as $term_type => $tmp) {
    $url = 'admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add';
    $edit = array(
      'name' => $this
        ->randomName(),
    );
    if ($term_type == 'child') {
      $edit['parent[]'] = array(
        $terms['parent']->tid,
      );
    }
    $this
      ->drupalPost($url, $edit, 'Save');
    $terms[$term_type] = $this
      ->getLastTerm($this->vocabulary);
  }
  actions_do('term_merge_action', $terms['parent'], array(
    'term_trunk' => $terms['child']->tid,
    'term_branch_keep' => FALSE,
  ));
  $this
    ->termMergeResistanceAssert($terms, 'Testing merging a parent into its child.');

  // Trying to merge a term into itself.
  $terms = array(
    'single' => FALSE,
  );
  foreach ($terms as $term_type => $tmp) {
    $url = 'admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/add';
    $name = $this
      ->randomName();
    $edit = array(
      'name' => $name,
    );
    $this
      ->drupalPost($url, $edit, 'Save');
    $terms[$term_type] = $this
      ->getLastTerm($this->vocabulary);
  }
  actions_do('term_merge_action', $terms['single'], array(
    'term_trunk' => $terms['single']->tid,
    'term_branch_keep' => FALSE,
  ));
  $this
    ->termMergeResistanceAssert($terms, 'Testing merging a term into itself.');

  // Making sure the access rights are respected.
  $account = $this
    ->drupalCreateUser(array(
    'merge vocabulary2 terms',
  ));
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('admin/structure/taxonomy/' . $this->vocabulary->machine_name . '/merge');
  $this
    ->assertResponse(403, 'Per vocabulary term merge permissions are respected in the module - an account cannot merge terms in the vocabulary in which he is not supposed to be able to merge.');
  $this
    ->drupalGet('admin/structure/taxonomy/vocabulary2/merge');
  $this
    ->assertResponse(200, 'Per vocabulary term merge permissions are respected in the module - an account can merge terms in the vocabulary in which he is supposed to be able to merge.');

  // Test the threshold for "select" widget of the trunk term.
  variable_set('term_merge_select_limit', 0);
  $this
    ->drupalGet('admin/structure/taxonomy/vocabulary2/merge');
  $this
    ->assertFieldByXPath('//input[@type="radio"][@name="term_trunk[widget]"][@value="autocomplete"][@checked="checked"]', NULL, 'Threshold for "select" widget of the trunk term is taken into consideration.');
}