Test crud operations of jobs.
function testJobs() {
$job = $this
->createJob();
$this
->assertEquals(Job::TYPE_NORMAL, $job
->getJobType());
$loaded_job = Job::load($job
->id());
$this
->assertEquals($job
->getSourceLangcode(), $loaded_job
->getSourceLangcode());
$this
->assertEquals($job
->getTargetLangcode(), $loaded_job
->getTargetLangcode());
// Assert that the created and changed information has been set to the
// default value.
$this
->assertTrue($loaded_job
->getCreatedTime() > 0);
$this
->assertTrue($loaded_job
->getChangedTime() > 0);
$this
->assertEquals(0, $loaded_job
->getState());
// Update the settings.
$job->reference = 7;
$this
->assertEquals(SAVED_UPDATED, $job
->save());
$loaded_job = Job::load($job
->id());
$this
->assertEquals($job
->getReference(), $loaded_job
->getReference());
// Test the job items.
$item1 = $job
->addItem('test_source', 'type', 5);
$item2 = $job
->addItem('test_source', 'type', 4);
// Load and compare the items.
$items = $job
->getItems();
$this
->assertCount(2, $items);
$this
->assertEquals($item1
->getPlugin(), $items[$item1
->id()]
->getPlugin());
$this
->assertEquals($item1
->getItemType(), $items[$item1
->id()]
->getItemType());
$this
->assertEquals($item1
->getItemId(), $items[$item1
->id()]
->getItemId());
$this
->assertEquals($item2
->getPlugin(), $items[$item2
->id()]
->getPlugin());
$this
->assertEquals($item2
->getItemType(), $items[$item2
->id()]
->getItemType());
$this
->assertEquals($item2
->getItemId(), $items[$item2
->id()]
->getItemId());
// Delete the job and make sure it is gone.
$job
->delete();
$this
->assertEmpty(Job::load($job
->id()));
}