Skip to content

Commit

Permalink
[BUGFIX] Fix extensionlaoded VH #2572
Browse files Browse the repository at this point in the history
  • Loading branch information
georgringer committed Nov 22, 2024
1 parent f534ef9 commit 34f53e1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Classes/ViewHelpers/ExtensionLoadedViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace GeorgRinger\News\ViewHelpers;

use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

class ExtensionLoadedViewHelper extends AbstractConditionViewHelper
Expand All @@ -23,10 +24,7 @@ public function initializeArguments()
parent::initializeArguments();
}

/**
* @param array|null $arguments
*/
protected static function evaluateCondition($arguments = null): bool
public static function verdict(array $arguments, RenderingContextInterface $renderingContext)
{
return ExtensionManagementUtility::isLoaded($arguments['extensionKey']);
}
Expand Down
48 changes: 48 additions & 0 deletions Tests/Functional/ViewHelpers/ExtensionLoadedViewHelperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Functional\ViewHelpers;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\IgnoreDeprecations;
use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContextFactory;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
use TYPO3Fluid\Fluid\View\TemplateView;

class ExtensionLoadedViewHelperTest extends FunctionalTestCase
{

public static function extensionLoadedDataProvider(): array
{
return [
'validExtension' => [
'<n:extensionLoaded extensionKey="core">1</n:extensionLoaded>',
'1',
],
'invalidExtension' => [
'<n:extensionLoaded extensionKey="something">1</n:extensionLoaded>',
'',
],
];
}

#[DataProvider('extensionLoadedDataProvider')]
#[IgnoreDeprecations]
#[Test]
public function extensionLoaded(string $src, string $expected): void
{
$src = '<html xmlns:n="http://typo3.org/ns/GeorgRinger/News/ViewHelpers" data-namespace-typo3-fluid="true">' . $src . '</html>';
$context = $this->get(RenderingContextFactory::class)->create();
$context->getTemplatePaths()->setTemplateSource($src);
self::assertSame($expected, (new TemplateView($context))->render());
}
}

0 comments on commit 34f53e1

Please sign in to comment.