tmgmt_ui.test 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <?php
  2. /*
  3. * @file
  4. * Contains tests for the default user interface.
  5. */
  6. /**
  7. * Test the UI of tmgmt, for example the checkout form.
  8. */
  9. class TMGMTUITestCase extends TMGMTBaseTestCase {
  10. static function getInfo() {
  11. return array(
  12. 'name' => 'UI tests',
  13. 'description' => 'Verifies basic functionality of the user interface',
  14. 'group' => 'Translation Management',
  15. );
  16. }
  17. function setUp() {
  18. parent::setup(array('tmgmt_ui'));
  19. parent::createLanguagesLoginTranslator();
  20. }
  21. /**
  22. * Test the page callbacks to create jobs and check them out.
  23. */
  24. function testCheckoutForm() {
  25. // Add a first item to the job. This will auto-create the job.
  26. $job = tmgmt_job_match_item('en', '');
  27. $job->addItem('test_source', 'test', 1);
  28. // Go to checkout form.
  29. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  30. $this->drupalGet(reset($redirects));
  31. // Check checkout form.
  32. $this->assertText('test_source:test:1');
  33. // Add two more job items.
  34. $job->addItem('test_source', 'test', 2);
  35. $job->addItem('test_source', 'test', 3);
  36. // Go to checkout form.
  37. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  38. $this->drupalGet(reset($redirects));
  39. // Check checkout form.
  40. $this->assertText('test_source:test:1');
  41. $this->assertText('test_source:test:2');
  42. $this->assertText('test_source:test:3');
  43. // @todo: Test ajax functionality.
  44. // Attempt to translate into greek.
  45. $edit = array(
  46. 'target_language' => 'el',
  47. 'settings[action]' => 'translate',
  48. );
  49. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  50. $this->assertText(t('@translator can not translate from @source to @target.', array('@translator' => 'Test translator (auto created)', '@source' => 'English', '@target' => 'Greek')));
  51. // Job still needs to be in state new.
  52. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  53. $this->assertTrue($job->isUnprocessed());
  54. $edit = array(
  55. 'target_language' => 'es',
  56. 'settings[action]' => 'translate',
  57. );
  58. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  59. // Job needs to be in state active.
  60. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  61. $this->assertTrue($job->isActive());
  62. foreach ($job->getItems() as $job_item) {
  63. /* @var $job_item TMGMTJobItem */
  64. $this->assertTrue($job_item->isNeedsReview());
  65. }
  66. $this->assertText(t('Test translation created'));
  67. $this->assertNoText(t('Test translator called'));
  68. // Test redirection.
  69. $this->assertText(t('Job overview'));
  70. // Another job.
  71. $previous_tjid = $job->tjid;
  72. $job = tmgmt_job_match_item('en', '');
  73. $job->addItem('test_source', 'test', 1);
  74. $this->assertNotEqual($job->tjid, $previous_tjid);
  75. // Go to checkout form.
  76. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  77. $this->drupalGet(reset($redirects));
  78. // Check checkout form.
  79. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  80. $this->assertText('test_source:test:1');
  81. $edit = array(
  82. 'target_language' => 'es',
  83. 'settings[action]' => 'submit',
  84. );
  85. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  86. $this->assertText(t('Test submit'));
  87. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  88. $this->assertTrue($job->isActive());
  89. // Another job.
  90. $job = tmgmt_job_match_item('en', 'es');
  91. $job->addItem('test_source', 'test', 1);
  92. // Go to checkout form.
  93. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  94. $this->drupalGet(reset($redirects));
  95. // Check checkout form.
  96. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  97. $this->assertText('test_source:test:1');
  98. $edit = array(
  99. 'settings[action]' => 'reject',
  100. );
  101. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  102. $this->assertText(t('This is not supported'));
  103. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  104. $this->assertTrue($job->isRejected());
  105. // Check displayed job messages.
  106. $args = array('@view' => 'view-tmgmt-ui-job-messages');
  107. $this->assertEqual(2, count($this->xpath('//div[contains(@class, @view)]//tbody/tr', $args)));
  108. // Check that the author for each is the current user.
  109. $message_authors = $this->xpath('////div[contains(@class, @view)]//td[contains(@class, @field)]/span', $args + array('@field' => 'views-field-name'));
  110. $this->assertEqual(2, count($message_authors));
  111. foreach ($message_authors as $message_author) {
  112. $this->assertEqual((string)$message_author, $this->translator_user->name);
  113. }
  114. // Make sure that rejected jobs can be re-submitted.
  115. $this->assertTrue($job->isSubmittable());
  116. $edit = array(
  117. 'settings[action]' => 'translate',
  118. );
  119. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  120. $this->assertText(t('Test translation created'));
  121. // Another job.
  122. $job = tmgmt_job_match_item('en', 'es');
  123. $job->addItem('test_source', 'test', 1);
  124. // Go to checkout form.
  125. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  126. $this->drupalGet(reset($redirects));
  127. // Check checkout form.
  128. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  129. $this->assertText('test_source:test:1');
  130. $edit = array(
  131. 'settings[action]' => 'fail',
  132. );
  133. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  134. $this->assertText(t('Service not reachable'));
  135. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  136. $this->assertTrue($job->isUnprocessed());
  137. // Verify that we are still on the form.
  138. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  139. // Another job.
  140. $job = tmgmt_job_match_item('en', 'es');
  141. $job->addItem('test_source', 'test', 1);
  142. // Go to checkout form.
  143. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  144. $this->drupalGet(reset($redirects));
  145. // Check checkout form.
  146. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  147. $this->assertText('test_source:test:1');
  148. $edit = array(
  149. 'settings[action]' => 'not_translatable',
  150. );
  151. $this->drupalPost(NULL, $edit, t('Submit to translator'));
  152. // @todo Update to correct failure message.
  153. $this->assertText(t('Fail'));
  154. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  155. $this->assertTrue($job->isUnprocessed());
  156. // Test default settings.
  157. $this->default_translator->settings['action'] = 'reject';
  158. $this->default_translator->save();
  159. $job = tmgmt_job_match_item('en', 'es');
  160. $job->addItem('test_source', 'test', 1);
  161. // Go to checkout form.
  162. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  163. $this->drupalGet(reset($redirects));
  164. // Check checkout form.
  165. $this->assertText('You can provide a label for this job in order to identify it easily later on.');
  166. $this->assertText('test_source:test:1');
  167. // The action should now default to reject.
  168. $this->drupalPost(NULL, array(), t('Submit to translator'));
  169. $this->assertText(t('This is not supported.'));
  170. $job = entity_load_unchanged('tmgmt_job', $job->tjid);
  171. $this->assertTrue($job->isRejected());
  172. }
  173. /**
  174. * Tests the tmgmt_ui_job_checkout() function.
  175. */
  176. function testCheckoutFunction() {
  177. $job = $this->createJob();
  178. // Check out a job when only the test translator is available. That one has
  179. // settings, so a checkout is necessary.
  180. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  181. $uri = $job->uri();
  182. $this->assertEqual($uri['path'], $redirects[0]);
  183. $this->assertTrue($job->isUnprocessed());
  184. $job->delete();
  185. // Hide settings on the test translator.
  186. $default_translator = tmgmt_translator_load('test_translator');
  187. $default_translator->settings = array(
  188. 'expose_settings' => FALSE,
  189. );
  190. $job = $this->createJob();
  191. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  192. $this->assertFalse($redirects);
  193. $this->assertTrue($job->isActive());
  194. // A job without target language needs to be checked out.
  195. $job = $this->createJob('en', '');
  196. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  197. $uri = $job->uri();
  198. $this->assertEqual($uri['path'], $redirects[0]);
  199. $this->assertTrue($job->isUnprocessed());
  200. // Create a second file translator. This should check
  201. // out immediately.
  202. $job = $this->createJob();
  203. $second_translator = $this->createTranslator();
  204. $second_translator->settings = array(
  205. 'expose_settings' => FALSE,
  206. );
  207. $second_translator->save();
  208. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  209. $uri = $job->uri();
  210. $this->assertEqual($uri['path'], $redirects[0]);
  211. $this->assertTrue($job->isUnprocessed());
  212. }
  213. /**
  214. * Tests of the job item review process.
  215. */
  216. public function testReview() {
  217. $job = $this->createJob();
  218. $job->translator = $this->default_translator->name;
  219. $job->settings = array();
  220. $job->save();
  221. $item = $job->addItem('test_source', 'test', 1);
  222. $data = tmgmt_flatten_data($item->getData());
  223. $keys = array_keys($data);
  224. $key = $keys[0];
  225. $this->drupalGet('admin/tmgmt/items/' . $item->tjiid);
  226. // Testing the result of the
  227. // TMGMTTranslatorUIControllerInterface::reviewDataItemElement()
  228. $this->assertText(t('Testing output of review data item element @key from the testing translator.', array('@key' => $key)));
  229. // Test the review tool source textarea.
  230. $this->assertFieldByName('dummy|deep_nesting[source]', $data[$key]['#text']);
  231. // Save translation.
  232. $this->drupalPost(NULL, array('dummy|deep_nesting[translation]' => $data[$key]['#text'] . 'translated'), t('Save'));
  233. $this->drupalGet('admin/tmgmt/items/' . $item->tjiid);
  234. // Check if translation has been saved.
  235. $this->assertFieldByName('dummy|deep_nesting[translation]', $data[$key]['#text'] . 'translated');
  236. }
  237. /**
  238. * Tests the UI of suggestions.
  239. */
  240. public function testSuggestions() {
  241. // Prepare a job and a node for testing.
  242. $job = $this->createJob();
  243. $job->addItem('test_source', 'test', 1);
  244. $job->addItem('test_source', 'test', 7);
  245. // Go to checkout form.
  246. $redirects = tmgmt_ui_job_checkout_multiple(array($job));
  247. $this->drupalGet(reset($redirects));
  248. $this->assertRaw('20');
  249. // Load all suggestions.
  250. $commands = $this->drupalPostAJAX(NULL, array(), array('op' => t('Load suggestions')));
  251. $this->assertEqual(count($commands), 4, 'Found 4 commands in AJAX-Request.');
  252. // Check each command for success.
  253. foreach ($commands as $command) {
  254. // No checks against the settings because we not use ajax to save.
  255. if ($command['command'] == 'settings') {
  256. }
  257. // Other commands must be from type "insert".
  258. else if ($command['command'] == 'insert') {
  259. // This should be the tableselect javascript file for the header.
  260. if (($command['method'] == 'prepend') && ($command['selector'] == 'head')) {
  261. $this->assertTrue(substr_count($command['data'], 'misc/tableselect.js'), 'Javascript for Tableselect found.');
  262. }
  263. // Check for the main content, the tableselect with the suggestions.
  264. else if (($command['method'] == NULL) && ($command['selector'] == NULL)) {
  265. $this->assertTrue(substr_count($command['data'], '</th>') == 5, 'Found five table header.');
  266. $this->assertTrue(substr_count($command['data'], '</tr>') == 3, 'Found two suggestion and one table header.');
  267. $this->assertTrue(substr_count($command['data'], '<td>11</td>') == 2, 'Found 10 words to translate per suggestion.');
  268. $this->assertTrue(substr_count($command['data'], 'value="Add suggestions"'), 'Found add button.');
  269. }
  270. // Nothing to prepend...
  271. else if (($command['method'] == 'prepend') && ($command['selector'] == NULL)) {
  272. $this->assertTrue(empty($command['data']), 'No content will be prepended.');
  273. }
  274. else {
  275. $this->fail('Unknown method/selector combination.');
  276. debug($command);
  277. }
  278. }
  279. else {
  280. $this->fail('Unknown command.');
  281. debug($command);
  282. }
  283. }
  284. $this->assertText('test_source:test_suggestion:1');
  285. $this->assertText('test_source:test_suggestion:7');
  286. $this->assertText('Test suggestion for test source 1');
  287. $this->assertText('Test suggestion for test source 7');
  288. // Add the second suggestion.
  289. $edit = array('suggestions_table[2]' => TRUE);
  290. $this->drupalPost(NULL, $edit, t('Add suggestions'));
  291. // Total word count should now include the added job.
  292. $this->assertRaw('31');
  293. // The suggestion for 7 was added, so there should now be a suggestion
  294. // or the suggestion instead.
  295. $this->assertNoText('Test suggestion for test source 7');
  296. $this->assertText('test_source:test_suggestion_suggestion:7');
  297. }
  298. /**
  299. * Test the process of aborting and resubmitting the job.
  300. */
  301. function testAbortJob() {
  302. $job = $this->createJob();
  303. $job->addItem('test_source', 'test', 1);
  304. $job->addItem('test_source', 'test', 2);
  305. $job->addItem('test_source', 'test', 3);
  306. $edit = array(
  307. 'target_language' => 'es',
  308. 'settings[action]' => 'translate',
  309. );
  310. $this->drupalPost('admin/tmgmt/jobs/' . $job->tjid, $edit, t('Submit to translator'));
  311. // Abort job.
  312. $this->drupalPost('admin/tmgmt/jobs/' . $job->tjid, array(), t('Abort job'));
  313. $this->drupalPost(NULL, array(), t('Confirm'));
  314. // Reload job and check its state.
  315. entity_get_controller('tmgmt_job')->resetCache();
  316. /** @var TMGMTJob $job */
  317. $job = tmgmt_job_load($job->tjid);
  318. $this->assertTrue($job->isAborted());
  319. foreach ($job->getItems() as $item) {
  320. $this->assertTrue($item->isAborted());
  321. }
  322. // Resubmit the job.
  323. $this->drupalPost('admin/tmgmt/jobs/' . $job->tjid, array(), t('Resubmit'));
  324. $this->drupalPost(NULL, array(), t('Confirm'));
  325. // Test for the log message.
  326. $this->assertRaw(t('This job is a duplicate of the previously aborted job <a href="@url">#@id</a>',
  327. array('@url' => url('admin/tmgmt/jobs/' . $job->tjid), '@id' => $job->tjid)));
  328. // Load the resubmitted job and check for its status and values.
  329. $url_parts = explode('/', $this->getUrl());
  330. $resubmitted_job = tmgmt_job_load(array_pop($url_parts));
  331. $this->assertTrue($resubmitted_job->isUnprocessed());
  332. $this->assertEqual($job->translator, $resubmitted_job->translator);
  333. $this->assertEqual($job->source_language, $resubmitted_job->source_language);
  334. $this->assertEqual($job->target_language, $resubmitted_job->target_language);
  335. $this->assertEqual($job->settings, $resubmitted_job->settings);
  336. // Test if job items were duplicated correctly.
  337. /** @var TMGMTJobItem $item */
  338. foreach ($job->getItems() as $item) {
  339. // We match job items based on "id #" string. This is not that straight
  340. // forward, but it works as the test source text is generated as follows:
  341. // Text for job item with type #type and id #id.
  342. $_items = $resubmitted_job->getItems(array('data' => array('value' => '%id ' . $item->item_id . '%', 'operator' => 'LIKE')));
  343. $_item = reset($_items);
  344. /** @var TMGMTJobItem $_item */
  345. $this->assertNotEqual($_item->tjid, $item->tjid);
  346. $this->assertEqual($_item->plugin, $item->plugin);
  347. $this->assertEqual($_item->item_id, $item->item_id);
  348. $this->assertEqual($_item->item_type, $item->item_type);
  349. // Make sure counts have been recalculated.
  350. $this->assertTrue($_item->word_count > 0);
  351. $this->assertTrue($_item->count_pending > 0);
  352. $this->assertEqual($_item->count_translated, 0);
  353. $this->assertEqual($_item->count_accepted, 0);
  354. $this->assertEqual($_item->count_reviewed, 0);
  355. }
  356. // Navigate back to the aborted job and check for the log message.
  357. $this->drupalGet('admin/tmgmt/jobs/' . $job->tjid);
  358. $this->assertRaw(t('Job has been duplicated as a new job <a href="@url">#@id</a>.',
  359. array('@url' => url('admin/tmgmt/jobs/' . $resubmitted_job->tjid), '@id' => $resubmitted_job->tjid)));
  360. $this->drupalGet('admin/tmgmt/jobs');
  361. $elements = $this->xpath('//table[contains(@class, @view)]//td[contains(., @text)]',
  362. array('@view' => 'views-table', '@text' => t('N/A')));
  363. $status = $elements[0];
  364. $this->assertEqual(trim((string)$status), t('N/A'));
  365. }
  366. /**
  367. * Test the cart functionality.
  368. */
  369. function testCart() {
  370. $this->setEnvironment('fr');
  371. $job_items = array();
  372. // Create a few job items and add them to the cart.
  373. for ($i = 1; $i < 6; $i++) {
  374. $job_item = tmgmt_job_item_create('test_source', 'test', $i);
  375. $job_item->save();
  376. $job_items[$i] = $job_item;
  377. }
  378. $this->loginAsTranslator();
  379. foreach ($job_items as $job_item) {
  380. $this->drupalGet('tmgmt-add-to-cart/' . $job_item->tjiid);
  381. }
  382. // Check if the items are displayed in the cart.
  383. $this->drupalGet('admin/tmgmt/cart');
  384. foreach ($job_items as $job_item) {
  385. $this->assertText($job_item->label());
  386. }
  387. // Test the remove items from cart functionality.
  388. $this->drupalPost(NULL, array('items[1]' => TRUE, 'items[4]' => TRUE), t('Remove selected'));
  389. $this->assertText($job_items[2]->label());
  390. $this->assertText($job_items[3]->label());
  391. $this->assertText($job_items[5]->label());
  392. $this->assertNoText($job_items[1]->label());
  393. $this->assertNoText($job_items[4]->label());
  394. $this->assertText(t('Job items were removed from the cart.'));
  395. // Test that removed job items from cart were deleted as well.
  396. $existing_items = tmgmt_job_item_load_multiple(NULL);
  397. $this->assertTrue(!isset($existing_items[$job_items[1]->tjiid]));
  398. $this->assertTrue(!isset($existing_items[$job_items[4]->tjiid]));
  399. $this->drupalPost(NULL, array(), t('Empty cart'));
  400. $this->assertNoText($job_items[2]->label());
  401. $this->assertNoText($job_items[3]->label());
  402. $this->assertNoText($job_items[5]->label());
  403. $this->assertText(t('All job items were removed from the cart.'));
  404. // No remaining job items.
  405. $existing_items = tmgmt_job_item_load_multiple(NULL);
  406. $this->assertTrue(empty($existing_items));
  407. $language_sequence = array('en', 'en', 'fr', 'fr', 'de', 'de');
  408. for ($i = 1; $i < 7; $i++) {
  409. $job_item = tmgmt_job_item_create('test_source', 'test', $i);
  410. $job_item->save();
  411. $job_items[$i] = $job_item;
  412. $languages[$job_items[$i]->tjiid] = $language_sequence[$i - 1];
  413. }
  414. variable_set('tmgmt_test_source_languages', $languages);
  415. foreach ($job_items as $job_item) {
  416. $this->drupalGet('tmgmt-add-to-cart/' . $job_item->tjiid);
  417. }
  418. $this->drupalPost('admin/tmgmt/cart', array(
  419. 'items[' . $job_items[1]->tjiid . ']' => TRUE,
  420. 'items[' . $job_items[2]->tjiid . ']' => TRUE,
  421. 'items[' . $job_items[3]->tjiid . ']' => TRUE,
  422. 'items[' . $job_items[4]->tjiid . ']' => TRUE,
  423. 'items[' . $job_items[5]->tjiid . ']' => TRUE,
  424. 'target_language[]' => array('en', 'de'),
  425. ), t('Request translation'));
  426. $this->assertText(t('@count jobs need to be checked out.', array('@count' => 4)));
  427. // We should have four jobs with following language combinations:
  428. // [fr, fr] => [en]
  429. // [de] => [en]
  430. // [en, en] => [de]
  431. // [fr, fr] => [de]
  432. $jobs = entity_load('tmgmt_job', FALSE, array('source_language' => 'fr', 'target_language' => 'en'));
  433. $job = reset($jobs);
  434. $this->assertEqual(count($job->getItems()), 2);
  435. $jobs = entity_load('tmgmt_job', FALSE, array('source_language' => 'de', 'target_language' => 'en'));
  436. $job = reset($jobs);
  437. $this->assertEqual(count($job->getItems()), 1);
  438. $jobs = entity_load('tmgmt_job', FALSE, array('source_language' => 'en', 'target_language' => 'de'));
  439. $job = reset($jobs);
  440. $this->assertEqual(count($job->getItems()), 2);
  441. $jobs = entity_load('tmgmt_job', FALSE, array('source_language' => 'fr', 'target_language' => 'de'));
  442. $job = reset($jobs);
  443. $this->assertEqual(count($job->getItems()), 2);
  444. $this->drupalGet('admin/tmgmt/cart');
  445. // Both fr and one de items must be gone.
  446. $this->assertNoText($job_items[1]->label());
  447. $this->assertNoText($job_items[2]->label());
  448. $this->assertNoText($job_items[3]->label());
  449. $this->assertNoText($job_items[4]->label());
  450. $this->assertNoText($job_items[5]->label());
  451. // One de item is in the cart as it was not selected for checkout.
  452. $this->assertText($job_items[6]->label());
  453. }
  454. /**
  455. * Test if the source is able to pull content in requested language.
  456. */
  457. function testCartEnforceSourceLanguage() {
  458. $this->setEnvironment('sk');
  459. $this->setEnvironment('cs');
  460. module_enable(array('tmgmt_node'));
  461. $content_type = $this->drupalCreateContentType();
  462. $node_sk = $this->drupalCreateNode(array(
  463. 'title' => $this->randomName(),
  464. 'language' => 'sk',
  465. 'body' => array('sk' => array(array($this->randomName()))),
  466. 'type' => $content_type->type,
  467. ));
  468. $this->drupalCreateNode(array(
  469. 'title' => $this->randomName(),
  470. 'language' => 'en',
  471. 'tnid' => $node_sk->nid,
  472. 'body' => array('en' => array(array($this->randomName()))),
  473. 'type' => $content_type->type,
  474. ));
  475. $node_cs = $this->drupalCreateNode(array(
  476. 'title' => $this->randomName(),
  477. 'language' => 'cs',
  478. 'body' => array('cs' => array(array($this->randomName()))),
  479. 'type' => $content_type->type,
  480. ));
  481. $this->loginAsTranslator();
  482. $job_item_sk = tmgmt_job_item_create('node', 'node', $node_sk->nid);
  483. $job_item_sk->save();
  484. $this->drupalGet('tmgmt-add-to-cart/' . $job_item_sk->tjiid);
  485. $job_items_data[$job_item_sk->item_id] = $job_item_sk->item_type;
  486. $job_item_cs = tmgmt_job_item_create('node', 'node', $node_cs->nid);
  487. $job_item_cs->save();
  488. $this->drupalGet('tmgmt-add-to-cart/' . $job_item_cs->tjiid);
  489. $job_items_data[$job_item_cs->item_id] = $job_item_cs->item_type;
  490. $this->drupalPost('admin/tmgmt/cart', array(
  491. 'enforced_source_language' => TRUE,
  492. 'source_language' => 'en',
  493. 'items[' . $job_item_cs->tjiid .']' => TRUE,
  494. 'items[' . $job_item_sk->tjiid .']' => TRUE,
  495. 'target_language[]' => array('es')
  496. ), t('Request translation'));
  497. $this->assertText(t('One job needs to be checked out.'));
  498. $this->assertRaw(t('One item skipped. @language translation unavailable.', array('@language' => 'English')));
  499. $args = explode('/', $this->getUrl());
  500. $tjid = array_pop($args);
  501. $this->drupalPost(NULL, array(), t('Submit to translator'));
  502. // We cannot test for the item data as items without a job are not able to
  503. // get the data in case the source language is overridden. Therefore only
  504. // testing for item_id and item_type values.
  505. foreach (tmgmt_job_load($tjid)->getItems() as $job_item) {
  506. $this->assertEqual($job_items_data[$job_item->item_id], $job_item->item_type);
  507. }
  508. $this->drupalGet('admin/tmgmt/cart');
  509. $this->assertText($node_cs->title);
  510. $this->assertNoText($node_sk->title);
  511. }
  512. }