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.
Install the package via Composer (PHP) or NPM (Node.js):
composer require mf2/tests
or
npm install microformats/tests --save-dev
Locate test files:
v1, v2, experimental) and microformat type (h-card, h-entry, etc.).vendor/mf2/tests/v2/h-card/test.html and test.json.First use case:
h-card parser by loading v2/h-card/test.html and asserting its output matches test.json.Versioned Testing:
v1, v2) to avoid mixing rules.v2 tests if your parser only supports v1.Dynamic Test Loading:
$testLoader = new MicroformatsTestLoader(base_path('vendor/mf2/tests'));
$tests = $testLoader->load('v2/h-card'); // Returns [['html' => "...", 'expected' => [...]], ...]
PHPUnit DataProvider Integration:
public function hCardProvider() {
return $this->testLoader->load('v2/h-card');
}
public function testHCard(array $test) {
$actual = $this->parser->parse($test['html']);
$this->assertEquals($test['expected'], $actual);
}
Selective Test Execution:
@h-entry) to run only relevant subsets in CI.Date/Time Validation:
2015-04-29 15:34Z).Parser Development:
h-entry support by running v2/h-entry tests).Regression Testing:
Edge-Case Coverage:
h-payment).Laravel Service Provider: Register the test loader as a singleton for global access:
$this->app->singleton(MicroformatsTestLoader::class, function ($app) {
return new MicroformatsTestLoader(base_path('vendor/mf2/tests'));
});
Artisan Command:
Create a php artisan microformats:test command to run specific test groups:
$tests = $this->loader->load('v2/h-card');
$this->runTests($tests);
JSON Schema Validation:
Use spatie/array-to-xml or json_schema to validate parser output against the test suite’s schema.
Version Mismatches:
v2 implied properties don’t apply to v1).Stale Tests:
h-payment).HTML5 Dependencies:
textContent behavior; older PHP/JS environments may fail.textContent if needed (e.g., element.textContent || element.innerText).False Positives:
deepEquals (e.g., PHPUnit’s assertEquals with custom normalizers).Performance:
@h-card).Test Output Mismatch:
dd() or var_dump().$actual = $this->parser->parse($html);
dd(['actual' => $actual, 'expected' => $expected]);
Parser-Specific Quirks:
textContent).$normalizedOutput = array_map('trim', $actual);
$this->assertEquals($expected, $normalizedOutput);
JSON File Naming:
test.html + test.json).Date/Time Formatting:
$this->parser->setDateFormat('Y-m-d H:i:sP'); // e.g., "2015-04-29 15:34+00:00"
Custom Test Formats:
experimental/ and updating change-log.html.Parser-Specific Adapters:
microformats2-php vs. custom parser).CI Integration:
- name: Run Microformats Tests
run: php artisan test --group microformats --filter "h-card"
Visual Regression Testing:
How can I help you explore Laravel packages today?