test
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseActivityPub Testing
ActivityPub测试
This skill provides guidance on writing and running tests for the WordPress ActivityPub plugin.
这个Skill为WordPress ActivityPub插件的测试编写与运行提供指导。
Quick Reference
快速参考
For complete testing commands and environment setup, see Testing Reference.
完整的测试命令与环境配置说明,请查看测试参考文档。
Key Commands
核心命令
- PHP:
npm run env-test - E2E:
npm run test:e2e - JavaScript:
npm run test:unit
- PHP:
npm run env-test - E2E:
npm run test:e2e - JavaScript:
npm run test:unit
PHPUnit Testing
PHPUnit测试
Test Structure
测试结构
php
<?php
namespace Activitypub\Tests;
use WP_UnitTestCase;
class Test_Feature extends WP_UnitTestCase {
public function set_up(): void {
parent::set_up();
// Setup
}
public function tear_down(): void {
// Cleanup
parent::tear_down();
}
public function test_functionality() {
// Test implementation
}
}php
<?php
namespace Activitypub\Tests;
use WP_UnitTestCase;
class Test_Feature extends WP_UnitTestCase {
public function set_up(): void {
parent::set_up();
// Setup
}
public function tear_down(): void {
// Cleanup
parent::tear_down();
}
public function test_functionality() {
// Test implementation
}
}Common Test Patterns
常用测试模式
For transformer and handler testing patterns, see Testing Reference - Writing Effective Tests.
For mocking HTTP requests and other utilities, see Testing Reference - Test Utilities.
关于转换器和处理器的测试模式,请查看测试参考 - 编写有效测试。
关于模拟HTTP请求和其他工具方法,请查看测试参考 - 测试工具。
Test Groups
测试分组
Use annotations:
@groupphp
/**
* @group activitypub
* @group federation
*/
public function test_federation_feature() {
// Test code
}使用注解:
@groupphp
/**
* @group activitypub
* @group federation
*/
public function test_federation_feature() {
// Test code
}E2E Testing with Playwright
基于Playwright的E2E测试
Basic E2E Test
基础E2E测试
javascript
const { test, expect } = require('@playwright/test');
test('ActivityPub settings page loads', async ({ page }) => {
await page.goto('/wp-admin/options-general.php?page=activitypub');
await expect(page.locator('h1')).toContainText('ActivityPub');
});javascript
const { test, expect } = require('@playwright/test');
test('ActivityPub settings page loads', async ({ page }) => {
await page.goto('/wp-admin/options-general.php?page=activitypub');
await expect(page.locator('h1')).toContainText('ActivityPub');
});Testing Federation
联邦功能测试
javascript
test('WebFinger discovery works', async ({ page }) => {
const response = await page.request.get('/.well-known/webfinger', {
params: {
resource: 'acct:admin@localhost:8888'
}
});
expect(response.ok()).toBeTruthy();
const json = await response.json();
expect(json.subject).toBe('acct:admin@localhost:8888');
});javascript
test('WebFinger discovery works', async ({ page }) => {
const response = await page.request.get('/.well-known/webfinger', {
params: {
resource: 'acct:admin@localhost:8888'
}
});
expect(response.ok()).toBeTruthy();
const json = await response.json();
expect(json.subject).toBe('acct:admin@localhost:8888');
});Test Data Factories
测试数据工厂
For creating test data (users, posts, comments), see Testing Reference - Test Utilities.
如需创建测试数据(用户、帖子、评论),请查看测试参考 - 测试工具。
Coverage Reports
覆盖率报告
See Testing Reference for detailed coverage generation instructions.
详细的覆盖率生成说明请查看测试参考文档。
Debugging Tests
测试调试
Debug Output
调试输出
php
// In tests
var_dump( $data );
error_log( print_r( $result, true ) );
// Run with verbose
npm run env-test -- --verbose --debugphp
// In tests
var_dump( $data );
error_log( print_r( $result, true ) );
// Run with verbose
npm run env-test -- --verbose --debugIsolating Tests
隔离测试
bash
undefinedbash
undefinedRun single test method
Run single test method
npm run env-test -- --filter=test_specific_method
npm run env-test -- --filter=test_specific_method
Stop on first failure
Stop on first failure
npm run env-test -- --stop-on-failure
undefinednpm run env-test -- --stop-on-failure
undefined