You are here

public function RedirectTermMergeWebTestCase::testTermMergeAction in Term Merge 7

Test the action 'term_merge_action' in terms of integration with Redirect.

File

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

Class

RedirectTermMergeWebTestCase
Test the integration between Term Merge module and Path/Redirect modules.

Code

public function testTermMergeAction() {
  $this
    ->drupalLogin($this->superAdmin);
  $terms = $this
    ->createTerms(array(
    'branch',
    'trunk',
  ));

  // Testing default value.
  actions_do('term_merge_action', $terms['branch'], array(
    'term_trunk' => $terms['trunk']->tid,
    'term_branch_keep' => TRUE,
  ));
  $this
    ->assertRedirectIntegration($terms, 'By default no redirects should be made.');

  // Testing no redirection.
  actions_do('term_merge_action', $terms['branch'], array(
    'term_trunk' => $terms['trunk']->tid,
    'term_branch_keep' => TRUE,
    'redirect' => TERM_MERGE_NO_REDIRECT,
  ));
  $this
    ->assertRedirectIntegration($terms, 'No redirects are made, if action is not instructed to make ones.');

  // Testing 301 redirection. Besides redirecting 'taxonomy/term/[branch-tid]'
  // to 'taxonomy/term/[trunk-tid]' and their path aliases we want to
  // additionally assert that all existing redirects to branch term will be
  // replaced with redirects to trunk term in Redirect module. Lastly, we also
  // assert that 'taxonomy/term/[branch-tid]/feed' path and all pointing there
  // redirects now point to 'taxonomy/term/[trunk-tid]/feed.
  $redirect_source = $this
    ->randomName();
  $redirect = new stdClass();
  redirect_object_prepare($redirect, array(
    'source' => $redirect_source,
    'redirect' => 'taxonomy/term/' . $terms['branch']->tid,
  ));
  redirect_hash($redirect);
  redirect_save($redirect);
  $redirect = new stdClass();
  redirect_object_prepare($redirect, array(
    'source' => $redirect_source . '/feed',
    'redirect' => 'taxonomy/term/' . $terms['branch']->tid . '/feed',
  ));
  redirect_hash($redirect);
  redirect_save($redirect);
  actions_do('term_merge_action', $terms['branch'], array(
    'term_trunk' => $terms['trunk']->tid,
    'redirect' => 301,
  ));
  $terms['branch']->redirect = $terms['trunk'];
  $this
    ->assertRedirectIntegration($terms, 'Redirects are made, if action is instructed to make ones.');
  $this
    ->drupalGet($redirect_source);
  $this
    ->assertUrl('taxonomy/term/' . $terms['trunk']->tid, array(), 'Redirect pointing to <em>taxonomy/term/[branch-tid]</em> now points to <em>taxonomy/term/[trunk-tid]</em>.');
  $this
    ->drupalGet($redirect_source . '/feed');
  $this
    ->assertUrl('taxonomy/term/' . $terms['trunk']->tid . '/feed', array(), 'Redirect pointing to <em>taxonomy/term/[branch-tid]/feed</em> now points to <em>taxonomy/term/[trunk-tid]/feed</em>.');
}