class CrudTest in Translation Management Tool 8
Basic crud operations for jobs and translators
@group tmgmt
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \PHPUnit\Framework\TestCase implements ServiceProviderInterface uses AssertContentTrait, AssertLegacyTrait, AssertHelperTrait, ConfigTestTrait, PhpunitCompatibilityTrait, RandomGeneratorTrait, TestRequirementsTrait
- class \Drupal\Tests\tmgmt\Kernel\TMGMTKernelTestBase
- class \Drupal\Tests\tmgmt\Kernel\CrudTest
- class \Drupal\Tests\tmgmt\Kernel\TMGMTKernelTestBase
Expanded class hierarchy of CrudTest
File
- tests/
src/ Kernel/ CrudTest.php, line 18
Namespace
Drupal\Tests\tmgmt\KernelView source
class CrudTest extends TMGMTKernelTestBase {
/**
* {@inheritdoc}
*/
public function setUp() : void {
parent::setUp();
\Drupal::service('router.builder')
->rebuild();
$this
->installEntitySchema('tmgmt_remote');
}
/**
* Test crud operations of translators.
*/
function testTranslators() {
$translator = $this
->createTranslator();
$loaded_translator = Translator::load($translator
->id());
$this
->assertEqual($translator
->id(), $loaded_translator
->id());
$this
->assertEqual($translator
->label(), $loaded_translator
->label());
$this
->assertEqual($translator
->getSettings(), $loaded_translator
->getSettings());
// Update the settings.
$translator
->setSetting('new_key', $this
->randomString());
$translator
->save();
$loaded_translator = Translator::load($translator
->id());
$this
->assertEqual($translator
->id(), $loaded_translator
->id());
$this
->assertEqual($translator
->label(), $loaded_translator
->label());
$this
->assertEqual($translator
->getSettings(), $loaded_translator
->getSettings());
// Delete the translator, make sure the translator is gone.
$translator
->delete();
$this
->assertNull(Translator::load($translator
->id()));
}
/**
* Tests job item states for 'reject' / 'submit' settings action job states.
*/
public function testRejectedJob() {
$job = $this
->createJob();
// Change job state to 'reject' through the API and request a translation.
$job->translator = $this->default_translator
->id();
$job->settings->action = 'reject';
$job
->save();
$job_item = $job
->addItem('test_source', 'type', 1);
$job
->requestTranslation();
// Check that job is rejected and job item is NOT active.
$job = \Drupal::entityTypeManager()
->getStorage('tmgmt_job')
->loadUnchanged($job
->id());
$this
->assertTrue($job
->isRejected());
$job_item = \Drupal::entityTypeManager()
->getStorage('tmgmt_job_item')
->loadUnchanged($job_item
->id());
$this
->assertTrue($job_item
->isInactive());
// Change job state to 'submit' through the API and request a translation.
$job->settings->action = 'submit';
$job
->save();
$job
->requestTranslation();
// Check that job is active and job item IS active.
$this
->assertTrue($job
->isActive());
$this
->assertTrue($job_item
->isActive());
}
/**
* Test crud operations of jobs.
*/
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()));
}
function testRemoteMappings() {
$data_key = '5][test_source][type';
$translator = $this
->createTranslator();
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->save();
$item1 = $job
->addItem('test_source', 'type', 5);
$item2 = $job
->addItem('test_source', 'type', 4);
$mapping_data = array(
'remote_identifier_2' => 'id12',
'remote_identifier_3' => 'id13',
'amount' => 1043,
'currency' => 'EUR',
);
$result = $item1
->addRemoteMapping($data_key, 'id11', $mapping_data);
$this
->assertEqual($result, SAVED_NEW);
$job_mappings = $job
->getRemoteMappings();
$item_mappings = $item1
->getRemoteMappings();
$job_mapping = array_shift($job_mappings);
$item_mapping = array_shift($item_mappings);
$_job = $job_mapping
->getJob();
$this
->assertEqual($job
->id(), $_job
->id());
$_job = $item_mapping
->getJob();
$this
->assertEqual($job
->id(), $_job
->id());
$_item1 = $item_mapping
->getJobItem();
$this
->assertEqual($item1
->id(), $_item1
->id());
$remote_mappings = RemoteMapping::loadByRemoteIdentifier('id11', 'id12', 'id13');
$remote_mapping = array_shift($remote_mappings);
$this
->assertEqual($remote_mapping
->id(), $item1
->id());
$this
->assertEqual($remote_mapping
->getAmount(), $mapping_data['amount']);
$this
->assertEqual($remote_mapping
->getCurrency(), $mapping_data['currency']);
$this
->assertEqual(count(RemoteMapping::loadByRemoteIdentifier('id11')), 1);
$this
->assertEqual(count(RemoteMapping::loadByRemoteIdentifier('id11', '')), 0);
$this
->assertEqual(count(RemoteMapping::loadByRemoteIdentifier('id11', NULL, '')), 0);
$this
->assertEqual(count(RemoteMapping::loadByRemoteIdentifier(NULL, NULL, 'id13')), 1);
$this
->assertEqual($remote_mapping
->getRemoteIdentifier1(), 'id11');
$this
->assertEqual($remote_mapping
->getRemoteIdentifier2(), 'id12');
$this
->assertEqual($remote_mapping
->getRemoteIdentifier3(), 'id13');
// Test remote data.
$item_mapping
->addRemoteData('test_data', 'test_value');
$item_mapping
->save();
$item_mapping = RemoteMapping::load($item_mapping
->id());
$this
->assertEqual($item_mapping
->getRemoteData('test_data'), 'test_value');
// Add mapping to the other job item as well.
$item2
->addRemoteMapping($data_key, 'id21', array(
'remote_identifier_2' => 'id22',
'remote_identifier_3' => 'id23',
));
// Test deleting.
// Delete item1.
$item1
->delete();
// Test if mapping for item1 has been removed as well.
$this
->assertEqual(count(RemoteMapping::loadByLocalData(NULL, $item1
->id())), 0);
// We still should have mapping for item2.
$this
->assertEqual(count(RemoteMapping::loadByLocalData(NULL, $item2
->id())), 1);
// Now delete the job and see if remaining mappings were removed as well.
$job
->delete();
$this
->assertEqual(count(RemoteMapping::loadByLocalData(NULL, $item2
->id())), 0);
}
/**
* Test crud operations of job items.
*/
function testJobItems() {
$job = $this
->createJob();
// Add some test items.
$item1 = $job
->addItem('test_source', 'type', 5);
$item2 = $job
->addItem('test_source', 'test_with_long_label', 4);
// Test single load callback.
$item = JobItem::load($item1
->id());
$this
->assertEqual($item1
->getPlugin(), $item
->getPlugin());
$this
->assertEqual($item1
->getItemType(), $item
->getItemType());
$this
->assertEqual($item1
->getItemId(), $item
->getItemId());
// Test multiple load callback.
$items = JobItem::loadMultiple(array(
$item1
->id(),
$item2
->id(),
));
$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());
// Test the second item label length - it must not exceed the
// TMGMT_JOB_LABEL_MAX_LENGTH.
$this
->assertTrue(Job::LABEL_MAX_LENGTH >= strlen($items[$item2
->id()]
->label()));
$translator = Translator::load('test_translator');
$translator
->setAutoAccept(TRUE)
->save();
$job = tmgmt_job_create('en', 'de');
$job->translator = 'test_translator';
$job
->save();
$job_item = tmgmt_job_item_create('test_source', 'test_type', 1, [
'tjid' => $job
->id(),
]);
$job_item
->save();
// Add translated data to the job item.
$translation['dummy']['deep_nesting']['#text'] = 'Invalid translation that will cause an exception';
$job_item
->addTranslatedData($translation);
// If it was set to Auto Accept but there was an error, the Job Item should
// be set as Needs Review.
$this
->assertEquals(JobItemInterface::STATE_REVIEW, $job_item
->getState());
// There should be a message if auto accept has failed.
$messages = $job
->getMessages();
$last_message = end($messages);
$this
->assertEquals('Failed to automatically accept translation, error: The translation cannot be saved.', $last_message
->getMessage());
}
/**
* Tests adding translated data and revision handling.
*/
function testAddingTranslatedData() {
$translator = $this
->createTranslator();
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->save();
// Add some test items.
$item1 = $job
->addItem('test_source', 'test_with_long_label', 5);
// Test the job label - it must not exceed the TMGMT_JOB_LABEL_MAX_LENGTH.
$this
->assertTrue(Job::LABEL_MAX_LENGTH >= strlen($job
->label()));
$key = array(
'dummy',
'deep_nesting',
);
$translation['dummy']['deep_nesting']['#text'] = 'translated 1';
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
// Check job messages.
$messages = $job
->getMessages();
$this
->assertEqual(count($messages), 1);
$last_message = end($messages);
$this
->assertEqual($last_message->message->value, 'The translation of <a href=":source_url">@source</a> to @language is finished and can now be <a href=":review_url">reviewed</a>.');
// Initial state - translation has been received for the first time.
$this
->assertEqual($data['#translation']['#text'], 'translated 1');
$this
->assertTrue(empty($data['#translation']['#text_revisions']));
$this
->assertEqual($data['#translation']['#origin'], 'remote');
$this
->assertEqual($data['#translation']['#timestamp'], \Drupal::time()
->getRequestTime());
// Set status back to pending as if the data item was rejected.
$item1
->updateData(array(
'dummy',
'deep_nesting',
), array(
'#status' => TMGMT_DATA_ITEM_STATE_PENDING,
));
// Add same translation text.
$translation['dummy']['deep_nesting']['#text'] = 'translated 1';
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
// Check if the status has been updated back to translated.
$this
->assertEqual($data['#status'], TMGMT_DATA_ITEM_STATE_TRANSLATED);
// Add translation, however locally customized.
$translation['dummy']['deep_nesting']['#text'] = 'translated 2';
$translation['dummy']['deep_nesting']['#origin'] = 'local';
$translation['dummy']['deep_nesting']['#timestamp'] = \Drupal::time()
->getRequestTime() - 5;
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
// The translation text is updated.
$this
->assertEqual($data['#translation']['#text'], 'translated 2');
$this
->assertEqual($data['#translation']['#timestamp'], \Drupal::time()
->getRequestTime() - 5);
// Previous translation is among text_revisions.
$this
->assertEqual($data['#translation']['#text_revisions'][0]['#text'], 'translated 1');
$this
->assertEqual($data['#translation']['#text_revisions'][0]['#origin'], 'remote');
$this
->assertEqual($data['#translation']['#text_revisions'][0]['#timestamp'], \Drupal::time()
->getRequestTime());
// Current translation origin is local.
$this
->assertEqual($data['#translation']['#origin'], 'local');
// Check job messages.
$messages = $job
->getMessages();
$this
->assertEqual(count($messages), 1);
// Add translation - not local.
$translation['dummy']['deep_nesting']['#text'] = 'translated 3';
unset($translation['dummy']['deep_nesting']['#origin']);
unset($translation['dummy']['deep_nesting']['#timestamp']);
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
// The translation text is NOT updated.
$this
->assertEqual($data['#translation']['#text'], 'translated 2');
$this
->assertEqual($data['#translation']['#timestamp'], \Drupal::time()
->getRequestTime() - 5);
// Received translation is the latest revision.
$last_revision = end($data['#translation']['#text_revisions']);
$this
->assertEqual($last_revision['#text'], 'translated 3');
$this
->assertEqual($last_revision['#origin'], 'remote');
$this
->assertEqual($last_revision['#timestamp'], \Drupal::time()
->getRequestTime());
// Current translation origin is local.
$this
->assertEqual($data['#translation']['#origin'], 'local');
// Check job messages.
$messages = $job
->getMessages();
$this
->assertEqual(count($messages), 2);
$last_message = end($messages);
$this
->assertEqual($last_message->message->value, 'Translation for customized @key received. Revert your changes if you wish to use it.');
// Revert to previous revision which is the latest received translation.
$item1
->dataItemRevert($key);
$data = $item1
->getData($key);
// The translation text is updated.
$this
->assertEqual($data['#translation']['#text'], 'translated 3');
$this
->assertEqual($data['#translation']['#origin'], 'remote');
$this
->assertEqual($data['#translation']['#timestamp'], \Drupal::time()
->getRequestTime());
// Latest revision is now the formerly added local translation.
$last_revision = end($data['#translation']['#text_revisions']);
$this
->assertNotEmpty($last_revision['#text'], 'translated 2');
$this
->assertNotEmpty($last_revision['#origin'], 'remote');
$this
->assertEqual($last_revision['#timestamp'], \Drupal::time()
->getRequestTime() - 5);
// Check job messages.
$messages = $job
->getMessages();
$this
->assertEqual(count($messages), 3);
$last_message = end($messages);
$this
->assertEqual($last_message->message->value, 'Translation for @key reverted to the latest version.');
// There should be three revisions now.
$this
->assertEqual(count($data['#translation']['#text_revisions']), 3);
// Attempt to update the translation with the same text, this should not
// lead to a new revision.
$translation['dummy']['deep_nesting']['#text'] = 'translated 3';
//unset($translation['dummy']['deep_nesting']['#origin']);
//unset($translation['dummy']['deep_nesting']['#timestamp']);
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
$this
->assertEqual(count($data['#translation']['#text_revisions']), 3);
// Mark the translation as reviewed, a new translation should not update the
// existing one but create a new translation.
$item1
->updateData($key, array(
'#status' => TMGMT_DATA_ITEM_STATE_REVIEWED,
));
$translation['dummy']['deep_nesting']['#text'] = 'translated 4';
$item1
->addTranslatedData($translation);
$data = $item1
->getData($key);
// The translation text is NOT updated.
$this
->assertEqual($data['#translation']['#text'], 'translated 3');
// Received translation is the latest revision.
$this
->assertEqual(count($data['#translation']['#text_revisions']), 4);
$last_revision = end($data['#translation']['#text_revisions']);
$this
->assertEqual($last_revision['#text'], 'translated 4');
$this
->assertEqual($last_revision['#origin'], 'remote');
$this
->assertEqual($last_revision['#timestamp'], \Drupal::time()
->getRequestTime());
// Check job messages.
$messages = $job
->getMessages();
$this
->assertEqual(count($messages), 4);
$last_message = end($messages);
$this
->assertEqual($last_message->message->value, 'Translation for already reviewed @key received and stored as a new revision. Revert to it if you wish to use it.');
// Add a new job item.
$new_item = $job
->addItem('test_source', 'test_with_long_label', 6);
$translation['dummy']['deep_nesting']['#text'] = 'translated 1';
$new_item
->addTranslatedData($translation);
$messages = $job
->getMessages();
$this
->assertCount(5, $messages);
$last_message = end($messages);
// Assert that the job and job item are loaded correctly.
$message_job = $last_message
->getJob();
$this
->assertInstanceOf(JobInterface::class, $message_job);
$this
->assertEquals($job
->id(), $message_job
->id());
$message_job_item = $last_message
->getJobItem();
$this
->assertInstanceOf(JobItemInterface::class, $message_job_item);
$this
->assertEquals($new_item
->id(), $message_job_item
->id());
}
/**
* Test the calculations of the counters.
*/
function testJobItemsCounters() {
$job = $this
->createJob();
// Some test data items.
$data1 = array(
'#text' => 'The text to be translated.',
);
$data2 = array(
'#text' => 'The text to be translated.',
'#translation' => '',
);
$data3 = array(
'#text' => 'The text to be translated.',
'#translation' => 'The translated data. Set by the translator plugin.',
);
$data4 = array(
'#text' => 'Another, longer text to be translated.',
'#translation' => 'The translated data. Set by the translator plugin.',
'#status' => TMGMT_DATA_ITEM_STATE_REVIEWED,
);
$data5 = array(
'#label' => 'label',
'data1' => $data1,
'data4' => $data4,
);
$data6 = array(
'#text' => '<p>Test the HTML tags count.</p>',
);
// No data items.
$this
->assertEqual(0, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountTranslated());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(0, $job
->getCountAccepted());
$this
->assertEqual(0, $job
->getWordCount());
// Add a test items.
$job_item1 = tmgmt_job_item_create('plugin', 'type', 4, array(
'tjid' => $job
->id(),
));
$job_item1
->save();
// No pending, translated and confirmed data items.
$job = Job::load($job
->id());
$job_item1 = JobItem::load($job_item1
->id());
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(0, $job_item1
->getCountPending());
$this
->assertEqual(0, $job_item1
->getCountTranslated());
$this
->assertEqual(0, $job_item1
->getCountReviewed());
$this
->assertEqual(0, $job_item1
->getCountAccepted());
$this
->assertEqual(0, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountTranslated());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(0, $job
->getCountAccepted());
// Add an untranslated data item.
$job_item1
->updateData('data_item1', $data1);
$job_item1
->save();
// One pending data items.
$job = Job::load($job
->id());
$job_item1 = JobItem::load($job_item1
->id());
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(1, $job_item1
->getCountPending());
$this
->assertEqual(0, $job_item1
->getCountTranslated());
$this
->assertEqual(0, $job_item1
->getCountReviewed());
$this
->assertEqual(5, $job_item1
->getWordCount());
$this
->assertEqual(1, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(0, $job
->getCountTranslated());
$this
->assertEqual(5, $job
->getWordCount());
// Add another untranslated data item.
// Test with an empty translation set.
$job_item1
->updateData('data_item1', $data2, TRUE);
$job_item1
->save();
// One pending data items.
$job = Job::load($job
->id());
$job_item1 = JobItem::load($job_item1
->id());
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(1, $job_item1
->getCountPending());
$this
->assertEqual(0, $job_item1
->getCountTranslated());
$this
->assertEqual(0, $job_item1
->getCountReviewed());
$this
->assertEqual(5, $job_item1
->getWordCount());
$this
->assertEqual(1, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountTranslated());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(5, $job
->getWordCount());
// Add a translated data item.
$job_item1
->updateData('data_item1', $data3, TRUE);
$job_item1
->save();
// One translated data items.
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(0, $job_item1
->getCountPending());
$this
->assertEqual(1, $job_item1
->getCountTranslated());
$this
->assertEqual(0, $job_item1
->getCountReviewed());
$this
->assertEqual(0, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(1, $job
->getCountTranslated());
// Add a confirmed data item.
$job_item1
->updateData('data_item1', $data4, TRUE);
$job_item1
->save();
// One reviewed data item.
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(1, $job_item1
->getCountReviewed());
$this
->assertEqual(1, $job
->getCountReviewed());
// Add a translated and an untranslated and a confirmed data item
$job = Job::load($job
->id());
$job_item1 = JobItem::load($job_item1
->id());
$job_item1
->updateData('data_item1', $data1, TRUE);
$job_item1
->updateData('data_item2', $data3, TRUE);
$job_item1
->updateData('data_item3', $data4, TRUE);
$job_item1
->save();
// One pending and translated data items each.
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(1, $job
->getCountPending());
$this
->assertEqual(1, $job
->getCountTranslated());
$this
->assertEqual(1, $job
->getCountReviewed());
$this
->assertEqual(16, $job
->getWordCount());
// Add nested data items.
$job_item1
->updateData('data_item1', $data5, TRUE);
$job_item1
->save();
// One pending data items.
$job = Job::load($job
->id());
$job_item1 = JobItem::load($job_item1
->id());
$this
->assertEqual('label', $job_item1
->getData()['data_item1']['#label']);
$this
->assertEqual(3, count($job_item1
->getData()['data_item1']));
// Add a greater number of data items
for ($index = 1; $index <= 3; $index++) {
$job_item1
->updateData('data_item' . $index, $data1, TRUE);
}
for ($index = 4; $index <= 10; $index++) {
$job_item1
->updateData('data_item' . $index, $data3, TRUE);
}
for ($index = 11; $index <= 15; $index++) {
$job_item1
->updateData('data_item' . $index, $data4, TRUE);
}
$job_item1
->save();
// 3 pending and 7 translated data items each.
$job = Job::load($job
->id());
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(3, $job
->getCountPending());
$this
->assertEqual(7, $job
->getCountTranslated());
$this
->assertEqual(5, $job
->getCountReviewed());
// Check for HTML tags count.
$job_item1
->updateData('data_item1', $data6);
$job_item1
->save();
$this
->assertEqual(2, $job_item1
->getTagsCount());
// Add several job items
$job_item2 = tmgmt_job_item_create('plugin', 'type', 5, array(
'tjid' => $job
->id(),
));
for ($index = 1; $index <= 4; $index++) {
$job_item2
->updateData('data_item' . $index, $data1, TRUE);
}
for ($index = 5; $index <= 12; $index++) {
$job_item2
->updateData('data_item' . $index, $data3, TRUE);
}
for ($index = 13; $index <= 16; $index++) {
$job_item2
->updateData('data_item' . $index, $data4, TRUE);
}
$job_item2
->save();
// 3 pending and 7 translated data items each.
$job = Job::load($job
->id());
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(7, $job
->getCountPending());
$this
->assertEqual(15, $job
->getCountTranslated());
$this
->assertEqual(9, $job
->getCountReviewed());
// Accept the job items.
foreach ($job
->getItems() as $item) {
// Set the state directly to avoid triggering translator and source
// controllers that do not exist.
$item
->setState(JobItem::STATE_ACCEPTED);
$item
->save();
}
drupal_static_reset('tmgmt_job_statistics_load');
$this
->assertEqual(0, $job
->getCountPending());
$this
->assertEqual(0, $job
->getCountTranslated());
$this
->assertEqual(0, $job
->getCountReviewed());
$this
->assertEqual(31, $job
->getCountAccepted());
}
/**
* Test crud operations of jobs.
*/
public function testContinuousTranslators() {
$translator = $this
->createTranslator();
$this
->assertTrue($translator
->getPlugin() instanceof ContinuousTranslatorInterface);
$job = $this
->createJob('en', 'de', 0, [
'job_type' => Job::TYPE_CONTINUOUS,
]);
$this
->assertEqual(Job::TYPE_CONTINUOUS, $job
->getJobType());
$job->translator = $translator
->id();
$job
->save();
// Add a test item.
$item = $job
->addItem('test_source', 'test', 1);
/** @var ContinuousTranslatorInterface $plugin */
$plugin = $job
->getTranslatorPlugin();
$plugin
->requestJobItemsTranslation([
$item,
]);
$this
->assertEqual($item
->getData()['dummy']['deep_nesting']['#translation']['#text'], 'de(de-ch): Text for job item with type test and id 1.');
}
/**
* Tests that with the preliminary state the item does not change.
*/
public function testPreliminaryState() {
$translator = $this
->createTranslator();
$job = $this
->createJob();
$job->translator = $translator
->id();
$job
->save();
// Add some test items.
$item = $job
->addItem('test_source', 'test', 1);
$key = array(
'dummy',
'deep_nesting',
);
// Test with preliminary state.
$translation['dummy']['deep_nesting']['#text'] = 'translated';
$item
->addTranslatedData($translation, [], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
$this
->assertEqual($item
->getData($key)['#status'], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
$this
->assertTrue($item
->isActive());
// Test with empty state.
$item
->addTranslatedData($translation);
$this
->assertEqual($item
->getData($key)['#status'], TMGMT_DATA_ITEM_STATE_PRELIMINARY);
$this
->assertTrue($item
->isActive());
// Test without state.
$item
->addTranslatedData($translation, [], TMGMT_DATA_ITEM_STATE_TRANSLATED);
$this
->assertEqual($item
->getData($key)['#status'], TMGMT_DATA_ITEM_STATE_TRANSLATED);
$this
->assertTrue($item
->isNeedsReview());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AssertContentTrait:: |
protected | property | The current raw content. | |
AssertContentTrait:: |
protected | property | The drupalSettings value from the current raw $content. | |
AssertContentTrait:: |
protected | property | The XML structure parsed from the current raw $content. | 1 |
AssertContentTrait:: |
protected | property | The plain-text content of raw $content (text nodes). | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page by the given XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a field exists in the current page with a given Xpath result. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is found. | |
AssertContentTrait:: |
protected | function | Asserts that each HTML ID is used for just a single element. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS NOT found escaped on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name or ID. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given ID and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist with the given name and value. | |
AssertContentTrait:: |
protected | function | Asserts that a field does not exist or its value does not match, by XPath. | |
AssertContentTrait:: |
protected | function | Asserts that a checkbox field in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Passes if a link with the specified label is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href (part) is not found. | |
AssertContentTrait:: |
protected | function | Passes if a link containing a given href is not found in the main region. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page does not exist. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is not checked. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the perl regex pattern is not found in raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text is NOT found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) does not contains the text. | |
AssertContentTrait:: |
protected | function | Pass if the page title is not the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found MORE THAN ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option with the visible text exists. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page is checked. | |
AssertContentTrait:: |
protected | function | Asserts that a select option in the current page exists. | |
AssertContentTrait:: |
protected | function | Triggers a pass if the Perl regex pattern is found in the raw content. | |
AssertContentTrait:: |
protected | function | Passes if the raw text IS found on the loaded page, fail otherwise. | |
AssertContentTrait:: |
protected | function | Passes if the page (with HTML stripped) contains the text. | |
AssertContentTrait:: |
protected | function | Helper for assertText and assertNoText. | |
AssertContentTrait:: |
protected | function | Asserts that a Perl regex pattern is found in the plain-text content. | |
AssertContentTrait:: |
protected | function | Asserts themed output. | |
AssertContentTrait:: |
protected | function | Pass if the page title is the given string. | |
AssertContentTrait:: |
protected | function | Passes if the text is found ONLY ONCE on the text version of the page. | |
AssertContentTrait:: |
protected | function | Helper for assertUniqueText and assertNoUniqueText. | |
AssertContentTrait:: |
protected | function | Builds an XPath query. | |
AssertContentTrait:: |
protected | function | Helper: Constructs an XPath for the given set of attributes and value. | |
AssertContentTrait:: |
protected | function | Searches elements using a CSS selector in the raw content. | |
AssertContentTrait:: |
protected | function | Get all option elements, including nested options, in a select. | |
AssertContentTrait:: |
protected | function | Gets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Gets the current raw content. | |
AssertContentTrait:: |
protected | function | Get the selected value from a select field. | |
AssertContentTrait:: |
protected | function | Retrieves the plain-text content from the current raw content. | |
AssertContentTrait:: |
protected | function | Get the current URL from the cURL handler. | 1 |
AssertContentTrait:: |
protected | function | Parse content returned from curlExec using DOM and SimpleXML. | |
AssertContentTrait:: |
protected | function | Removes all white-space between HTML tags from the raw content. | |
AssertContentTrait:: |
protected | function | Sets the value of drupalSettings for the currently-loaded page. | |
AssertContentTrait:: |
protected | function | Sets the raw content (e.g. HTML). | |
AssertContentTrait:: |
protected | function | Performs an xpath search on the contents of the internal browser. | |
AssertHelperTrait:: |
protected static | function | Casts MarkupInterface objects into strings. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotEquals() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertNotSame() instead. | |
AssertLegacyTrait:: |
protected | function | Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue() instead. | |
AssertLegacyTrait:: |
protected | function | ||
ConfigTestTrait:: |
protected | function | Returns a ConfigImporter object to import test configuration. | |
ConfigTestTrait:: |
protected | function | Copies configuration objects from source storage to target storage. | |
CrudTest:: |
public | function |
Overrides TMGMTKernelTestBase:: |
|
CrudTest:: |
function | Tests adding translated data and revision handling. | ||
CrudTest:: |
public | function | Test crud operations of jobs. | |
CrudTest:: |
function | Test crud operations of job items. | ||
CrudTest:: |
function | Test the calculations of the counters. | ||
CrudTest:: |
function | Test crud operations of jobs. | ||
CrudTest:: |
public | function | Tests that with the preliminary state the item does not change. | |
CrudTest:: |
public | function | Tests job item states for 'reject' / 'submit' settings action job states. | |
CrudTest:: |
function | |||
CrudTest:: |
function | Test crud operations of translators. | ||
KernelTestBase:: |
protected | property | Back up and restore any global variables that may be changed by tests. | |
KernelTestBase:: |
protected | property | Back up and restore static class properties that may be changed by tests. | |
KernelTestBase:: |
protected | property | Contains a few static class properties for performance. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | @todo Move into Config test base class. | 7 |
KernelTestBase:: |
protected static | property | An array of config object names that are excluded from schema checking. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Do not forward any global state from the parent process to the processes that run the actual tests. | |
KernelTestBase:: |
protected | property | The app root. | |
KernelTestBase:: |
protected | property | Kernel tests are run in separate processes because they allow autoloading of code from extensions. Running the test in a separate process isolates this behavior from other tests. Subclasses should not override this property. | |
KernelTestBase:: |
protected | property | ||
KernelTestBase:: |
protected | property | Set to TRUE to strict check all configuration saved. | 6 |
KernelTestBase:: |
protected | property | The virtual filesystem root directory. | |
KernelTestBase:: |
protected | function | 1 | |
KernelTestBase:: |
protected | function | Bootstraps a basic test environment. | |
KernelTestBase:: |
private | function | Bootstraps a kernel for a test. | |
KernelTestBase:: |
protected | function | Configuration accessor for tests. Returns non-overridden configuration. | |
KernelTestBase:: |
protected | function | Disables modules for this test. | |
KernelTestBase:: |
protected | function | Enables modules for this test. | |
KernelTestBase:: |
protected | function | Gets the config schema exclusions for this test. | |
KernelTestBase:: |
protected | function | Returns the Database connection info to be used for this test. | 1 |
KernelTestBase:: |
public | function | ||
KernelTestBase:: |
private | function | Returns Extension objects for $modules to enable. | |
KernelTestBase:: |
private static | function | Returns the modules to enable for this test. | |
KernelTestBase:: |
protected | function | Initializes the FileCache component. | |
KernelTestBase:: |
protected | function | Installs default configuration for a given list of modules. | |
KernelTestBase:: |
protected | function | Installs the storage schema for a specific entity type. | |
KernelTestBase:: |
protected | function | Installs database tables from a module schema definition. | |
KernelTestBase:: |
protected | function | Returns whether the current test method is running in a separate process. | |
KernelTestBase:: |
protected | function | ||
KernelTestBase:: |
public | function |
Registers test-specific services. Overrides ServiceProviderInterface:: |
26 |
KernelTestBase:: |
protected | function | Renders a render array. | 1 |
KernelTestBase:: |
protected | function | Sets the install profile and rebuilds the container to update it. | |
KernelTestBase:: |
protected | function | Sets an in-memory Settings variable. | |
KernelTestBase:: |
public static | function | 1 | |
KernelTestBase:: |
protected | function | Sets up the filesystem, so things like the file directory. | 2 |
KernelTestBase:: |
protected | function | Stops test execution. | |
KernelTestBase:: |
protected | function | 6 | |
KernelTestBase:: |
public | function | @after | |
KernelTestBase:: |
protected | function | Dumps the current state of the virtual filesystem to STDOUT. | |
KernelTestBase:: |
public | function | BC: Automatically resolve former KernelTestBase class properties. | |
KernelTestBase:: |
public | function | Prevents serializing any properties. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
RandomGeneratorTrait:: |
protected | property | The random generator. | |
RandomGeneratorTrait:: |
protected | function | Gets the random generator for the utility methods. | |
RandomGeneratorTrait:: |
protected | function | Generates a unique random string containing letters and numbers. | 1 |
RandomGeneratorTrait:: |
public | function | Generates a random PHP object. | |
RandomGeneratorTrait:: |
public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |
RandomGeneratorTrait:: |
public | function | Callback for random string validation. | |
StorageCopyTrait:: |
protected static | function | Copy the configuration from one storage to another and remove stale items. | |
TestRequirementsTrait:: |
private | function | Checks missing module requirements. | |
TestRequirementsTrait:: |
protected | function | Check module requirements for the Drupal use case. | 1 |
TestRequirementsTrait:: |
protected static | function | Returns the Drupal root directory. | |
TMGMTKernelTestBase:: |
protected | property | A default translator using the test translator. | |
TMGMTKernelTestBase:: |
public static | property |
Modules to enable. Overrides KernelTestBase:: |
4 |
TMGMTKernelTestBase:: |
function | Sets the proper environment. | ||
TMGMTKernelTestBase:: |
function | Asserts job item language codes. | ||
TMGMTKernelTestBase:: |
protected | function | Creates, saves and returns a translation job. | |
TMGMTKernelTestBase:: |
function | Creates, saves and returns a translator. |