Files
pricebuddy/tests/Unit/Services/AutoCreateStoreMicrodataTest.php
Jeremy 0d685c1cc3 feat: AI self-healing and microdata fallback extraction
Improve meta extraction with AI self-healing and HTML microdata support.

- AI self-heal the existing-store and auto-create extraction paths when no price
  is found, returning the detected/updated store (AiConfigHealer::applyPreviewToStore)
- Expose scrape_settings and settings on StoreResource
- Microdata (itemprop / <data>) fallback extraction across SchemaOrgService,
  StrategyExtractor and AutoCreateStore, with JSON-LD precedence locked by a test
- Use filled() for the price heal-gate; parseSchemaOrg returns ?string for
  ImageObject arrays
2026-06-18 23:13:06 +10:00

32 lines
1.1 KiB
PHP

<?php
namespace Tests\Unit\Services;
use App\Services\AutoCreateStore;
use Tests\TestCase;
class AutoCreateStoreMicrodataTest extends TestCase
{
private function microdataHtml(): string
{
return '<html><body><div itemscope itemtype="https://schema.org/Product">'
.'<h1 itemprop="name">Premium Leather Boots</h1>'
.'<div itemprop="offers" itemscope itemtype="https://schema.org/Offer">'
.'<span itemprop="price" content="149.99">149.99</span>'
.'</div></div></body></html>';
}
public function test_detects_a_store_strategy_from_microdata(): void
{
$detected = AutoCreateStore::new('https://shop.test/boots', $this->microdataHtml())
->setLogErrors(false)
->detect();
$this->assertNotNull($detected);
$this->assertSame('schema_org', data_get($detected, 'fields.title.type'));
$this->assertSame('schema_org', data_get($detected, 'fields.price.type'));
$this->assertSame('Premium Leather Boots', data_get($detected, 'extracted.title'));
$this->assertSame(149.99, data_get($detected, 'extracted.price'));
}
}