Search code examples
typo3functional-testing

Should I simulate FE request in Functional Testing in TYPO3?


I'm trying to understand concepts of Functional Testing in a scope of TYPO3 and overall.

My intention is to test Controller of my extension. For simplicity let's imagine, that it has only two methods: listAction() and addAction($object).

I've checked some Core tests and one of them was EnableFieldsTest from Extbase, which does following: loads some special crafted extension, simulates FE (via special JsonRenderer.ts), which calls listAction() of that extension and the output (specail JSON) is examined then.

So, I decided to do same with my Controller, simulated FE, which called my listAction(). The only difference is that my extension doesn't use JSON View, but usual Fluid, which produces HTML.

To make it work as expected I need either:

  1. Make significant changes in my extension, so it outputs JSON in Testing context, but this seems kinda hacky for me.
  2. Do not use provided HasRecordConstraint from the Core, but simply examine HTML, that was output with assertContains(), which also seems hacky.
  3. Create customized version of my extension, which outputs expected JSON and use it only as Fixture. But this makes such test useless at all.

Therefore I'm stuck at this point and need to understand:

  1. Is it right to simulate FE request, like I do, or I'm now out of Functional Testing concept?
  2. In case I want to test object creation via addAction($object) and ensure, that f.e. a request to a REST service is made, should I stub that Service or I can catch a call somehow different?

Solution

  • Since TYPO3 8, acceptance tests are integrated which are more the thing you want to have.

    • Use functional tests to call the action and check the return value of that but don't use a frontend
    • Use acceptance tests to call the frontend and check the HTML output of your plugin.

    The best would be to check out the acceptance tests of the core.