Skip to content

Commit

Permalink
TASK: Add test for fusion plugin rendering another fusion view
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Oct 20, 2024
1 parent 8b93bcc commit 0985b84
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
13 changes: 13 additions & 0 deletions Neos.Neos/Tests/Behavior/Features/Bootstrap/DispatcherTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\CRTestSuiteRuntimeVariables;
use Neos\Fusion\Core\Cache\ContentCache;
use Neos\Neos\Domain\Service\FusionService;
use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\Assert;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestFactoryInterface;
Expand Down Expand Up @@ -47,6 +48,18 @@ public function setupDispatcherTest(): void
$this->response = null;
}

/**
* @When I have the following Fusion file :fileName:
*/
public function iHaveTheFollowingFusionFile(PyStringNode $fusionCode, string $fileName)
{
if (!str_starts_with($fileName, 'vfs://fusion/')) {
throw new \InvalidArgumentException('Fusion file name must be virtual.');
}
vfsStream::setup('fusion');
file_put_contents($fileName, $fusionCode->getRaw());
}

/**
* @When the sites Fusion code is:
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Feature: Tests for sub-request on the frontend node controller in case of the "N
return "list\nmyPluginProp: $myPluginProp\nuri to show: $uri";
}
public function showAction() // string $propToOtherAction doesnt work because the object is not proxied
public function showAction() // string $item doesnt work because the object is not proxied
{
$myPluginProp = $this->request->getInternalArgument('__myPluginProp');
$item = $this->request->getArgument('item');
Expand Down Expand Up @@ -118,6 +118,7 @@ Feature: Tests for sub-request on the frontend node controller in case of the "N
public static function getPublicActionMethods($objectManager)
{
// hack, as this class is not proxied reflection doesnt work and doesnt return the desired public action methods
return array_fill_keys(get_class_methods(get_called_class()), true);
}
}
Expand Down Expand Up @@ -227,3 +228,69 @@ Feature: Tests for sub-request on the frontend node controller in case of the "N
body:
body contents
"""

Scenario: Default output
When I have the following Fusion file "vfs://fusion/Root.fusion":
"""
Vendor.Site.MyPluginWithFusionController.render = 'hello from the plugins fusion view'
"""

When I declare the following controller 'Vendor\Site\Controller\MyPluginWithFusionController':
"""php
// <?php
namespace Vendor\Site\Controller;
use Neos\Flow\Mvc\View\ViewInterface;
use Neos\Flow\Mvc\Controller\ActionController;
use Neos\Fusion\View\FusionView;
class MyPluginWithFusionController extends ActionController
{
protected $defaultViewObjectName = FusionView::class;
public function initializeView(ViewInterface $view)
{
$view->setOption('fusionPathPatterns', ['vfs://fusion/Root.fusion']);
}
public function renderAction()
{
}
public static function getPublicActionMethods($objectManager)
{
// hack, as this class is not proxied reflection doesnt work and doesnt return the desired public action methods
return array_fill_keys(get_class_methods(get_called_class()), true);
}
}
"""

When the sites Fusion code is:
"""fusion
prototype(Neos.Neos:Test.DocumentType) < prototype(Neos.Fusion:Component) {
renderer = afx`
title: {node.properties.title}{String.chr(10)}
body:{String.chr(10)}
<Neos.Neos:ContentCase @context.node={q(node).children().get(0)} />
`
}
prototype(Neos.Neos:Content.MyPlugin) < prototype(Neos.Neos:Plugin) {
package = 'Vendor.Site'
controller = 'MyPluginWithFusion'
action = 'render'
}
"""

When I dispatch the following request "/a1"
Then I expect the following response:
"""
HTTP/1.1 200 OK
Content-Type: text/html
X-Flow-Powered: Flow/dev Neos/dev
title: Node a1
body:
hello from the plugins fusion view
"""

0 comments on commit 0985b84

Please sign in to comment.