Initial commit: CloudOps infrastructure platform
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Model;
|
||||
|
||||
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;
|
||||
|
||||
class FocusModelFunctionalTest extends MauticMysqlTestCase
|
||||
{
|
||||
private Lead $lead;
|
||||
|
||||
private FocusModel $focusModel;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->focusModel = static::getContainer()->get('mautic.focus.model.focus');
|
||||
$this->lead = $this->createLead();
|
||||
}
|
||||
|
||||
public function testGetStats(): void
|
||||
{
|
||||
$focusPopupA = $this->createFocus('popup focus A');
|
||||
$focusStatExpected = $this->setTestsData($this->lead, $focusPopupA);
|
||||
|
||||
$to = new \DateTime('+1 day');
|
||||
$from = new \DateTime('-1 month');
|
||||
|
||||
$focusStat = $this->focusModel->getStats($focusPopupA, null, $from, $to);
|
||||
|
||||
$focusViewsCount = array_sum($focusStat['datasets'][0]['data']);
|
||||
$focusClickCount = array_sum($focusStat['datasets'][1]['data']);
|
||||
|
||||
$this->assertEquals($focusStatExpected['view'], $focusViewsCount);
|
||||
$this->assertEquals($focusStatExpected['click'], $focusClickCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
private function setTestsData(Lead $lead, Focus $focus): array
|
||||
{
|
||||
$hitPopupA = new Hit();
|
||||
$hitPopupA->setLead($lead);
|
||||
|
||||
$this->focusModel->addStat($focus, Stat::TYPE_NOTIFICATION, null, $lead);
|
||||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead);
|
||||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead);
|
||||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead);
|
||||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead);
|
||||
|
||||
return ['view' => 1, 'click' => 4];
|
||||
}
|
||||
|
||||
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,
|
||||
]);
|
||||
|
||||
$this->focusModel->saveEntity($focus);
|
||||
|
||||
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,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace MauticPlugin\MauticFocusBundle\Tests\Model;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Mautic\CoreBundle\Helper\CoreParametersHelper;
|
||||
use Mautic\CoreBundle\Helper\UserHelper;
|
||||
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
|
||||
use Mautic\CoreBundle\Translation\Translator;
|
||||
use Mautic\FormBundle\Model\FormModel;
|
||||
use Mautic\LeadBundle\Model\FieldModel;
|
||||
use Mautic\LeadBundle\Tracker\ContactTracker;
|
||||
use Mautic\PageBundle\Model\TrackableModel;
|
||||
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Twig\Environment;
|
||||
|
||||
class FocusModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ContactTracker|MockObject
|
||||
*/
|
||||
private MockObject $contactTracker;
|
||||
|
||||
/**
|
||||
* @var MockObject|EventDispatcherInterface
|
||||
*/
|
||||
private MockObject $dispatcher;
|
||||
|
||||
/**
|
||||
* @var FormModel|MockObject
|
||||
*/
|
||||
private MockObject $formModel;
|
||||
|
||||
/**
|
||||
* @var FieldModel|MockObject
|
||||
*/
|
||||
private MockObject $leadFieldModel;
|
||||
|
||||
/**
|
||||
* @var Environment|mixed|MockObject
|
||||
*/
|
||||
private MockObject $twig;
|
||||
|
||||
/**
|
||||
* @var TrackableModel|mixed|MockObject
|
||||
*/
|
||||
private MockObject $trackableModel;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->formModel = $this->createMock(FormModel::class);
|
||||
$this->trackableModel = $this->createMock(TrackableModel::class);
|
||||
$this->twig = $this->createMock(Environment::class);
|
||||
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||
$this->leadFieldModel = $this->createMock(FieldModel::class);
|
||||
$this->contactTracker = $this->createMock(ContactTracker::class);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\DataProvider('focusTypeProvider')]
|
||||
public function testGetContentWithForm(string $type, InvokedCount $count): void
|
||||
{
|
||||
$this->formModel->expects(self::once())->method('getPages')->willReturn(['', '']);
|
||||
|
||||
$this->formModel->expects($count)->method('getEntity');
|
||||
|
||||
$focusModel = new FocusModel(
|
||||
$this->formModel,
|
||||
$this->trackableModel,
|
||||
$this->twig,
|
||||
$this->leadFieldModel,
|
||||
$this->contactTracker,
|
||||
$this->createMock(EntityManagerInterface::class),
|
||||
$this->createMock(CorePermissions::class),
|
||||
$this->dispatcher,
|
||||
$this->createMock(UrlGeneratorInterface::class),
|
||||
$this->createMock(Translator::class),
|
||||
$this->createMock(UserHelper::class),
|
||||
$this->createMock(LoggerInterface::class),
|
||||
$this->createMock(CoreParametersHelper::class)
|
||||
);
|
||||
$focus = [
|
||||
'form' => 'xxx',
|
||||
'type' => $type,
|
||||
];
|
||||
|
||||
$focusModel->getContent($focus);
|
||||
}
|
||||
|
||||
public static function focusTypeProvider(): \Generator
|
||||
{
|
||||
yield ['form', self::once()];
|
||||
yield ['notice', self::never()];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user