function LocaleUpdateInterfaceTest::testInterface

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.

File

drupal/core/modules/locale/lib/Drupal/locale/Tests/LocaleUpdateInterfaceTest.php, line 44
Contains Drupal\locale\Tests\LocaleUpdateInterfaceTest.

Class

LocaleUpdateInterfaceTest
Tests for the locale translation update status user interfaces.

Namespace

Drupal\locale\Tests

Code

function testInterface() {

  // 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/reports/translations');
  $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.
  $edit = array(
    'predefined_langcode' => 'de',
  );
  $this
    ->drupalPost('admin/config/regional/language/add', $edit, t('Add language'));

  // Drupal core is probably in 8.x, but tests may also be executed with
  // stable releases. As this is an uncontrolled factor in the test, we will
  // ignore Drupal core here and continue with the prepared modules.
  $status = \Drupal::state()
    ->get('locale.translation_status');
  unset($status['drupal']);
  \Drupal::state()
    ->set('locale.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/reports/translations');
  $this
    ->assertText(t('All translations up to date.'), 'Translations up to date');

  // Set locale_test_translate module to have a local translation available.
  $status = \Drupal::state()
    ->get('locale.translation_status');
  $status['locale_test_translate']['de']->type = 'local';
  \Drupal::state()
    ->set('locale.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/reports/translations'),
  )), 'Updates available message');
  $this
    ->drupalGet('admin/reports/translations');
  $this
    ->assertText(t('Updates for: @modules', array(
    '@modules' => 'Locale test translate',
  )), 'Translations avaiable');

  // Set locale_test_translate module to have a dev release and no
  // translation found.
  $status = \Drupal::state()
    ->get('locale.translation_status');
  $status['locale_test_translate']['de']->version = '1.3-dev';
  unset($status['locale_test_translate']['de']->type);
  \Drupal::state()
    ->set('locale.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/reports/translations'),
  )), 'Missing translations message');
  $this
    ->drupalGet('admin/reports/translations');
  $this
    ->assertText(t('Missing translations for one project'), 'No translations found');
  $this
    ->assertText(t('@module (@version).', array(
    '@module' => 'Locale test translate',
    '@version' => '1.3-dev',
  )), 'Release details');
  $this
    ->assertText(t('No translation files are provided for development releases.'), 'Release info');
}