一键导入
drupal-kernel
Drupal Kernel tests with KernelTestBase — testing services, database operations, hooks, and entity operations with minimal Drupal bootstrap.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Drupal Kernel tests with KernelTestBase — testing services, database operations, hooks, and entity operations with minimal Drupal bootstrap.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
HTMX in Drupal 11.3+ core — the Htmx PHP fluent builder, dynamic forms with swapOob, partial routes with _htmx_route, response headers, and Drupal.behaviors integration. Use when building interactive UI without full-page reloads using Drupal's native HTMX support.
DDEV local development expertise. Use when working with DDEV projects, containers, configuration, or troubleshooting DDEV environments.
Custom Docker Compose local development patterns. Use when working with Docker-based local environments, container configuration, or troubleshooting Docker setups.
Drupal access control — permissions.yml, access callbacks, AccessResult, custom access checkers, and entity access.
Drupal Cache API — cache tags, contexts, max-age, cache bins, invalidation, and adding cache metadata to render arrays.
Drupal Composer management — requiring modules, updates, patches via composer-patches, and version constraints.
| name | drupal-kernel |
| description | Drupal Kernel tests with KernelTestBase — testing services, database operations, hooks, and entity operations with minimal Drupal bootstrap. |
// tests/src/Kernel/MyServiceTest.php
namespace Drupal\Tests\my_module\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
/**
* Tests MyService integration.
*
* @group my_module
*/
final class MyServiceTest extends KernelTestBase {
protected static $modules = [
'system',
'user',
'node',
'field',
'text',
'my_module',
];
protected function setUp(): void {
parent::setUp();
$this->installSchema('system', ['sequences']);
$this->installSchema('node', ['node_access']);
$this->installEntitySchema('user');
$this->installEntitySchema('node');
$this->installConfig('my_module');
// Create content type
NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
}
public function testServiceProcessesNode(): void {
$node = Node::create([
'type' => 'article',
'title' => 'Test Node',
'status' => 1,
]);
$node->save();
$service = $this->container->get('my_module.my_service');
$result = $service->process($node);
$this->assertTrue($result);
}
}
// For entity types (creates entity tables)
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installEntitySchema('taxonomy_term');
$this->installEntitySchema('paragraph');
// For specific table schemas (not entity-based)
$this->installSchema('system', ['sequences', 'key_value']);
$this->installSchema('node', ['node_access']);
// For config from a module's config/install
$this->installConfig('my_module');
$this->installConfig(['node', 'user']);
use Drupal\user\Entity\User;
$user = User::create([
'name' => 'test_user',
'mail' => 'test@example.com',
'status' => 1,
]);
$user->save();
// Set as current user
$this->setCurrentUser($user);
$config = $this->config('my_module.settings');
$this->assertTrue($config->get('enabled'));
// Update config
$this->config('my_module.settings')
->set('enabled', FALSE)
->save();
public function testHookNodePresave(): void {
$node = Node::create(['type' => 'article', 'title' => 'Test']);
$node->save();
// Reload to verify hook ran
$node = Node::load($node->id());
$this->assertEquals('Modified by hook', $node->get('field_processed')->value);
}