Spaces:
No application file
No application file
File size: 2,061 Bytes
d2897cd |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
<?php
declare(strict_types=1);
namespace Mautic\WebhookBundle\Tests\Controller;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\WebhookBundle\Entity\Event;
use Mautic\WebhookBundle\Entity\Log;
use Mautic\WebhookBundle\Entity\Webhook;
use PHPUnit\Framework\Assert;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class WebhookControllerTest extends MauticMysqlTestCase
{
public function testViewWebhookDetail(): void
{
$webhook = $this->createWebhook('test', 'http://domain.tld', 'secret');
$this->createWebhookEvent($webhook, 'Type');
for ($log = 1; $log <= 105; ++$log) {
$this->createWebhookLog($webhook, 'test', 200);
}
$this->em->flush();
$this->em->clear();
$crawler = $this->client->request(Request::METHOD_GET, '/s/webhooks/view/'.$webhook->getId());
Assert::assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
$logList = $crawler->filter('.table.table-responsive > tbody > tr')->count();
Assert::assertSame(Webhook::LOGS_DISPLAY_LIMIT, $logList);
}
private function createWebhook(string $name, string $url, string $secret): Webhook
{
$webhook = new Webhook();
$webhook->setName($name);
$webhook->setWebhookUrl($url);
$webhook->setSecret($secret);
$this->em->persist($webhook);
return $webhook;
}
private function createWebhookEvent(Webhook $webhook, string $type): Event
{
$event = new Event();
$event->setWebhook($webhook);
$event->setEventType($type);
$this->em->persist($event);
return $event;
}
private function createWebhookLog(Webhook $webhook, string $note, int $statusCode): Log
{
$log = new Log();
$log->setWebhook($webhook);
$log->setNote($note);
$log->setStatusCode($statusCode);
$this->em->persist($log);
return $log;
}
}
|