tmgmt.crud.test 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. <?php
  2. /*
  3. * @file
  4. * Contains tests for Translation management
  5. */
  6. /**
  7. * Basic CRUD tests.
  8. */
  9. class TMGMTCRUDTestCase extends TMGMTBaseTestCase {
  10. static function getInfo() {
  11. return array(
  12. 'name' => 'CRUD tests',
  13. 'description' => 'Basic crud operations for jobs and translators',
  14. 'group' => 'Translation Management',
  15. );
  16. }
  17. /**
  18. * Test crud operations of translators.
  19. */
  20. function testTranslators() {
  21. $translator = $this->createTranslator();
  22. $loaded_translator = tmgmt_translator_load($translator->tid);
  23. $this->assertEqual($translator->name, $loaded_translator->name);
  24. $this->assertEqual($translator->label, $loaded_translator->label);
  25. $this->assertEqual($translator->settings, $loaded_translator->settings);
  26. // Update the settings.
  27. $translator->settings['new_key'] = $this->randomString();
  28. $this->assertEqual(SAVED_UPDATED, $translator->save());
  29. $loaded_translator = tmgmt_translator_load($translator->tid);
  30. $this->assertEqual($translator->name, $loaded_translator->name);
  31. $this->assertEqual($translator->label, $loaded_translator->label);
  32. $this->assertEqual($translator->settings, $loaded_translator->settings);
  33. // Delete the translator, make sure the translator is gone.
  34. $translator->delete();
  35. $this->assertFalse(tmgmt_translator_load($translator->tid));
  36. }
  37. /**
  38. * Test crud operations of jobs.
  39. */
  40. function testJobs() {
  41. $job = $this->createJob();
  42. $loaded_job = tmgmt_job_load($job->tjid);
  43. $this->assertEqual($job->source_language, $loaded_job->source_language);
  44. $this->assertEqual($job->target_language, $loaded_job->target_language);
  45. // Assert that the created and changed information has been set to the
  46. // default value.
  47. $this->assertTrue($loaded_job->created > 0);
  48. $this->assertTrue($loaded_job->changed > 0);
  49. $this->assertEqual(0, $loaded_job->state);
  50. // Update the settings.
  51. $job->reference = 7;
  52. $this->assertEqual(SAVED_UPDATED, $job->save());
  53. $loaded_job = tmgmt_job_load($job->tjid);
  54. $this->assertEqual($job->reference, $loaded_job->reference);
  55. // Test the job items.
  56. $item1 = $job->addItem('test_source', 'type', 5);
  57. $item2 = $job->addItem('test_source', 'type', 4);
  58. // Load and compare the items.
  59. $items = $job->getItems();
  60. $this->assertEqual(2, count($items));
  61. $this->assertEqual($item1->plugin, $items[$item1->tjiid]->plugin);
  62. $this->assertEqual($item1->item_type, $items[$item1->tjiid]->item_type);
  63. $this->assertEqual($item1->item_id, $items[$item1->tjiid]->item_id);
  64. $this->assertEqual($item2->plugin, $items[$item2->tjiid]->plugin);
  65. $this->assertEqual($item2->item_type, $items[$item2->tjiid]->item_type);
  66. $this->assertEqual($item2->item_id, $items[$item2->tjiid]->item_id);
  67. // Delete the job and make sure it is gone.
  68. $job->delete();
  69. $this->assertFalse(tmgmt_job_load($job->tjid));
  70. }
  71. function testRemoteMappings() {
  72. $data_key = '5][test_source][type';
  73. $translator = $this->createTranslator();
  74. $job = $this->createJob();
  75. $job->translator = $translator->name;
  76. $job->save();
  77. $item1 = $job->addItem('test_source', 'type', 5);
  78. $item2 = $job->addItem('test_source', 'type', 4);
  79. $mapping_data = array(
  80. 'remote_identifier_2' => 'id12',
  81. 'remote_identifier_3' => 'id13',
  82. 'amount' => 1043,
  83. 'currency' => 'EUR',
  84. );
  85. $result = $item1->addRemoteMapping($data_key, 'id11', $mapping_data);
  86. $this->assertEqual($result, SAVED_NEW);
  87. $job_mappings = $job->getRemoteMappings();
  88. $item_mappings = $item1->getRemoteMappings();
  89. $job_mapping = array_shift($job_mappings);
  90. $item_mapping = array_shift($item_mappings);
  91. $_job = $job_mapping->getJob();
  92. $this->assertEqual($job->tjid, $_job->tjid);
  93. $_job = $item_mapping->getJob();
  94. $this->assertEqual($job->tjid, $_job->tjid);
  95. $_item1 = $item_mapping->getJobItem();
  96. $this->assertEqual($item1->tjiid, $_item1->tjiid);
  97. /**
  98. * @var TMGMTRemoteController $remote_mapping_controller
  99. */
  100. $remote_mapping_controller = entity_get_controller('tmgmt_remote');
  101. $remote_mappings = $remote_mapping_controller->loadByRemoteIdentifier('id11', 'id12', 'id13');
  102. $remote_mapping = array_shift($remote_mappings);
  103. $this->assertEqual($remote_mapping->tjiid, $item1->tjiid);
  104. $this->assertEqual($remote_mapping->amount, $mapping_data['amount']);
  105. $this->assertEqual($remote_mapping->currency, $mapping_data['currency']);
  106. $this->assertEqual(count($remote_mapping_controller->loadByRemoteIdentifier('id11')), 1);
  107. $this->assertEqual(count($remote_mapping_controller->loadByRemoteIdentifier('id11', '')), 0);
  108. $this->assertEqual(count($remote_mapping_controller->loadByRemoteIdentifier('id11', NULL, '')), 0);
  109. $this->assertEqual(count($remote_mapping_controller->loadByRemoteIdentifier(NULL, NULL, 'id13')), 1);
  110. // Test remote data.
  111. $item_mapping->addRemoteData('test_data', 'test_value');
  112. entity_save('tmgmt_remote', $item_mapping);
  113. $item_mapping = entity_load_single('tmgmt_remote', $item_mapping->trid);
  114. $this->assertEqual($item_mapping->getRemoteData('test_data'), 'test_value');
  115. // Add mapping to the other job item as well.
  116. $item2->addRemoteMapping($data_key, 'id21', array('remote_identifier_2' => 'id22', 'remote_identifier_3' => 'id23'));
  117. // Test deleting.
  118. // Delete item1.
  119. entity_get_controller('tmgmt_job_item')->delete(array($item1->tjiid));
  120. // Test if mapping for item1 has been removed as well.
  121. $this->assertEqual(count($remote_mapping_controller->loadByLocalData(NULL, $item1->tjiid)), 0);
  122. // We still should have mapping for item2.
  123. $this->assertEqual(count($remote_mapping_controller->loadByLocalData(NULL, $item2->tjiid)), 1);
  124. // Now delete the job and see if remaining mappings were removed as well.
  125. entity_get_controller('tmgmt_job')->delete(array($job->tjid));
  126. $this->assertEqual(count($remote_mapping_controller->loadByLocalData(NULL, $item2->tjiid)), 0);
  127. }
  128. /**
  129. * Test crud operations of job items.
  130. */
  131. function testJobItems() {
  132. $job = $this->createJob();
  133. // Add some test items.
  134. $item1 = $job->addItem('test_source', 'type', 5);
  135. $item2 = $job->addItem('test_source', 'test_with_long_label', 4);
  136. // Test single load callback.
  137. $item = tmgmt_job_item_load($item1->tjiid);
  138. $this->assertEqual($item1->plugin, $item->plugin);
  139. $this->assertEqual($item1->item_type, $item->item_type);
  140. $this->assertEqual($item1->item_id, $item->item_id);
  141. // Test multiple load callback.
  142. $items = tmgmt_job_item_load_multiple(array($item1->tjiid, $item2->tjiid));
  143. $this->assertEqual(2, count($items));
  144. $this->assertEqual($item1->plugin, $items[$item1->tjiid]->plugin);
  145. $this->assertEqual($item1->item_type, $items[$item1->tjiid]->item_type);
  146. $this->assertEqual($item1->item_id, $items[$item1->tjiid]->item_id);
  147. $this->assertEqual($item2->plugin, $items[$item2->tjiid]->plugin);
  148. $this->assertEqual($item2->item_type, $items[$item2->tjiid]->item_type);
  149. $this->assertEqual($item2->item_id, $items[$item2->tjiid]->item_id);
  150. // Test the second item label length - it must not exceed the
  151. // TMGMT_JOB_LABEL_MAX_LENGTH.
  152. $this->assertTrue(TMGMT_JOB_LABEL_MAX_LENGTH >= strlen($items[$item2->tjiid]->label()));
  153. }
  154. /**
  155. * Tests adding translated data and revision handling.
  156. */
  157. function testAddingTranslatedData() {
  158. $translator = $this->createTranslator();
  159. $job = $this->createJob();
  160. $job->translator = $translator->name;
  161. $job->save();
  162. // Add some test items.
  163. $item1 = $job->addItem('test_source', 'test_with_long_label', 5);
  164. // Test the job label - it must not exceed the TMGMT_JOB_LABEL_MAX_LENGTH.
  165. $this->assertTrue(TMGMT_JOB_LABEL_MAX_LENGTH >= strlen($job->label()));
  166. $key = array('dummy', 'deep_nesting');
  167. $translation['dummy']['deep_nesting']['#text'] = 'translated 1';
  168. $item1->addTranslatedData($translation);
  169. $data = $item1->getData($key);
  170. // Check job messages.
  171. $messages = $job->getMessages();
  172. $this->assertEqual(count($messages), 1);
  173. $last_message = end($messages);
  174. $this->assertEqual($last_message->message, 'The translation of !source to @language is finished and can now be <a href="!review_url">reviewed</a>.');
  175. // Initial state - translation has been received for the first time.
  176. $this->assertEqual($data['#translation']['#text'], 'translated 1');
  177. $this->assertTrue(empty($data['#translation']['#text_revisions']));
  178. $this->assertEqual($data['#translation']['#origin'], 'remote');
  179. $this->assertEqual($data['#translation']['#timestamp'], REQUEST_TIME);
  180. // Set status back to pending as if the data item was rejected.
  181. $item1->updateData(array('dummy', 'deep_nesting'), array('#status' => TMGMT_DATA_ITEM_STATE_PENDING));
  182. // Add same translation text.
  183. $translation['dummy']['deep_nesting']['#text'] = 'translated 1';
  184. $item1->addTranslatedData($translation);
  185. $data = $item1->getData($key);
  186. // Check if the status has been updated back to translated.
  187. $this->assertEqual($data['#status'], TMGMT_DATA_ITEM_STATE_TRANSLATED);
  188. // Add translation, however locally customized.
  189. $translation['dummy']['deep_nesting']['#text'] = 'translated 2';
  190. $translation['dummy']['deep_nesting']['#origin'] = 'local';
  191. $translation['dummy']['deep_nesting']['#timestamp'] = REQUEST_TIME - 5;
  192. $item1->addTranslatedData($translation);
  193. $data = $item1->getData($key);
  194. // The translation text is updated.
  195. $this->assertEqual($data['#translation']['#text'], 'translated 2');
  196. $this->assertEqual($data['#translation']['#timestamp'], REQUEST_TIME - 5);
  197. // Previous translation is among text_revisions.
  198. $this->assertEqual($data['#translation']['#text_revisions'][0]['#text'], 'translated 1');
  199. $this->assertEqual($data['#translation']['#text_revisions'][0]['#origin'], 'remote');
  200. $this->assertEqual($data['#translation']['#text_revisions'][0]['#timestamp'], REQUEST_TIME);
  201. // Current translation origin is local.
  202. $this->assertEqual($data['#translation']['#origin'], 'local');
  203. // Check job messages.
  204. $messages = $job->getMessages();
  205. $this->assertEqual(count($messages), 1);
  206. // Add translation - not local.
  207. $translation['dummy']['deep_nesting']['#text'] = 'translated 3';
  208. unset($translation['dummy']['deep_nesting']['#origin']);
  209. unset($translation['dummy']['deep_nesting']['#timestamp']);
  210. $item1->addTranslatedData($translation);
  211. $data = $item1->getData($key);
  212. // The translation text is NOT updated.
  213. $this->assertEqual($data['#translation']['#text'], 'translated 2');
  214. $this->assertEqual($data['#translation']['#timestamp'], REQUEST_TIME - 5);
  215. // Received translation is the latest revision.
  216. $last_revision = end($data['#translation']['#text_revisions']);
  217. $this->assertEqual($last_revision['#text'], 'translated 3');
  218. $this->assertEqual($last_revision['#origin'], 'remote');
  219. $this->assertEqual($last_revision['#timestamp'], REQUEST_TIME);
  220. // Current translation origin is local.
  221. $this->assertEqual($data['#translation']['#origin'], 'local');
  222. // Check job messages.
  223. $messages = $job->getMessages();
  224. $this->assertEqual(count($messages), 2);
  225. $last_message = end($messages);
  226. $this->assertEqual($last_message->message, 'Translation for customized @key received. Revert your changes if you wish to use it.');
  227. // Revert to previous revision which is the latest received translation.
  228. $item1->dataItemRevert($key);
  229. $data = $item1->getData($key);
  230. // The translation text is updated.
  231. $this->assertEqual($data['#translation']['#text'], 'translated 3');
  232. $this->assertEqual($data['#translation']['#origin'], 'remote');
  233. $this->assertEqual($data['#translation']['#timestamp'], REQUEST_TIME);
  234. // Latest revision is now the formerly added local translation.
  235. $last_revision = end($data['#translation']['#text_revisions']);
  236. $this->assertTrue($last_revision['#text'], 'translated 2');
  237. $this->assertTrue($last_revision['#origin'], 'remote');
  238. $this->assertEqual($last_revision['#timestamp'], REQUEST_TIME - 5);
  239. // Check job messages.
  240. $messages = $job->getMessages();
  241. $this->assertEqual(count($messages), 3);
  242. $last_message = end($messages);
  243. $this->assertEqual($last_message->message, 'Translation for @key reverted to the latest version.');
  244. // There should be three revisions now.
  245. $this->assertEqual(count($data['#translation']['#text_revisions']), 3);
  246. // Attempt to update the translation with the same text, this should not
  247. // lead to a new revision.
  248. $translation['dummy']['deep_nesting']['#text'] = 'translated 3';
  249. //unset($translation['dummy']['deep_nesting']['#origin']);
  250. //unset($translation['dummy']['deep_nesting']['#timestamp']);
  251. $item1->addTranslatedData($translation);
  252. $data = $item1->getData($key);
  253. $this->assertEqual(count($data['#translation']['#text_revisions']), 3);
  254. // Mark the translation as reviewed, a new translation should not update the
  255. // existing one but create a new translation.
  256. $item1->updateData($key, array('#status' => TMGMT_DATA_ITEM_STATE_REVIEWED));
  257. $translation['dummy']['deep_nesting']['#text'] = 'translated 4';
  258. $item1->addTranslatedData($translation);
  259. $data = $item1->getData($key);
  260. // The translation text is NOT updated.
  261. $this->assertEqual($data['#translation']['#text'], 'translated 3');
  262. // Received translation is the latest revision.
  263. $this->assertEqual(count($data['#translation']['#text_revisions']), 4);
  264. $last_revision = end($data['#translation']['#text_revisions']);
  265. $this->assertEqual($last_revision['#text'], 'translated 4');
  266. $this->assertEqual($last_revision['#origin'], 'remote');
  267. $this->assertEqual($last_revision['#timestamp'], REQUEST_TIME);
  268. // Check job messages.
  269. $messages = $job->getMessages();
  270. $this->assertEqual(count($messages), 4);
  271. $last_message = end($messages);
  272. $this->assertEqual($last_message->message, 'Translation for already reviewed @key received and stored as a new revision. Revert to it if you wish to use it.');
  273. }
  274. /**
  275. * Test the calculations of the counters.
  276. */
  277. function testJobItemsCounters() {
  278. $job = $this->createJob();
  279. // Some test data items.
  280. $data1 = array(
  281. '#text' => 'The text to be translated.',
  282. );
  283. $data2 = array(
  284. '#text' => 'The text to be translated.',
  285. '#translation' => '',
  286. );
  287. $data3 = array(
  288. '#text' => 'The text to be translated.',
  289. '#translation' => 'The translated data. Set by the translator plugin.',
  290. );
  291. $data4 = array(
  292. '#text' => 'Another, longer text to be translated.',
  293. '#translation' => 'The translated data. Set by the translator plugin.',
  294. '#status' => TMGMT_DATA_ITEM_STATE_REVIEWED,
  295. );
  296. $data5 = array(
  297. '#label' => 'label',
  298. 'data1' => $data1,
  299. 'data4' => $data4,
  300. );
  301. // No data items.
  302. $this->assertEqual(0, $job->getCountPending());
  303. $this->assertEqual(0, $job->getCountTranslated());
  304. $this->assertEqual(0, $job->getCountReviewed());
  305. $this->assertEqual(0, $job->getCountAccepted());
  306. $this->assertEqual(0, $job->getWordCount());
  307. // Add a test items.
  308. $job_item1 = tmgmt_job_item_create('plugin', 'type', 4, array('tjid' => $job->tjid));
  309. $job_item1->save();
  310. // No pending, translated and confirmed data items.
  311. $job = entity_load_single('tmgmt_job', $job->tjid);
  312. $job_item1 = entity_load_single('tmgmt_job_item', $job_item1->tjiid);
  313. drupal_static_reset('tmgmt_job_statistics_load');
  314. $this->assertEqual(0, $job_item1->getCountPending());
  315. $this->assertEqual(0, $job_item1->getCountTranslated());
  316. $this->assertEqual(0, $job_item1->getCountReviewed());
  317. $this->assertEqual(0, $job_item1->getCountAccepted());
  318. $this->assertEqual(0, $job->getCountPending());
  319. $this->assertEqual(0, $job->getCountTranslated());
  320. $this->assertEqual(0, $job->getCountReviewed());
  321. $this->assertEqual(0, $job->getCountAccepted());
  322. // Add an untranslated data item.
  323. $job_item1->data['data_item1'] = $data1;
  324. $job_item1->save();
  325. // One pending data items.
  326. $job = entity_load_single('tmgmt_job', $job->tjid);
  327. $job_item1 = entity_load_single('tmgmt_job_item', $job_item1->tjiid);
  328. drupal_static_reset('tmgmt_job_statistics_load');
  329. $this->assertEqual(1, $job_item1->getCountPending());
  330. $this->assertEqual(0, $job_item1->getCountTranslated());
  331. $this->assertEqual(0, $job_item1->getCountReviewed());
  332. $this->assertEqual(5, $job_item1->getWordCount());
  333. $this->assertEqual(1, $job->getCountPending());
  334. $this->assertEqual(0, $job->getCountReviewed());
  335. $this->assertEqual(0, $job->getCountTranslated());
  336. $this->assertEqual(5, $job->getWordCount());
  337. // Add another untranslated data item.
  338. // Test with an empty translation set.
  339. $job_item1->data['data_item1'] = $data2;
  340. $job_item1->save();
  341. // One pending data items.
  342. $job = entity_load_single('tmgmt_job', $job->tjid);
  343. $job_item1 = entity_load_single('tmgmt_job_item', $job_item1->tjiid);
  344. drupal_static_reset('tmgmt_job_statistics_load');
  345. $this->assertEqual(1, $job_item1->getCountPending());
  346. $this->assertEqual(0, $job_item1->getCountTranslated());
  347. $this->assertEqual(0, $job_item1->getCountReviewed());
  348. $this->assertEqual(5, $job_item1->getWordCount());
  349. $this->assertEqual(1, $job->getCountPending());
  350. $this->assertEqual(0, $job->getCountTranslated());
  351. $this->assertEqual(0, $job->getCountReviewed());
  352. $this->assertEqual(5, $job->getWordCount());
  353. // Add a translated data item.
  354. $job_item1->data['data_item1'] = $data3;
  355. $job_item1->save();
  356. // One translated data items.
  357. drupal_static_reset('tmgmt_job_statistics_load');
  358. $this->assertEqual(0, $job_item1->getCountPending());
  359. $this->assertEqual(1, $job_item1->getCountTranslated());
  360. $this->assertEqual(0, $job_item1->getCountReviewed());
  361. $this->assertEqual(0, $job->getCountPending());
  362. $this->assertEqual(0, $job->getCountReviewed());
  363. $this->assertEqual(1, $job->getCountTranslated());
  364. // Add a confirmed data item.
  365. $job_item1->data['data_item1'] = $data4;
  366. $job_item1->save();
  367. // One reviewed data item.
  368. drupal_static_reset('tmgmt_job_statistics_load');
  369. $this->assertEqual(1, $job_item1->getCountReviewed());
  370. $this->assertEqual(1, $job->getCountReviewed());
  371. // Add a translated and an untranslated and a confirmed data item
  372. $job = entity_load_single('tmgmt_job', $job->tjid);
  373. $job_item1 = entity_load_single('tmgmt_job_item', $job_item1->tjiid);
  374. $job_item1->data['data_item1'] = $data1;
  375. $job_item1->data['data_item2'] = $data3;
  376. $job_item1->data['data_item3'] = $data4;
  377. $job_item1->save();
  378. // One pending and translated data items each.
  379. drupal_static_reset('tmgmt_job_statistics_load');
  380. $this->assertEqual(1, $job->getCountPending());
  381. $this->assertEqual(1, $job->getCountTranslated());
  382. $this->assertEqual(1, $job->getCountReviewed());
  383. $this->assertEqual(16, $job->getWordCount());
  384. // Add nested data items.
  385. $job_item1->data['data_item1'] = $data5;
  386. $job_item1->save();
  387. // One pending data items.
  388. $job = entity_load_single('tmgmt_job', $job->tjid);
  389. $job_item1 = entity_load_single('tmgmt_job_item', $job_item1->tjiid);
  390. $this->assertEqual('label', $job_item1->data['data_item1']['#label']);
  391. $this->assertEqual(3, count($job_item1->data['data_item1']));
  392. // Add a greater number of data items
  393. for ($index = 1; $index <= 3; $index++) {
  394. $job_item1->data['data_item' . $index] = $data1;
  395. }
  396. for ($index = 4; $index <= 10; $index++) {
  397. $job_item1->data['data_item' . $index] = $data3;
  398. }
  399. for ($index = 11; $index <= 15; $index++) {
  400. $job_item1->data['data_item' . $index] = $data4;
  401. }
  402. $job_item1->save();
  403. // 3 pending and 7 translated data items each.
  404. $job = entity_load_single('tmgmt_job', $job->tjid);
  405. drupal_static_reset('tmgmt_job_statistics_load');
  406. $this->assertEqual(3, $job->getCountPending());
  407. $this->assertEqual(7, $job->getCountTranslated());
  408. $this->assertEqual(5, $job->getCountReviewed());
  409. // Add several job items
  410. $job_item2 = tmgmt_job_item_create('plugin', 'type', 5, array('tjid' => $job->tjid));
  411. for ($index = 1; $index <= 4; $index++) {
  412. $job_item2->data['data_item' . $index] = $data1;
  413. }
  414. for ($index = 5; $index <= 12; $index++) {
  415. $job_item2->data['data_item' . $index] = $data3;
  416. }
  417. for ($index = 13; $index <= 16; $index++) {
  418. $job_item2->data['data_item' . $index] = $data4;
  419. }
  420. $job_item2->save();
  421. // 3 pending and 7 translated data items each.
  422. $job = entity_load_single('tmgmt_job', $job->tjid);
  423. drupal_static_reset('tmgmt_job_statistics_load');
  424. $this->assertEqual(7, $job->getCountPending());
  425. $this->assertEqual(15, $job->getCountTranslated());
  426. $this->assertEqual(9, $job->getCountReviewed());
  427. // Accept the job items.
  428. foreach ($job->getItems() as $item) {
  429. // Set the state directly to avoid triggering translator and source
  430. // controllers that do not exist.
  431. $item->setState(TMGMT_JOB_ITEM_STATE_ACCEPTED);
  432. $item->save();
  433. }
  434. drupal_static_reset('tmgmt_job_statistics_load');
  435. $this->assertEqual(0, $job->getCountPending());
  436. $this->assertEqual(0, $job->getCountTranslated());
  437. $this->assertEqual(0, $job->getCountReviewed());
  438. $this->assertEqual(31, $job->getCountAccepted());
  439. }
  440. }