diff --git a/core-bundle/tests/Controller/ContentElement/ContentElementControllerTest.php b/core-bundle/tests/Controller/ContentElement/ContentElementControllerTest.php index 848fed7d4bf..5c6b9512785 100644 --- a/core-bundle/tests/Controller/ContentElement/ContentElementControllerTest.php +++ b/core-bundle/tests/Controller/ContentElement/ContentElementControllerTest.php @@ -22,12 +22,15 @@ use Contao\CoreBundle\Twig\Loader\ContaoFilesystemLoader; use Contao\System; use Symfony\Bridge\PhpUnit\ClockMock; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; class ContentElementControllerTest extends TestCase { + use ExpectDeprecationTrait; + private ContainerBuilder $container; protected function setUp(): void @@ -50,8 +53,13 @@ protected function tearDown(): void parent::tearDown(); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheClassName(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getContentModel(), 'main'); @@ -60,8 +68,13 @@ public function testCreatesTheTemplateFromTheClassName(): void $this->assertSame('ce_test', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheTypeFragmentOptions(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(['type' => 'foo']); $response = $controller(new Request(), $this->getContentModel(), 'main'); @@ -70,8 +83,13 @@ public function testCreatesTheTemplateFromTheTypeFragmentOptions(): void $this->assertSame('ce_foo', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheTemplateFragmentOption(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(['template' => 'ce_bar']); $response = $controller(new Request(), $this->getContentModel(), 'main'); @@ -80,8 +98,13 @@ public function testCreatesTheTemplateFromTheTemplateFragmentOption(): void $this->assertSame('ce_bar', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromACustomTpl(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $this->container->set('request_stack', new RequestStack()); $controller = $this->getTestController(['template' => 'ce_bar']); @@ -94,8 +117,13 @@ public function testCreatesTheTemplateFromACustomTpl(): void $this->assertSame('ce_bar', $template['templateName']); } + /** + * @group legacy + */ public function testDoesNotCreateTheTemplateFromACustomTplInTheBackend(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $request = new Request([], [], ['_scope' => 'backend']); $requestStack = new RequestStack(); $requestStack->push($request); @@ -113,8 +141,13 @@ public function testDoesNotCreateTheTemplateFromACustomTplInTheBackend(): void $this->assertSame('ce_test', $template['templateName']); } + /** + * @group legacy + */ public function testSetsTheClassFromTheType(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getContentModel(), 'main'); @@ -124,8 +157,13 @@ public function testSetsTheClassFromTheType(): void $this->assertSame('ce_test', $template['class']); } + /** + * @group legacy + */ public function testSetsTheHeadlineFromTheModel(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $model = $this->getContentModel(['headline' => serialize(['unit' => 'h6', 'value' => 'foobar'])]); @@ -137,8 +175,13 @@ public function testSetsTheHeadlineFromTheModel(): void $this->assertSame('h6', $template['hl']); } + /** + * @group legacy + */ public function testSetsTheCssIdAndClassFromTheModel(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $model = $this->getContentModel(['cssID' => serialize(['foo', 'bar'])]); @@ -150,8 +193,13 @@ public function testSetsTheCssIdAndClassFromTheModel(): void $this->assertSame('ce_test bar', $template['class']); } + /** + * @group legacy + */ public function testSetsTheLayoutSection(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getContentModel(), 'left'); @@ -160,8 +208,13 @@ public function testSetsTheLayoutSection(): void $this->assertSame('left', $template['inColumn']); } + /** + * @group legacy + */ public function testSetsTheClasses(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getContentModel(), 'main', ['first', 'last']); @@ -224,8 +277,13 @@ public function provideScope(): \Generator yield 'backend' => [true]; } + /** + * @group legacy + */ public function testAddsTheCacheTags(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $model = $this->getContentModel(['id' => 42]); $entityCacheTags = $this->createMock(EntityCacheTags::class); @@ -242,8 +300,13 @@ public function testAddsTheCacheTags(): void $controller(new Request(), $model, 'main'); } + /** + * @group legacy + */ public function testSetsTheSharedMaxAgeIfTheElementHasAStartDate(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + ClockMock::withClockMock(true); $time = time(); @@ -262,8 +325,13 @@ public function testSetsTheSharedMaxAgeIfTheElementHasAStartDate(): void ClockMock::withClockMock(false); } + /** + * @group legacy + */ public function testSetsTheSharedMaxAgeIfTheElementHasAStopDate(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + ClockMock::withClockMock(true); $time = time(); @@ -282,8 +350,13 @@ public function testSetsTheSharedMaxAgeIfTheElementHasAStopDate(): void ClockMock::withClockMock(false); } + /** + * @group legacy + */ public function testDoesNotSetTheSharedMaxAgeIfTheElementHasNeitherAStartNorAStopDate(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = new TestSharedMaxAgeController(); $controller->setContainer($this->container); diff --git a/core-bundle/tests/Controller/ContentElement/MarkdownControllerTest.php b/core-bundle/tests/Controller/ContentElement/MarkdownControllerTest.php index ce0e728e7f4..7e48c4707c2 100644 --- a/core-bundle/tests/Controller/ContentElement/MarkdownControllerTest.php +++ b/core-bundle/tests/Controller/ContentElement/MarkdownControllerTest.php @@ -21,6 +21,7 @@ use Contao\FrontendTemplate; use Contao\Input; use Contao\System; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; @@ -28,6 +29,8 @@ class MarkdownControllerTest extends TestCase { + use ExpectDeprecationTrait; + protected function tearDown(): void { $this->resetStaticProperties([System::class]); @@ -35,8 +38,13 @@ protected function tearDown(): void parent::tearDown(); } + /** + * @group legacy + */ public function testWithCodeInput(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $container = $this->mockContainer('

Headline

'."\n"); $contentModel = $this->mockClassWithProperties(ContentModel::class); @@ -48,8 +56,13 @@ public function testWithCodeInput(): void $controller(new Request(), $contentModel, 'main'); } + /** + * @group legacy + */ public function testDisallowedTagsAreCorrectlyStripped(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $expectedHtml = <<<'HTML'

Headline

<iframe src="https://example.com"></iframe> @@ -86,8 +99,13 @@ public function testDisallowedTagsAreCorrectlyStripped(): void $controller(new Request(), $contentModel, 'main'); } + /** + * @group legacy + */ public function testWithFileInput(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $fs = new Filesystem(); $tempTestFile = $fs->tempnam($this->getTempDir(), ''); $fs->dumpFile($tempTestFile, '# Headline'); diff --git a/core-bundle/tests/Controller/ContentElement/TemplateControllerTest.php b/core-bundle/tests/Controller/ContentElement/TemplateControllerTest.php index d9261914b51..3cb7fd737f5 100644 --- a/core-bundle/tests/Controller/ContentElement/TemplateControllerTest.php +++ b/core-bundle/tests/Controller/ContentElement/TemplateControllerTest.php @@ -18,6 +18,7 @@ use Contao\CoreBundle\Routing\ScopeMatcher; use Contao\CoreBundle\Tests\TestCase; use Contao\FrontendTemplate; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -25,8 +26,15 @@ class TemplateControllerTest extends TestCase { + use ExpectDeprecationTrait; + + /** + * @group legacy + */ public function testWithDataInput(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $data = [ ['key' => 'Key 1', 'value' => 'Value 1'], ['key' => 'Key 1', 'value' => 'Value 1'], @@ -43,8 +51,13 @@ public function testWithDataInput(): void $controller(new Request(), $contentModel, 'main'); } + /** + * @group legacy + */ public function testWithoutDataInput(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $container = $this->mockContainer([], 'ce_template'); $contentModel = $this->mockClassWithProperties(ContentModel::class); @@ -56,8 +69,13 @@ public function testWithoutDataInput(): void $controller(new Request(), $contentModel, 'main'); } + /** + * @group legacy + */ public function testWithCustomTemplate(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $data = [ ['key' => 'Key 1', 'value' => 'Value 1'], ['key' => 'Key 1', 'value' => 'Value 1'], diff --git a/core-bundle/tests/Controller/FrontendModule/FrontendModuleControllerTest.php b/core-bundle/tests/Controller/FrontendModule/FrontendModuleControllerTest.php index e0601f36dd6..12322c3b949 100644 --- a/core-bundle/tests/Controller/FrontendModule/FrontendModuleControllerTest.php +++ b/core-bundle/tests/Controller/FrontendModule/FrontendModuleControllerTest.php @@ -22,6 +22,7 @@ use Contao\CoreBundle\Twig\Loader\ContaoFilesystemLoader; use Contao\ModuleModel; use Contao\System; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -29,6 +30,8 @@ class FrontendModuleControllerTest extends TestCase { + use ExpectDeprecationTrait; + private ContainerBuilder $container; protected function setUp(): void @@ -50,8 +53,13 @@ protected function tearDown(): void parent::tearDown(); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheClassName(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request([], [], ['_scope' => 'frontend']), $this->getModuleModel(), 'main'); @@ -60,8 +68,13 @@ public function testCreatesTheTemplateFromTheClassName(): void $this->assertSame('mod_test', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheTypeFragmentOption(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(['type' => 'foo']); $response = $controller(new Request(), $this->getModuleModel(), 'main'); @@ -70,8 +83,13 @@ public function testCreatesTheTemplateFromTheTypeFragmentOption(): void $this->assertSame('mod_foo', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromTheTemplateFragmentOption(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(['template' => 'mod_bar']); $response = $controller(new Request(), $this->getModuleModel(), 'main'); @@ -80,8 +98,13 @@ public function testCreatesTheTemplateFromTheTemplateFragmentOption(): void $this->assertSame('mod_bar', $template['templateName']); } + /** + * @group legacy + */ public function testCreatesTheTemplateFromACustomTpl(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $this->container->set('request_stack', new RequestStack()); $controller = $this->getTestController(); @@ -94,8 +117,13 @@ public function testCreatesTheTemplateFromACustomTpl(): void $this->assertSame('mod_bar', $template['templateName']); } + /** + * @group legacy + */ public function testSetsTheClassFromTheType(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getModuleModel(), 'main'); @@ -105,8 +133,13 @@ public function testSetsTheClassFromTheType(): void $this->assertSame('mod_test', $template['class']); } + /** + * @group legacy + */ public function testSetsTheHeadlineFromTheModel(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $model = $this->getModuleModel(['headline' => serialize(['unit' => 'h6', 'value' => 'foobar'])]); @@ -118,8 +151,13 @@ public function testSetsTheHeadlineFromTheModel(): void $this->assertSame('h6', $template['hl']); } + /** + * @group legacy + */ public function testSetsTheCssIdAndClassFromTheModel(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $model = $this->getModuleModel(['cssID' => serialize(['foo', 'bar'])]); @@ -131,8 +169,13 @@ public function testSetsTheCssIdAndClassFromTheModel(): void $this->assertSame('mod_test bar', $template['class']); } + /** + * @group legacy + */ public function testSetsTheLayoutSection(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $controller = $this->getTestController(); $response = $controller(new Request(), $this->getModuleModel(), 'left'); @@ -248,8 +291,13 @@ public function provideScope(): \Generator yield 'backend' => [true]; } + /** + * @group legacy + */ public function testAddsTheCacheTags(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $model = $this->getModuleModel(); $model->id = 42; diff --git a/core-bundle/tests/Controller/FrontendModule/TwoFactorControllerTest.php b/core-bundle/tests/Controller/FrontendModule/TwoFactorControllerTest.php index 3b93e384a7e..17fae706f88 100644 --- a/core-bundle/tests/Controller/FrontendModule/TwoFactorControllerTest.php +++ b/core-bundle/tests/Controller/FrontendModule/TwoFactorControllerTest.php @@ -26,6 +26,7 @@ use Contao\System; use PHPUnit\Framework\MockObject\MockObject; use Scheb\TwoFactorBundle\Security\Authentication\Exception\InvalidTwoFactorCodeException; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; @@ -38,6 +39,8 @@ class TwoFactorControllerTest extends TestCase { + use ExpectDeprecationTrait; + protected function tearDown(): void { $this->resetStaticProperties([System::class]); @@ -65,8 +68,13 @@ public function testReturnsEmptyResponseIfTheUserIsNotFullyAuthenticated(): void $this->assertSame(204, $response->getStatusCode()); } + /** + * @group legacy + */ public function testReturnsIfTheUserIsNotAFrontendUser(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->createMock(BackendUser::class); $container = $this->getContainerWithFrameworkTemplate( @@ -86,8 +94,13 @@ public function testReturnsIfTheUserIsNotAFrontendUser(): void $this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); } + /** + * @group legacy + */ public function testReturnsAResponseIfTheUserIsAFrontendUser(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = '1'; @@ -111,8 +124,13 @@ public function testReturnsAResponseIfTheUserIsAFrontendUser(): void $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); } + /** + * @group legacy + */ public function testReturnsIfTwoFactorAuthenticationIsAlreadyDisabled(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = ''; @@ -137,8 +155,13 @@ public function testReturnsIfTwoFactorAuthenticationIsAlreadyDisabled(): void $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); } + /** + * @group legacy + */ public function testRedirectsAfterTwoFactorHasBeenDisabled(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = '1'; @@ -182,8 +205,13 @@ public function testRedirectsAfterTwoFactorHasBeenDisabled(): void $this->assertSame('https://localhost.wip/foobar', $response->getTargetUrl()); } + /** + * @group legacy + */ public function testReturnsIfTwoFactorAuthenticationIsAlreadyEnabled(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = '1'; @@ -213,8 +241,13 @@ public function testReturnsIfTwoFactorAuthenticationIsAlreadyEnabled(): void $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); } + /** + * @group legacy + */ public function testFailsIfTheTwoFactorCodeIsInvalid(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = ''; @@ -243,8 +276,13 @@ public function testFailsIfTheTwoFactorCodeIsInvalid(): void $controller($request, $module, 'main', null, $page); } + /** + * @group legacy + */ public function testDoesNotRedirectIfTheTwoFactorCodeIsInvalid(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = ''; @@ -275,8 +313,13 @@ public function testDoesNotRedirectIfTheTwoFactorCodeIsInvalid(): void $controller($request, $module, 'main', null, $page); } + /** + * @group legacy + */ public function testRedirectsIfTheTwoFactorCodeIsValid(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = ''; @@ -314,8 +357,13 @@ public function testRedirectsIfTheTwoFactorCodeIsValid(): void $this->assertInstanceOf(RedirectResponse::class, $response); } + /** + * @group legacy + */ public function testShowsTheBackupCodes(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = '1'; @@ -341,8 +389,13 @@ public function testShowsTheBackupCodes(): void $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); } + /** + * @group legacy + */ public function testGeneratesTheBackupCodes(): void { + $this->expectDeprecation('Since contao/core-bundle 5.0: Creating fragments with legacy templates is deprecated and will not work anymore in Contao 6.'); + $user = $this->mockClassWithProperties(FrontendUser::class); $user->secret = ''; $user->useTwoFactor = '1';