test

โดย automattic

รูปแบบการทดสอบสำหรับ PHPUnit และ Playwright E2E tests ใช้เมื่อเขียนทดสอบ แก้ไขข้อผิดพลาดในการทดสอบ ตั้งค่าความครอบคลุมการทดสอบ หรือนำรูปแบบการทดสอบไปใช้งาน…

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

Skills เพิ่มเติมจาก automattic

testing-js
automattic
แนวทางสำหรับการตรวจสอบไฟล์ JavaScript เพื่อหาข้อผิดพลาดทางไวยากรณ์
setup
automattic
ตรวจสอบว่า dn CLI ได้ถูกติดตั้งและกำหนดค่าแล้ว ใช้เมื่อผู้ใช้ติดตั้งปลั๊กอิน domain-names เป็นครั้งแรก หรือเมื่อคำสั่ง dn ล้มเหลวเนื่องจาก CLI ยัง...
studio-cli
automattic
ใช้ Studio CLI เพื่อจัดการไซต์ WordPress ในพื้นที่ การยืนยันตัวตน และไซต์ตัวอย่าง เรียกใช้สกิลนี้เมื่อคุณต้องการรันคำสั่ง Studio CLI จัดการ…
dn-info
automattic
รับข้อมูลรายละเอียดของโดเมนที่ลงทะเบียนโดยใช้ dn CLI ใช้เมื่อผู้ใช้ต้องการดูรายละเอียดโดเมน เช่น วันหมดอายุ เนมเซิร์ฟเวอร์ ผู้ติดต่อ…
qa
automattic
เปรียบเทียบเนื้อหา WXR ที่แยกออกมากับหน้าเว็บไซต์ต้นฉบับทีละหน้า ค้นหาข้อความ หัวข้อ รูปภาพ และลิงก์ที่หายไป แก้ไขโดยการแพตช์ WXR หรือ…
add-skill
automattic
เพิ่มทักษะใหม่ให้กับปลั๊กอิน a8c-design ใช้เมื่อคุณได้สร้างทักษะ Claude Code และต้องการนำไปร่วมในปลั๊กอิน Automattic a8c-design ที่ใช้ร่วมกัน —…
design-foundations
automattic
สร้าง design-foundation JSON ที่สอดคล้องกันจากไซต์ที่ถูกปลดปล่อย — บทบาทสี/ตัวอักษร/ระยะห่างเชิงความหมายพร้อมหลักฐานประกอบ ใช้โครงร่างบางส่วน…
wp-phpstan
automattic
ใช้เมื่อกำหนดค่า เรียกใช้ หรือแก้ไขการวิเคราะห์แบบสแตติกของ PHPStan ในโปรเจกต์ WordPress (ปลั๊กอิน/ธีม/ไซต์): การตั้งค่า phpstan.neon, เบสไลน์,…