Skip to content

Commit

Permalink
Adopt func tests to be compatible with TYPO3 13 again (#146)
Browse files Browse the repository at this point in the history
* Update func tests to be compatible with TYPO3 13 again

* Update lines mentioned by php-cs-fixer
  • Loading branch information
sfroemkenjw authored Sep 5, 2024
1 parent d05197c commit ddeb8eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Tests/Functional/Domain/Repository/CommentRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

use PHPUnit\Framework\Attributes\Test;
use T3docs\BlogExample\Domain\Repository\CommentRepository;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

final class CommentRepositoryTest extends FunctionalTestCase
Expand All @@ -36,6 +39,11 @@ protected function setUp(): void

$this->importCSVDataSet(__DIR__ . '/../../Fixtures/tx_blogexample_domain_model_comment.csv');

// Init ConfigurationManagerInterface stateful singleton, usually done by extbase bootstrap
$this->get(ConfigurationManagerInterface::class)->setRequest(
(new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE),
);

// Must be called with "makeInstance", else "initializeObject" will not be called
$this->subject = GeneralUtility::makeInstance(CommentRepository::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
use PHPUnit\Framework\Attributes\Test;
use T3docs\BlogExample\Domain\Model\Comment;
use T3docs\BlogExample\Property\TypeConverters\HiddenCommentConverter;
use TYPO3\CMS\Core\Core\SystemEnvironmentBuilder;
use TYPO3\CMS\Core\Http\ServerRequest;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;

class HiddenCommentConverterTest extends FunctionalTestCase
Expand All @@ -37,6 +40,11 @@ protected function setUp(): void

$this->importCSVDataSet(__DIR__ . '/../../Fixtures/tx_blogexample_domain_model_comment.csv');

// Init ConfigurationManagerInterface stateful singleton, usually done by extbase bootstrap
$this->get(ConfigurationManagerInterface::class)->setRequest(
(new ServerRequest())->withAttribute('applicationType', SystemEnvironmentBuilder::REQUESTTYPE_BE),
);

// Must be called with "makeInstance", else the "inject" methods will not be called
$this->subject = GeneralUtility::makeInstance(HiddenCommentConverter::class);
}
Expand Down
9 changes: 5 additions & 4 deletions Tests/Functional/ViewHelpers/GravatarViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
use T3docs\BlogExample\ViewHelpers\GravatarViewHelper;
use TYPO3\CMS\Core\Http\UriFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;

class GravatarViewHelperTest extends FunctionalTestCase
{
Expand Down Expand Up @@ -82,15 +83,15 @@ public static function renderDataProvider(): array
#[Test]
public function render(string $templateSource, string $expected): void
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplateSource(sprintf(
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource(sprintf(
$this->getFluidTemplateSource(),
$templateSource,
));

self::assertSame(
$expected,
$view->render(),
(new TemplateView($context))->render(),
);
}

Expand Down

0 comments on commit ddeb8eb

Please sign in to comment.