public function TMGMTSuggestionsTestCase::testSuggestions in Translation Management Tool 7
Test suggested entities from a translation job.
File
- sources/
entity/ tmgmt_entity.suggestions.test, line 245
Class
- TMGMTSuggestionsTestCase
- Basic Source-Suggestions tests.
Code
public function testSuggestions() {
// Prepare a job and a node for testing.
$job = $this
->createJob();
$node = $this
->prepareTranslationSuggestions();
$item = $job
->addItem('entity', 'node', $node->nid);
// Get all suggestions and clean the list.
$suggestions = $job
->getSuggestions();
$job
->cleanSuggestionsList($suggestions);
// Check for suggestions.
$this
->assertEqual(count($suggestions), 4, 'Found four suggestions.');
// Check for valid attributes on the suggestions.
foreach ($suggestions as $suggestion) {
switch ($suggestion['reason']) {
case 'Field Field 1':
$this
->assertEqual($suggestion['job_item']
->getWordCount(), 3, 'Three translatable words in the suggestion.');
$this
->assertEqual($suggestion['job_item']->plugin, 'entity', 'Got an entity as plugin in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_type, 'file', 'Got a file in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_id, $node->field1[LANGUAGE_NONE][1]['fid'], 'File id match between node and suggestion.');
break;
case 'Field Field 2':
$this
->assertEqual($suggestion['job_item']
->getWordCount(), 3, 'Three translatable words in the suggestion.');
$this
->assertEqual($suggestion['job_item']->plugin, 'entity', 'Got an entity as plugin in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_type, 'file', 'Got a file in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_id, $node->field2[LANGUAGE_NONE][1]['fid'], 'File id match between node and suggestion.');
break;
case 'Field Field 3':
$this
->assertEqual($suggestion['job_item']
->getWordCount(), 2, 'Two translatable words in the suggestion');
$this
->assertEqual($suggestion['job_item']->plugin, 'entity', 'Got an entity as plugin in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_type, 'node', 'Got a node in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_id, $node->field3[LANGUAGE_NONE][0]['target_id'], 'File id match between node and suggestion.');
break;
case 'Menu link Menu link one':
$this
->assertEqual($suggestion['job_item']
->getWordCount(), 3, 'Three translatable words in the suggestion' . $suggestion['job_item']->plugin . $suggestion['job_item']->item_type);
$this
->assertEqual($suggestion['job_item']->plugin, 'i18n_string', 'Got a string as plugin in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_type, 'menu_link', 'Got a menu link in the suggestion.');
$this
->assertEqual($suggestion['job_item']->item_id, 'menu:item:' . $node->link['mlid'], 'Menu link id match between menu link and suggestion.');
break;
default:
$this
->fail('Found an invalid suggestion.');
break;
}
$this
->assertEqual($suggestion['from_item'], $item->tjiid);
$job
->addExistingItem($suggestion['job_item']);
}
// Re-get all suggestions.
$suggestions = $job
->getSuggestions();
$job
->cleanSuggestionsList($suggestions);
// Check for no more suggestions.
$this
->assertEqual(count($suggestions), 0, 'Found no more suggestion.');
}