for ($i = 0; $i < 3; $i++) {
      $language = new Language();
      $language->id = $this->randomName(2);
      $language->weight = -$i;
      language_save($language);
    }

If this generates a language id of 'en' or 'En' or 'eN' then this is going to fail!

* Drupal\language\Tests\LanguageFallbackTest (2 pass(es), 1 fail(s), and 1 exception(s))
   - [fail] [Completion check] "The test did not complete due to a fatal error." in LanguageFallbackTest.php on line 43 of Drupal\language\Tests\LanguageFallbackTest->testCandidates().
   - [exception] [Notice] "Undefined index: language.entity.eNDrupal\Core\Config\ConfigFactory->get('language.entity.eN')
Drupal\Core\Config\Entity\ConfigEntityStorage->has('eN', Object)
Drupal\Core\Entity\EntityStorageBase->save(Object)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object)
Drupal\Core\Entity\Entity->save()
language_save(Object)
Drupal\language\Tests\LanguageFallbackTest->setUp()
Drupal\simpletest\TestBase->run()
simpletest_script_run_one_test('451', 'Drupal\language\Tests\LanguageFallbackTest')
" in ConfigFactory.php on line 107 of Drupal\Core\Config\ConfigFactory->get().
CommentFileSizeAuthor
#1 2291777.1.patch759 bytesalexpott
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Status: Active » Needs review
FileSize
759 bytes
martin107’s picture

Makes perfect sense ... in this instance constrained random name generation is the only safe way.

Especially as it fits a similar pattern already in core.

see Drupal\language\Tests\LanguageConfigurationElementTest.

  /**
   * Tests that the language_get_default_langcode() returns the correct values.
   */
  public function testDefaultLangcode() {
    // Add some custom languages.
    foreach (array('aa', 'bb', 'cc') as $language_code) {
      $language = new Language(array(
        'id' => $language_code,
        'name' => $this->randomName(),
      ));
      language_save($language);
    }
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

  • Commit fdfd3c7 on 8.x by catch:
    Issue #2291777 by alexpott: Fixed Random fail in LanguageFallbackTest.
    
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.