mirror of
https://github.com/jez500/pricebuddy.git
synced 2026-11-24 19:58:13 +01:00
60 lines
1.4 KiB
PHP
Executable File
60 lines
1.4 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
|
|
{
|
|
$html = View::make('tests.product-page', [
|
|
'price' => $price,
|
|
'title' => $title,
|
|
'image' => $image,
|
|
'availability' => $availability,
|
|
])->render();
|
|
|
|
Http::fake([
|
|
'*/api/article*' => Http::response([
|
|
'fullContent' => $html,
|
|
]),
|
|
'*' => Http::response($html),
|
|
]);
|
|
}
|
|
|
|
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),
|
|
]);
|
|
}
|
|
}
|