Skip to content

Writing tests

ekes edited this page Jun 4, 2020 · 1 revision

Creating entities to use in tests

Suggestion from localgovdrupal/localgov_core#8

If the test is checking what happens with an entity to make the entity use *CreationTraits like NodeCreationTrait, ContentTypeCreationTrait, BlockCreationTrait... in preference to posting the form in the UI.

Testing creating entities

Another suggestion for review. If the test is to actually check the creation of an entity, fill in the form explicitly field by field 'as a user' using the Mink Session:

Drupal\Tests\BrowserTestBase::getSession()::getPage() and then any of the methods like fillField, selectFieldOptions, checkField, pressButton... more details in the docs.

This rather than automating all the fields together with drupalPostForm.

Example PagesIntegrationTest probably not the best example, but to hand, please for a better commented exclusively form example.