l10n_update_test.module 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. /**
  3. * @file
  4. * Simulate a custom module with a local po file.
  5. */
  6. /**
  7. * Implements hook_system_info_alter().
  8. *
  9. * Make the test scripts to be believe this is not a hidden test module, but
  10. * a regular custom module.
  11. */
  12. function l10n_update_test_system_info_alter(&$info, $file, $type) {
  13. // Only modify the system info if required.
  14. // By default the l10n_update_test modules are hidden and have a project
  15. // specified.
  16. // To test the module detection process by l10n_update_project_list() the
  17. // test modules should mimic a custom module. I.e. be non-hidden.
  18. if (variable_get('l10n_update_test_system_info_alter', FALSE)) {
  19. if ($file->name == 'l10n_update_test' || $file->name == 'l10n_update_test_translate') {
  20. // Don't hide the module.
  21. $info['hidden'] = FALSE;
  22. }
  23. }
  24. }
  25. /**
  26. * Implements hook_l10n_update_projects_alter().
  27. *
  28. * The translation status process by default checks the status of the installed
  29. * projects. This function replaces the data of the installed modules by a
  30. * predefined set of modules with fixed file names and release versions. Project
  31. * names, versions, timestamps etc must be fixed because they must match the
  32. * files created by the test script.
  33. *
  34. * The "l10n_update_test_projects_alter" variable must be set by the test script
  35. * in order for this hook to take effect.
  36. */
  37. function l10n_update_test_l10n_update_projects_alter(&$projects) {
  38. if (variable_get('l10n_update_test_projects_alter', FALSE)) {
  39. // Instead of the default ftp.drupal.org we use the file system of the test
  40. // instance to simulate a remote file location.
  41. $wrapper = file_stream_wrapper_get_instance_by_uri('public://');
  42. $remote_url = $wrapper->getExternalUrl() . '/remote/';
  43. // Completely replace the project data with a set of test projects.
  44. $projects = array(
  45. 'contrib_module_one' => array(
  46. 'name' => 'contrib_module_one',
  47. 'info' => array(
  48. 'name' => 'Contributed module one',
  49. 'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
  50. 'package' => 'Other',
  51. 'version' => '7.x-1.1',
  52. 'project' => 'contrib_module_one',
  53. 'datestamp' => '1344471537',
  54. '_info_file_ctime' => 1348767306,
  55. ),
  56. 'datestamp' => '1344471537',
  57. 'includes' => array(
  58. 'contrib_module_one' => 'Contributed module one',
  59. ),
  60. 'project_type' => 'module',
  61. 'project_status' => TRUE,
  62. ),
  63. 'contrib_module_two' => array(
  64. 'name' => 'contrib_module_two',
  65. 'info' => array(
  66. 'name' => 'Contributed module two',
  67. 'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
  68. 'package' => 'Other',
  69. 'version' => '7.x-2.0-beta4',
  70. 'project' => 'contrib_module_two',
  71. 'datestamp' => '1344471537',
  72. '_info_file_ctime' => 1348767306,
  73. ),
  74. 'datestamp' => '1344471537',
  75. 'includes' => array(
  76. 'contrib_module_two' => 'Contributed module two',
  77. ),
  78. 'project_type' => 'module',
  79. 'project_status' => TRUE,
  80. ),
  81. 'contrib_module_three' => array(
  82. 'name' => 'contrib_module_three',
  83. 'info' => array(
  84. 'name' => 'Contributed module three',
  85. 'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
  86. 'package' => 'Other',
  87. 'version' => '7.x-1.0',
  88. 'project' => 'contrib_module_three',
  89. 'datestamp' => '1344471537',
  90. '_info_file_ctime' => 1348767306,
  91. ),
  92. 'datestamp' => '1344471537',
  93. 'includes' => array(
  94. 'contrib_module_three' => 'Contributed module three',
  95. ),
  96. 'project_type' => 'module',
  97. 'project_status' => TRUE,
  98. ),
  99. 'l10n_update_test' => array(
  100. 'name' => 'l10n_update_test',
  101. 'info' => array(
  102. 'name' => 'Locale test',
  103. 'interface translation project' => 'l10n_update_test',
  104. 'l10n path' => drupal_get_path('module', 'l10n_update') . '/tests/test.%language.po',
  105. 'package' => 'Other',
  106. 'version' => NULL,
  107. 'project' => 'l10n_update_test',
  108. '_info_file_ctime' => 1348767306,
  109. 'datestamp' => 0,
  110. ),
  111. 'datestamp' => 0,
  112. 'includes' => array(
  113. 'l10n_update_test' => 'Locale test',
  114. ),
  115. 'project_type' => 'module',
  116. 'project_status' => TRUE,
  117. ),
  118. 'custom_module_one' => array(
  119. 'name' => 'custom_module_one',
  120. 'info' => array(
  121. 'name' => 'Custom module one',
  122. 'interface translation project' => 'custom_module_one',
  123. 'l10n path' => 'translations://custom_module_one.%language.po',
  124. 'package' => 'Other',
  125. 'version' => NULL,
  126. 'project' => 'custom_module_one',
  127. '_info_file_ctime' => 1348767306,
  128. 'datestamp' => 0,
  129. ),
  130. 'datestamp' => 0,
  131. 'includes' => array(
  132. 'custom_module_one' => 'Custom module one',
  133. ),
  134. 'project_type' => 'module',
  135. 'project_status' => TRUE,
  136. ),
  137. );
  138. }
  139. }