Skip to content

Commit

Permalink
expect self deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vo committed Apr 9, 2022
1 parent 9ad7872 commit 23fecb1
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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');
Expand All @@ -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']);
Expand All @@ -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);
Expand All @@ -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');
Expand All @@ -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'])]);
Expand All @@ -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'])]);
Expand All @@ -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');
Expand All @@ -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']);
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,30 @@
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;
use Symfony\Component\HttpFoundation\Response;

class MarkdownControllerTest extends TestCase
{
use ExpectDeprecationTrait;

protected function tearDown(): void
{
$this->resetStaticProperties([System::class]);

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('<h1>Headline</h1>'."\n");

$contentModel = $this->mockClassWithProperties(ContentModel::class);
Expand All @@ -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'
<h1>Headline</h1>
&lt;iframe src&#61;&#34;https://example.com&#34;&#62;&lt;/iframe&#62;
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,23 @@
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;
use Symfony\Component\HttpFoundation\Response;

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'],
Expand All @@ -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);
Expand All @@ -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'],
Expand Down

0 comments on commit 23fecb1

Please sign in to comment.