function CrudTest::testJobs in Translation Management Tool 8
Test crud operations of jobs.
File
- tests/
src/ Kernel/ CrudTest.php, line 86
Class
- CrudTest
- Basic crud operations for jobs and translators
Namespace
Drupal\Tests\tmgmt\KernelCode
function testJobs() {
$job = $this
->createJob();
$this
->assertEqual(Job::TYPE_NORMAL, $job
->getJobType());
$loaded_job = Job::load($job
->id());
$this
->assertEqual($job
->getSourceLangcode(), $loaded_job
->getSourceLangcode());
$this
->assertEqual($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
->assertEqual(0, $loaded_job
->getState());
// Update the settings.
$job->reference = 7;
$this
->assertEqual(SAVED_UPDATED, $job
->save());
$loaded_job = Job::load($job
->id());
$this
->assertEqual($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
->assertEqual(2, count($items));
$this
->assertEqual($item1
->getPlugin(), $items[$item1
->id()]
->getPlugin());
$this
->assertEqual($item1
->getItemType(), $items[$item1
->id()]
->getItemType());
$this
->assertEqual($item1
->getItemId(), $items[$item1
->id()]
->getItemId());
$this
->assertEqual($item2
->getPlugin(), $items[$item2
->id()]
->getPlugin());
$this
->assertEqual($item2
->getItemType(), $items[$item2
->id()]
->getItemType());
$this
->assertEqual($item2
->getItemId(), $items[$item2
->id()]
->getItemId());
// Delete the job and make sure it is gone.
$job
->delete();
$this
->assertEmpty(Job::load($job
->id()));
}