mirror of
https://github.com/OPSnet/Logchecker.git
synced 2026-01-16 18:04:27 -05:00
53 lines
1.8 KiB
PHP
53 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace OrpheusNET\Logchecker\Parser\EAC;
|
|
|
|
use FilesystemIterator;
|
|
use OrpheusNET\Logchecker\Exception\UnknownLanguageException;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class TranslatorTest extends TestCase
|
|
{
|
|
public function foreignLogDataProvider()
|
|
{
|
|
$logs = [];
|
|
$logPath = implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'transcoded_foreign_logs']);
|
|
foreach (new FilesystemIterator($logPath, FilesystemIterator::SKIP_DOTS) as $dir) {
|
|
if ($dir->isFile()) {
|
|
continue;
|
|
}
|
|
foreach (new FilesystemIterator($dir->getPathname(), FilesystemIterator::SKIP_DOTS) as $logFiles) {
|
|
if (preg_match("/[0-9]+\.log/", $logFiles->getFilename())) {
|
|
$logs[] = [$dir->getFilename(), $logFiles->getPathname()];
|
|
}
|
|
}
|
|
}
|
|
return $logs;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider foreignLogDataProvider
|
|
*/
|
|
public function testTranslateLog($language, $logPath)
|
|
{
|
|
$log = file_get_contents($logPath);
|
|
$translatedLogPath = str_replace('.log', '_en.log', $logPath);
|
|
$langDetails = Translator::getLanguage($log);
|
|
$this->assertSame($language, $langDetails['code']);
|
|
$this->assertNotNull($langDetails['name']);
|
|
$this->assertNotNull($langDetails['name_english']);
|
|
$this->assertStringEqualsFile($translatedLogPath, Translator::translate($log, $language));
|
|
}
|
|
|
|
public function testInvalidLanguage()
|
|
{
|
|
$this->expectException(UnknownLanguageException::class);
|
|
$this->expectExceptionMessage('Could not determine language of EAC log');
|
|
Translator::getLanguage(
|
|
file_get_contents(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'logs', 'xld', 'xld_perfect.log']))
|
|
);
|
|
}
|
|
}
|