You are here

function TMGMTNodeSourceUITestCase::testPermissions in Translation Management Tool 7

Tests the create, submit and accept permissions.

File

sources/node/ui/tmgmt_node_ui.test, line 40

Class

TMGMTNodeSourceUITestCase
Basic Node Source UI tests.

Code

function testPermissions() {
  $no_permissions = $this
    ->drupalCreateUser();
  $this
    ->drupalLogin($no_permissions);
  $this
    ->drupalGet('admin/tmgmt');
  $this
    ->assertResponse(403);

  // Test with a user that is only allowed to create jobs.
  $create_user = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'translate content',
    'create translation jobs',
  ));
  $this
    ->drupalLogin($create_user);

  // Create an english source node.
  $node = $this
    ->drupalCreateNode(array(
    'type' => 'page',
    'language' => 'en',
    'body' => array(
      'en' => array(
        array(),
      ),
    ),
  ));

  // Go to the translate tab.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->clickLink('Translate');

  // Request a translation for german.
  $edit = array(
    'languages[de]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Request translation'));
  $this
    ->assertText(t('One job has been created.'));

  // Verify that we are still on the translate tab.
  $this
    ->assertText(t('Translations of @title', array(
    '@title' => $node->title,
  )));

  // The job is unprocessed, check the status flag in the source list.
  $this
    ->drupalGet('admin/tmgmt/sources');
  $links = $this
    ->xpath('//a[contains(@title, :title)]', array(
    ':title' => t('Active job item: @state', array(
      '@state' => t('Unprocessed'),
    )),
  ));
  $attributes = $links[0]
    ->attributes();

  // Check if the found link points to the job checkout page instead of the
  // job item review form.
  $this
    ->assertEqual($attributes['href'], url('admin/tmgmt/jobs/1', array(
    'query' => array(
      'destination' => 'admin/tmgmt/sources',
    ),
  )));
  $this
    ->drupalGet('admin/tmgmt');
  $this
    ->assertResponse(200);
  $this
    ->assertLink(t('manage'));
  $this
    ->assertNoLink(t('submit'));
  $this
    ->assertNoLink(t('delete'));
  $this
    ->assertText(t('@title', array(
    '@title' => $node->title,
  )));
  $this
    ->clickLink(t('manage'));
  $this
    ->assertResponse(200);
  $this
    ->assertNoRaw(t('Submit to translator'));

  // Try to access the delete page directly.
  $this
    ->drupalGet($this
    ->getUrl() . '/delete');
  $this
    ->assertResponse(403);

  // Log in as user with only submit permission.
  $submit_user = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'translate content',
    'submit translation jobs',
  ));
  $this
    ->drupalLogin($submit_user);

  // Go to the translate tab, verify that there is no request translation
  // button.
  $this
    ->drupalGet('node/' . $node->nid);
  $this
    ->clickLink('Translate');
  $this
    ->assertNoRaw(t('Request translation'));

  // Go to the overview and submit the job.
  $this
    ->drupalGet('admin/tmgmt');
  $this
    ->assertResponse(200);
  $this
    ->assertLink(t('submit'));
  $this
    ->assertNoLink(t('manage'));
  $this
    ->assertNoLink(t('delete'));
  $this
    ->assertText(t('@title', array(
    '@title' => $node->title,
  )));

  // Check VBO actions - "submit translation job" has the right to cancel
  // translation only.
  $element = $this
    ->xpath('//select[@id=:id]/option/@value', array(
    ':id' => 'edit-operation',
  ));
  $options = array();
  foreach ($element as $option) {
    $options[] = (string) $option;
  }
  $this
    ->assertTrue(in_array('rules_component::rules_tmgmt_job_abort_translation', $options));

  // Go to the job checkout page and submit it.
  $this
    ->clickLink('submit');
  $this
    ->drupalPost(NULL, array(), t('Submit to translator'));

  // After submit the redirect goes back to the job overview.
  $this
    ->assertUrl('admin/tmgmt');

  // Make sure that the job is active now.
  $this
    ->assertText(t('Active'));

  // Click abort link and check if we are at the job abort confirm page.
  $this
    ->clickLink(t('abort'));
  $this
    ->assertText(t('This will send a request to the translator to abort the job. After the action the job translation process will be aborted and only remaining action will be resubmitting it.'));

  // Return back to job overview and test the manage link.
  $this
    ->drupalGet('admin/tmgmt');
  $this
    ->clickLink(t('manage'));
  $this
    ->assertText(t('Needs review'));
  $this
    ->assertNoLink(t('review'));

  // Now log in as user with only accept permission and review the job.
  $accept_user = $this
    ->drupalCreateUser(array(
    'access administration pages',
    'accept translation jobs',
  ));
  $this
    ->drupalLogin($accept_user);
  $this
    ->drupalGet('admin/tmgmt');

  // Check VBO actions - "accept translation jobs" has the right to accept
  // translation only.
  $element = $this
    ->xpath('//select[@id=:id]/option/@value', array(
    ':id' => 'edit-operation',
  ));
  $options = array();
  foreach ($element as $option) {
    $options[] = (string) $option;
  }
  $this
    ->assertTrue(in_array('rules_component::rules_tmgmt_job_accept_translation', $options));
  $this
    ->clickLink('manage');
  $this
    ->clickLink('review');
  $this
    ->drupalPost(NULL, array(), '✓');

  // Verify that the accepted character is shown.
  $this
    ->assertText('☑');
  $this
    ->drupalPost(NULL, array(), t('Save as completed'));
  $this
    ->assertText(t('Accepted'));
  $this
    ->assertText('1/0/0');
  $create_user = $this
    ->loginAsAdmin();
  $this
    ->drupalLogin($create_user);
  $this
    ->drupalGet('admin/tmgmt');

  // Check VBO actions - "administer tmgmt" has rights for all actions.
  $element = $this
    ->xpath('//select[@id=:id]/option/@value', array(
    ':id' => 'edit-operation',
  ));
  $options = array();
  foreach ($element as $option) {
    $options[] = (string) $option;
  }
  $this
    ->assertTrue(in_array('rules_component::rules_tmgmt_job_accept_translation', $options));
  $this
    ->assertTrue(in_array('rules_component::rules_tmgmt_job_abort_translation', $options));
  $this
    ->assertTrue(in_array('rules_component::rules_tmgmt_job_delete', $options));

  // Go to the translate tab, verify that there is no request translation
  // button.

  //$this->drupalGet('node/' . $node->nid);

  //$this->clickLink('Translate');

  //$this->assertNoRaw(t('Request translation'));
}