Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Controller\Api;
|
||||
|
||||
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
|
||||
use PHPUnit\Framework\Assert;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class FocusApiControllerTest extends MauticMysqlTestCase
|
||||
{
|
||||
/**
|
||||
* @var array<string,mixed>
|
||||
*/
|
||||
private array $testPayload = [
|
||||
'name' => 'test',
|
||||
'type' => 'notice',
|
||||
'website' => 'http://',
|
||||
'style' => 'bar',
|
||||
'htmlMode' => 1,
|
||||
'html' => '<div><strong style="color:red">html mode enabled</strong></div>',
|
||||
'properties' => [
|
||||
'bar' => [
|
||||
'allow_hide' => 1,
|
||||
'sticky' => 1,
|
||||
'size' => 'large',
|
||||
'placement' => 'top',
|
||||
],
|
||||
'modal' => [
|
||||
'placement' => 'top',
|
||||
],
|
||||
'notification' => [
|
||||
'placement' => 'top_left',
|
||||
],
|
||||
'animate' => 1,
|
||||
'link_activation' => 1,
|
||||
'colors' => [
|
||||
'primary' => '27184e',
|
||||
],
|
||||
'content' => [
|
||||
'headline' => '',
|
||||
'font' => 'Arial, Helvetica, sans-serif',
|
||||
],
|
||||
'when' => 'immediately',
|
||||
'frequency' => 'everypage',
|
||||
'stop_after_conversion' => 1,
|
||||
],
|
||||
];
|
||||
|
||||
public function testFocusApiNew(): void
|
||||
{
|
||||
// Create a focus item.
|
||||
$this->client->request(Request::METHOD_POST, '/api/focus/new', $this->testPayload);
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode(), $response->getContent());
|
||||
|
||||
$createdItem = json_decode($response->getContent(), true)['focus'];
|
||||
|
||||
Assert::assertNotEmpty($createdItem['id'], $response->getContent());
|
||||
Assert::assertSame($this->testPayload['name'], $createdItem['name'], $response->getContent());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
|
||||
use Mautic\LeadBundle\Entity\Lead;
|
||||
use Mautic\PageBundle\Entity\Hit;
|
||||
use MauticPlugin\MauticFocusBundle\Entity\Focus;
|
||||
use MauticPlugin\MauticFocusBundle\Entity\Stat;
|
||||
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class FocusAjaxControllerFunctionalTest extends MauticMysqlTestCase
|
||||
{
|
||||
public function testViewsCount(): void
|
||||
{
|
||||
/** @var FocusModel $focusModel */
|
||||
$focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$focus = $this->createFocus('popup');
|
||||
$focusModel->saveEntity($focus);
|
||||
|
||||
$leads = [
|
||||
$this->createLead(),
|
||||
$this->createLead(),
|
||||
];
|
||||
|
||||
$focusModel->addStat($focus, Stat::TYPE_NOTIFICATION, null, $leads[0]);
|
||||
$focusModel->addStat($focus, Stat::TYPE_NOTIFICATION, null, $leads[0]);
|
||||
$focusModel->addStat($focus, Stat::TYPE_NOTIFICATION, null, $leads[1]);
|
||||
|
||||
$this->client->xmlHttpRequest(Request::METHOD_GET, "/s/ajax?action=plugin:focus:getViewsCount&focusId={$focus->getId()}");
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertSame([
|
||||
'success' => 1,
|
||||
'views' => 3,
|
||||
'uniqueViews' => 2,
|
||||
], json_decode($response->getContent(), true));
|
||||
}
|
||||
|
||||
public function testClickThroughCount(): void
|
||||
{
|
||||
/** @var FocusModel $focusModel */
|
||||
$focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$focus = $this->createFocus('popup');
|
||||
$focusModel->saveEntity($focus);
|
||||
|
||||
$lead1 = $this->createLead();
|
||||
$lead2 = $this->createLead();
|
||||
|
||||
$focusModel->addStat($focus, Stat::TYPE_CLICK, $this->createHit($lead1), $lead1);
|
||||
$focusModel->addStat($focus, Stat::TYPE_CLICK, $this->createHit($lead1), $lead1);
|
||||
$focusModel->addStat($focus, Stat::TYPE_CLICK, $this->createHit($lead2), $lead2);
|
||||
|
||||
$this->client->xmlHttpRequest(Request::METHOD_GET, "/s/ajax?action=plugin:focus:getClickThroughCount&focusId={$focus->getId()}");
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertSame([
|
||||
'success' => 1,
|
||||
'clickThrough' => 2,
|
||||
], json_decode($response->getContent(), true));
|
||||
}
|
||||
|
||||
private function createHit(Lead $lead): Hit
|
||||
{
|
||||
$hit = new Hit();
|
||||
$hit->setLead($lead);
|
||||
|
||||
return $hit;
|
||||
}
|
||||
|
||||
private function createFocus(string $name): Focus
|
||||
{
|
||||
$focus = new Focus();
|
||||
$focus->setName($name);
|
||||
$focus->setType('link');
|
||||
$focus->setStyle('modal');
|
||||
$focus->setProperties([
|
||||
'bar' => [
|
||||
'allow_hide' => 1,
|
||||
'push_page' => 1,
|
||||
'sticky' => 1,
|
||||
'size' => 'large',
|
||||
'placement' => 'top',
|
||||
],
|
||||
'modal' => [
|
||||
'placement' => 'top',
|
||||
],
|
||||
'notification' => [
|
||||
'placement' => 'top_left',
|
||||
],
|
||||
'page' => [],
|
||||
'animate' => 0,
|
||||
'link_activation' => 1,
|
||||
'colors' => [
|
||||
'primary' => '4e5d9d',
|
||||
'text' => '000000',
|
||||
'button' => 'fdb933',
|
||||
'button_text' => 'ffffff',
|
||||
],
|
||||
'content' => [
|
||||
'headline' => null,
|
||||
'tagline' => null,
|
||||
'link_text' => null,
|
||||
'link_url' => null,
|
||||
'link_new_window' => 1,
|
||||
'font' => 'Arial, Helvetica, sans-serif',
|
||||
'css' => null,
|
||||
],
|
||||
'when' => 'immediately',
|
||||
'timeout' => null,
|
||||
'frequency' => 'everypage',
|
||||
'stop_after_conversion' => 1,
|
||||
]);
|
||||
|
||||
return $focus;
|
||||
}
|
||||
|
||||
private function createLead(): Lead
|
||||
{
|
||||
$lead = new Lead();
|
||||
$lead->setFirstname('Contact');
|
||||
$lead->setEmail('test@test.com');
|
||||
$this->em->persist($lead);
|
||||
$this->em->flush();
|
||||
|
||||
return $lead;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
|
||||
use MauticPlugin\MauticFocusBundle\Entity\Focus;
|
||||
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
final class FocusControllerTest extends MauticMysqlTestCase
|
||||
{
|
||||
public function testIndexActionIsSuccessful(): void
|
||||
{
|
||||
$this->client->request(Request::METHOD_GET, '/s/focus');
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testNewActionIsSuccessful(): void
|
||||
{
|
||||
$this->client->request(Request::METHOD_GET, '/s/focus/new');
|
||||
$response = $this->client->getResponse();
|
||||
|
||||
$this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
|
||||
}
|
||||
|
||||
public function testRecentActivityFeedOnFocusDetailsPage(): void
|
||||
{
|
||||
$focus = new Focus();
|
||||
$focus->setName('Test Focus');
|
||||
$focus->setType('link');
|
||||
$focus->setStyle('modal');
|
||||
$focus->setProperties([
|
||||
'bar' => [
|
||||
'allow_hide' => 1,
|
||||
'push_page' => 1,
|
||||
'sticky' => 1,
|
||||
'size' => 'large',
|
||||
'placement' => 'top',
|
||||
],
|
||||
'modal' => [
|
||||
'placement' => 'top',
|
||||
],
|
||||
'notification' => [
|
||||
'placement' => 'top_left',
|
||||
],
|
||||
'page' => [],
|
||||
'animate' => 0,
|
||||
'link_activation' => 1,
|
||||
'colors' => [
|
||||
'primary' => '4e5d9d',
|
||||
'text' => '000000',
|
||||
'button' => 'fdb933',
|
||||
'button_text' => 'ffffff',
|
||||
],
|
||||
'content' => [
|
||||
'headline' => null,
|
||||
'tagline' => null,
|
||||
'link_text' => null,
|
||||
'link_url' => null,
|
||||
'link_new_window' => 1,
|
||||
'font' => 'Arial, Helvetica, sans-serif',
|
||||
'css' => null,
|
||||
],
|
||||
'when' => 'immediately',
|
||||
'timeout' => null,
|
||||
'frequency' => 'everypage',
|
||||
'stop_after_conversion' => 1,
|
||||
]);
|
||||
|
||||
/** @var FocusModel $focusModel */
|
||||
$focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$focusModel->saveEntity($focus);
|
||||
|
||||
$this->em->clear();
|
||||
|
||||
$crawler = $this->client->request(Request::METHOD_GET, '/s/focus/edit/'.$focus->getId());
|
||||
$this->assertResponseIsSuccessful();
|
||||
$form = $crawler->selectButton('focus_buttons_apply')->form();
|
||||
$form['focus[isPublished]']->setValue('0');
|
||||
$this->client->submit($form);
|
||||
|
||||
$crawler = $this->client->request(Request::METHOD_GET, '/s/focus/view/'.$focus->getId());
|
||||
$this->assertResponseIsSuccessful();
|
||||
|
||||
$translator = self::getContainer()->get('translator');
|
||||
|
||||
$this->assertStringContainsString($translator->trans('mautic.core.recent.activity'), $this->client->getResponse()->getContent());
|
||||
$this->assertCount(2, $crawler->filterXPath('//ul[contains(@class, "media-list-feed")]/li'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Controller;
|
||||
|
||||
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
|
||||
use MauticPlugin\MauticFocusBundle\Entity\Focus;
|
||||
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
class FocusPublicControllerFunctionalTest extends MauticMysqlTestCase
|
||||
{
|
||||
public function testGenerateFocusItemScript(): void
|
||||
{
|
||||
/** @var FocusModel $focusModel */
|
||||
$focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$focus = $this->createFocus('popup');
|
||||
$focusModel->saveEntity($focus);
|
||||
|
||||
$this->client->request(Request::METHOD_GET, "/focus/{$focus->getId()}.js");
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isOk());
|
||||
$this->assertNotEmpty($response->getContent());
|
||||
}
|
||||
|
||||
public function testInactiveFocusItemScript(): void
|
||||
{
|
||||
/** @var FocusModel $focusModel */
|
||||
$focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$focus = $this->createFocus('popup');
|
||||
$focus->setIsPublished(false);
|
||||
$focusModel->saveEntity($focus);
|
||||
|
||||
$this->client->request(Request::METHOD_GET, "/focus/{$focus->getId()}.js");
|
||||
$response = $this->client->getResponse();
|
||||
$this->assertTrue($response->isNotFound());
|
||||
$this->assertEmpty($response->getContent());
|
||||
}
|
||||
|
||||
private function createFocus(string $name): Focus
|
||||
{
|
||||
$focus = new Focus();
|
||||
$focus->setName($name);
|
||||
$focus->setType('link');
|
||||
$focus->setStyle('modal');
|
||||
$focus->setProperties([
|
||||
'bar' => [
|
||||
'allow_hide' => 1,
|
||||
'push_page' => 1,
|
||||
'sticky' => 1,
|
||||
'size' => 'large',
|
||||
'placement' => 'top',
|
||||
],
|
||||
'modal' => [
|
||||
'placement' => 'top',
|
||||
],
|
||||
'notification' => [
|
||||
'placement' => 'top_left',
|
||||
],
|
||||
'page' => [],
|
||||
'animate' => 0,
|
||||
'link_activation' => 1,
|
||||
'colors' => [
|
||||
'primary' => '4e5d9d',
|
||||
'text' => '000000',
|
||||
'button' => 'fdb933',
|
||||
'button_text' => 'ffffff',
|
||||
],
|
||||
'content' => [
|
||||
'headline' => null,
|
||||
'tagline' => null,
|
||||
'link_text' => null,
|
||||
'link_url' => null,
|
||||
'link_new_window' => 1,
|
||||
'font' => 'Arial, Helvetica, sans-serif',
|
||||
'css' => null,
|
||||
],
|
||||
'when' => 'immediately',
|
||||
'timeout' => null,
|
||||
'frequency' => 'everypage',
|
||||
'stop_after_conversion' => 1,
|
||||
]);
|
||||
|
||||
return $focus;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user