public function TMGMTUiTest::testProgress in Translation Management Tool 8
Tests of the job item review process.
File
- tests/
src/ Functional/ TMGMTUiTest.php, line 854
Class
- TMGMTUiTest
- Verifies basic functionality of the user interface
Namespace
Drupal\Tests\tmgmt\FunctionalCode
public function testProgress() {
// Test that there are no jobs at the beginning.
$this
->drupalGet('admin/tmgmt/jobs');
$this
->assertText('No jobs available.');
$this
->assertOptionByText('edit-state', 'Items - In progress');
$this
->assertOptionByText('edit-state', 'Items - Needs review');
$this
->assertOptionByText('edit-state', 'Items - Translation is requested from the elders of the Internet');
// Make sure the legend label is displayed for the test translator state.
$this
->assertText('Translation is requested from the elders of the Internet');
$this
->drupalGet('admin/tmgmt/sources');
// Create Jobs.
$job1 = $this
->createJob();
$job1
->save();
$job1
->setState(Job::STATE_UNPROCESSED);
$job2 = $this
->createJob();
$job2
->save();
$job2
->setState(Job::STATE_ACTIVE);
$job3 = $this
->createJob();
$job3
->save();
$job3
->setState(Job::STATE_REJECTED);
$job4 = $this
->createJob();
$job4
->save();
$job4
->setState(Job::STATE_ABORTED);
$job5 = $this
->createJob();
$job5
->save();
$job5
->setState(Job::STATE_FINISHED);
// Test their icons.
$this
->drupalGet('admin/tmgmt/jobs', array(
'query' => array(
'state' => 'All',
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 5);
$this
->assertJobStateIcon(1, 'Unprocessed');
$this
->assertJobStateIcon(2, 'In progress');
$this
->assertJobStateIcon(3, 'Rejected');
$this
->assertJobStateIcon(4, 'Aborted');
$this
->assertJobStateIcon(5, 'Finished');
// Test the row amount for each state selected.
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => 'open_jobs',
],
]);
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 3);
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => JobInterface::STATE_UNPROCESSED,
],
]);
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => JobInterface::STATE_REJECTED,
],
]);
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->drupalGet('admin/tmgmt/jobs', array(
'query' => array(
'state' => JobInterface::STATE_ABORTED,
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->drupalGet('admin/tmgmt/jobs', array(
'query' => array(
'state' => JobInterface::STATE_FINISHED,
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
\Drupal::state()
->set('tmgmt.test_source_data', array(
'title' => array(
'deep_nesting' => array(
'#text' => '<p><em><strong>Six dummy HTML tags in the title.</strong></em></p>',
'#label' => 'Title',
),
),
'body' => array(
'deep_nesting' => array(
'#text' => '<p>Two dummy HTML tags in the body.</p>',
'#label' => 'Body',
),
),
));
// Add 2 items to job1 and submit it to provider.
$item1 = $job1
->addItem('test_source', 'test', 1);
$job1
->addItem('test_source', 'test', 2);
$this
->drupalGet('admin/tmgmt/job_items', array(
'query' => array(
'state' => 'All',
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 2);
$this
->assertJobItemOverviewStateIcon(1, 'Inactive');
$this
->assertLink($job1
->label());
$this
->drupalGet($job1
->toUrl());
$edit = array(
'target_language' => 'de',
'settings[action]' => 'submit',
);
$this
->drupalPostForm(NULL, $edit, t('Submit to provider'));
// Translate body of one item.
$this
->drupalGet('admin/tmgmt/items/' . $item1
->id());
$this
->drupalPostForm(NULL, array(
'body|deep_nesting[translation]' => 'translation',
), t('Save'));
// Check job item state is still in progress.
$this
->assertJobItemStateIcon(1, 'In progress');
$this
->drupalGet('admin/tmgmt/job_items', array(
'query' => array(
'state' => JobItemInterface::STATE_ACTIVE,
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 2);
$this
->assertJobItemOverviewStateIcon(1, 'In progress');
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => 'job_item_' . JobItemInterface::STATE_ACTIVE,
],
]);
// Check progress bar and icon.
$this
->assertJobProgress(1, 3, 1, 0, 0);
$this
->assertJobStateIcon(1, 'In progress');
// Set the translator status to tmgmt_test_generating.
\Drupal::entityTypeManager()
->getStorage('tmgmt_job_item')
->resetCache();
$item1 = JobItem::load($item1
->id());
$item1
->setTranslatorState('tmgmt_test_generating');
$item1
->save();
$this
->drupalGet('admin/tmgmt/job_items', array(
'query' => array(
'state' => 'tmgmt_test_generating',
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->assertJobItemOverviewStateIcon(1, 'Translation is requested from the elders of the Internet');
$this
->assertRaw('earth.svg"');
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => 'job_item_' . JobItemInterface::STATE_ACTIVE,
],
]);
$this
->assertJobProgress(1, 3, 1, 0, 0);
$this
->assertJobStateIcon(1, 'Translation is requested from the elders of the Internet');
$this
->assertRaw('earth.svg"');
// Also check the translator state.
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => 'job_item_tmgmt_test_generating',
],
]);
$this
->assertJobProgress(1, 3, 1, 0, 0);
$this
->assertJobStateIcon(1, 'Translation is requested from the elders of the Internet');
$this
->assertRaw('earth.svg"');
// Translate title of one item.
$this
->drupalGet('admin/tmgmt/items/' . $item1
->id());
$this
->drupalPostForm(NULL, array(
'title|deep_nesting[translation]' => 'translation',
), t('Save'));
// Check job item state changed to needs review.
$this
->assertJobItemStateIcon(1, 'Needs review');
$this
->drupalGet('admin/tmgmt/job_items', array(
'query' => array(
'state' => JobItemInterface::STATE_REVIEW,
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->assertJobItemOverviewStateIcon(1, 'Needs review');
// Check exposed filter for needs review.
$this
->drupalGet('admin/tmgmt/jobs', [
'query' => [
'state' => 'job_item_' . JobItemInterface::STATE_REVIEW,
],
]);
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
// Check progress bar and icon.
$this
->assertJobProgress(1, 2, 2, 0, 0);
$this
->assertJobStateIcon(1, 'Needs review');
// Review the translation one by one.
$page = $this
->getSession()
->getPage();
$this
->drupalGet('admin/tmgmt/items/' . $item1
->id());
$page
->pressButton('reviewed-body|deep_nesting');
$this
->drupalGet('admin/tmgmt/jobs/' . $job1
->id());
// Check the icon of the job item.
$this
->assertJobItemStateIcon(1, 'Needs review');
$this
->drupalGet('admin/tmgmt/items/' . $item1
->id());
$page
->pressButton('reviewed-title|deep_nesting');
$this
->drupalGet('admin/tmgmt/jobs/' . $job1
->id());
// Check the icon of the job item.
$this
->assertJobItemStateIcon(1, 'Needs review');
$this
->drupalGet('admin/tmgmt/jobs', array(
'query' => array(
'state' => 'open_jobs',
),
));
// Check progress bar and icon.
$this
->assertJobProgress(1, 2, 0, 2, 0);
$this
->assertJobStateIcon(1, 'Needs review');
// Save one job item as completed.
$this
->drupalPostForm('admin/tmgmt/items/' . $item1
->id(), NULL, t('Save as completed'));
// Check job item state changed to accepted.
$this
->assertJobItemStateIcon(1, 'Accepted');
$this
->drupalGet('admin/tmgmt/job_items', array(
'query' => array(
'state' => JobItemInterface::STATE_ACCEPTED,
),
));
$this
->assertEqual(count($this
->xpath('//tbody/tr')), 1);
$this
->assertJobItemOverviewStateIcon(1, 'Accepted');
$this
->drupalGet('admin/tmgmt/jobs', array(
'query' => array(
'state' => 'open_jobs',
),
));
// Check progress bar and icon.
$this
->assertJobProgress(1, 2, 0, 0, 2);
$this
->assertJobStateIcon(1, 'In progress');
// Assert the legend.
$this
->drupalGet('admin/tmgmt/items/' . $item1
->id());
$this
->assertRaw('class="tmgmt-color-legend');
}