Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources for Functional Testing #64

Open
laceysanderson opened this issue Mar 22, 2024 · 0 comments
Open

Resources for Functional Testing #64

laceysanderson opened this issue Mar 22, 2024 · 0 comments
Labels
API: Fields TOPIC: Extending Tripal Documentation on developing custom modules, fields, themes, etc.

Comments

@laceysanderson
Copy link
Member

laceysanderson commented Mar 22, 2024

Functional testing should only be used when directly navigating the page virtually through the testing environment. This is done in Drupal by a collection of Drupal methods and the Behat Mink web driver. Here are the resources I use when figuring out which of the multitude of methods available to me fit my needs:

Note: these links are for a development version of the Drupal api docs since the official site doesn't show all pages well.

  • BrowserTestBase: This is the class all our Chado functional tests are based off of. As such all of these functions can be used via $this->METHOD().
  • UiHelperTrait: This class helps with navigating pages and specifically forms. It is included by default in the browser base so all of these functions can be used via $this->METHOD().
  • WebAssert: This class provides assertions specific to the page. These methods are accessed through the UiHelperTrait::assertSession() as follows $this->assertSession()->METHOD().
  • FieldUiTestTrait: This class is specifically for testing fields through the UI. I have not tested this approach but want to save it here so I don't lose it. This trait would need to be added to your test class via a use statement.
  • Behat Mink: Traversing Pages: This documentation shows you how to use the mink browser controller directly to find specific fields. These methods are accessed by using $this->getSession() to get a MinkSession or $this->getSession()->getPage() to get a TraversableElement.

Additionally, here are some examples of functional tests in Drupal that I'm using to piece all this together.

  • EntityReferenceAdminTest: This is a functional test that walks through a variety of forms while testing the Drupal Entity Reference field.
  • MediaThumbnailFormatterTest: This is a functional test that creates a Media Reference field programatically and then tests a content edit page, I think? But is from DRUPAL 9
@laceysanderson laceysanderson added TOPIC: Extending Tripal Documentation on developing custom modules, fields, themes, etc. API: Fields labels Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Fields TOPIC: Extending Tripal Documentation on developing custom modules, fields, themes, etc.
Projects
None yet
Development

No branches or pull requests

1 participant