function LocaleSourceTest::testInexistantSource

Tests that system behaves correctly with an non-existing locales.

File

sources/locale/tests/src/Kernel/LocaleSourceTest.php, line 180

Class

LocaleSourceTest
Basic Locale Source tests.

Namespace

Drupal\Tests\tmgmt_locale\Kernel

Code

function testInexistantSource() {

  // Create inexistant locale object.
  $locale_object = new \stdClass();
  $locale_object->lid = 0;

  // Create the job.
  $job = $this
    ->createJob();
  $job->translator = $this->default_translator
    ->id();
  $job->settings = array();
  $job
    ->save();

  // Create the job item.
  try {
    $job
      ->addItem('locale', 'default', $locale_object->lid);
    $this
      ->fail('Job item add with an inexistant locale.');
  } catch (\Exception $e) {

    // Exception thrown when trying to translate non-existing locale string.
  }

  // Try to translate a source string without translation from german to
  // spanish.
  $lid = \Drupal::database()
    ->insert('locales_source')
    ->fields(array(
    'source' => 'No translation',
    'context' => '',
  ))
    ->execute();
  $job = $this
    ->createJob('de', 'fr');
  $job->translator = $this->default_translator
    ->id();
  $job->settings = array();
  $job
    ->save();
  try {
    $job
      ->addItem('locale', 'default', $lid);
    $this
      ->fail('Job item add with an non-existing locale did not fail.');
  } catch (\Exception $e) {

    // Job item add with an non-existing locale did fail.
  }
}