Chris@0: set('weight', $i--); Chris@0: $language->save(); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests language fallback candidates. Chris@0: */ Chris@0: public function testCandidates() { Chris@0: $language_list = $this->languageManager->getLanguages(); Chris@0: $expected = array_keys($language_list + [LanguageInterface::LANGCODE_NOT_SPECIFIED => NULL]); Chris@0: Chris@0: // Check that language fallback candidates by default are all the available Chris@0: // languages sorted by weight. Chris@0: $candidates = $this->languageManager->getFallbackCandidates(); Chris@0: $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are properly returned.'); Chris@0: Chris@0: // Check that candidates are alterable. Chris@0: $this->state->set('language_test.fallback_alter.candidates', TRUE); Chris@0: $expected = array_slice($expected, 0, count($expected) - 1); Chris@0: $candidates = $this->languageManager->getFallbackCandidates(); Chris@0: $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable.'); Chris@0: Chris@0: // Check that candidates are alterable for specific operations. Chris@0: $this->state->set('language_test.fallback_alter.candidates', FALSE); Chris@0: $this->state->set('language_test.fallback_operation_alter.candidates', TRUE); Chris@0: $expected[] = LanguageInterface::LANGCODE_NOT_SPECIFIED; Chris@0: $expected[] = LanguageInterface::LANGCODE_NOT_APPLICABLE; Chris@0: $candidates = $this->languageManager->getFallbackCandidates(['operation' => 'test']); Chris@0: $this->assertEqual(array_values($candidates), $expected, 'Language fallback candidates are alterable for specific operations.'); Chris@0: Chris@0: // Check that when the site is monolingual no language fallback is applied. Chris@0: $langcodes_to_delete = []; Chris@0: foreach ($language_list as $langcode => $language) { Chris@0: if (!$language->isDefault()) { Chris@0: $langcodes_to_delete[] = $langcode; Chris@0: } Chris@0: } Chris@0: entity_delete_multiple('configurable_language', $langcodes_to_delete); Chris@0: $candidates = $this->languageManager->getFallbackCandidates(); Chris@0: $this->assertEqual(array_values($candidates), [LanguageInterface::LANGCODE_DEFAULT], 'Language fallback is not applied when the Language module is not enabled.'); Chris@0: } Chris@0: Chris@0: }