non security modules update

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 16:32:07 +02:00
parent 6a8d30db08
commit 37fbabab56
466 changed files with 32690 additions and 9652 deletions

View File

@@ -0,0 +1,115 @@
<?php
/**
* @file
* Contains L10nUpdateCronTest.
*/
/**
* Tests for translation update using cron.
*/
class L10nUpdateCronTest extends L10nUpdateTestBase {
protected $batch_output = array();
public static function getInfo() {
return array(
'name' => 'Update translations using cron',
'description' => 'Tests for using cron to update project interface translations.',
'group' => 'Localization Update',
);
}
function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
$this->addLanguage('de');
}
/**
* Tests interface translation update using cron.
*/
function testUpdateCron() {
// Set a flag to let the l10n_update_test module replace the project data
// with a set of test projects.
variable_set('l10n_update_test_projects_alter', TRUE);
// Setup local and remote translations files.
$this->setTranslationFiles();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Update translations using batch to ensure a clean test starting point.
$this->drupalGet('admin/config/regional/translate/check');
$this->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));
// Store translation status for comparison.
$initial_history = l10n_update_get_file_history();
// Prepare for test: Simulate new translations being available.
// Change the last updated timestamp of a translation file.
$contrib_module_two_uri = 'public://local/contrib_module_two-7.x-2.0-beta4.de._po';
touch(drupal_realpath($contrib_module_two_uri), REQUEST_TIME);
// Prepare for test: Simulate that the file has not been checked for a long
// time. Set the last_check timestamp to zero.
$query = db_update('l10n_update_file');
$query->fields(array('last_checked' => 0));
$query->condition('project', 'contrib_module_two');
$query->condition('language', 'de');
$query->execute();
// Test: Disable cron update and verify that no tasks are added to the
// queue.
$edit = array(
'l10n_update_check_frequency' => '0',
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Execute l10n_update cron taks to add tasks to the queue.
l10n_update_cron();
// Check whether no tasks are added to the queue.
$queue = DrupalQueue::get('l10n_update', TRUE);
$this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
// Test: Enable cron update and check if update tasks are added to the
// queue.
// Set cron update to Weekly.
$edit = array(
'l10n_update_check_frequency' => '7',
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Execute l10n_update cron task to add tasks to the queue.
l10n_update_cron();
// Check whether tasks are added to the queue.
$queue = DrupalQueue::get('l10n_update', TRUE);
$this->assertEqual($queue->numberOfItems(), 3, 'Queue holds tasks for one project.');
$item = $queue->claimItem();
$queue->releaseItem($item);
$this->assertEqual($item->data[1][0], 'contrib_module_two', 'Queue holds tasks for contrib module one.');
// Test: Run cron for a second time and check if tasks are not added to
// the queue twice.
l10n_update_cron();
// Check whether no more tasks are added to the queue.
$queue = DrupalQueue::get('l10n_update', TRUE);
$this->assertEqual($queue->numberOfItems(), 3, 'Queue holds tasks for one project.');
// Ensure last checked is updated to a greater time than the initial value.
sleep(1);
// Test: Execute cron and check if tasks are executed correctly.
// Run cron to process the tasks in the queue.
$this->drupalGet('admin/reports/status/run-cron');
drupal_static_reset('l10n_update_get_file_history');
$history = l10n_update_get_file_history();
$initial = $initial_history['contrib_module_two']['de'];
$current = $history['contrib_module_two']['de'];
$this->assertTrue($current->timestamp > $initial->timestamp, 'Timestamp is updated');
$this->assertTrue($current->last_checked > $initial->last_checked, 'Last checked is updated');
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* @file
* Contains L10nUpdateInterfaceTest.
*/
/**
* Tests for the l10n_update status user interfaces.
*/
class L10nUpdateInterfaceTest extends L10nUpdateTestBase {
public static function getInfo() {
return array(
'name' => 'Update translations user interface',
'description' => 'Tests for the user interface of project interface translations.',
'group' => 'Localization Update',
);
}
function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
}
/**
* Tests the user interfaces of the interface translation update system.
*
* Testing the Available updates summary on the side wide status page and the
* Avaiable translation updates page.
*/
function testInterface() {
// Enable the module this test uses for its translations.
module_enable(array('l10n_update_test_translate'));
// No language added.
// Check status page and Available translation updates page.
$this->drupalGet('admin/reports/status');
$this->assertNoText(t('Translation update status'), 'No status message');
$this->drupalGet('admin/config/regional/translate/update');
$this->assertRaw(t('No translatable languages available. <a href="@add_language">Add a language</a> first.', array('@add_language' => url('admin/config/regional/language'))), 'Language message');
// Add German language.
$this->addLanguage('de');
// Drupal core is probably in 7.x, but tests may also be executed with
// stable releases. As this is an uncontrolled factor in the test, we will
// mark Drupal core as translated and continue with the prepared modules.
$status = l10n_update_get_status();
$status['drupal']['de']->type = 'current';
variable_set('l10n_update_translation_status', $status);
// One language added, all translations up to date.
$this->drupalGet('admin/reports/status');
$this->assertText(t('Translation update status'), 'Status message');
$this->assertText(t('Up to date'), 'Translations up to date');
$this->drupalGet('admin/config/regional/translate/update');
$this->assertText(t('All translations up to date.'), 'Translations up to date');
// Set l10n_update_test_translate module to have a local translation available.
$status = l10n_update_get_status();
$status['l10n_update_test_translate']['de']->type = 'local';
variable_set('l10n_update_translation_status', $status);
// Check if updates are available for German.
$this->drupalGet('admin/reports/status');
$this->assertText(t('Translation update status'), 'Status message');
$this->assertRaw(t('Updates available for: @languages. See the <a href="@updates">Available translation updates</a> page for more information.', array('@languages' => t('German'), '@updates' => url('admin/config/regional/translate/update'))), 'Updates available message');
$this->drupalGet('admin/config/regional/translate/update');
$this->assertText(t('Updates for: @modules', array('@modules' => 'Localization Update test translate')), 'Translations avaiable');
// Set l10n_update_test_translate module to have a dev release and no
// translation found.
$status = l10n_update_get_status();
$status['l10n_update_test_translate']['de']->version = '1.3-dev';
$status['l10n_update_test_translate']['de']->type = '';
variable_set('l10n_update_translation_status', $status);
// Check if no updates were found.
$this->drupalGet('admin/reports/status');
$this->assertText(t('Translation update status'), 'Status message');
$this->assertRaw(t('Missing translations for: @languages. See the <a href="@updates">Available translation updates</a> page for more information.', array('@languages' => t('German'), '@updates' => url('admin/config/regional/translate/update'))), 'Missing translations message');
$this->drupalGet('admin/config/regional/translate/update');
$this->assertText(t('Missing translations for one project'), 'No translations found');
$this->assertText(t('@module (@version).', array('@module' => 'Localization Update test translate', '@version' => '1.3-dev')), 'Release details');
$this->assertText(t('No translation files are provided for development releases.'), 'Release info');
}
}

View File

@@ -0,0 +1,440 @@
<?php
/**
* @file
* Contains L10nUpdateTest.
*/
/**
* Tests for update translations.
*/
class L10nUpdateTest extends L10nUpdateTestBase {
public static function getInfo() {
return array(
'name' => 'Update translations',
'description' => 'Tests for updating the interface translations of projects.',
'group' => 'Localization Update',
);
}
function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer site configuration', 'administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
// We use German as test language. This language must match the translation
// file that come with the l10n_update_test module (test.de.po) and can therefore
// not be chosen randomly.
$this->addLanguage('de');
module_load_include('compare.inc', 'l10n_update');
module_load_include('fetch.inc', 'l10n_update');
}
/**
* Checks if a list of translatable projects gets build.
*/
function testUpdateProjects() {
module_load_include('compare.inc', 'l10n_update');
variable_set('l10n_update_test_projects_alter', TRUE);
// Make the test modules look like a normal custom module. i.e. make the
// modules not hidden. l10n_update_test_system_info_alter() modifies the project
// info of the l10n_update_test and l10n_update_test_translate modules.
variable_set('l10n_update_test_system_info_alter', TRUE);
$this->resetAll();
// Check if interface translation data is collected from hook_info.
$projects = l10n_update_project_list();
$this->assertFalse(isset($projects['l10n_update_test_translate']), 'Hidden module not found');
$this->assertEqual($projects['l10n_update_test']['info']['interface translation server pattern'], 'sites/all/modules/l10n_update/tests/test.%language.po', 'Interface translation parameter found in project info.');
$this->assertEqual($projects['l10n_update_test']['name'] , 'l10n_update_test', format_string('%key found in project info.', array('%key' => 'interface translation project')));
}
/**
* Checks if local or remote translation sources are detected.
*
* The translation status process by default checks the status of the
* installed projects. For testing purpose a predefined set of modules with
* fixed file names and release versions is used. This custom project
* definition is applied using a hook_l10n_update_projects_alter
* implementation in the l10n_update_test module.
*
* This test generates a set of local and remote translation files in their
* respective local and remote translation directory. The test checks whether
* the most recent files are selected in the different check scenarios: check
* for local files only, check for both local and remote files.
*/
function testUpdateCheckStatus() {
// Set a flag to let the l10n_update_test module replace the project data with a
// set of test projects.
variable_set('l10n_update_test_projects_alter', TRUE);
// Create local and remote translations files.
$this->setTranslationFiles();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Set the test conditions.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_LOCAL,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Get status of translation sources at local file system.
$this->drupalGet('admin/config/regional/translate/check');
$result = l10n_update_get_status();
$this->assertEqual($result['contrib_module_one']['de']->type, L10N_UPDATE_LOCAL, 'Translation of contrib_module_one found');
$this->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestamp_old, 'Translation timestamp found');
$this->assertEqual($result['contrib_module_two']['de']->type, L10N_UPDATE_LOCAL, 'Translation of contrib_module_two found');
$this->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found');
$this->assertEqual($result['l10n_update_test']['de']->type, L10N_UPDATE_LOCAL, 'Translation of l10n_update_test found');
$this->assertEqual($result['custom_module_one']['de']->type, L10N_UPDATE_LOCAL, 'Translation of custom_module_one found');
// Set the test conditions.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Get status of translation sources at both local and remote locations.
$this->drupalGet('admin/config/regional/translate/check');
$result = l10n_update_get_status();
$this->assertEqual($result['contrib_module_one']['de']->type, L10N_UPDATE_REMOTE, 'Translation of contrib_module_one found');
$this->assertEqual($result['contrib_module_one']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found');
$this->assertEqual($result['contrib_module_two']['de']->type, L10N_UPDATE_LOCAL, 'Translation of contrib_module_two found');
$this->assertEqual($result['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation timestamp found');
$this->assertEqual($result['contrib_module_three']['de']->type, L10N_UPDATE_LOCAL, 'Translation of contrib_module_three found');
$this->assertEqual($result['contrib_module_three']['de']->timestamp, $this->timestamp_old, 'Translation timestamp found');
$this->assertEqual($result['l10n_update_test']['de']->type, L10N_UPDATE_LOCAL, 'Translation of l10n_update_test found');
$this->assertEqual($result['custom_module_one']['de']->type, L10N_UPDATE_LOCAL, 'Translation of custom_module_one found');
}
/**
* Tests translation import from remote sources.
*
* Test conditions:
* - Source: remote and local files
* - Import overwrite: all existing translations
*/
function testUpdateImportSourceRemote() {
// Build the test environment.
$this->setTranslationFiles();
$this-> setCurrentTranslations();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Set the update conditions for this test.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL,
'overwrite' => LOCALE_IMPORT_OVERWRITE,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Get the translation status.
$this->drupalGet('admin/config/regional/translate/check');
// Check the status on the Available translation status page.
$this->assertRaw('<label class="element-invisible" for="edit-langcodes-de">Update German </label>', 'German language found');
$this->assertText('Updates for: Contributed module one, Contributed module two, Custom module one, Locale test', 'Updates found');
$this->assertText('Contributed module one (' . format_date($this->timestamp_new, 'medium') . ')', 'Updates for Contrib module one');
$this->assertText('Contributed module two (' . format_date($this->timestamp_new, 'medium') . ')', 'Updates for Contrib module two');
// Execute the translation update.
$this->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));
// Check if the translation has been updated, using the status cache.
$status = l10n_update_get_status();
$this->assertEqual($status['contrib_module_one']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_one found');
$this->assertEqual($status['contrib_module_two']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_two found');
$this->assertEqual($status['contrib_module_three']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_three found');
// Check the new translation status.
// The static cache needs to be flushed first to get the most recent data
// from the database. The function was called earlier during this test.
drupal_static_reset('l10n_update_get_file_history');
$history = l10n_update_get_file_history();
$this->assertTrue($history['contrib_module_one']['de']->timestamp >= $this->timestamp_now, 'Translation of contrib_module_one is imported');
$this->assertTrue($history['contrib_module_one']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_one is updated');
$this->assertEqual($history['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation of contrib_module_two is imported');
$this->assertTrue($history['contrib_module_two']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_two is updated');
$this->assertEqual($history['contrib_module_three']['de']->timestamp, $this->timestamp_medium, 'Translation of contrib_module_three is not imported');
$this->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_three is not updated');
// Check whether existing translations have (not) been overwritten.
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_1', 'Translation of January');
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_2', 'Translation of February');
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
}
/**
* Tests translation import from local sources.
*
* Test conditions:
* - Source: local files only
* - Import overwrite: all existing translations
*/
function testUpdateImportSourceLocal() {
// Build the test environment.
$this->setTranslationFiles();
$this-> setCurrentTranslations();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Set the update conditions for this test.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_LOCAL,
'overwrite' => LOCALE_IMPORT_OVERWRITE,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Execute the translation update.
$this->drupalGet('admin/config/regional/translate/check');
$this->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));
// Check if the translation has been updated, using the status cache.
$status = l10n_update_get_status();
$this->assertEqual($status['contrib_module_one']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_one found');
$this->assertEqual($status['contrib_module_two']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_two found');
$this->assertEqual($status['contrib_module_three']['de']->type, L10N_UPDATE_CURRENT, 'Translation of contrib_module_three found');
// Check the new translation status.
// The static cache needs to be flushed first to get the most recent data
// from the database. The function was called earlier during this test.
drupal_static_reset('l10n_update_get_file_history');
$history = l10n_update_get_file_history();
$this->assertTrue($history['contrib_module_one']['de']->timestamp >= $this->timestamp_medium, 'Translation of contrib_module_one is imported');
$this->assertEqual($history['contrib_module_one']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_one is updated');
$this->assertEqual($history['contrib_module_two']['de']->timestamp, $this->timestamp_new, 'Translation of contrib_module_two is imported');
$this->assertTrue($history['contrib_module_two']['de']->last_checked >= $this->timestamp_now, 'Translation of contrib_module_two is updated');
$this->assertEqual($history['contrib_module_three']['de']->timestamp, $this->timestamp_medium, 'Translation of contrib_module_three is not imported');
$this->assertEqual($history['contrib_module_three']['de']->last_checked, $this->timestamp_medium, 'Translation of contrib_module_three is not updated');
// Check whether existing translations have (not) been overwritten.
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_customized', 'Translation of January');
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_2', 'Translation of February');
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
}
/**
* Tests translation import and only overwrite non-customized translations.
*
* Test conditions:
* - Source: remote and local files
* - Import overwrite: only overwrite non-customized translations
*/
function testUpdateImportModeNonCustomized() {
// Build the test environment.
$this->setTranslationFiles();
$this-> setCurrentTranslations();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Set the test conditions.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL,
'overwrite' => L10N_UPDATE_OVERWRITE_NON_CUSTOMIZED,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Execute translation update.
$this->drupalGet('admin/config/regional/translate/check');
$this->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));
// Check whether existing translations have (not) been overwritten.
$this->assertEqual(t('January', array(), array('langcode' => 'de')), 'Januar_customized', 'Translation of January');
$this->assertEqual(t('February', array(), array('langcode' => 'de')), 'Februar_customized', 'Translation of February');
$this->assertEqual(t('March', array(), array('langcode' => 'de')), 'Marz_2', 'Translation of March');
$this->assertEqual(t('April', array(), array('langcode' => 'de')), 'April_2', 'Translation of April');
$this->assertEqual(t('May', array(), array('langcode' => 'de')), 'Mai_customized', 'Translation of May');
$this->assertEqual(t('June', array(), array('langcode' => 'de')), 'Juni', 'Translation of June');
$this->assertEqual(t('Monday', array(), array('langcode' => 'de')), 'Montag', 'Translation of Monday');
}
/**
* Tests translation import and don't overwrite any translation.
*
* Test conditions:
* - Source: remote and local files
* - Import overwrite: don't overwrite any existing translation
*/
function testUpdateImportModeNone() {
// Build the test environment.
$this->setTranslationFiles();
$this-> setCurrentTranslations();
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Set the test conditions.
$edit = array(
'l10n_update_check_mode' => L10N_UPDATE_USE_SOURCE_REMOTE_AND_LOCAL,
'overwrite' => LOCALE_IMPORT_KEEP,
);
$this->drupalPost('admin/config/regional/language/update', $edit, t('Save configuration'));
// Execute translation update.
$this->drupalGet('admin/config/regional/translate/check');
$this->drupalPost('admin/config/regional/translate/update', array(), t('Update translations'));
// Check whether existing translations have (not) been overwritten.
$this->assertTranslation('January', 'Januar_customized', 'de');
$this->assertTranslation('February', 'Februar_customized', 'de');
$this->assertTranslation('March', 'Marz', 'de');
$this->assertTranslation('April', 'April_2', 'de');
$this->assertTranslation('May', 'Mai_customized', 'de');
$this->assertTranslation('June', 'Juni', 'de');
$this->assertTranslation('Monday', 'Montag', 'de');
}
/**
* Tests automatic translation import when a module is enabled.
*/
function testEnableUninstallModule() {
// Make the hidden test modules look like a normal custom module.
variable_set('l10n_update_test_system_info_alter', TRUE);
// Check if there is no translation yet.
$this->assertTranslation('Tuesday', '', 'de');
// Enable a module.
$edit = array(
'modules[Testing][l10n_update_test_translate][enable]' => '1',
);
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
// Check if translations have been imported.
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
array('%number' => 0, '%update' => 7, '%delete' => 0)), 'One translation file imported.');
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
// // Disable and uninstall a module
// module_disable(array('l10n_update_test_translate'));
// $edit = array(
// 'uninstall[l10n_update_test_translate]' => '1',
// );
// $this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
// $this->drupalPost(NULL, array(), t('Uninstall'));
//
// // Check if the file data is removed from the database.
// $history = l10n_update_get_file_history();
// $this->assertFalse(isset($history['l10n_update_test_translate']), 'Project removed from the file history');
// $projects = l10n_update_get_projects();
// $this->assertFalse(isset($projects['l10n_update_test_translate']), 'Project removed from the project list');
}
/**
* Tests automatic translation import when a langauge is enabled.
*
* When a language is added, the system will check for translations files of
* enabled modules and will import them. When a language is removed the system
* will remove all translations of that langugue from the database.
*/
function testEnableLanguage() {
// Make the hidden test modules look like a normal custom module.
variable_set('l10n_update_test_system_info_alter', TRUE);
// Enable a module.
$edit = array(
'modules[Testing][l10n_update_test_translate][enable]' => '1',
);
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
// Check if there is no Dutch translation yet.
$this->assertTranslation('Extraday', '', 'nl');
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
// Add a language.
$this->addLanguage('nl');
// Check if the right number of translations are added.
$this->assertRaw(t('One translation file imported. %number translations were added, %update translations were updated and %delete translations were removed.',
array('%number' => 0, '%update' => 8, '%delete' => 0)), 'One language added.');
$this->assertTranslation('Extraday', 'extra dag', 'nl');
// Check if the language data is added to the database.
$result = db_query("SELECT project FROM {l10n_update_file} WHERE language='nl'")->fetchField();
$this->assertTrue((boolean) $result, 'Files removed from file history');
// Remove a language.
$this->drupalPost('admin/config/regional/language/delete/nl', array(), t('Delete'));
// Check if the language data is removed from the database.
$result = db_query("SELECT project FROM {l10n_update_file} WHERE language='nl'")->fetchField();
$this->assertFalse($result, 'Files removed from file history');
// Check that the Dutch translation is gone.
$this->assertTranslation('Extraday', '', 'nl');
$this->assertTranslation('Tuesday', 'Dienstag', 'de');
}
/**
* Tests automatic translation import when a custom langauge is enabled.
*/
function testEnableCustomLanguage() {
// Make the hidden test modules look like a normal custom module.
variable_set('l10n_update_test_system_info_alter', TRUE);
// Enable a module.
$edit = array(
'modules[Testing][l10n_update_test_translate][enable]' => '1',
);
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
// Create and enable a custom language with language code 'xx' and a random
// name.
$langcode = 'xx';
$name = $this->randomName(16);
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $name,
'prefix' => $langcode,
'direction' => '0',
);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language'));
drupal_static_reset('language_list');
$languages = language_list();
$this->assertTrue(isset($languages[$langcode]), format_string('Language %langcode added.', array('%langcode' => $langcode)));
// Ensure the translation file is automatically imported when the language
// was added.
$this->assertText(t('One translation file imported.'), 'Language file automatically imported.');
$this->assertText(t('One translation string was skipped because of disallowed or malformed HTML'), 'Language file automatically imported.');
// Ensure the strings were successfully imported.
$search = array(
'string' => 'lundi',
'language' => $langcode,
'translation' => 'translated',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertNoText(t('No strings available.'), 'String successfully imported.');
// Ensure the multiline string was imported.
$search = array(
'string' => 'Source string for multiline translation',
'language' => $langcode,
'translation' => 'all',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
$this->assertText('Source string for multiline translation', 'String successfully imported.');
// Ensure 'Allowed HTML source string' was imported but the translation for
// 'Another allowed HTML source string' was not because it contains invalid
// HTML.
$search = array(
'string' => 'HTML source string',
'language' => $langcode,
'translation' => 'translated',
);
$this->drupalPost('admin/config/regional/translate/translate', $search, t('Filter'));
// $this->assertText('Allowed HTML source string', 'String successfully imported.');
$this->assertNoText('Another allowed HTML source string', 'String with disallowed translation not imported.');
}
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* @file
* Contains L10nUpdateTest.
*/
/**
* Tests for update translations.
*/
class L10nUpdateTestBase extends DrupalWebTestCase {
/**
* Timestamp for an old translation.
*
* @var integer
*/
protected $timestamp_old;
/**
* Timestamp for a medium aged translation.
*
* @var integer
*/
protected $timestamp_medium;
/**
* Timestamp for a new translation.
*
* @var integer
*/
protected $timestamp_new;
function setUp() {
parent::setUp('update', 'locale', 'l10n_update', 'l10n_update_test');
// Setup timestamps to identify old and new translation sources.
$this->timestamp_old = REQUEST_TIME - 300;
$this->timestamp_medium = REQUEST_TIME - 200;
$this->timestamp_new = REQUEST_TIME - 100;
$this->timestamp_now = REQUEST_TIME;
}
/**
* Sets the value of the default translations directory.
*
* @param string $path
* Path of the translations directory relative to the drupal installation
* directory.
*/
protected function setTranslationsDirectory($path) {
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
variable_set('l10n_update_download_store', $path);
}
/**
* Adds a language.
*
* @param $langcode
* The language code of the language to add.
*/
protected function addLanguage($langcode) {
$edit = array('langcode' => $langcode);
$this->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));
drupal_static_reset('language_list');
$languages = language_list();
$this->assertTrue(isset($languages[$langcode]), format_string('Language %langcode added.', array('%langcode' => $langcode)));
}
/**
* Creates a translation file and tests its timestamp.
*
* @param string $path
* Path of the file relative to the public file path.
* @param string $filename
* Name of the file to create.
* @param integer $timestamp
* Timestamp to set the file to. Defaults to current time.
* @param array $translations
* Array of source/target value translation strings. Only singular strings
* are supported, no plurals. No double quotes are allowed in source and
* translations strings.
*/
protected function makePoFile($path, $filename, $timestamp = NULL, $translations = array()) {
$timestamp = $timestamp ? $timestamp : REQUEST_TIME;
$path = 'public://' . $path;
$text = '';
$po_header = <<<EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
EOF;
// Convert array of translations to Gettext source and translation strings.
if ($translations) {
foreach ($translations as $source => $target) {
$text .= 'msgid "'. $source . '"' . "\n";
$text .= 'msgstr "'. $target . '"' . "\n";
}
}
file_prepare_directory($path, FILE_CREATE_DIRECTORY);
$file = (object) array(
'uid' => 1,
'filename' => $filename,
'uri' => $path . '/' . $filename,
'filemime' => 'text/x-gettext-translation',
'timestamp' => $timestamp,
'status' => FILE_STATUS_PERMANENT,
);
file_put_contents($file->uri, $po_header . $text);
touch(drupal_realpath($file->uri), $timestamp);
file_save($file);
}
/**
* Setup the environment containing local and remote translation files.
*
* Update tests require a simulated environment for local and remote files.
* Normally remote files are located at a remote server (e.g. ftp.drupal.org).
* For testing we can not rely on this. A directory in the file system of the
* test site is designated for remote files and is addressed using an absolute
* URL. Because Drupal does not allow files with a po extension to be accessed
* (denied in .htaccess) the translation files get a _po extension. Another
* directory is designated for local translation files.
*
* The environment is set up with the following files. File creation times are
* set to create different variations in test conditions.
* contrib_module_one
* - remote file: timestamp new
* - local file: timestamp old
* - current: timestamp medium
* contrib_module_two
* - remote file: timestamp old
* - local file: timestamp new
* - current: timestamp medium
* contrib_module_three
* - remote file: timestamp old
* - local file: timestamp old
* - current: timestamp medium
* custom_module_one
* - local file: timestamp new
* - current: timestamp medium
* Time stamp of current translation set by setCurrentTranslations() is always
* timestamp medium. This makes it easy to predict which translation will be
* imported.
*/
protected function setTranslationFiles() {
// A flag is set to let the l10n_update_test module replace the project data with
// a set of test projects which match the below project files.
variable_set('l10n_update_test_projects_alter', TRUE);
// Setup the environment.
$public_path = drupal_realpath('public://');
$this->setTranslationsDirectory($public_path . '/local');
variable_set('l10n_update_default_filename', '%project-%release.%language._po');
// Setting up sets of translations for the translation files.
$translations_one = array('January' => 'Januar_1', 'February' => 'Februar_1', 'March' => 'Marz_1');
$translations_two = array( 'February' => 'Februar_2', 'March' => 'Marz_2', 'April' => 'April_2');
$translations_three = array('April' => 'April_3', 'May' => 'Mai_3', 'June' => 'Juni_3');
// Add a number of files to the local file system to serve as remote
// translation server and match the project definitions set in
// l10n_update_test_l10n_update_projects_alter().
$this->makePoFile('remote/7.x/contrib_module_one', 'contrib_module_one-7.x-1.1.de._po', $this->timestamp_new, $translations_one);
$this->makePoFile('remote/7.x/contrib_module_two', 'contrib_module_two-7.x-2.0-beta4.de._po', $this->timestamp_old, $translations_two);
$this->makePoFile('remote/7.x/contrib_module_three', 'contrib_module_three-7.x-1.0.de._po', $this->timestamp_old, $translations_three);
// Add a number of files to the local file system to serve as local
// translation files and match the project definitions set in
// l10n_update_test_l10n_update_projects_alter().
$this->makePoFile('local', 'contrib_module_one-7.x-1.1.de._po', $this->timestamp_old, $translations_one);
$this->makePoFile('local', 'contrib_module_two-7.x-2.0-beta4.de._po', $this->timestamp_new, $translations_two);
$this->makePoFile('local', 'contrib_module_three-7.x-1.0.de._po', $this->timestamp_old, $translations_three);
$this->makePoFile('local', 'custom_module_one.de.po', $this->timestamp_new);
}
/**
* Setup existing translations in the database and set up the status of
* existing translations.
*/
protected function setCurrentTranslations() {
// Setup to add German translations to the database.
$langcode = 'de';
$writer = new PoDatabaseWriter();
$writer->setLangcode($langcode);
$writer->setOptions(array(
'overwrite_options' => array(
'not_customized' => TRUE,
'customized' => TRUE,
),
));
// Add non customized translations to the database.
$writer->setOptions(array('customized' => L10N_UPDATE_NOT_CUSTOMIZED));
$non_customized_translations = array(
'March' => 'Marz',
'June' => 'Juni',
);
foreach ($non_customized_translations as $source => $translation) {
$poItem = new PoItem();
$poItem->setFromArray(array(
'source' => $source,
'translation' => $translation,
));
$writer->writeItem($poItem);
}
// Add customized translations to the database.
$writer->setOptions(array('customized' => L10N_UPDATE_CUSTOMIZED));
$customized_translations = array(
'January' => 'Januar_customized',
'February' => 'Februar_customized',
'May' => 'Mai_customized',
);
foreach ($customized_translations as $source => $translation) {
$poItem = new PoItem();
$poItem->setFromArray(array(
'source' => $source,
'translation' => $translation,
));
$writer->writeItem($poItem);
}
// Add a state of current translations in l10n_update_files.
$default = array(
'language' => $langcode,
'uri' => '',
'timestamp' => $this->timestamp_medium,
'last_checked' => $this->timestamp_medium,
);
$data[] = array(
'project' => 'contrib_module_one',
'filename' => 'contrib_module_one-7.x-1.1.de._po',
'version' => '7.x-1.1',
);
$data[] = array(
'project' => 'contrib_module_two',
'filename' => 'contrib_module_two-7.x-2.0-beta4.de._po',
'version' => '7.x-2.0-beta4',
);
$data[] = array(
'project' => 'contrib_module_three',
'filename' => 'contrib_module_three-7.x-1.0.de._po',
'version' => '7.x-1.0',
);
$data[] = array(
'project' => 'custom_module_one',
'filename' => 'custom_module_one.de.po',
'version' => '',
);
foreach ($data as $file) {
$file = (object) array_merge($default, $file);
drupal_write_record('l10n_update_file', $file);
}
}
/**
* Checks the translation of a string.
*
* @param string $source
* Translation source string
* @param string $translation
* Translation to check. Use empty string to check for a not existing
* translation.
* @param string $langcode
* Language code of the language to translate to.
* @param string $message
* (optional) A message to display with the assertion.
*/
protected function assertTranslation($source, $translation, $langcode, $message = '') {
$db_translation = db_query('SELECT translation FROM {locales_target} lt INNER JOIN {locales_source} ls ON ls.lid = lt.lid WHERE ls.source = :source AND lt.language = :langcode', array(':source' => $source, ':langcode' => $langcode))->fetchField();
$db_translation = $db_translation == FALSE ? '' : $db_translation;
$this->assertEqual($translation, $db_translation, $message ? $message : format_string('Correct translation of %source (%language)', array('%source' => $source, '%language' => $langcode)));
}
}

View File

@@ -0,0 +1,14 @@
name = 'Localization Update test'
type = module
description = 'Support module for Localization Update module testing.'
package = Testing
version = '1.2'
core = 7.x
hidden = true
; Information added by Drupal.org packaging script on 2014-11-10
version = "7.x-2.0"
core = "7.x"
project = "l10n_update"
datestamp = "1415625781"

View File

@@ -0,0 +1,15 @@
<?php
/**
* @file
* Install, update and uninstall functions for the l10n_update_test module.
*/
/**
* Implements hook_uninstall().
*/
function l10n_update_test_uninstall() {
// Clear variables.
variable_del('l10n_update_test_system_info_alter');
variable_del('l10n_update_test_projects_alter');
}

View File

@@ -0,0 +1,143 @@
<?php
/**
* @file
* Simulate a custom module with a local po file.
*/
/**
* Implements hook_system_info_alter().
*
* Make the test scripts to be believe this is not a hidden test module, but
* a regular custom module.
*/
function l10n_update_test_system_info_alter(&$info, $file, $type) {
// Only modify the system info if required.
// By default the l10n_update_test modules are hidden and have a project specified.
// To test the module detection process by l10n_update_project_list() the
// test modules should mimic a custom module. I.e. be non-hidden.
if (variable_get('l10n_update_test_system_info_alter', FALSE)) {
if ($file->name == 'l10n_update_test' || $file->name == 'l10n_update_test_translate') {
// Don't hide the module.
$info['hidden'] = FALSE;
}
}
}
/**
* Implements hook_l10n_update_projects_alter().
*
* The translation status process by default checks the status of the installed
* projects. This function replaces the data of the installed modules by a
* predefined set of modules with fixed file names and release versions. Project
* names, versions, timestamps etc must be fixed because they must match the
* files created by the test script.
*
* The "l10n_update_test_projects_alter" variable must be set by the test script
* in order for this hook to take effect.
*/
function l10n_update_test_l10n_update_projects_alter(&$projects) {
if (variable_get('l10n_update_test_projects_alter', FALSE)) {
// Instead of the default ftp.drupal.org we use the file system of the test
// instance to simulate a remote file location.
$wrapper = file_stream_wrapper_get_instance_by_uri('public://');
$remote_url = $wrapper->getExternalUrl() . '/remote/';
// Completely replace the project data with a set of test projects.
$projects = array (
'contrib_module_one' => array (
'name' => 'contrib_module_one',
'info' => array (
'name' => 'Contributed module one',
'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
'package' => 'Other',
'version' => '7.x-1.1',
'project' => 'contrib_module_one',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
'datestamp' => '1344471537',
'includes' => array (
'contrib_module_one' => 'Contributed module one',
),
'project_type' => 'module',
'project_status' => TRUE,
),
'contrib_module_two' => array (
'name' => 'contrib_module_two',
'info' => array (
'name' => 'Contributed module two',
'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
'package' => 'Other',
'version' => '7.x-2.0-beta4',
'project' => 'contrib_module_two',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
'datestamp' => '1344471537',
'includes' => array (
'contrib_module_two' => 'Contributed module two',
),
'project_type' => 'module',
'project_status' => TRUE,
),
'contrib_module_three' => array (
'name' => 'contrib_module_three',
'info' => array (
'name' => 'Contributed module three',
'l10n path' => $remote_url . '%core/%project/%project-%release.%language._po',
'package' => 'Other',
'version' => '7.x-1.0',
'project' => 'contrib_module_three',
'datestamp' => '1344471537',
'_info_file_ctime' => 1348767306,
),
'datestamp' => '1344471537',
'includes' => array (
'contrib_module_three' => 'Contributed module three',
),
'project_type' => 'module',
'project_status' => TRUE,
),
'l10n_update_test' => array (
'name' => 'l10n_update_test',
'info' => array (
'name' => 'Locale test',
'interface translation project' => 'l10n_update_test',
'l10n path' => 'sites/all/modules/l10n_update/tests/test.%language.po',
'package' => 'Other',
'version' => NULL,
'project' => 'l10n_update_test',
'_info_file_ctime' => 1348767306,
'datestamp' => 0,
),
'datestamp' => 0,
'includes' => array (
'l10n_update_test' => 'Locale test',
),
'project_type' => 'module',
'project_status' => TRUE,
),
'custom_module_one' => array (
'name' => 'custom_module_one',
'info' => array (
'name' => 'Custom module one',
'interface translation project' => 'custom_module_one',
'l10n path' => 'translations://custom_module_one.%language.po',
'package' => 'Other',
'version' => NULL,
'project' => 'custom_module_one',
'_info_file_ctime' => 1348767306,
'datestamp' => 0,
),
'datestamp' => 0,
'includes' => array (
'custom_module_one' => 'Custom module one',
),
'project_type' => 'module',
'project_status' => TRUE,
),
);
}
}

View File

@@ -0,0 +1,16 @@
name = 'Localization Update test translate'
type = module
description = 'Translation test module for Localization Update module testing.'
package = Testing
version = '1.3'
core = 7.x
hidden = true
interface translation project = l10n_update_test_translate
l10n path = sites/all/modules/contrib/l10n_update/tests/modules/l10n_update_test_translate/translations/l10n_update_test_translate.%language.po
; Information added by Drupal.org packaging script on 2014-11-10
version = "7.x-2.0"
core = "7.x"
project = "l10n_update"
datestamp = "1415625781"

View File

@@ -0,0 +1,28 @@
<?php
/**
* @file
* Simulates a custom module with a local po file.
*/
/**
* Implements hook_system_info_alter().
*
* By default this modules is hidden but once enabled it behaves like a normal
* (not hidden) module. This hook implementation changes the .info.yml data by
* setting the hidden status to FALSE.
*/
function l10n_update_test_translate_system_info_alter(&$info, $file, $type) {
if ($file->name == 'l10n_update_test_translate') {
// Don't hide the module.
if (isset($info['hidden'])) {
$info['hidden'] = FALSE;
}
// Correct the path to the translation file. At a test-environment, the
// module may be place in a different path.
$basename = basename($info['l10n path']);
$path = drupal_get_path('module', 'l10n_update') . '/tests/modules/l10n_update_test_translate/translations/';
$info['l10n path'] = $path . $basename;
}
}

View File

@@ -0,0 +1,28 @@
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "Montag"
msgid "Tuesday"
msgstr "Dienstag"
msgid "Wednesday"
msgstr "Mittwoch"
msgid "Thursday"
msgstr "Donnerstag"
msgid "Friday"
msgstr "Freitag"
msgid "Saturday"
msgstr "Samstag"
msgid "Sunday"
msgstr "Sonntag"

View File

@@ -0,0 +1,31 @@
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "maandag"
msgid "Tuesday"
msgstr "dinsdag"
msgid "Wednesday"
msgstr "woensdag"
msgid "Thursday"
msgstr "donderdag"
msgid "Extraday"
msgstr "extra dag"
msgid "Friday"
msgstr "vrijdag"
msgid "Saturday"
msgstr "zaterdag"
msgid "Sunday"
msgstr "zondag"

View File

@@ -0,0 +1,40 @@
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "lundi"
msgid "Tuesday"
msgstr "mardi"
msgid "Wednesday"
msgstr "mercredi"
msgid "Thursday"
msgstr "jeudi"
msgid "Friday"
msgstr "vendredi"
msgid "Saturday"
msgstr "samedi"
msgid "Sunday"
msgstr "dimanche"
msgid "Allowed HTML source string"
msgstr "<strong>Allowed HTML translation string</strong>"
msgid "Another allowed HTML source string"
msgstr "<script>Disallowed HTML translation string</script>"
msgid "Source string for multiline translation"
msgstr ""
"Multiline translation string "
"to make sure that "
"import works with it."

View File

@@ -0,0 +1,10 @@
msgid ""
msgstr ""
"Project-Id-Version: Drupal 7\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "Montag"