mf2/tests
Microformats test suite for validating microformats parsers. Provides HTML fragment tests with matching JSON expected output, organized by spec version and type (e.g., h-card). Install/update via npm. Community-maintained; contributions welcome with changelog updates.
microformats2-php) adhere to Microformats 1/2 standards. Ideal for projects requiring structured data extraction (e.g., h-card for profiles, h-entry for posts) with verifiable accuracy.composer require mf2/tests) and load static files programmatically. No PHP runtime dependencies.DataProvider to dynamically load test cases from the suite’s directory structure (e.g., tests/v2/h-card/*.html).assertEquals or deep comparison libraries (e.g., spatie/array-sorter).textContent behavior in PHP vs. JS).value vs. content) may not align with modern parser logic.microformats2-php, ensure it handles the test suite’s HTML5 textContent and date formatting rules.composer require mf2/tests.DataProvider to load tests dynamically.MicroformatsTestLoader) to recursively parse the suite’s directory structure (tests/vX.X/*/*.{html,json}).microformats.js), run tests via NPM (but adds polyglot complexity).Phase 1: Proof of Concept (1–2 Days)
composer require mf2/tests
// app/Services/MicroformatsTestLoader.php
class MicroformatsTestLoader {
public function load(string $version, string $type): array {
$tests = [];
$path = __DIR__ . "/../../vendor/mf2/tests/{$version}/{$type}";
foreach (glob("{$path}/*.html") as $htmlFile) {
$jsonFile = str_replace('.html', '.json', $htmlFile);
$tests[] = [
'html' => file_get_contents($htmlFile),
'expected' => json_decode(file_get_contents($jsonFile), true),
];
}
return $tests;
}
}
h-card) against an existing parser to validate integration.Phase 2: Full Integration (3–5 Days)
# Example script to generate test files
php artisan make:microformats-tests
@microformats-v1, @h-entry) for selective execution.textContent vs. innerText).Phase 3: CI/CD (1–2 Days)
phpunit.xml or Pest config:
<!-- phpunit.xml -->
<group name="microformats">
<directory>tests/Feature/Microformats</directory>
</group>
# .github/workflows/tests.yml
- name: Run Microformats Tests
run: php artisan test --group microformats --strict
textContent behavior. Modern Laravel apps (PHP 8+) should have no issues, but legacy parsers may need adjustments.rel-urls, value). Validate the parser’s output matches this schema:
$this->assertArrayHasKey('rel-urls', $actual);
$this->assertEqualsCanonicalizing($expected['value'], $actual['value']);
composer require mf2/tests
MicroformatsTestLoader).$loader = new MicroformatsTestLoader();
$hCardTests = $loader->load('v2', 'h-card');
DataProvider:
use Tests\MicroformatsTestLoader;
class MicroformatsTest extends TestCase {
public function hCardProvider() {
return (new MicroformatsTestLoader())->load('v2', 'h-card');
}
/**
* @dataProvider hCardProvider
*/
public function testHCardParsing(string $html, array $expected) {
$actual = $this->parser->parse($html);
$this->assertEquals($expected, $actual);
}
}
.github/workflows/tests.yml:
jobs:
test:
steps:
- run: php artisan test --group microformats --strict
How can I help you explore Laravel packages today?