View source
<?php
namespace Drupal\locale\Tests;
class LocaleUpdateCronTest extends LocaleUpdateBase {
protected $batchOutput = array();
protected 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');
}
public function testUpdateCron() {
\Drupal::state()
->set('locale.test_projects_alter', TRUE);
$this
->setTranslationFiles();
$this
->config('locale.settings')
->set('translation.default_filename', '%project-%version.%language._po')
->save();
$this
->drupalGet('admin/reports/translations/check');
$this
->drupalPostForm('admin/reports/translations', array(), t('Update translations'));
$initial_history = locale_translation_get_file_history();
$contrib_module_two_uri = 'public://local/contrib_module_two-8.x-2.0-beta4.de._po';
touch(drupal_realpath($contrib_module_two_uri), REQUEST_TIME);
$query = db_update('locale_file');
$query
->fields(array(
'last_checked' => 0,
));
$query
->condition('project', 'contrib_module_two');
$query
->condition('langcode', 'de');
$query
->execute();
$edit = array(
'update_interval_days' => 0,
);
$this
->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
locale_cron();
$queue = \Drupal::queue('locale_translation', TRUE);
$this
->assertEqual($queue
->numberOfItems(), 0, 'Queue is empty');
$edit = array(
'update_interval_days' => 7,
);
$this
->drupalPostForm('admin/config/regional/translate/settings', $edit, t('Save configuration'));
locale_cron();
$queue = \Drupal::queue('locale_translation', 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.');
locale_cron();
$queue = \Drupal::queue('locale_translation', TRUE);
$this
->assertEqual($queue
->numberOfItems(), 3, 'Queue holds tasks for one project.');
sleep(1);
$this
->cronRun();
drupal_static_reset('locale_translation_get_file_history');
$history = locale_translation_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');
}
}