Test the deletion and abortion of job item.
@todo There will be some overlap with Aborting items & testAbortJob.
function testJobItemDelete() {
$this
->loginAsAdmin();
// Create a translator.
$translator = $this
->createTranslator();
// Create a job and attach to the translator.
$job = $this
->createJob();
$job->translator = $translator;
$job->settings = array();
$job
->save();
$job
->setState(Job::STATE_ACTIVE);
// Add item to the job.
$item = $job
->addItem('test_source', 'test', 1);
$item
->setState(JobItem::STATE_ACTIVE);
// Check that there is no delete link on item review form.
$this
->drupalGet('admin/tmgmt/items/' . $item
->id());
$this
->assertSession()
->fieldNotExists('edit-delete');
$this
->drupalGet('admin/tmgmt/jobs/' . $job
->id());
// Check that there is no delete link.
$this
->assertSession()
->linkNotExists('Delete');
// Check for abort link.
$this
->assertSession()
->linkExists('Abort');
$this
->clickLink('Abort');
$this
->assertSession()
->pageTextContains('Are you sure you want to abort the job item test_source:test:1?');
// Check if cancel button is present or not.
$this
->assertSession()
->linkExists('Cancel');
// Abort the job item.
$this
->submitForm([], 'Confirm');
// Reload job and check its state and state of its item.
\Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->resetCache();
$job = Job::load($job
->id());
$this
->assertTrue($job
->isFinished());
$items = $job
->getItems();
$item = reset($items);
$this
->assertTrue($item
->isAborted());
// Check that there is no delete button on item review form.
$this
->drupalGet('admin/tmgmt/items/' . $item
->id());
$this
->assertSession()
->fieldNotExists('edit-delete');
// Check that there is no accept button on item review form.
$this
->assertSession()
->fieldNotExists('edit-accept');
$this
->drupalGet('admin/tmgmt/jobs/' . $job
->id());
// Check that there is no delete link on job overview.
$this
->assertSession()
->linkNotExists('Delete');
}