tmgmt_locale.ui.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Basic Locale Source tests.
  4. */
  5. class TMGMTLocaleSourceUiTestCase extends TMGMTBaseTestCase {
  6. static function getInfo() {
  7. return array(
  8. 'name' => 'Locale Source UI tests',
  9. 'description' => 'Tests the locale source overview',
  10. 'group' => 'Translation Management',
  11. );
  12. }
  13. function setUp() {
  14. parent::setUp(array('tmgmt_locale', 'tmgmt_ui'));
  15. $this->langcode = 'de';
  16. $this->context = 'default';
  17. $file = new stdClass();
  18. $file->uri = drupal_realpath(drupal_get_path('module', 'tmgmt_locale') . '/tests/test.xx.po');
  19. $this->pofile = file_save($file);
  20. $this->setEnvironment($this->langcode);
  21. $this->setEnvironment('gsw-berne');
  22. }
  23. public function testOverview() {
  24. // Load PO file to create a locale structure in the database.
  25. _locale_import_po($this->pofile, $this->langcode, LOCALE_IMPORT_OVERWRITE, $this->context);
  26. $this->loginAsTranslator();
  27. $this->drupalGet('admin/tmgmt/sources/locale_default');
  28. $this->assertText('Hello World');
  29. $this->assertText('Example');
  30. $rows = $this->xpath('//tbody/tr');
  31. foreach ($rows as $row) {
  32. if ($row->td[1] == 'Hello World') {
  33. $this->assertEqual((string) $row->td[3]->div['title'], t('Translation up to date'));
  34. $this->assertEqual((string) $row->td[4]->div['title'], t('Not translated'));
  35. }
  36. }
  37. // Filter on the label.
  38. $edit = array('search[label]' => 'Hello');
  39. $this->drupalPost(NULL, $edit, t('Search'));
  40. $this->assertText('Hello World');
  41. $this->assertNoText('Example');
  42. $locale_object = db_query('SELECT * FROM {locales_source} WHERE source = :source LIMIT 1', array(':source' => 'Hello World'))->fetchObject();
  43. // First add source to the cart to test its functionality.
  44. $edit = array(
  45. 'items[' . $locale_object->lid . ']' => TRUE,
  46. );
  47. $this->drupalPost(NULL, $edit, t('Add to cart'));
  48. $this->assertRaw(t('@count content source was added into the <a href="@url">cart</a>.', array('@count' => 1, '@url' => url('admin/tmgmt/cart'))));
  49. $edit['target_language[]'] = array('gsw-berne');
  50. $this->drupalPost('admin/tmgmt/cart', $edit, t('Request translation'));
  51. // Assert that the job item is displayed.
  52. $this->assertText('Hello World');
  53. $this->assertText(t('Locale'));
  54. $this->assertText('2');
  55. $this->drupalPost(NULL, array('target_language' => 'gsw-berne'), t('Submit to translator'));
  56. // Test for the translation flag title.
  57. $this->drupalGet('admin/tmgmt/sources/locale_default');
  58. $this->assertRaw(t('Active job item: Needs review'));
  59. // Review and accept the job item.
  60. $job_items = tmgmt_job_item_load_latest('locale', 'default', $locale_object->lid, 'en');
  61. $this->drupalGet('admin/tmgmt/items/' . $job_items['gsw-berne']->tjiid);
  62. $this->assertRaw('gsw-berne_Hello World');
  63. $this->drupalPost(NULL, array(), t('Save as completed'));
  64. $this->drupalGet('admin/tmgmt/sources/locale_default');
  65. $this->assertNoRaw(t('Active job item: Needs review'));
  66. $rows = $this->xpath('//tbody/tr');
  67. foreach ($rows as $row) {
  68. if ($row->td[1] == 'Hello World') {
  69. $this->assertEqual((string) $row->td[3]->div['title'], t('Translation up to date'));
  70. $this->assertEqual((string) $row->td[4]->div['title'], t('Translation up to date'));
  71. }
  72. }
  73. // Test the missing translation filter.
  74. $this->drupalGet('admin/tmgmt/sources/locale_default');
  75. // Check that the source language (en) has been removed from the target language
  76. // select box.
  77. $elements = $this->xpath('//select[@name=:name]//option[@value=:option]', array(':name' => 'search[target_language]', ':option' => 'en'));
  78. $this->assertTrue(empty($elements));
  79. // Filter on the "Not translated to".
  80. $edit = array('search[missing_target_language]' => 'gsw-berne');
  81. $this->drupalPost(NULL, $edit, t('Search'));
  82. // Hello World is translated to "gsw-berne" therefore it must not show up in the
  83. // list.
  84. $this->assertNoText('Hello World');
  85. }
  86. }