Testing
Automated tests live under tests/. A companion test module provides a sample term plugin.
Test layout
| Path | Type | Coverage |
|---|---|---|
tests/src/Kernel/MembershipTest.php |
Kernel | Membership entity, term plugins, activation, renewal, expiration |
tests/src/Kernel/ListBuilderTest.php |
Kernel | Membership list builder operations (Renew, Membership periods) |
tests/src/Kernel/MembershipTypeAccessControlHandlerTest.php |
Kernel | Membership Type access permissions |
tests/src/Unit/Access/MembershipTypeAccessControlHandlerTest.php |
Unit | Membership Type access handler (isolated) |
tests/src/Unit/ListBuilder/MembershipListBuilderTest.php |
Unit | Membership list builder (isolated) |
tests/src/Unit/ListBuilder/MembershipPeriodListBuilderTest.php |
Unit | Membership period list builder (isolated) |
tests/src/Unit/ListBuilder/MembershipTypeListBuilderTest.php |
Unit | Membership type list builder (isolated) |
tests/src/FunctionalJavascript/MembershipTypeTest.php |
FunctionalJavascript | Membership Type form, plugin config AJAX |
tests/src/TimeMockTrait.php |
Trait | Shared time mocking for kernel tests |
Run tests from a Drupal root with the module installed. See Drupal automated testing for environment setup.
This repository includes a root phpunit.xml targeting web/modules/custom/**/tests:
./vendor/bin/phpunit -c phpunit.xml
For a standard contrib install, use the module path under web/modules/contrib/ instead:
./vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/contrib/crm_membership/tests
Test module: crm_membership_test
Path: tests/crm_membership_test/
Provides Counter term plugin (plugin ID: counter) for kernel tests. Extends MembershipTermBase with custom DI (State service) to track activate/renew/expire call counts.
Enable in test environments only — not for production sites.
Reference: tests/crm_membership_test/src/Plugin/MembershipTerm/Counter.php
Known gaps
- No tests for cron hook expiration logic —
CronHooks::cron()and queue processing are untested. See Roadmap. isExpiredFor()is unimplemented in the base plugin; no dedicated tests for expiration detection via that method.
Contributions adding cron/queue kernel tests are welcome.
Writing new tests
Follow Drupal automated testing conventions:
- Use PHPUnit attributes (
#[Group('crm_membership')], etc.) - Kernel tests for entity + plugin integration
- FunctionalJavascript for admin form AJAX (see
MembershipTypeTest)
When testing custom term plugins, consider enabling crm_membership_test or defining a minimal plugin in your test module.
Related
- Custom plugins — Counter reference implementation
- Cron and queue — Untested expiration pipeline
- Roadmap — Planned test coverage
- Forms and workflows — UI covered by FunctionalJavascript tests