/**
  * @dataProvider provideFetchLanguageCodes
  */
 public function testGetFetchLanguageCodes(array $languages)
 {
     $languagesWithConversion = array();
     foreach ($languages as $language) {
         $languagesWithConversion[] = LanguageWithConversion::factory($language);
     }
     $chain = new LanguageFallbackChain($languagesWithConversion);
     $codes = $chain->getFetchLanguageCodes();
     $this->assertEquals($languages, $codes);
 }
 public function provideGetLabelDescriptionLookup()
 {
     $termLookup = $this->getMock('Wikibase\\DataModel\\Services\\Lookup\\TermLookup');
     $termLookup->expects($this->any())->method('getLabel')->will($this->returnCallback(function ($item, $language) {
         if ($language === 'de') {
             return 'Kätzchen';
         }
         throw new OutOfBoundsException('no bananas');
     }));
     $termLookup->expects($this->any())->method('getLabels')->will($this->returnValue(array('de' => 'Kätzchen')));
     $labelDescriptionLookup = new LanguageLabelDescriptionLookup($termLookup, 'de');
     $deChChain = new LanguageFallbackChain(array(LanguageWithConversion::factory('de-ch'), LanguageWithConversion::factory('de')));
     $frChain = new LanguageFallbackChain(array(LanguageWithConversion::factory('fr')));
     return array('language' => array($termLookup, new FormatterOptions(array(ValueFormatter::OPT_LANG => 'de')), 'Kätzchen'), 'language and fallback chain' => array($termLookup, new FormatterOptions(array(ValueFormatter::OPT_LANG => 'fr', FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN => $deChChain)), 'Kätzchen'), 'language and fallback chain and LabelDescriptionLookup' => array($termLookup, new FormatterOptions(array(ValueFormatter::OPT_LANG => 'fr', FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN => $frChain, FormatterLabelDescriptionLookupFactory::OPT_LABEL_DESCRIPTION_LOOKUP => $labelDescriptionLookup)), 'Kätzchen'));
 }
 /**
  * Build fallback chain array for a given babel array.
  *
  * @param array $babel
  *
  * @return LanguageWithConversion[]
  */
 public function buildFromBabel(array $babel)
 {
     $chain = array();
     $fetched = array();
     // First pass to get "compatible" languages (self and variants)
     foreach ($babel as $languageCodes) {
         // Already sorted when added
         foreach (array(self::FALLBACK_SELF, self::FALLBACK_VARIANTS) as $mode) {
             foreach ($languageCodes as $languageCode) {
                 try {
                     $languageCode = LanguageWithConversion::validateLanguageCode($languageCode);
                 } catch (MWException $e) {
                     continue;
                 }
                 $this->buildFromLanguage($languageCode, $mode, $chain, $fetched);
             }
         }
     }
     // Second pass to get other languages from system fallback chain
     foreach ($babel as $languageCodes) {
         foreach ($languageCodes as $languageCode) {
             try {
                 $languageCode = LanguageWithConversion::validateLanguageCode($languageCode);
             } catch (MWException $e) {
                 continue;
             }
             $this->buildFromLanguage($languageCode, self::FALLBACK_OTHERS | self::FALLBACK_VARIANTS, $chain, $fetched);
         }
     }
     return $chain;
 }
 private function getLinkBeginHookHandler()
 {
     $languageFallback = new LanguageFallbackChain(array(LanguageWithConversion::factory('de-ch'), LanguageWithConversion::factory('de'), LanguageWithConversion::factory('en')));
     return new LinkBeginHookHandler($this->getEntityIdLookup(), $this->getTermLookup(), $this->getEntityNamespaceLookup(), $languageFallback, Language::factory('en'));
 }