Skip to content

Drupal module used to alter existing site content and other configurations when running tests.

License

Notifications You must be signed in to change notification settings

AlexSkrypnyk/testmode

Repository files navigation

Test mode

Testmode

GitHub Issues GitHub Pull Requests CircleCI GitHub release (latest by date) LICENSE Renovate

Drupal 9 Drupal 10 Drupal 11


This Drupal module is designed to modify existing site content and configurations while running tests.

Features

This is a module to support testing, so it is not expected to be used in production (although, it adheres to Drupal coding standards and has good test coverage).

Installation

composer require drupal/testmode

Use case

Running a Behat test on the site with existing content may result in false-positives because of the live content being mixed with the test content.

Example: list of 3 featured articles. When the test creates 3 articles and makes them featured, there may be existing featured articles that will confuse tests resulting in a false-positive failure.

How it works

  1. When writing Behat tests, all test content items (nodes, terms, users) follow specific pattern. For example, node titles start with [TEST] .
  2. A machine name of a view, which needs to be tested, is added to Testmode configuration form.
  3. Behat test tagged with @testmode will put the site in test mode that will filter-out all items in the view that do not fit the pattern, leaving only content items created by the test.

Maintenance / Development

Releases in GitHub are automatically pushed to http://drupal.org/project/testmode by CI.

Issues

https://www.drupal.org/project/issues/testmode

Local development

Provided that you have PHP installed locally, you can develop an extension using the provided scripts.

Build

Run .devtools/buid.sh (or ahoy build if Ahoy is installed) to start inbuilt PHP server locally and run the same commands as in CI, plus installing a site and your extension automatically.

Code linting

Run tools individually (or ahoy lint to run all tools if Ahoy is installed) to lint your code according to the Drupal coding standards.

cd build

vendor/bin/phpcs
vendor/bin/phpstan
vendor/bin/rector --clear-cache --dry-run
vendor/bin/phpmd . text phpmd.xml
vendor/bin/twig-cs-fixer
  • PHPCS config: phpcs.xml
  • PHPStan config: phpstan.neon
  • PHPMD config: phpmd.xml
  • Rector config: rector.php
  • Twig CS Fixer config: .twig-cs-fixer.php
  • Patches can be applied to the dependencies: add a patch to the patches section of composer.json. Local patches will be sourced from the patches directory.

Tests

Run tests individually with cd build && ./vendor/bin/phpunit (or ahoy test if Ahoy is installed) to run all test for your extension.

Browsing SQLite database

To browse the contents of created SQLite database (located at /tmp/site_[EXTENSION_NAME].sqlite), use DB Browser for SQLite.

About

Drupal module used to alter existing site content and other configurations when running tests.

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages