neos-development-collection icon indicating copy to clipboard operation
neos-development-collection copied to clipboard

9.0 Test, (Refactor) and rename Neos' Fusion View

Open mhsdesign opened this issue 1 year ago • 0 comments

Related: to be overhauled draft pr: https://github.com/neos/neos-development-collection/pull/4495

Wilhelm and me spend some time at the sprint discussing how the fusion view should work in the future and how it would be testable like this:

  Scenario: Page rendering
    Given the current Site package is My.Site
    And Packages Neos.Fusion and Neos.Neos are autoladed:
    When I have the fusion code for the package "My.Site":
    """fusion
    include: resource://Neos.Fusion/Private/Fusion/Root.fusion
    include: resource://Neos.Neos/Private/Fusion/Root.fusion

    prototype(Neos.Neos:Test.DocumentType1) < prototype(Neos.Fusion:Value) {
      value = 'implementation for DocumentType1'
    }
    """
    And i render the current request i expect
    """
    implementation for DocumentType2
    """

Steps

  • rename Neos's FusionView to SiteFusionView
  • extract logic to acquire document node etc to outside
    • by convention node documentNode and site must be passed, but they will be passed straight into the fusion runtime
    • other variables would work as well
    • maybe: throw an error if value is assigned as there is no legacy behaviour for this anymore?
  • the fusion view requires a dynamic variable / or option? siteResourcePackageKey which will be used to include the site package and as cache identifier in production
  • the view will get an additional option 'autoIncludes' => [] which can be configured for testing for example like ['Neos.Neos', 'Neos.Fusion'], if empty the global Neos.Neos.fusion.autoInclude configuration will be used.
  • Introduce package key dto in flow
  • introduce FusionAutoIncludeHandler in Neos.Neos that can be stubbed for testing, but by default checks if the package exits and loads the file from resource://
interface FusionAutoIncludeHandler
{
    public function loadFusionFromPackage(string $packageKey, FusionSourceCodeCollection $sourceCodeCollection): FusionSourceCodeCollection;
}

which will be used like this in the fusion view

$sourceCodeCollection = FusionSourceCodeCollection::empty();
foreach ($this->getOption('autoInclude') ?: array_keys(array_filter($this->fusionAutoIncludeConfiguration, fn ($val) => $val === true)) as $packageKey) {
    $sourceCodeCollection = $this->fusionLoader->loadFusionFromPackage($packageKey, $sourceCodeCollection);
}

in the FusionService - which is discussable if we still need this empty service ... (see @todo reintroduce with edit preview mode support)

public function createFusionConfigurationFromSite(Site $site, FusionSourceCodeCollection $sourceCode): FusionConfiguration
{
    return $this->fusionConfigurationCache->cacheFusionConfigurationBySite($site, function () use ($site, $sourceCode) {
        $siteResourcesPackageKey = $site->getSiteResourcesPackageKey();
        $protypeGenerantorstuff = $this->fusionSourceCodeFactory->createFromNodeTypeDefinitions($site->getConfiguration()->contentRepositoryId);
        return $this->fusionParser->parseFromSource(
            $this->fusionLoader->loadFusionFromPackage(
                $siteResourcesPackageKey,
                $protypeGenerantorstuff
                    ->union($sourceCode)
            )

        );
    });
}

For testing the FusionAutoIncludeHandler will just return either the actual sources for Neos.Neos or fake stuff declared for MyTemp.Package

mhsdesign avatar Mar 12 '24 17:03 mhsdesign