Get the FREE Ultimate OpenClaw Setup Guide →

activitypub-testing

Scanned
npx machina-cli add skill Microck/ordinary-claude-skills/activitypub-testing --openclaw
Files (1)
SKILL.md
2.8 KB

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

Source

git clone https://github.com/Microck/ordinary-claude-skills/blob/main/skills_all/activitypub-testing/SKILL.mdView on GitHub

Overview

This skill guides you through writing and running tests for the WordPress ActivityPub plugin using PHPUnit and Playwright E2E. It covers test structure, patterns, debugging, coverage setup, and federation-focused test workflows.

How This Skill Works

PHPUnit tests follow a WP_UnitTestCase structure with set_up/tear_down and test methods, including group annotations. E2E tests use Playwright to verify admin pages and federation endpoints, demonstrated by basic page load checks and WebFinger tests. The Quick Reference points you to environment commands and Testing Reference docs for patterns and utilities.

When to Use It

  • Writing PHPUnit tests for ActivityPub transformers and handlers.
  • Mocking HTTP requests and other utilities in tests.
  • Creating Playwright E2E tests for settings pages or federation flows.
  • Debugging failing tests or isolating a single test to investigate.
  • Validating test coverage using the Testing Reference utilities.

Quick Start

  1. Step 1: Create a PHPUnit test class (extending WP_UnitTestCase) or a Playwright test file for your target (unit or E2E).
  2. Step 2: Run tests with npm run env-test (PHPUnit) or npm run test:e2e (Playwright).
  3. Step 3: If failures occur, run with verbose/debug and use --filter to isolate the failing test.

Best Practices

  • Follow the PHPUnit test skeleton with set_up/tear_down and clearly named test methods.
  • Annotate tests with @group activitypub and @group federation to organize scope.
  • Refer to Testing Reference for common patterns, utilities, and test data handling.
  • Keep E2E tests deterministic with stable selectors and explicit waits where needed.
  • Use the provided npm scripts (env-test, test:e2e, test:unit) and enable verbose/debug for debugging.

Example Use Cases

  • A PHPUnit test class skeleton extending WP_UnitTestCase with set_up, tear_down, and test_functionality.
  • A PHPUnit test annotated with @group activitypub and @group federation.
  • A Basic Playwright E2E test that verifies the ActivityPub settings page loads.
  • A Playwright test that validates WebFinger discovery at /.well-known/webfinger.
  • Debug output and isolation approach using var_dump, error_log, and npm run env-test --verbose --debug.

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers