test

Các mẫu kiểm thử cho PHPUnit và Playwright E2E. Sử dụng khi viết bài kiểm thử, gỡ lỗi lỗi kiểm thử, thiết lập phạm vi kiểm thử, hoặc triển khai các mẫu kiểm thử…

npx skills add https://github.com/automattic/wordpress-activitypub --skill test

ActivityPub Testing

This skill provides guidance on writing and running tests for the WordPress ActivityPub plugin.

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

PHPUnit Testing

Test Structure

<?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.

Test Groups

Use @group annotations:

/**
 * @group activitypub
 * @group federation
 */
public function test_federation_feature() {
    // Test code
}

E2E Testing with Playwright

Basic E2E Test

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

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

// In tests
var_dump( $data );
error_log( print_r( $result, true ) );

// Run with verbose
npm run env-test -- --verbose --debug

Isolating Tests

# Run single test method
npm run env-test -- --filter=test_specific_method

# Stop on first failure
npm run env-test -- --stop-on-failure

Thêm skills từ automattic

wp-phpstan
automattic
Sử dụng khi cấu hình, chạy hoặc sửa lỗi phân tích tĩnh PHPStan trong các dự án WordPress (plugin/giao diện/trang web): thiết lập phpstan.neon, baselines,…
official
wp-playground
automattic
Sử dụng cho quy trình làm việc WordPress Playground: các phiên bản WP nhanh, dùng một lần trong trình duyệt hoặc cục bộ qua @wp-playground/cli (server, run-blueprint, build-snapshot),…
official
wp-plugin-development
automattic
Sử dụng khi phát triển plugin WordPress: kiến trúc và hooks, kích hoạt/hủy kích hoạt/gỡ cài đặt, giao diện quản trị và Settings API, lưu trữ dữ liệu, cron/tác vụ, bảo mật…
official
wp-project-triage
automattic
Sử dụng khi bạn cần kiểm tra xác định một kho lưu trữ WordPress (plugin/theme/block theme/WP core/Gutenberg/full site) bao gồm công cụ/kiểm tra/phiên bản…
official
wp-rest-api
automattic
Sử dụng khi xây dựng, mở rộng hoặc gỡ lỗi các endpoint/route của WordPress REST API: register_rest_route, các lớp WP_REST_Controller/controller, schema/argument…
official
wp-wpcli-and-ops
automattic
Sử dụng khi làm việc với WP-CLI (wp) cho các thao tác WordPress: tìm kiếm-thay thế an toàn, xuất/nhập db, quản lý plugin/chủ đề/người dùng/nội dung, cron, xóa bộ nhớ đệm,…
official
wpds
automattic
Sử dụng khi xây dựng giao diện người dùng dựa trên Hệ thống Thiết kế WordPress (WPDS) và các thành phần, token, mẫu thiết kế của nó.
official
woocommerce-finalize
automattic
Kiểm tra sức khỏe mã nguồn và khả năng truy vết trước khi phát hành cho các plugin WooCommerce. Chạy sau khi đánh giá mã -- tập trung vào mã chết, trùng lặp, độ phức tạp cấu trúc, và…
official