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))); } }
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'); }
/** * @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()); }
/** * @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); }
public function testToString() { $language = Language::get('de'); $this->assertEquals('de', $language->__toString()); }
public function testExtendsLanguagePriority() { /** @noinspection PhpDeprecationInspection */ $prioriry = new LanguagePrioriry([Language::get('de')]); $this->assertInstanceOf(LanguagePriority::class, $prioriry); }
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)); }