Files
pricebuddy/tests/Traits/ScraperTrait.php
Gordon HeydonandJeremy 6e35588f49 [#127] Add product availability tracking with stock status matching
Add availability field to URLs for tracking product stock status (in stock, pre-order, back order, special order, out of stock, discontinued). Includes configurable match rules per store with exact match and regex support, priority-based matching, and a default status fallback. Out-of-stock products can now be added with price set to 0. Added The Tech Geeks store with availability detection and seeded Ubiquiti products.
2026-03-27 13:52:51 +11:00

55 lines
1.3 KiB
PHP
Executable File

<?php
namespace Tests\Traits;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\View;
trait ScraperTrait
{
protected function mockScrape(mixed $price, mixed $title = null, mixed $image = null, mixed $availability = null): void
{
Http::fake([
'*' => Http::response(View::make('tests.product-page', [
'price' => $price,
'title' => $title,
'image' => $image,
'availability' => $availability,
])->render()),
]);
}
protected function mockScrapeSchema(mixed $price, mixed $title = null, mixed $image = null): void
{
$json = json_encode([
'@context' => 'https://schema.org/',
'@type' => 'Product',
'name' => $title,
'image' => $image,
'description' => 'Schema description',
'offers' => [
'@type' => 'Offer',
'priceCurrency' => 'USD',
'price' => $price,
],
]);
$html = <<<HTML
<html>
<head>
<script type="application/ld+json">
{$json}
</script>
</head>
<body>
<p>This page is used for test responses with schema.org</p>
</body>
</html>
HTML;
Http::fake([
'*' => Http::response($html),
]);
}
}