Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

53 rindas
1.8 KiB

  1. <?php
  2. declare(strict_types=1);
  3. namespace OrpheusNET\Logchecker\Parser\EAC;
  4. use FilesystemIterator;
  5. use OrpheusNET\Logchecker\Exception\UnknownLanguageException;
  6. use PHPUnit\Framework\TestCase;
  7. class TranslatorTest extends TestCase
  8. {
  9. public function foreignLogDataProvider()
  10. {
  11. $logs = [];
  12. $logPath = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'transcoded_foreign_logs']);
  13. foreach (new FilesystemIterator($logPath, FilesystemIterator::SKIP_DOTS) as $dir) {
  14. if ($dir->isFile()) {
  15. continue;
  16. }
  17. foreach (new FilesystemIterator($dir->getPathname(), FilesystemIterator::SKIP_DOTS) as $logFiles) {
  18. if (preg_match("/[0-9]+\.log/", $logFiles->getFilename())) {
  19. $logs[] = [$dir->getFilename(), $logFiles->getPathname()];
  20. }
  21. }
  22. }
  23. return $logs;
  24. }
  25. /**
  26. * @dataProvider foreignLogDataProvider
  27. */
  28. public function testTranslateLog($language, $logPath)
  29. {
  30. $log = file_get_contents($logPath);
  31. $translatedLogPath = str_replace('.log', '_en.log', $logPath);
  32. $langDetails = Translator::getLanguage($log);
  33. $this->assertSame($language, $langDetails['code']);
  34. $this->assertNotNull($langDetails['name']);
  35. $this->assertNotNull($langDetails['name_english']);
  36. $this->assertStringEqualsFile($translatedLogPath, Translator::translate($log, $language));
  37. }
  38. public function testInvalidLanguage()
  39. {
  40. $this->expectException(UnknownLanguageException::class);
  41. $this->expectExceptionMessage('Could not determine language of EAC log');
  42. Translator::getLanguage(
  43. file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'xld', 'xld_perfect.log']))
  44. );
  45. }
  46. }