Skip to content

Add a Fluid view helper and write a functional test for it #2168

Description

@cumuru

Story

As an integrator, I want a view helper that eases my templates or adds some cool new functionality, because the developer wants to add their test for it ;)

As a developer, I want to have an example for a good view helper test so that I can copy from it for my own extension when I create custom view helpers there.

Acceptance criteria

  • New custom view helper created and used somewhere in the Fluid templates
  • Functional test that asserts the view helper‘s output
  • Test method with #[DataProvider] attribute to show how to test the VH for various input variants

Additional information

This is the code for the functional test I came up with in my own project, maybe it helps. Putting it here so it doesn‘t get lost:

        $template = '{namespace tea=TTN\\Tea\\ViewHelpers}<tea:my.viewHelper attribute="{attribute}">{content}</tea:my.viewHelper>';
        /** @var FluidViewAdapter $view */
        $view = GeneralUtility::makeInstance(ViewFactoryInterface::class)
            ->create(new ViewFactoryData());
        $view->getRenderingContext()->getTemplatePaths()->setTemplateSource($template);
        $view->assignMultiple([
            'attribute' => $attribute,
            'content' => $content,
        ]);
        $result = $view->render();
        $this->assertSame('Expected result', $result);

More code examples (still V11-compatible, so might need some adaption):

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions