Spaces:
No application file
No application file
File size: 2,837 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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
<?php
declare(strict_types=1);
namespace Mautic\DynamicContentBundle\Tests\Controller;
use Mautic\CoreBundle\Helper\ClickthroughHelper;
use Mautic\CoreBundle\Test\IsolatedTestTrait;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\DynamicContentBundle\Entity\DynamicContent;
use Mautic\DynamicContentBundle\Entity\DynamicContentLeadData;
use Mautic\EmailBundle\Entity\Stat;
use Mautic\LeadBundle\Entity\Lead;
use PHPUnit\Framework\Assert;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* @runTestsInSeparateProcesses
*
* @preserveGlobalState disabled
*/
class DynamicContentApiControllerFunctionalTest extends MauticMysqlTestCase
{
use IsolatedTestTrait;
public function testDwcGetEndpointForNoSlotNorContact(): void
{
$this->client->request(Request::METHOD_GET, '/dwc/slot-a');
Assert::assertSame(Response::HTTP_NO_CONTENT, $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
}
public function testDwcGetEndpointForASlotAndContact(): void
{
$contact = new Lead();
$contact->setEmail('johana@doe.email');
$dwc = new DynamicContent();
$dwc->setContent('<some>content</some>');
$dwc->setName('Slot A');
$dwc->setSlotName('slot-a');
$dwcContact = new DynamicContentLeadData();
$dwcContact->setDateAdded(new \DateTime());
$dwcContact->setDynamicContent($dwc);
$dwcContact->setLead($contact);
$dwcContact->setSlot($dwc->getSlotName());
$stat = new Stat();
$stat->setLead($contact);
$stat->setTrackingHash('tracking-hash-1');
$stat->setEmailAddress($contact->getEmail());
$stat->setDateSent(new \DateTime());
$this->em->persist($contact);
$this->em->persist($stat);
$this->em->persist($dwc);
$this->em->persist($dwcContact);
$this->em->flush();
$ct = ClickthroughHelper::encodeArrayForUrl(['stat' => 'tracking-hash-1']);
$this->client->request(Request::METHOD_GET, "/dwc/slot-a?ct={$ct}");
Assert::assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
$responseArray = json_decode($this->client->getResponse()->getContent(), true);
Assert::assertSame('<some>content</some>', $responseArray['content']);
}
public function testCreateDwc(): void
{
$payload = [
'name' => 'API test',
'content' => 'API test',
];
$this->client->request(Request::METHOD_POST, '/api/dynamiccontents/new', $payload);
Assert::assertSame(Response::HTTP_CREATED, $this->client->getResponse()->getStatusCode(), $this->client->getResponse()->getContent());
}
}
|