Present 34 agribusiness opportunities in existing corridor sections
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
require __DIR__.'/../vendor/autoload.php';
|
||||
// Offline verification against the preserved article exemplar; no database or source writes.
|
||||
$path = $argv[1] ?? throw new RuntimeException('Pass the preserved agronegocio article JSON path.');
|
||||
$sourceHash = hash_file('sha256', $path);
|
||||
$source = json_decode(file_get_contents($path), true, 512, JSON_THROW_ON_ERROR);
|
||||
if (($source['format'] ?? '') !== 'investmoz-legacy-article-v1' || ($source['slug'] ?? '') !== 'agronegocio') {
|
||||
throw new RuntimeException('Unexpected source article.');
|
||||
}
|
||||
$original = (new App\Services\LegacyContent)->sanitize($source['content_html']);
|
||||
$html = (new App\Services\CorridorAgribusiness)->enrich($original);
|
||||
$doc = new DOMDocument;
|
||||
$doc->loadHTML('<?xml encoding="UTF-8">'.$html);
|
||||
$xpath = new DOMXPath($doc);
|
||||
$groups = $xpath->query('//ul[starts-with(@id,"agronegocio-oportunidades-")]');
|
||||
$entries = $xpath->query('//ul[starts-with(@id,"agronegocio-oportunidades-")]/li');
|
||||
if ($groups->length !== 6 || $entries->length !== 34 || $sourceHash !== hash_file('sha256', $path)) {
|
||||
throw new RuntimeException('Incomplete integration or source changed.');
|
||||
}
|
||||
// Removing only the additions must recover the exact sanitized original.
|
||||
foreach (iterator_to_array($groups) as $group) {
|
||||
$group->parentNode->removeChild($group->previousSibling);
|
||||
$group->parentNode->removeChild($group->nextSibling);
|
||||
$group->parentNode->removeChild($group);
|
||||
}
|
||||
$body = $doc->getElementsByTagName('body')->item(0);
|
||||
$recovered = implode('', array_map(fn ($node) => $doc->saveHTML($node), iterator_to_array($body->childNodes)));
|
||||
if ($recovered !== $original) {
|
||||
throw new RuntimeException('Original displayed content was changed.');
|
||||
}
|
||||
echo json_encode(['source_sha256' => $sourceHash, 'source_unchanged' => true, 'original_display_preserved' => true,
|
||||
'corridors' => 6, 'agribusiness_entries' => 34, 'database_writes' => 0], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE).PHP_EOL;
|
||||
Reference in New Issue
Block a user