Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/agent/tests/Fixtures/Tool/scraper-page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example Page Title</title>
</head>
<body>
<h1>Welcome to Example Page</h1>
<p>This is some visible text content.</p>
<p>More content here with useful information.</p>
</body>
</html>
54 changes: 54 additions & 0 deletions src/agent/tests/Toolbox/Tool/ScraperTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Agent\Tests\Toolbox\Tool;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Agent\Toolbox\Tool\Scraper;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;

final class ScraperTest extends TestCase
{
public function testInvoke()
{
$htmlContent = file_get_contents(__DIR__.'/../../Fixtures/Tool/scraper-page.html');
$response = new MockResponse($htmlContent);
$httpClient = new MockHttpClient($response);

$scraper = new Scraper($httpClient);

$result = $scraper('https://example.com');

$this->assertArrayHasKey('title', $result);
$this->assertArrayHasKey('content', $result);
$this->assertSame('Example Page Title', $result['title']);
$this->assertStringContainsString('Welcome to Example Page', $result['content']);
$this->assertStringContainsString('This is some visible text content.', $result['content']);
}

public function testSourceIsAdded()
{
$htmlContent = file_get_contents(__DIR__.'/../../Fixtures/Tool/scraper-page.html');
$response = new MockResponse($htmlContent);
$httpClient = new MockHttpClient($response);

$scraper = new Scraper($httpClient);

$scraper('https://example.com');

$sources = $scraper->getSourceMap()->getSources();
$this->assertCount(1, $sources);
$this->assertSame('Example Page Title', $sources[0]->getName());
$this->assertSame('https://example.com', $sources[0]->getReference());
$this->assertStringContainsString('Welcome to Example Page', $sources[0]->getContent());
}
}
Loading