Drupal Testing logo

Drupal Testing

Community
grasmash
drupal-testing

Test-driven development for Drupal with PHPUnit and Drupal Test Traits (DTT). Use when writing or fixing tests, reproducing a bug before fixing it, choosing a bootstrap level (Unit vs Kernel vs ExistingSite/functional), testing permission gates, or debugging tests that silently run zero assertions. Covers the bug-fix RED-first discipline, bootstrap cost tradeoffs, the anonymous-403 permission trap, and the PHPUnit-version pin that makes Drupal tests pass vacuously.

Overview

Publishergrasmash
Repositorydrupal-claude-skills
Skill namedrupal-testing
Stars
77
Forks
4
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by grasmash on GitHub. Read the source before you install it.

Installation

Install the Drupal Testing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/grasmash/drupal-claude-skills.git /tmp/drupal-claude-skills
mkdir -p .claude/skills
cp -r /tmp/drupal-claude-skills/skills/drupal-testing .claude/skills/drupal-testing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Drupal Testing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Drupal Testing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Drupal Testing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Drupal Testing (TDD)

Hard-won testing discipline for Drupal. Pairs with the test-writer and test-runner agents — this skill is the how, those agents are the who.

Bug-fix TDD — the RED step is non-negotiable

Every bug fix follows this exact sequence. Skipping step 2 is what makes "fixed" bugs come back.

  1. Write a test that reproduces the bug — exercise the real code path the user hits, not a paraphrase of the suspected logic.
  2. Run it and assert it FAILS, with the symptom matching the report. If it doesn't fail, you haven't reproduced the bug — keep digging until it fails for the right reason. The red-to-green transition is your only proof the test actually exercises the bug; without it, you can't tell whether the test catches the bug or just happens to pass on green.
  3. Fix the production code.
  4. Re-run the same test and assert it now passes.

Pick the lightest bootstrap that fits — it dominates cost

Drupal test base classes differ in bootstrap cost by orders of magnitude. Default to the cheapest one that can express the assertion.

Base classBootstrapUse for
UnitTestCasenone (pure PHP)isolated logic, no Drupal services
KernelTestBaseminimal; declare deps in protected static $modulesservices / business logic in isolation
ExistingSite (DTT ExistingSiteBase)runs against the served site (real config, contrib, field storage)flows that need the full installed site
Functional/BrowserTestBasefull reinstall per testlast resort; very slow

Prefer Unit and Kernel where the logic doesn't need the full site — they're far faster. Within ExistingSite, the cost is not bootstrap; it's drupalLogin() + drupalGet() (real HTTP, ~25s each). Before adding those, ask whether the assertion is about HTTP/auth/redirects or about rendered output:

  • Service logic → call \Drupal::service(...)->method() directly. No HTTP.
  • Template render → build the render array, call \Drupal::service('renderer')->renderInIsolation($build). No HTTP.
  • Entity render → DTT's EntityCrawlerTrait::getRenderedEntityCrawler($entity, $view_mode). No HTTP.
  • Controller wiring, auth, redirectsdrupalLogin + drupalGet. Keep to one smoke test per feature.

Data providers multiply cost: an 11-row matrix × drupalLogin + drupalGet ≈ 5 minutes. Split into a fast service/render matrix plus a single HTTP smoke test.

The anonymous-403 permission trap

A "returns 403 for anonymous" test does not prove a route's _permission is enforced. Two ways it lies:

  1. A route gated with both _user_is_logged_in: TRUE and _permission rejects anonymous on the login gate first — so deleting _permission entirely still passes the anonymous test.
  2. When the gating permission sits on the authenticated role, no logged-in user can ever be denied, so the gate is effectively open.

_permission syntax: + is OR, , is AND.

To actually test the gate, do one of:

  • Log in a user who genuinely lacks the permission and assert 403, or
  • Pin the gate at the route-definition level: assert $route->getRequirement('_permission') equals the expected string, so loosening the gate fails a test.

TDD the guard: strip the permission → confirm RED → restore.

Tests that pass vacuously (the silent-zero trap)

If a whole class of tests suddenly "passes" while running 0 assertions, suspect a PHPUnit-version mismatch, not green code.

  • Drupal core supports a specific PHPUnit major. A wrong pin (e.g. PHPUnit 12 against a core that only supports 11) makes every test extending a Drupal base class (UnitTestCase/KernelTestBase) collect zero tests and exit 0 — there's no compatibility shim, so collection fatals silently. Meanwhile plain \PHPUnit\Framework\TestCase + DTT ExistingSite tests still run, masking the breakage.
  • PHPUnit 10+ uses PHP 8 attributes (#[Group('x')]), not @group docblock annotations. --exclude-group/--group won't match legacy annotations — migrate to attributes.
  • Sanity check: a passing test run should report a non-trivial assertion count. OK (0 tests, 0 assertions) for a suite you know has tests means the runner isn't collecting them.

Verify the real code path locally — passing unit tests aren't enough

For any change to runtime behavior (cron jobs, drush commands, data processing, API endpoints, service logic), execute the changed code path locally and confirm the real-world outcome before declaring it done — don't stop at green unit tests. Run the actual command/service (e.g. via DDEV: ddev drush <command>), then check the resulting state (DB rows, updated field values, emitted output). This catches what tests miss: environment differences, data-dependent bugs, and integration failures across the real installed site. Unit/Kernel tests prove the logic in isolation; only running it proves the wiring.

CI: fix failing tests locally, not by re-pushing

When CI fails on test errors, don't iterate by pushing commits and re-running the full suite (often ~20 min/run):

  1. Identify the failing tests from CI logs.
  2. Reproduce locally (vendor/bin/phpunit --filter Class::method path/to/Test.php).
  3. Fix and run each test individually until green.
  4. Commit.
  5. Only then re-run the full CI suite.

phpcs in test files

  • Section-divider comments (// ---) before a docblock violate both CommentEmptyLine.SpacingAfter and FunctionSpacing.Before. Don't use them in test files.
  • Run vendor/bin/phpcbf <file> to auto-fix before recommitting.

Frequently asked questions

What does the Drupal Testing AI skill do?

Test-driven development for Drupal with PHPUnit and Drupal Test Traits (DTT). Use when writing or fixing tests, reproducing a bug before fixing it, choosing a bootstrap level (Unit vs Kernel vs ExistingSite/functional), testing permission gates, or debugging tests that silently run zero assertions. Covers the bug-fix RED-first discipline, bootstrap cost tradeoffs, the anonymous-403 permission trap, and the PHPUnit-version pin that makes Drupal tests pass vacuously.

Why use Drupal Testing on TypingMind?

Because you install it once and use it with any model. Drupal Testing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Drupal Testing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/grasmash/drupal-claude-skills/tree/main/skills/drupal-testing. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Drupal Testing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Drupal Testing?

As many as you like. As long as a model supports skills, you can use Drupal Testing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Drupal Testing AI skill free?

It is published on GitHub by grasmash. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇