Release 2.47 (#5784)
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Model\InvoiceDocument;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Twig\Environment;
|
||||
@@ -93,34 +94,85 @@ class TwigRendererTest extends KernelTestCase
|
||||
|
||||
/** @var FilesystemLoader $loader */
|
||||
$loader = $twig->getLoader();
|
||||
$loader->addPath($this->getInvoiceTemplatePath(), 'invoice');
|
||||
|
||||
$dirs = [
|
||||
__DIR__ . '/../../../templates/invoice/renderer/',
|
||||
__DIR__ . '/../../../var/invoices/',
|
||||
__DIR__ . '/../../../var/invoices_customer/',
|
||||
__DIR__ . '/../../../var/invoices_old/',
|
||||
];
|
||||
|
||||
$files = [];
|
||||
|
||||
$dirs = [
|
||||
realpath($this->getInvoiceTemplatePath()),
|
||||
realpath(__DIR__ . '/../templates/'),
|
||||
realpath(__DIR__ . '/../../../var/invoices/'),
|
||||
];
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
if (!is_dir($dir)) {
|
||||
if ($dir === false || !is_dir($dir)) {
|
||||
continue;
|
||||
}
|
||||
$dir = realpath($dir);
|
||||
$loader->addPath($dir . '/', 'invoice');
|
||||
$found = glob($dir . '/*.html.twig');
|
||||
if ($found !== false) {
|
||||
$files = array_merge($files, $found);
|
||||
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->in($dir)
|
||||
->name('*.html.twig')
|
||||
->sortByName()
|
||||
->files();
|
||||
|
||||
foreach ($finder->getIterator() as $splFile) {
|
||||
$filename = $splFile->getRealPath();
|
||||
if ($filename === false) {
|
||||
continue;
|
||||
}
|
||||
$dir = \dirname($filename) . '/';
|
||||
if (!\array_key_exists($dir, $files)) {
|
||||
$loader->addPath($dir . '/', 'invoice');
|
||||
}
|
||||
$files[$dir][] = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
// search for custom templates, that shall not be shipped
|
||||
$dirs = [
|
||||
realpath(__DIR__ . '/../../../var/templates/'),
|
||||
];
|
||||
|
||||
foreach ($dirs as $dir) {
|
||||
if ($dir === false || !is_dir($dir)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$finder = new Finder();
|
||||
$finder
|
||||
->in($dir)
|
||||
->name('*.html.twig')
|
||||
->path('invoice-tpl/')
|
||||
->sortByName()
|
||||
->files();
|
||||
|
||||
foreach ($finder->getIterator() as $splFile) {
|
||||
$filename = $splFile->getRealPath();
|
||||
if ($filename === false) {
|
||||
continue;
|
||||
}
|
||||
$dir = \dirname($filename) . '/';
|
||||
if (!\array_key_exists($dir, $files)) {
|
||||
$loader->addPath($dir . '/', 'invoice');
|
||||
}
|
||||
$files[$dir][] = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
$allFiles = [];
|
||||
|
||||
foreach ($files as $templates) {
|
||||
foreach ($templates as $filename) {
|
||||
$allFiles[] = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
self::assertGreaterThanOrEqual(2, \count($allFiles));
|
||||
|
||||
$sut = new TwigRenderer($twig);
|
||||
|
||||
$model = $this->getInvoiceModel();
|
||||
$model->getTemplate()->setLanguage('de');
|
||||
|
||||
foreach ($files as $filename) {
|
||||
foreach ($allFiles as $filename) {
|
||||
$document = new InvoiceDocument(new \SplFileInfo($filename));
|
||||
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
Reference in New Issue
Block a user