Writing a functional test
Now that we know our code is working, let’s prove that a user can see the formatted string when they visit a node. Functional tests use an emulated browser that allows us to simulate users navigating the site. Functional tests install Drupal and test in an isolated fashion, so there is no risk of corrupting your current Drupal installation.
How to do it…
With a functional test, we can navigate the browser as if we were a real user, navigating and performing all kinds of assertions that unit and kernel tests cannot do. Like before, we do need to set some configurations in place in order to test. Within your tests/src
directory, create a new directory called Functional
, and then create a file inside of it called CamelCaseFormatterDisplayTest.php
.
In this new test file, we are going to borrow some of the setups from the previous kernel test:
<?php namespace Drupal\Tests\chapter13\Functional; use Drupal\Core\Entity\Entity\EntityViewDisplay...