From dbc3da7bc3b404d8e996aa934e77d16fdb260147 Mon Sep 17 00:00:00 2001 From: Pierre Goiffon Date: Fri, 28 Jan 2022 17:25:14 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B03129=20Remove=20twig-bundle=20Test=20dir?= =?UTF-8?q?=20Thanks=20to=20iTopComposerTest::testNoDeniedDirIsPresentForN?= =?UTF-8?q?ow=20:o)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/.gitignore | 3 +- .../Tests/ContainerAwareRuntimeLoaderTest.php | 41 -- .../Controller/ExceptionControllerTest.php | 92 ----- .../Controller/PreviewErrorControllerTest.php | 53 --- .../Compiler/ExtensionPassTest.php | 46 --- .../Compiler/TwigEnvironmentPassTest.php | 45 --- .../Compiler/TwigLoaderPassTest.php | 95 ----- .../DependencyInjection/ConfigurationTest.php | 31 -- .../Resources/views/layout.html.twig | 1 - .../Resources/views/layout.html.twig | 1 - .../Resources/views/layout.html.twig | 1 - .../Resources/views/layout.html.twig | 1 - .../TwigBundle/views/layout.html.twig | 1 - .../Fixtures/Resources/views/layout.html.twig | 1 - .../php/customTemplateEscapingGuesser.php | 6 - .../Fixtures/php/empty.php | 3 - .../Fixtures/php/extra.php | 7 - .../Fixtures/php/formats.php | 14 - .../DependencyInjection/Fixtures/php/full.php | 27 -- .../bundles/BarBundle/layout.html.twig | 1 - .../bundles/TwigBundle/layout.html.twig | 1 - .../Fixtures/templates/layout.html.twig | 1 - .../xml/customTemplateEscapingGuesser.xml | 10 - .../Fixtures/xml/empty.xml | 10 - .../Fixtures/xml/extra.xml | 12 - .../Fixtures/xml/formats.xml | 12 - .../DependencyInjection/Fixtures/xml/full.xml | 19 - .../yml/customTemplateEscapingGuesser.yml | 3 - .../Fixtures/yml/empty.yml | 1 - .../Fixtures/yml/extra.yml | 3 - .../Fixtures/yml/formats.yml | 9 - .../DependencyInjection/Fixtures/yml/full.yml | 21 -- .../DependencyInjection/TwigExtensionTest.php | 355 ------------------ .../BarBundle/Resources/views/index.html.twig | 1 - .../Fixtures/templates/Foo/index.html.twig | 1 - .../Resources/BarBundle/views/base.html.twig | 0 .../Resources/views/layout.html.twig | 1 - .../Resources/views/sub/sub.html.twig | 1 - .../Tests/Functional/CacheWarmingTest.php | 124 ------ .../Tests/Functional/EmptyAppTest.php | 51 --- .../Functional/NoTemplatingEntryTest.php | 80 ---- .../Resources/config/empty_routing.yml | 0 .../Resources/views/index.html.twig | 1 - .../Tests/Loader/FilesystemLoaderTest.php | 125 ------ .../Tests/TemplateIteratorTest.php | 44 --- lib/symfony/twig-bundle/Tests/TestCase.php | 18 - 46 files changed, 2 insertions(+), 1372 deletions(-) delete mode 100644 lib/symfony/twig-bundle/Tests/ContainerAwareRuntimeLoaderTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Controller/ExceptionControllerTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Controller/PreviewErrorControllerTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigEnvironmentPassTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/ConfigurationTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildTwigBundle/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildTwigBundle/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/TwigBundle/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/empty.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/extra.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/formats.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/full.php delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/BarBundle/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/TwigBundle/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/empty.xml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/extra.xml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/formats.xml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/full.xml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/empty.yml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/extra.yml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/formats.yml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/full.yml delete mode 100644 lib/symfony/twig-bundle/Tests/DependencyInjection/TwigExtensionTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Fixtures/templates/BarBundle/Resources/views/index.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Fixtures/templates/Foo/index.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/BarBundle/views/base.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/layout.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/sub/sub.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Functional/CacheWarmingTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Functional/EmptyAppTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Functional/NoTemplatingEntryTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/Functional/Resources/config/empty_routing.yml delete mode 100644 lib/symfony/twig-bundle/Tests/Functional/Resources/views/index.html.twig delete mode 100644 lib/symfony/twig-bundle/Tests/Loader/FilesystemLoaderTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/TemplateIteratorTest.php delete mode 100644 lib/symfony/twig-bundle/Tests/TestCase.php diff --git a/lib/.gitignore b/lib/.gitignore index fe9051d17..db8232362 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -32,4 +32,5 @@ # TWIG /twig/twig/doc /twig/twig/test -/twig/twig/drupal_test.sh \ No newline at end of file +/twig/twig/drupal_test.sh +/symfony/twig-bundle/Tests diff --git a/lib/symfony/twig-bundle/Tests/ContainerAwareRuntimeLoaderTest.php b/lib/symfony/twig-bundle/Tests/ContainerAwareRuntimeLoaderTest.php deleted file mode 100644 index 88f8fb21e..000000000 --- a/lib/symfony/twig-bundle/Tests/ContainerAwareRuntimeLoaderTest.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests; - -use Psr\Log\LoggerInterface; -use Symfony\Bundle\TwigBundle\ContainerAwareRuntimeLoader; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * @group legacy - */ -class ContainerAwareRuntimeLoaderTest extends TestCase -{ - public function testLoad() - { - $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); - $container->expects($this->once())->method('get')->with('foo'); - - $loader = new ContainerAwareRuntimeLoader($container, [ - 'FooClass' => 'foo', - ]); - $loader->load('FooClass'); - } - - public function testLoadWithoutAMatch() - { - $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); - $logger->expects($this->once())->method('warning')->with('Class "BarClass" is not configured as a Twig runtime. Add the "twig.runtime" tag to the related service in the container.'); - $loader = new ContainerAwareRuntimeLoader($this->getMockBuilder(ContainerInterface::class)->getMock(), [], $logger); - $this->assertNull($loader->load('BarClass')); - } -} diff --git a/lib/symfony/twig-bundle/Tests/Controller/ExceptionControllerTest.php b/lib/symfony/twig-bundle/Tests/Controller/ExceptionControllerTest.php deleted file mode 100644 index 800da68c9..000000000 --- a/lib/symfony/twig-bundle/Tests/Controller/ExceptionControllerTest.php +++ /dev/null @@ -1,92 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Controller; - -use Symfony\Bundle\TwigBundle\Controller\ExceptionController; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Component\Debug\Exception\FlattenException; -use Symfony\Component\HttpFoundation\Request; -use Twig\Environment; -use Twig\Loader\ArrayLoader; - -class ExceptionControllerTest extends TestCase -{ - public function testShowActionCanBeForcedToShowErrorPage() - { - $twig = $this->createTwigEnv(['@Twig/Exception/error404.html.twig' => 'not found']); - - $request = $this->createRequest('html'); - $request->attributes->set('showException', false); - $exception = FlattenException::create(new \Exception(), 404); - $controller = new ExceptionController($twig, /* "showException" defaults to --> */ true); - - $response = $controller->showAction($request, $exception, null); - - $this->assertEquals(200, $response->getStatusCode()); // successful request - $this->assertEquals('not found', $response->getContent()); - } - - public function testFallbackToHtmlIfNoTemplateForRequestedFormat() - { - $twig = $this->createTwigEnv(['@Twig/Exception/error.html.twig' => '']); - - $request = $this->createRequest('txt'); - $exception = FlattenException::create(new \Exception()); - $controller = new ExceptionController($twig, false); - - $controller->showAction($request, $exception); - - $this->assertEquals('html', $request->getRequestFormat()); - } - - public function testFallbackToHtmlWithFullExceptionIfNoTemplateForRequestedFormatAndExceptionsShouldBeShown() - { - $twig = $this->createTwigEnv(['@Twig/Exception/exception_full.html.twig' => '']); - - $request = $this->createRequest('txt'); - $request->attributes->set('showException', true); - $exception = FlattenException::create(new \Exception()); - $controller = new ExceptionController($twig, false); - - $controller->showAction($request, $exception); - - $this->assertEquals('html', $request->getRequestFormat()); - } - - public function testResponseHasRequestedMimeType() - { - $twig = $this->createTwigEnv(['@Twig/Exception/error.json.twig' => '{}']); - - $request = $this->createRequest('json'); - $exception = FlattenException::create(new \Exception()); - $controller = new ExceptionController($twig, false); - - $response = $controller->showAction($request, $exception); - - $this->assertEquals('json', $request->getRequestFormat()); - $this->assertEquals($request->getMimeType('json'), $response->headers->get('Content-Type')); - } - - private function createRequest($requestFormat) - { - $request = Request::create('whatever'); - $request->headers->set('X-Php-Ob-Level', 1); - $request->setRequestFormat($requestFormat); - - return $request; - } - - private function createTwigEnv(array $templates) - { - return new Environment(new ArrayLoader($templates)); - } -} diff --git a/lib/symfony/twig-bundle/Tests/Controller/PreviewErrorControllerTest.php b/lib/symfony/twig-bundle/Tests/Controller/PreviewErrorControllerTest.php deleted file mode 100644 index ae740e1ab..000000000 --- a/lib/symfony/twig-bundle/Tests/Controller/PreviewErrorControllerTest.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Controller; - -use Symfony\Bundle\TwigBundle\Controller\PreviewErrorController; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Component\Debug\Exception\FlattenException; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\HttpKernelInterface; - -class PreviewErrorControllerTest extends TestCase -{ - public function testForwardRequestToConfiguredController() - { - $request = Request::create('whatever'); - $response = new Response(''); - $code = 123; - $logicalControllerName = 'foo:bar:baz'; - - $kernel = $this->getMockBuilder('\Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - $kernel - ->expects($this->once()) - ->method('handle') - ->with( - $this->callback(function (Request $request) use ($logicalControllerName, $code) { - $this->assertEquals($logicalControllerName, $request->attributes->get('_controller')); - - $exception = $request->attributes->get('exception'); - $this->assertInstanceOf(FlattenException::class, $exception); - $this->assertEquals($code, $exception->getStatusCode()); - $this->assertFalse($request->attributes->get('showException')); - - return true; - }), - $this->equalTo(HttpKernelInterface::SUB_REQUEST) - ) - ->willReturn($response); - - $controller = new PreviewErrorController($kernel, $logicalControllerName); - - $this->assertSame($response, $controller->previewErrorPageAction($request, $code)); - } -} diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php deleted file mode 100644 index 539a952a6..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/ExtensionPassTest.php +++ /dev/null @@ -1,46 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; - -use PHPUnit\Framework\TestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\ExtensionPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; - -class ExtensionPassTest extends TestCase -{ - public function testProcessDoesNotDropExistingFileLoaderMethodCalls() - { - $container = new ContainerBuilder(); - $container->setParameter('kernel.debug', false); - - $container->register('twig.app_variable', '\Symfony\Bridge\Twig\AppVariable'); - $container->register('templating', '\Symfony\Bundle\TwigBundle\TwigEngine'); - $container->register('twig.extension.yaml'); - $container->register('twig.extension.debug.stopwatch'); - $container->register('twig.extension.expression'); - - $nativeTwigLoader = new Definition('\Twig\Loader\FilesystemLoader'); - $nativeTwigLoader->addMethodCall('addPath', []); - $container->setDefinition('twig.loader.native_filesystem', $nativeTwigLoader); - - $filesystemLoader = new Definition('\Symfony\Bundle\TwigBundle\Loader\FilesystemLoader'); - $filesystemLoader->setArguments([null, null, null]); - $filesystemLoader->addMethodCall('addPath', []); - $container->setDefinition('twig.loader.filesystem', $filesystemLoader); - - $extensionPass = new ExtensionPass(); - $extensionPass->process($container); - - $this->assertCount(2, $filesystemLoader->getMethodCalls()); - } -} diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigEnvironmentPassTest.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigEnvironmentPassTest.php deleted file mode 100644 index 0af3fe4b3..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigEnvironmentPassTest.php +++ /dev/null @@ -1,45 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; - -use PHPUnit\Framework\TestCase; -use Symfony\Bridge\Twig\Extension\FormExtension; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigEnvironmentPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Reference; - -class TwigEnvironmentPassTest extends TestCase -{ - public function testTwigBridgeExtensionsAreRegisteredFirst() - { - $container = new ContainerBuilder(); - $twigDefinition = $container->register('twig'); - $container->register('other_extension', 'Foo\Bar') - ->addTag('twig.extension'); - $container->register('twig_bridge_extension', FormExtension::class) - ->addTag('twig.extension'); - - $twigEnvironmentPass = new TwigEnvironmentPass(); - $twigEnvironmentPass->process($container); - - $methodCalls = $twigDefinition->getMethodCalls(); - $this->assertCount(2, $methodCalls); - - $twigBridgeExtensionReference = $methodCalls[0][1][0]; - $this->assertInstanceOf(Reference::class, $twigBridgeExtensionReference); - $this->assertSame('twig_bridge_extension', (string) $twigBridgeExtensionReference); - - $otherExtensionReference = $methodCalls[1][1][0]; - $this->assertInstanceOf(Reference::class, $otherExtensionReference); - $this->assertSame('other_extension', (string) $otherExtensionReference); - } -} diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php deleted file mode 100644 index a112b64b5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Compiler/TwigLoaderPassTest.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection\Compiler; - -use PHPUnit\Framework\TestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\TwigLoaderPass; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Definition; - -class TwigLoaderPassTest extends TestCase -{ - /** - * @var ContainerBuilder - */ - private $builder; - /** - * @var Definition - */ - private $chainLoader; - /** - * @var TwigLoaderPass - */ - private $pass; - - protected function setUp() - { - $this->builder = new ContainerBuilder(); - $this->builder->register('twig'); - $this->chainLoader = new Definition('loader'); - $this->pass = new TwigLoaderPass(); - } - - public function testMapperPassWithOneTaggedLoader() - { - $this->builder->register('test_loader_1') - ->addTag('twig.loader'); - - $this->pass->process($this->builder); - - $this->assertSame('test_loader_1', (string) $this->builder->getAlias('twig.loader')); - } - - public function testMapperPassWithTwoTaggedLoaders() - { - $this->builder->setDefinition('twig.loader.chain', $this->chainLoader); - $this->builder->register('test_loader_1') - ->addTag('twig.loader'); - $this->builder->register('test_loader_2') - ->addTag('twig.loader'); - - $this->pass->process($this->builder); - - $this->assertSame('twig.loader.chain', (string) $this->builder->getAlias('twig.loader')); - $calls = $this->chainLoader->getMethodCalls(); - $this->assertCount(2, $calls); - $this->assertEquals('addLoader', $calls[0][0]); - $this->assertEquals('addLoader', $calls[1][0]); - $this->assertEquals('test_loader_1', (string) $calls[0][1][0]); - $this->assertEquals('test_loader_2', (string) $calls[1][1][0]); - } - - public function testMapperPassWithTwoTaggedLoadersWithPriority() - { - $this->builder->setDefinition('twig.loader.chain', $this->chainLoader); - $this->builder->register('test_loader_1') - ->addTag('twig.loader', ['priority' => 100]); - $this->builder->register('test_loader_2') - ->addTag('twig.loader', ['priority' => 200]); - - $this->pass->process($this->builder); - - $this->assertSame('twig.loader.chain', (string) $this->builder->getAlias('twig.loader')); - $calls = $this->chainLoader->getMethodCalls(); - $this->assertCount(2, $calls); - $this->assertEquals('addLoader', $calls[0][0]); - $this->assertEquals('addLoader', $calls[1][0]); - $this->assertEquals('test_loader_2', (string) $calls[0][1][0]); - $this->assertEquals('test_loader_1', (string) $calls[1][1][0]); - } - - public function testMapperPassWithZeroTaggedLoaders() - { - $this->expectException('Symfony\Component\DependencyInjection\Exception\LogicException'); - $this->pass->process($this->builder); - } -} diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/ConfigurationTest.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/ConfigurationTest.php deleted file mode 100644 index 049d05b5c..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/ConfigurationTest.php +++ /dev/null @@ -1,31 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; - -use PHPUnit\Framework\TestCase; -use Symfony\Bundle\TwigBundle\DependencyInjection\Configuration; -use Symfony\Component\Config\Definition\Processor; - -class ConfigurationTest extends TestCase -{ - public function testDoNoDuplicateDefaultFormResources() - { - $input = [ - 'form_themes' => ['form_div_layout.html.twig'], - ]; - - $processor = new Processor(); - $config = $processor->processConfiguration(new Configuration(), [$input]); - - $this->assertEquals(['form_div_layout.html.twig'], $config['form_themes']); - } -} diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildTwigBundle/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildTwigBundle/Resources/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildChildTwigBundle/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildTwigBundle/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildTwigBundle/Resources/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Bundle/ChildTwigBundle/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/TwigBundle/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/TwigBundle/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/TwigBundle/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/views/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php deleted file mode 100644 index c9acb3c25..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/customTemplateEscapingGuesser.php +++ /dev/null @@ -1,6 +0,0 @@ -loadFromExtension('twig', [ - 'autoescape_service' => 'my_project.some_bundle.template_escaping_guesser', - 'autoescape_service_method' => 'guess', -]); diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/empty.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/empty.php deleted file mode 100644 index d107fd90d..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/empty.php +++ /dev/null @@ -1,3 +0,0 @@ -loadFromExtension('twig', []); diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/extra.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/extra.php deleted file mode 100644 index 49acc87a8..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/extra.php +++ /dev/null @@ -1,7 +0,0 @@ -loadFromExtension('twig', [ - 'paths' => [ - 'namespaced_path3' => 'namespace3', - ], -]); diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/formats.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/formats.php deleted file mode 100644 index 7e8573880..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/formats.php +++ /dev/null @@ -1,14 +0,0 @@ -loadFromExtension('twig', [ - 'date' => [ - 'format' => 'Y-m-d', - 'interval_format' => '%d', - 'timezone' => 'Europe/Berlin', - ], - 'number_format' => [ - 'decimals' => 2, - 'decimal_point' => ',', - 'thousands_separator' => '.', - ], -]); diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/full.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/full.php deleted file mode 100644 index 8dd2be409..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/php/full.php +++ /dev/null @@ -1,27 +0,0 @@ -loadFromExtension('twig', [ - 'form_themes' => [ - 'MyBundle::form.html.twig', - ], - 'globals' => [ - 'foo' => '@bar', - 'baz' => '@@qux', - 'pi' => 3.14, - 'bad' => ['key' => 'foo'], - ], - 'auto_reload' => true, - 'autoescape' => true, - 'base_template_class' => 'stdClass', - 'cache' => '/tmp', - 'charset' => 'ISO-8859-1', - 'debug' => true, - 'strict_variables' => true, - 'default_path' => '%kernel.project_dir%/Fixtures/templates', - 'paths' => [ - 'path1', - 'path2', - 'namespaced_path1' => 'namespace1', - 'namespaced_path2' => 'namespace2', - ], -]); diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/BarBundle/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/BarBundle/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/BarBundle/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/TwigBundle/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/TwigBundle/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/bundles/TwigBundle/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/layout.html.twig b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/layout.html.twig deleted file mode 100644 index bb07ecfe5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/templates/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -This is a layout diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml deleted file mode 100644 index f72bed9d1..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/customTemplateEscapingGuesser.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/empty.xml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/empty.xml deleted file mode 100644 index f3b51fa24..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/empty.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/extra.xml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/extra.xml deleted file mode 100644 index 17bcf0acd..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/extra.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - namespaced_path3 - - diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/formats.xml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/formats.xml deleted file mode 100644 index fa888b30a..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/formats.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/full.xml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/full.xml deleted file mode 100644 index 8ece3b80b..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/xml/full.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - MyBundle::form.html.twig - - @@qux - 3.14 - path1 - path2 - namespaced_path1 - namespaced_path2 - - diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml deleted file mode 100644 index eb26e7165..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/customTemplateEscapingGuesser.yml +++ /dev/null @@ -1,3 +0,0 @@ -twig: - autoescape_service: my_project.some_bundle.template_escaping_guesser - autoescape_service_method: guess diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/empty.yml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/empty.yml deleted file mode 100644 index a472b2698..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/empty.yml +++ /dev/null @@ -1 +0,0 @@ -twig: diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/extra.yml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/extra.yml deleted file mode 100644 index 3c5e6a3b5..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/extra.yml +++ /dev/null @@ -1,3 +0,0 @@ -twig: - paths: - namespaced_path3: namespace3 diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/formats.yml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/formats.yml deleted file mode 100644 index 290921630..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/formats.yml +++ /dev/null @@ -1,9 +0,0 @@ -twig: - date: - format: Y-m-d - interval_format: '%d' - timezone: Europe/Berlin - number_format: - decimals: 2 - decimal_point: ',' - thousands_separator: . diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/full.yml b/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/full.yml deleted file mode 100644 index 24c10c23f..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/Fixtures/yml/full.yml +++ /dev/null @@ -1,21 +0,0 @@ -twig: - form_themes: - - MyBundle::form.html.twig - globals: - foo: "@bar" - baz: "@@qux" - pi: 3.14 - bad: {key: foo} - auto_reload: true - autoescape: true - base_template_class: stdClass - cache: /tmp - charset: ISO-8859-1 - debug: true - strict_variables: true - default_path: '%kernel.project_dir%/Fixtures/templates' - paths: - path1: '' - path2: '' - namespaced_path1: namespace1 - namespaced_path2: namespace2 diff --git a/lib/symfony/twig-bundle/Tests/DependencyInjection/TwigExtensionTest.php b/lib/symfony/twig-bundle/Tests/DependencyInjection/TwigExtensionTest.php deleted file mode 100644 index 7e14857fa..000000000 --- a/lib/symfony/twig-bundle/Tests/DependencyInjection/TwigExtensionTest.php +++ /dev/null @@ -1,355 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\DependencyInjection; - -use Symfony\Bundle\TwigBundle\DependencyInjection\Compiler\RuntimeLoaderPass; -use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Component\Config\FileLocator; -use Symfony\Component\DependencyInjection\Compiler\PassConfig; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\DependencyInjection\Loader\PhpFileLoader; -use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; -use Symfony\Component\DependencyInjection\Reference; - -class TwigExtensionTest extends TestCase -{ - public function testLoadEmptyConfiguration() - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $container->loadFromExtension('twig', []); - $this->compileContainer($container); - - $this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); - - $this->assertContains('form_div_layout.html.twig', $container->getParameter('twig.form.resources'), '->load() includes default template for form resources'); - - // Twig options - $options = $container->getDefinition('twig')->getArgument(1); - $this->assertEquals('%kernel.cache_dir%/twig', $options['cache'], '->load() sets default value for cache option'); - $this->assertEquals('%kernel.charset%', $options['charset'], '->load() sets default value for charset option'); - $this->assertEquals('%kernel.debug%', $options['debug'], '->load() sets default value for debug option'); - } - - /** - * @dataProvider getFormats - */ - public function testLoadFullConfiguration($format) - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'full', $format); - $this->compileContainer($container); - - $this->assertEquals('Twig\Environment', $container->getDefinition('twig')->getClass(), '->load() loads the twig.xml file'); - - // Form resources - $resources = $container->getParameter('twig.form.resources'); - $this->assertContains('form_div_layout.html.twig', $resources, '->load() includes default template for form resources'); - $this->assertContains('MyBundle::form.html.twig', $resources, '->load() merges new templates into form resources'); - - // Globals - $calls = $container->getDefinition('twig')->getMethodCalls(); - $this->assertEquals('app', $calls[0][1][0], '->load() registers services as Twig globals'); - $this->assertEquals(new Reference('twig.app_variable'), $calls[0][1][1]); - $this->assertEquals('foo', $calls[2][1][0], '->load() registers services as Twig globals'); - $this->assertEquals(new Reference('bar'), $calls[2][1][1], '->load() registers services as Twig globals'); - $this->assertEquals('baz', $calls[3][1][0], '->load() registers variables as Twig globals'); - $this->assertEquals('@qux', $calls[3][1][1], '->load() allows escaping of service identifiers'); - $this->assertEquals('pi', $calls[4][1][0], '->load() registers variables as Twig globals'); - $this->assertEquals(3.14, $calls[4][1][1], '->load() registers variables as Twig globals'); - - // Yaml and Php specific configs - if (\in_array($format, ['yml', 'php'])) { - $this->assertEquals('bad', $calls[5][1][0], '->load() registers variables as Twig globals'); - $this->assertEquals(['key' => 'foo'], $calls[5][1][1], '->load() registers variables as Twig globals'); - } - - // Twig options - $options = $container->getDefinition('twig')->getArgument(1); - $this->assertTrue($options['auto_reload'], '->load() sets the auto_reload option'); - $this->assertTrue($options['autoescape'], '->load() sets the autoescape option'); - $this->assertEquals('stdClass', $options['base_template_class'], '->load() sets the base_template_class option'); - $this->assertEquals('/tmp', $options['cache'], '->load() sets the cache option'); - $this->assertEquals('ISO-8859-1', $options['charset'], '->load() sets the charset option'); - $this->assertTrue($options['debug'], '->load() sets the debug option'); - $this->assertTrue($options['strict_variables'], '->load() sets the strict_variables option'); - } - - /** - * @dataProvider getFormats - */ - public function testLoadCustomTemplateEscapingGuesserConfiguration($format) - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'customTemplateEscapingGuesser', $format); - $this->compileContainer($container); - - $options = $container->getDefinition('twig')->getArgument(1); - $this->assertEquals([new Reference('my_project.some_bundle.template_escaping_guesser'), 'guess'], $options['autoescape']); - } - - /** - * @dataProvider getFormats - */ - public function testLoadDefaultTemplateEscapingGuesserConfiguration($format) - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'empty', $format); - $this->compileContainer($container); - - $options = $container->getDefinition('twig')->getArgument(1); - $this->assertEquals('name', $options['autoescape']); - } - - /** - * @dataProvider getFormats - */ - public function testLoadCustomDateFormats($fileFormat) - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'formats', $fileFormat); - $this->compileContainer($container); - - $environmentConfigurator = $container->getDefinition('twig.configurator.environment'); - - $this->assertSame('Y-m-d', $environmentConfigurator->getArgument(0)); - $this->assertSame('%d', $environmentConfigurator->getArgument(1)); - $this->assertSame('Europe/Berlin', $environmentConfigurator->getArgument(2)); - $this->assertSame(2, $environmentConfigurator->getArgument(3)); - $this->assertSame(',', $environmentConfigurator->getArgument(4)); - $this->assertSame('.', $environmentConfigurator->getArgument(5)); - } - - public function testGlobalsWithDifferentTypesAndValues() - { - $globals = [ - 'array' => [], - 'false' => false, - 'float' => 2.0, - 'integer' => 3, - 'null' => null, - 'object' => new \stdClass(), - 'string' => 'foo', - 'true' => true, - ]; - - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $container->loadFromExtension('twig', ['globals' => $globals]); - $this->compileContainer($container); - - $calls = $container->getDefinition('twig')->getMethodCalls(); - foreach (\array_slice($calls, 2) as $call) { - $this->assertEquals(key($globals), $call[1][0]); - $this->assertSame(current($globals), $call[1][1]); - - next($globals); - } - } - - /** - * @dataProvider getFormats - */ - public function testTwigLoaderPaths($format) - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $this->loadFromFile($container, 'full', $format); - $this->loadFromFile($container, 'extra', $format); - $this->compileContainer($container); - - $def = $container->getDefinition('twig.loader.native_filesystem'); - $paths = []; - foreach ($def->getMethodCalls() as $call) { - if ('addPath' === $call[0] && false === strpos($call[1][0], 'Form')) { - $paths[] = $call[1]; - } - } - - $this->assertEquals([ - ['path1'], - ['path2'], - ['namespaced_path1', 'namespace1'], - ['namespaced_path2', 'namespace2'], - ['namespaced_path3', 'namespace3'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'Twig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'Twig'], - [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'Twig'], - [__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'Twig'], - [__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'], - [__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'], - [realpath(__DIR__.'/../..').'/Resources/views', 'Twig'], - [realpath(__DIR__.'/../..').'/Resources/views', '!Twig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildTwigBundle/Resources/views', 'ChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildChildTwig'], - [__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildChildTwig'], - [__DIR__.'/Fixtures/Resources/views'], - [__DIR__.'/Fixtures/templates'], - ], $paths); - } - - public function getFormats() - { - return [ - ['php'], - ['yml'], - ['xml'], - ]; - } - - /** - * @dataProvider stopwatchExtensionAvailabilityProvider - */ - public function testStopwatchExtensionAvailability($debug, $stopwatchEnabled, $expected) - { - $container = $this->createContainer(); - $container->setParameter('kernel.debug', $debug); - if ($stopwatchEnabled) { - $container->register('debug.stopwatch', 'Symfony\Component\Stopwatch\Stopwatch'); - } - $container->registerExtension(new TwigExtension()); - $container->loadFromExtension('twig', []); - $container->setAlias('test.twig.extension.debug.stopwatch', 'twig.extension.debug.stopwatch')->setPublic(true); - $this->compileContainer($container); - - $tokenParsers = $container->get('test.twig.extension.debug.stopwatch')->getTokenParsers(); - $stopwatchIsAvailable = new \ReflectionProperty($tokenParsers[0], 'stopwatchIsAvailable'); - $stopwatchIsAvailable->setAccessible(true); - - $this->assertSame($expected, $stopwatchIsAvailable->getValue($tokenParsers[0])); - } - - public function stopwatchExtensionAvailabilityProvider() - { - return [ - 'debug-and-stopwatch-enabled' => [true, true, true], - 'only-stopwatch-enabled' => [false, true, false], - 'only-debug-enabled' => [true, false, false], - 'debug-and-stopwatch-disabled' => [false, false, false], - ]; - } - - public function testRuntimeLoader() - { - $container = $this->createContainer(); - $container->registerExtension(new TwigExtension()); - $container->loadFromExtension('twig', []); - $container->setParameter('kernel.environment', 'test'); - $container->setParameter('debug.file_link_format', 'test'); - $container->setParameter('foo', 'FooClass'); - $container->register('http_kernel', 'FooClass'); - $container->register('templating.locator', 'FooClass'); - $container->register('templating.name_parser', 'FooClass'); - $container->register('foo', '%foo%')->addTag('twig.runtime'); - $container->addCompilerPass(new RuntimeLoaderPass(), PassConfig::TYPE_BEFORE_REMOVING); - $container->getCompilerPassConfig()->setRemovingPasses([]); - $container->getCompilerPassConfig()->setAfterRemovingPasses([]); - $container->compile(); - - $loader = $container->getDefinition('twig.runtime_loader'); - $args = $container->getDefinition((string) $loader->getArgument(0))->getArgument(0); - $this->assertArrayHasKey('Symfony\Component\Form\FormRenderer', $args); - $this->assertArrayHasKey('FooClass', $args); - $this->assertEquals('twig.form.renderer', $args['Symfony\Component\Form\FormRenderer']->getValues()[0]); - $this->assertEquals('foo', $args['FooClass']->getValues()[0]); - } - - private function createContainer() - { - $container = new ContainerBuilder(new ParameterBag([ - 'kernel.cache_dir' => __DIR__, - 'kernel.root_dir' => __DIR__.'/Fixtures', - 'kernel.project_dir' => __DIR__, - 'kernel.charset' => 'UTF-8', - 'kernel.debug' => false, - 'kernel.bundles' => [ - 'TwigBundle' => 'Symfony\\Bundle\\TwigBundle\\TwigBundle', - 'ChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle', - 'ChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle', - 'ChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle', - 'ChildChildChildChildTwigBundle' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle', - ], - 'kernel.bundles_metadata' => [ - 'ChildChildChildChildTwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildChildTwigBundle\\ChildChildChildChildTwigBundle', - 'parent' => 'ChildChildChildTwigBundle', - 'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle', - ], - 'TwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle', - 'parent' => null, - 'path' => realpath(__DIR__.'/../..'), - ], - 'ChildTwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildTwigBundle\\ChildTwigBundle', - 'parent' => 'TwigBundle', - 'path' => __DIR__.'/Fixtures/Bundle/ChildTwigBundle', - ], - 'ChildChildChildTwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildChildTwigBundle\\ChildChildChildTwigBundle', - 'parent' => 'ChildChildTwigBundle', - 'path' => __DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle', - ], - 'ChildChildTwigBundle' => [ - 'namespace' => 'Symfony\\Bundle\\TwigBundle\\Tests\\DependencyInjection\\Fixtures\\Bundle\\ChildChildTwigBundle\\ChildChildTwigBundle', - 'parent' => 'ChildTwigBundle', - 'path' => __DIR__.'/Fixtures/Bundle/ChildChildTwigBundle', - ], - ], - ])); - - return $container; - } - - private function compileContainer(ContainerBuilder $container) - { - $container->getCompilerPassConfig()->setOptimizationPasses([]); - $container->getCompilerPassConfig()->setRemovingPasses([]); - $container->getCompilerPassConfig()->setAfterRemovingPasses([]); - $container->compile(); - } - - private function loadFromFile(ContainerBuilder $container, $file, $format) - { - $locator = new FileLocator(__DIR__.'/Fixtures/'.$format); - - switch ($format) { - case 'php': - $loader = new PhpFileLoader($container, $locator); - break; - case 'xml': - $loader = new XmlFileLoader($container, $locator); - break; - case 'yml': - $loader = new YamlFileLoader($container, $locator); - break; - default: - throw new \InvalidArgumentException(sprintf('Unsupported format: "%s"', $format)); - } - - $loader->load($file.'.'.$format); - } -} diff --git a/lib/symfony/twig-bundle/Tests/Fixtures/templates/BarBundle/Resources/views/index.html.twig b/lib/symfony/twig-bundle/Tests/Fixtures/templates/BarBundle/Resources/views/index.html.twig deleted file mode 100644 index 1975b0e15..000000000 --- a/lib/symfony/twig-bundle/Tests/Fixtures/templates/BarBundle/Resources/views/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# Twig template #} diff --git a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Foo/index.html.twig b/lib/symfony/twig-bundle/Tests/Fixtures/templates/Foo/index.html.twig deleted file mode 100644 index 1975b0e15..000000000 --- a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Foo/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# Twig template #} diff --git a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/BarBundle/views/base.html.twig b/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/BarBundle/views/base.html.twig deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/layout.html.twig b/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/layout.html.twig deleted file mode 100644 index 1975b0e15..000000000 --- a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/layout.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# Twig template #} diff --git a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/sub/sub.html.twig b/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/sub/sub.html.twig deleted file mode 100644 index 1975b0e15..000000000 --- a/lib/symfony/twig-bundle/Tests/Fixtures/templates/Resources/views/sub/sub.html.twig +++ /dev/null @@ -1 +0,0 @@ -{# Twig template #} diff --git a/lib/symfony/twig-bundle/Tests/Functional/CacheWarmingTest.php b/lib/symfony/twig-bundle/Tests/Functional/CacheWarmingTest.php deleted file mode 100644 index 63710a8e1..000000000 --- a/lib/symfony/twig-bundle/Tests/Functional/CacheWarmingTest.php +++ /dev/null @@ -1,124 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Functional; - -use Symfony\Bundle\FrameworkBundle\FrameworkBundle; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\TwigBundle; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Kernel; - -class CacheWarmingTest extends TestCase -{ - public function testCacheIsProperlyWarmedWhenTemplatingIsAvailable() - { - $kernel = new CacheWarmingKernel(true); - $kernel->boot(); - - $warmer = $kernel->getContainer()->get('cache_warmer'); - $warmer->enableOptionalWarmers(); - $warmer->warmUp($kernel->getCacheDir()); - - $this->assertFileExists($kernel->getCacheDir().'/twig'); - } - - public function testCacheIsProperlyWarmedWhenTemplatingIsDisabled() - { - $kernel = new CacheWarmingKernel(false); - $kernel->boot(); - - $warmer = $kernel->getContainer()->get('cache_warmer'); - $warmer->enableOptionalWarmers(); - $warmer->warmUp($kernel->getCacheDir()); - - $this->assertFileExists($kernel->getCacheDir().'/twig'); - } - - protected function setUp() - { - $this->deleteTempDir(); - } - - protected function tearDown() - { - $this->deleteTempDir(); - } - - private function deleteTempDir() - { - if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel')) { - return; - } - - $fs = new Filesystem(); - $fs->remove($dir); - } -} - -class CacheWarmingKernel extends Kernel -{ - private $withTemplating; - - public function __construct($withTemplating) - { - $this->withTemplating = $withTemplating; - - parent::__construct(($withTemplating ? 'with' : 'without').'_templating', true); - } - - public function getName() - { - return 'CacheWarming'; - } - - public function registerBundles() - { - return [new FrameworkBundle(), new TwigBundle()]; - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - $loader->load(function ($container) { - $container->loadFromExtension('framework', [ - 'secret' => '$ecret', - 'form' => ['enabled' => false], - ]); - }); - - if ($this->withTemplating) { - $loader->load(function ($container) { - $container->loadFromExtension('framework', [ - 'secret' => '$ecret', - 'templating' => ['engines' => ['twig']], - 'router' => ['resource' => '%kernel.project_dir%/Resources/config/empty_routing.yml'], - 'form' => ['enabled' => false], - ]); - }); - } - } - - public function getProjectDir() - { - return __DIR__; - } - - public function getCacheDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/cache/'.$this->environment; - } - - public function getLogDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/CacheWarmingKernel/logs'; - } -} diff --git a/lib/symfony/twig-bundle/Tests/Functional/EmptyAppTest.php b/lib/symfony/twig-bundle/Tests/Functional/EmptyAppTest.php deleted file mode 100644 index 86d933b55..000000000 --- a/lib/symfony/twig-bundle/Tests/Functional/EmptyAppTest.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Functional; - -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\TwigBundle; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\HttpKernel\Kernel; - -class EmptyAppTest extends TestCase -{ - public function testBootEmptyApp() - { - $kernel = new EmptyAppKernel('test', true); - $kernel->boot(); - - $this->assertTrue($kernel->getContainer()->hasParameter('twig.default_path')); - $this->assertNotEmpty($kernel->getContainer()->getParameter('twig.default_path')); - } -} - -class EmptyAppKernel extends Kernel -{ - public function registerBundles() - { - return [new TwigBundle()]; - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - } - - public function getCacheDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/cache/'.$this->environment; - } - - public function getLogDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/EmptyAppKernel/logs'; - } -} diff --git a/lib/symfony/twig-bundle/Tests/Functional/NoTemplatingEntryTest.php b/lib/symfony/twig-bundle/Tests/Functional/NoTemplatingEntryTest.php deleted file mode 100644 index 3d509c44e..000000000 --- a/lib/symfony/twig-bundle/Tests/Functional/NoTemplatingEntryTest.php +++ /dev/null @@ -1,80 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Functional; - -use Symfony\Bundle\FrameworkBundle\FrameworkBundle; -use Symfony\Bundle\TwigBundle\Tests\TestCase; -use Symfony\Bundle\TwigBundle\TwigBundle; -use Symfony\Component\Config\Loader\LoaderInterface; -use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\HttpKernel\Kernel; - -class NoTemplatingEntryTest extends TestCase -{ - public function test() - { - $kernel = new NoTemplatingEntryKernel('dev', true); - $kernel->boot(); - - $container = $kernel->getContainer(); - $content = $container->get('twig')->render('index.html.twig'); - $this->assertStringContainsString('{ a: b }', $content); - } - - protected function setUp() - { - $this->deleteTempDir(); - } - - protected function tearDown() - { - $this->deleteTempDir(); - } - - protected function deleteTempDir() - { - if (!file_exists($dir = sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel')) { - return; - } - - $fs = new Filesystem(); - $fs->remove($dir); - } -} - -class NoTemplatingEntryKernel extends Kernel -{ - public function registerBundles() - { - return [new FrameworkBundle(), new TwigBundle()]; - } - - public function registerContainerConfiguration(LoaderInterface $loader) - { - $loader->load(function ($container) { - $container->loadFromExtension('framework', [ - 'secret' => '$ecret', - 'form' => ['enabled' => false], - ]); - }); - } - - public function getCacheDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/cache/'.$this->environment; - } - - public function getLogDir() - { - return sys_get_temp_dir().'/'.Kernel::VERSION.'/NoTemplatingEntryKernel/logs'; - } -} diff --git a/lib/symfony/twig-bundle/Tests/Functional/Resources/config/empty_routing.yml b/lib/symfony/twig-bundle/Tests/Functional/Resources/config/empty_routing.yml deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/symfony/twig-bundle/Tests/Functional/Resources/views/index.html.twig b/lib/symfony/twig-bundle/Tests/Functional/Resources/views/index.html.twig deleted file mode 100644 index ddc4eb440..000000000 --- a/lib/symfony/twig-bundle/Tests/Functional/Resources/views/index.html.twig +++ /dev/null @@ -1 +0,0 @@ -{{ {a: 'b'}|yaml_encode }} diff --git a/lib/symfony/twig-bundle/Tests/Loader/FilesystemLoaderTest.php b/lib/symfony/twig-bundle/Tests/Loader/FilesystemLoaderTest.php deleted file mode 100644 index c8958670a..000000000 --- a/lib/symfony/twig-bundle/Tests/Loader/FilesystemLoaderTest.php +++ /dev/null @@ -1,125 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests\Loader; - -use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference; -use Symfony\Bundle\TwigBundle\Loader\FilesystemLoader; -use Symfony\Bundle\TwigBundle\Tests\TestCase; - -class FilesystemLoaderTest extends TestCase -{ - public function testGetSourceContext() - { - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - $locator - ->expects($this->once()) - ->method('locate') - ->willReturn(__DIR__.'/../DependencyInjection/Fixtures/Resources/views/layout.html.twig') - ; - $loader = new FilesystemLoader($locator, $parser); - $loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views', 'namespace'); - - // Twig-style - $this->assertEquals("This is a layout\n", $loader->getSourceContext('@namespace/layout.html.twig')->getCode()); - - // Symfony-style - $this->assertEquals("This is a layout\n", $loader->getSourceContext('TwigBundle::layout.html.twig')->getCode()); - } - - public function testExists() - { - // should return true for templates that Twig does not find, but Symfony does - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - $locator - ->expects($this->once()) - ->method('locate') - ->willReturn($template = __DIR__.'/../DependencyInjection/Fixtures/Resources/views/layout.html.twig') - ; - $loader = new FilesystemLoader($locator, $parser); - - $this->assertTrue($loader->exists($template)); - } - - public function testTwigErrorIfLocatorThrowsInvalid() - { - $this->expectException('Twig\Error\LoaderError'); - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $parser - ->expects($this->once()) - ->method('parse') - ->with('name.format.engine') - ->willReturn(new TemplateReference('', '', 'name', 'format', 'engine')) - ; - - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - $locator - ->expects($this->once()) - ->method('locate') - ->willThrowException(new \InvalidArgumentException('Unable to find template "NonExistent".')) - ; - - $loader = new FilesystemLoader($locator, $parser); - $loader->getCacheKey('name.format.engine'); - } - - public function testTwigErrorIfLocatorReturnsFalse() - { - $this->expectException('Twig\Error\LoaderError'); - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $parser - ->expects($this->once()) - ->method('parse') - ->with('name.format.engine') - ->willReturn(new TemplateReference('', '', 'name', 'format', 'engine')) - ; - - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - $locator - ->expects($this->once()) - ->method('locate') - ->willReturn(false) - ; - - $loader = new FilesystemLoader($locator, $parser); - $loader->getCacheKey('name.format.engine'); - } - - public function testTwigErrorIfTemplateDoesNotExist() - { - $this->expectException('Twig\Error\LoaderError'); - $this->expectExceptionMessageMatches('/Unable to find template "name\.format\.engine" \(looked into: .*Tests.Loader.\.\..DependencyInjection.Fixtures.Resources.views\)/'); - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - - $loader = new FilesystemLoader($locator, $parser); - $loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views'); - - $method = new \ReflectionMethod('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader', 'findTemplate'); - $method->setAccessible(true); - $method->invoke($loader, 'name.format.engine'); - } - - public function testTwigSoftErrorIfTemplateDoesNotExist() - { - $parser = $this->getMockBuilder('Symfony\Component\Templating\TemplateNameParserInterface')->getMock(); - $locator = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock(); - - $loader = new FilesystemLoader($locator, $parser); - $loader->addPath(__DIR__.'/../DependencyInjection/Fixtures/Resources/views'); - - $method = new \ReflectionMethod('Symfony\Bundle\TwigBundle\Loader\FilesystemLoader', 'findTemplate'); - $method->setAccessible(true); - $this->assertFalse($method->invoke($loader, 'name.format.engine', false)); - } -} diff --git a/lib/symfony/twig-bundle/Tests/TemplateIteratorTest.php b/lib/symfony/twig-bundle/Tests/TemplateIteratorTest.php deleted file mode 100644 index b9092af3e..000000000 --- a/lib/symfony/twig-bundle/Tests/TemplateIteratorTest.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests; - -use Symfony\Bundle\TwigBundle\TemplateIterator; - -class TemplateIteratorTest extends TestCase -{ - public function testGetIterator() - { - $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock(); - $bundle->expects($this->any())->method('getName')->willReturn('BarBundle'); - $bundle->expects($this->any())->method('getPath')->willReturn(__DIR__.'/Fixtures/templates/BarBundle'); - - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Kernel')->disableOriginalConstructor()->getMock(); - $kernel->expects($this->any())->method('getBundles')->willReturn([ - $bundle, - ]); - $iterator = new TemplateIterator($kernel, __DIR__.'/Fixtures/templates', [__DIR__.'/Fixtures/templates/Foo' => 'Foo'], __DIR__.'/DependencyInjection/Fixtures/templates'); - - $sorted = iterator_to_array($iterator); - sort($sorted); - $this->assertEquals( - [ - '@Bar/base.html.twig', - '@Bar/index.html.twig', - '@Bar/layout.html.twig', - '@Foo/index.html.twig', - 'layout.html.twig', - 'sub/sub.html.twig', - ], - $sorted - ); - } -} diff --git a/lib/symfony/twig-bundle/Tests/TestCase.php b/lib/symfony/twig-bundle/Tests/TestCase.php deleted file mode 100644 index 800be3008..000000000 --- a/lib/symfony/twig-bundle/Tests/TestCase.php +++ /dev/null @@ -1,18 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bundle\TwigBundle\Tests; - -use PHPUnit\Framework\TestCase as PHPUnitTestCase; - -class TestCase extends PHPUnitTestCase -{ -}