Example #1
0
 public function testGetText()
 {
     $text = 'Test';
     $translation = new Translation(Language::get('de'), $text);
     $returnedText = $translation->getText();
     $this->assertEquals($text, $returnedText);
 }
 /**
  * @param array $mapData
  * @dataProvider validMapData
  */
 public function testCreate(array $mapData)
 {
     $map = $this->factory->create($mapData);
     foreach ($mapData as $lang => $text) {
         $this->assertEquals($text, $map->get(Language::get($lang)));
     }
 }
Example #3
0
 public function testJsonSerialize()
 {
     $map = new TranslationMap([new Translation(Language::get('en'), 'My Test'), new Translation(Language::get('de'), 'Mein Test')]);
     $json = $map->jsonSerialize();
     $this->assertCount(2, $json);
     $this->assertEquals($json['en'], 'My Test');
     $this->assertEquals($json['de'], 'Mein Test');
 }
Example #4
0
 /**
  * @param TranslationMapInterface $map
  * @return string
  */
 private function extractFromFallbacks(TranslationMapInterface $map)
 {
     $english = Language::get('en');
     if ($map->has($english)) {
         return $map->get($english);
     }
     $translations = $map->getAll();
     reset($translations);
     /** @var TranslationInterface $translation */
     $translation = current($translations);
     return $map->get($translation->getLanguage());
 }
Example #5
0
 /**
  * @param array $mapData
  * @return TranslationMapInterface|null Returns null if the map data doesn't contain any translations
  */
 public function create(array $mapData)
 {
     $mapData = array_map('trim', $mapData);
     $mapData = array_filter($mapData, [$this, 'isTextNotEmpty']);
     if (count($mapData) === 0) {
         return null;
     }
     $translations = array_map(function ($text, $lang) {
         return new Translation(Language::get($lang), $text);
     }, $mapData, array_keys($mapData));
     return new TranslationMap($translations);
 }
Example #6
0
 public function testToString()
 {
     $language = Language::get('de');
     $this->assertEquals('de', $language->__toString());
 }
Example #7
0
 public function testExtendsLanguagePriority()
 {
     /** @noinspection PhpDeprecationInspection */
     $prioriry = new LanguagePrioriry([Language::get('de')]);
     $this->assertInstanceOf(LanguagePriority::class, $prioriry);
 }
Example #8
0
 public function testPrimary()
 {
     $priority = new LanguagePriority([Language::get('de-AT'), Language::get('en-US')]);
     $this->assertSame(Language::get('de-AT'), $priority->primary());
 }
 private function createPriority(array $priorityData)
 {
     return new LanguagePriority(array_map(function ($language) {
         return Language::get($language);
     }, $priorityData));
 }