tmgmt_node_ui.test 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <?php
  2. /**
  3. * Basic Node Source UI tests.
  4. */
  5. class TMGMTNodeSourceUITestCase extends TMGMTEntityTestCaseUtility {
  6. static function getInfo() {
  7. return array(
  8. 'name' => 'Node Source UI tests',
  9. 'description' => 'Tests the user interface for node translation sources.',
  10. 'group' => 'Translation Management',
  11. );
  12. }
  13. function setUp() {
  14. parent::setUp(array('tmgmt_node_ui', 'block'));
  15. // We need the administer blocks permission.
  16. $this->loginAsAdmin(array('administer blocks'));
  17. $this->setEnvironment('de');
  18. $this->setEnvironment('fr');
  19. $this->setEnvironment('es');
  20. $this->setEnvironment('el');
  21. // @todo Re-enable this when switching to testing profile.
  22. // Enable the main page content block for hook_page_alter() to work.
  23. $edit = array(
  24. 'blocks[system_main][region]' => 'content',
  25. );
  26. $this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  27. $this->createNodeType('page', 'Page', TRANSLATION_ENABLED, FALSE);
  28. }
  29. /**
  30. * Tests the create, submit and accept permissions.
  31. */
  32. function testPermissions() {
  33. $no_permissions = $this->drupalCreateUser();
  34. $this->drupalLogin($no_permissions);
  35. $this->drupalGet('admin/tmgmt');
  36. $this->assertResponse(403);
  37. // Test with a user that is only allowed to create jobs.
  38. $create_user = $this->drupalCreateUser(array('access administration pages', 'translate content', 'create translation jobs'));
  39. $this->drupalLogin($create_user);
  40. // Create an english source node.
  41. $node = $this->drupalCreateNode(array('type' => 'page', 'language' => 'en', 'body' => array('en' => array(array()))));
  42. // Go to the translate tab.
  43. $this->drupalGet('node/' . $node->nid);
  44. $this->clickLink('Translate');
  45. // Request a translation for german.
  46. $edit = array(
  47. 'languages[de]' => TRUE,
  48. );
  49. $this->drupalPost(NULL, $edit, t('Request translation'));
  50. $this->assertText(t('One job has been created.'));
  51. // Verify that we are still on the translate tab.
  52. $this->assertText(t('Translations of @title', array('@title' => $node->title)));
  53. // The job is unprocessed, check the status flag in the source list.
  54. $this->drupalGet('admin/tmgmt/sources');
  55. $links = $this->xpath('//a[contains(@title, :title)]', array(':title' => t('Active job item: @state', array('@state' => t('Unprocessed')))));
  56. $attributes = $links[0]->attributes();
  57. // Check if the found link points to the job checkout page instead of the
  58. // job item review form.
  59. $this->assertEqual($attributes['href'], url('admin/tmgmt/jobs/1', array('query' => array('destination' => 'admin/tmgmt/sources'))));
  60. $this->drupalGet('admin/tmgmt');
  61. $this->assertResponse(200);
  62. $this->assertLink(t('manage'));
  63. $this->assertNoLink(t('submit'));
  64. $this->assertNoLink(t('delete'));
  65. $this->assertText(t('@title', array('@title' => $node->title)));
  66. $this->clickLink(t('manage'));
  67. $this->assertResponse(200);
  68. $this->assertNoRaw(t('Submit to translator'));
  69. // Try to access the delete page directly.
  70. $this->drupalGet($this->getUrl() . '/delete');
  71. $this->assertResponse(403);
  72. // Log in as user with only submit permission.
  73. $submit_user = $this->drupalCreateUser(array('access administration pages', 'translate content', 'submit translation jobs'));
  74. $this->drupalLogin($submit_user);
  75. // Go to the translate tab, verify that there is no request translation
  76. // button.
  77. $this->drupalGet('node/' . $node->nid);
  78. $this->clickLink('Translate');
  79. $this->assertNoRaw(t('Request translation'));
  80. // Go to the overview and submit the job.
  81. $this->drupalGet('admin/tmgmt');
  82. $this->assertResponse(200);
  83. $this->assertLink(t('submit'));
  84. $this->assertNoLink(t('manage'));
  85. $this->assertNoLink(t('delete'));
  86. $this->assertText(t('@title', array('@title' => $node->title)));
  87. // Check VBO actions - "submit translation job" has the right to cancel
  88. // translation only.
  89. $element = $this->xpath('//select[@id=:id]/option/@value', array(':id' => 'edit-operation'));
  90. $options = array();
  91. foreach ($element as $option) {
  92. $options[] = (string) $option;
  93. }
  94. $this->assertTrue(in_array('rules_component::rules_tmgmt_job_abort_translation', $options));
  95. // Go to the job checkout page and submit it.
  96. $this->clickLink('submit');
  97. $this->drupalPost(NULL, array(), t('Submit to translator'));
  98. // After submit the redirect goes back to the job overview.
  99. $this->assertUrl('admin/tmgmt');
  100. // Make sure that the job is active now.
  101. $this->assertText(t('Active'));
  102. // Click abort link and check if we are at the job abort confirm page.
  103. $this->clickLink(t('abort'));
  104. $this->assertText(t('This will send a request to the translator to abort the job. After the action the job translation process will be aborted and only remaining action will be resubmitting it.'));
  105. // Return back to job overview and test the manage link.
  106. $this->drupalGet('admin/tmgmt');
  107. $this->clickLink(t('manage'));
  108. $this->assertText(t('Needs review'));
  109. $this->assertNoLink(t('review'));
  110. // Now log in as user with only accept permission and review the job.
  111. $accept_user = $this->drupalCreateUser(array('access administration pages', 'accept translation jobs'));
  112. $this->drupalLogin($accept_user);
  113. $this->drupalGet('admin/tmgmt');
  114. // Check VBO actions - "accept translation jobs" has the right to accept
  115. // translation only.
  116. $element = $this->xpath('//select[@id=:id]/option/@value', array(':id' => 'edit-operation'));
  117. $options = array();
  118. foreach ($element as $option) {
  119. $options[] = (string) $option;
  120. }
  121. $this->assertTrue(in_array('rules_component::rules_tmgmt_job_accept_translation', $options));
  122. $this->clickLink('manage');
  123. $this->clickLink('review');
  124. $this->drupalPost(NULL, array(), '✓');
  125. // Verify that the accepted character is shown.
  126. $this->assertText('&#x2611;');
  127. $this->drupalPost(NULL, array(), t('Save as completed'));
  128. $this->assertText(t('Accepted'));
  129. $this->assertText('1/0/0');
  130. $create_user = $this->loginAsAdmin();
  131. $this->drupalLogin($create_user);
  132. $this->drupalGet('admin/tmgmt');
  133. // Check VBO actions - "administer tmgmt" has rights for all actions.
  134. $element = $this->xpath('//select[@id=:id]/option/@value', array(':id' => 'edit-operation'));
  135. $options = array();
  136. foreach ($element as $option) {
  137. $options[] = (string) $option;
  138. }
  139. $this->assertTrue(in_array('rules_component::rules_tmgmt_job_accept_translation', $options));
  140. $this->assertTrue(in_array('rules_component::rules_tmgmt_job_abort_translation', $options));
  141. $this->assertTrue(in_array('rules_component::rules_tmgmt_job_delete', $options));
  142. // Go to the translate tab, verify that there is no request translation
  143. // button.
  144. //$this->drupalGet('node/' . $node->nid);
  145. //$this->clickLink('Translate');
  146. //$this->assertNoRaw(t('Request translation'));
  147. }
  148. /**
  149. * Test the translate tab for a single checkout.
  150. */
  151. function testTranslateTabSingleCheckout() {
  152. // Create a user that is allowed to translate nodes.
  153. $translater = $this->drupalCreateUser(array('translate content', 'create translation jobs', 'submit translation jobs', 'accept translation jobs'));
  154. $this->drupalLogin($translater);
  155. // Create an english source node.
  156. $node = $this->drupalCreateNode(array('type' => 'page', 'language' => 'en', 'body' => array('en' => array(array()))));
  157. // Go to the translate tab.
  158. $this->drupalGet('node/' . $node->nid);
  159. $this->clickLink('Translate');
  160. // Assert some basic strings on that page.
  161. $this->assertText(t('Translations of @title', array('@title' => $node->title)));
  162. $this->assertText(t('Pending Translations'));
  163. // Request a translation for german.
  164. $edit = array(
  165. 'languages[de]' => TRUE,
  166. );
  167. $this->drupalPost(NULL, $edit, t('Request translation'));
  168. // Verify that we are on the translate tab.
  169. $this->assertText(t('One job needs to be checked out.'));
  170. $this->assertText($node->title);
  171. // Go to the translate tab and check if the pending translation label is
  172. // "Unprocessed" and links to the job checkout page.
  173. $this->drupalGet('node/' . $node->nid . '/translate');
  174. $this->assertLink(t('Unprocessed'));
  175. $this->clickLink(t('Unprocessed'));
  176. // Submit.
  177. $this->drupalPost(NULL, array(), t('Submit to translator'));
  178. // Make sure that we're back on the translate tab.
  179. $this->assertEqual(url('node/' . $node->nid . '/translate', array('absolute' => TRUE)), $this->getUrl());
  180. $this->assertText(t('Test translation created.'));
  181. $this->assertText(t('The translation of @title to @language is finished and can now be reviewed.', array('@title' => $node->title, '@language' => t('German'))));
  182. // Review.
  183. $this->clickLink(t('Needs review'));
  184. // @todo Review job throuh the UI.
  185. $items = tmgmt_job_item_load_latest('node', 'node', $node->nid, 'en');
  186. $items['de']->acceptTranslation();
  187. // German node should now be listed and be clickable.
  188. $this->drupalGet('node/' . $node->nid . '/translate');
  189. $this->clickLink('de_' . $node->title);
  190. // Test that the destination query argument does not break the redirect
  191. // and we are redirected back to the correct page.
  192. $this->drupalGet('node/' . $node->nid . '/translate', array('query' => array('destination' => 'node')));
  193. // Request a spanish translation.
  194. $edit = array(
  195. 'languages[es]' => TRUE,
  196. );
  197. $this->drupalPost(NULL, $edit, t('Request translation'));
  198. // Verify that we are on the checkout page.
  199. $this->assertText(t('One job needs to be checked out.'));
  200. $this->assertText($node->title);
  201. $this->drupalPost(NULL, array(), t('Submit to translator'));
  202. // Make sure that we're back on the originally defined destination URL.
  203. $this->assertEqual(url('node', array('absolute' => TRUE)), $this->getUrl());
  204. }
  205. /**
  206. * Test the translate tab for a single checkout.
  207. */
  208. function testTranslateTabMultipeCheckout() {
  209. // Create a user that is allowed to translate nodes.
  210. $translater = $this->drupalCreateUser(array('translate content', 'create translation jobs', 'submit translation jobs', 'accept translation jobs'));
  211. $this->drupalLogin($translater);
  212. // Create an english source node.
  213. $node = $this->drupalCreateNode(array('type' => 'page', 'language' => 'en', 'body' => array('en' => array(array()))));
  214. // Go to the translate tab.
  215. $this->drupalGet('node/' . $node->nid);
  216. $this->clickLink('Translate');
  217. // Assert some basic strings on that page.
  218. $this->assertText(t('Translations of @title', array('@title' => $node->title)));
  219. $this->assertText(t('Pending Translations'));
  220. // Request a translation for german.
  221. $edit = array(
  222. 'languages[de]' => TRUE,
  223. 'languages[es]' => TRUE,
  224. );
  225. $this->drupalPost(NULL, $edit, t('Request translation'));
  226. // Verify that we are on the translate tab.
  227. $this->assertText(t('2 jobs need to be checked out.'));
  228. // Submit all jobs.
  229. $this->assertText($node->title);
  230. $this->drupalPost(NULL, array(), t('Submit to translator and continue'));
  231. $this->assertText($node->title);
  232. $this->drupalPost(NULL, array(), t('Submit to translator'));
  233. // Make sure that we're back on the translate tab.
  234. $this->assertEqual(url('node/' . $node->nid . '/translate', array('absolute' => TRUE)), $this->getUrl());
  235. $this->assertText(t('Test translation created.'));
  236. $this->assertText(t('The translation of @title to @language is finished and can now be reviewed.', array('@title' => $node->title, '@language' => t('Spanish'))));
  237. // Review.
  238. $this->clickLink(t('Needs review'));
  239. // @todo Review job throuh the UI.
  240. $items = tmgmt_job_item_load_latest('node', 'node', $node->nid, 'en');
  241. $items['de']->acceptTranslation();
  242. $items['es']->acceptTranslation();
  243. // Translated nodes should now be listed and be clickable.
  244. $this->drupalGet('node/' . $node->nid . '/translate');
  245. $this->clickLink('de_' . $node->title);
  246. // Translated nodes should now be listed and be clickable.
  247. $this->drupalGet('node/' . $node->nid . '/translate');
  248. $this->clickLink('es_' . $node->title);
  249. }
  250. /**
  251. * Test the translate tab for a single checkout.
  252. */
  253. function testTranslateTabAutomatedCheckout() {
  254. // Hide settings on the test translator.
  255. $default_translator = tmgmt_translator_load('test_translator');
  256. $default_translator->settings = array(
  257. 'expose_settings' => FALSE,
  258. );
  259. $default_translator->save();
  260. // Create a user that is allowed to translate nodes.
  261. $translater = $this->drupalCreateUser(array('translate content', 'create translation jobs', 'submit translation jobs', 'accept translation jobs'));
  262. $this->drupalLogin($translater);
  263. // Create an english source node.
  264. $node = $this->drupalCreateNode(array('type' => 'page', 'language' => 'en', 'body' => array('en' => array(array()))));
  265. // Go to the translate tab.
  266. $this->drupalGet('node/' . $node->nid);
  267. $this->clickLink('Translate');
  268. // Assert some basic strings on that page.
  269. $this->assertText(t('Translations of @title', array('@title' => $node->title)));
  270. $this->assertText(t('Pending Translations'));
  271. // Request a translation for german.
  272. $edit = array(
  273. 'languages[de]' => TRUE,
  274. );
  275. $this->drupalPost(NULL, $edit, t('Request translation'));
  276. // Verify that we are on the translate tab.
  277. $this->assertNoText(t('One job needs to be checked out.'));
  278. // Make sure that we're back on the translate tab.
  279. $this->assertEqual(url('node/' . $node->nid . '/translate', array('absolute' => TRUE)), $this->getUrl());
  280. $this->assertText(t('Test translation created.'));
  281. $this->assertText(t('The translation of @title to @language is finished and can now be reviewed.', array('@title' => $node->title, '@language' => t('German'))));
  282. // Review.
  283. $this->clickLink(t('Needs review'));
  284. // @todo Review job throuh the UI.
  285. $items = tmgmt_job_item_load_latest('node', 'node', $node->nid, 'en');
  286. $items['de']->acceptTranslation();
  287. // German node should now be listed and be clickable.
  288. $this->drupalGet('node/' . $node->nid . '/translate');
  289. $this->clickLink('de_' . $node->title);
  290. }
  291. /**
  292. * Test the translate tab for a single checkout.
  293. */
  294. function testTranslateTabDisabledQuickCheckout() {
  295. variable_set('tmgmt_quick_checkout', FALSE);
  296. // Hide settings on the test translator.
  297. $default_translator = tmgmt_translator_load('test_translator');
  298. $default_translator->settings = array(
  299. 'expose_settings' => FALSE,
  300. );
  301. $default_translator->save();
  302. // Create a user that is allowed to translate nodes.
  303. $translater = $this->drupalCreateUser(array('translate content', 'create translation jobs', 'submit translation jobs', 'accept translation jobs'));
  304. $this->drupalLogin($translater);
  305. // Create an english source node.
  306. $node = $this->drupalCreateNode(array('type' => 'page', 'language' => 'en', 'body' => array('en' => array(array()))));
  307. // Go to the translate tab.
  308. $this->drupalGet('node/' . $node->nid);
  309. $this->clickLink('Translate');
  310. // Assert some basic strings on that page.
  311. $this->assertText(t('Translations of @title', array('@title' => $node->title)));
  312. $this->assertText(t('Pending Translations'));
  313. // Request a translation for german.
  314. $edit = array(
  315. 'languages[de]' => TRUE,
  316. );
  317. $this->drupalPost(NULL, $edit, t('Request translation'));
  318. // Verify that we are on the translate tab.
  319. $this->assertText(t('One job needs to be checked out.'));
  320. $this->assertText($node->title);
  321. // Submit.
  322. $this->drupalPost(NULL, array(), t('Submit to translator'));
  323. // Make sure that we're back on the translate tab.
  324. $this->assertEqual(url('node/' . $node->nid . '/translate', array('absolute' => TRUE)), $this->getUrl());
  325. $this->assertText(t('Test translation created.'));
  326. $this->assertText(t('The translation of @title to @language is finished and can now be reviewed.', array('@title' => $node->title, '@language' => t('German'))));
  327. // Review.
  328. $this->clickLink(t('Needs review'));
  329. // @todo Review job throuh the UI.
  330. $items = tmgmt_job_item_load_latest('node', 'node', $node->nid, 'en');
  331. $items['de']->acceptTranslation();
  332. // German node should now be listed and be clickable.
  333. $this->drupalGet('node/' . $node->nid . '/translate');
  334. $this->clickLink('de_' . $node->title);
  335. }
  336. /**
  337. * Test the node source specific cart functionality.
  338. */
  339. function testCart() {
  340. $nodes = array();
  341. for ($i = 0; $i < 4; $i++) {
  342. $nodes[] = $this->createNode('page');
  343. }
  344. $this->loginAsAdmin(array_merge($this->translator_permissions, array('translate content')));
  345. // Test the source overview.
  346. $this->drupalPost('admin/tmgmt/sources/node', array(
  347. 'views_bulk_operations[0]' => TRUE,
  348. 'views_bulk_operations[1]' => TRUE,
  349. ), t('Add to cart'));
  350. $this->drupalGet('admin/tmgmt/cart');
  351. $this->assertText($nodes[0]->title);
  352. $this->assertText($nodes[1]->title);
  353. // Test the translate tab.
  354. $this->drupalGet('node/' . $nodes[3]->nid . '/translate');
  355. $this->assertRaw(t('There are @count items in the <a href="@url">translation cart</a>.',
  356. array('@count' => 2, '@url' => url('admin/tmgmt/cart'))));
  357. $this->drupalPost(NULL, array(), t('Add to cart'));
  358. $this->assertRaw(t('@count content source was added into the <a href="@url">cart</a>.', array('@count' => 1, '@url' => url('admin/tmgmt/cart'))));
  359. $this->assertRaw(t('There are @count items in the <a href="@url">translation cart</a> including the current item.',
  360. array('@count' => 3, '@url' => url('admin/tmgmt/cart'))));
  361. }
  362. }