mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
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.
55 lines
1.3 KiB
PHP
Executable File
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),
|
|
]);
|
|
}
|
|
}
|