1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<?php
/**
* Device Detector - The Universal Device Detection library for parsing User Agents
*
* @link https://matomo.org
*
* @license http://www.gnu.org/licenses/lgpl.html LGPL v3 or later
*/
declare(strict_types=1);
namespace DeviceDetector\Tests\Parser;
use DeviceDetector\Parser\Bot;
use PHPUnit\Framework\TestCase;
class BotTest extends TestCase
{
public function testGetInfoFromUABot(): void
{
$expected = [
'name' => 'Googlebot',
'category' => 'Search bot',
'url' => 'https://developers.google.com/search/docs/crawling-indexing/overview-google-crawlers',
'producer' => [
'name' => 'Google Inc.',
'url' => 'https://www.google.com/',
],
];
$botParser = new Bot();
$botParser->setUserAgent('Googlebot/2.1 (http://www.googlebot.com/bot.html)');
$this->assertEquals($expected, $botParser->parse());
}
public function testParseNoDetails(): void
{
$botParser = new Bot();
$botParser->discardDetails();
$botParser->setUserAgent('Googlebot/2.1 (http://www.googlebot.com/bot.html)');
$this->assertEquals([true], $botParser->parse());
}
public function testParseNoBot(): void
{
$botParser = new Bot();
$botParser->setUserAgent('Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; SV1; SE 2.x)');
$this->assertNull($botParser->parse());
}
}
|