Skip to content
Snippets Groups Projects
Commit 567ba33b authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Clean up workdir before/after & add test coverage

parent 3e9be61b
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/php -q
<?php
declare(strict_types=1);
use SimpleSAML\Module;
use SimpleSAML\Utils;
use Symfony\Component\Filesystem\Filesystem;
// This is the base directory of the SimpleSAMLphp installation
$baseDir = dirname(dirname(__FILE__));
......@@ -11,7 +15,12 @@ require_once($baseDir . '/lib/_autoload.php');
$transUtils = new Utils\Translate();
$sysUtils = new Utils\System();
$filesystem = new Filesystem();
$tempDirBase = $sysUtils->getTempDir() . "/temptemplatestemp";
// Ensure no leftover from any previous invocation
$filesystem->remove($tempDirBase);
$outputSuffix = '/locales/en/LC_MESSAGES';
$modules = ['', 'core', 'admin', 'cron', 'exampleauth', 'multiauth', 'saml'];
......@@ -25,5 +34,5 @@ foreach($modules as $module) {
print `xgettext --default-domain=$domain -p $outputDir --from-code=UTF-8 -j --no-location -ktrans -L PHP $tempDir/*/*.php`;
}
// TODO: clean up workdir before/after run
$filesystem->remove($tempDirBase);
// TODO: merge new strings into translated languages catalogs
......@@ -22,9 +22,9 @@ class Translate
{
$config = Configuration::loadFromArray(['template.cache' => $outputDir, 'module.enable' => [$module => true]]);
$baseDir = $config->getBaseDir();
$tplSuffix = '/templates/';
$tplSuffix = DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR;
$tplDir = $baseDir . ($module === '' ? '' : 'modules/' . $module) . $tplSuffix;
$tplDir = $baseDir . ($module === '' ? '' : 'modules' . DIRECTORY_SEPARATOR . $module) . $tplSuffix;
$templateprefix = ($module === '' ? '' : $module . ":");
foreach (
......
......@@ -16,7 +16,7 @@ use SimpleSAML\Utils;
/**
* Tests for SimpleSAML\Utils\System.
*
* @covers \SimpleSAML\Utils\Random
* @covers \SimpleSAML\Utils\System
*/
class SystemTest extends TestCase
{
......
<?php
declare(strict_types=1);
namespace SimpleSAML\Test\Utils;
use InvalidArgumentException;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use SimpleSAML\Configuration;
use SimpleSAML\Error;
use SimpleSAML\Utils;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
/**
* Tests for SimpleSAML\Utils\Translate.
*
* @covers \SimpleSAML\Utils\Translate
*/
class TranslateTest extends TestCase
{
protected Utils\System $sysUtils;
protected Utils\Translate $translate;
protected Filesystem $filesystem;
protected string $tempdir;
public function setUp(): void
{
$this->filesystem = new Filesystem();
$this->sysUtils = new Utils\System();
do {
$tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . mt_rand();
} while (!@mkdir($tmp, 0700));
$this->tempdir = $tmp;
$this->translate = new Utils\Translate();
}
/**
* @test
*/
public function testCompileAllTemplatesMain(): void
{
$workdir = $this->tempdir . DIRECTORY_SEPARATOR . "testall";
$this->translate->compileAllTemplates('', $workdir);
$this->checkAllFilesAreCompiledTemplates($workdir);
}
/**
* @test
*/
public function testCompileAllTemplatesModule(): void
{
$workdir = $this->tempdir . DIRECTORY_SEPARATOR . "testadmin";
$this->translate->compileAllTemplates('admin', $workdir);
$this->checkAllFilesAreCompiledTemplates($workdir);
}
public function tearDown(): void
{
$this->filesystem->remove($this->tempdir);
}
protected function checkAllFilesAreCompiledTemplates(string $dir)
{
$finder = new Finder();
$finder->files()->in($dir);
$this->assertTrue($finder->hasResults());
foreach ($finder as $file) {
$this->assertEquals('php', $file->getExtension());
$this->assertStringContainsString('class __TwigTemplate', $file->getContents());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment