Initial commit: CloudOps infrastructure platform

This commit is contained in:
root
2026-04-09 19:58:57 +02:00
commit 1166a52f26
7762 changed files with 839452 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Entity\DoNotContact;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Event\ChannelSubscriptionChange;
class ChannelSubscriptionChangeTest extends \PHPUnit\Framework\TestCase
{
#[\PHPUnit\Framework\Attributes\TestDox('Tests that getters returns same values as the contstruct')]
public function testGetterReturnConstruct(): void
{
$lead = new Lead();
$channel = 'email';
$oldStatus = DoNotContact::IS_CONTACTABLE;
$newStatus = DoNotContact::UNSUBSCRIBED;
$event = new ChannelSubscriptionChange($lead, $channel, $oldStatus, $newStatus);
$this->assertEquals($lead, $event->getLead());
$this->assertEquals($channel, $event->getChannel());
$this->assertEquals($oldStatus, $event->getOldStatus());
$this->assertEquals($newStatus, $event->getNewStatus());
$this->assertEquals('contactable', $event->getOldStatusVerb());
$this->assertEquals('unsubscribed', $event->getNewStatusVerb());
}
#[\PHPUnit\Framework\Attributes\TestDox('Test that the default verb is unsubscribed if not recongized')]
public function testGetStatusVerbReturnsUnsubscribedForUnrecognized(): void
{
$lead = new Lead();
$channel = 'email';
$oldStatus = DoNotContact::IS_CONTACTABLE;
$event = new ChannelSubscriptionChange($lead, $channel, $oldStatus, 456);
$this->assertEquals('unsubscribed', $event->getNewStatusVerb());
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Entity\Company;
use Mautic\LeadBundle\Event\CompanyEvent;
class CompanyEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$company = new Company();
$isNew = false;
$score = 1;
$event = new CompanyEvent($company, $isNew, $score);
$this->assertEquals($company, $event->getCompany());
$this->assertEquals($isNew, $event->isNew());
$this->assertEquals($score, $event->getScore());
$isNew = true;
$event = new CompanyEvent($company, $isNew, $score);
$this->assertEquals($isNew, $event->isNew());
$company2 = new Company();
$company2->setName('otherCompany');
$event->setCompany($company2);
$this->assertEquals($company2, $event->getCompany());
$secondScore = 2;
$event->changeScore($secondScore);
$this->assertEquals($secondScore, $event->getScore());
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Entity\Company;
use Mautic\LeadBundle\Event\CompanyMergeEvent;
use PHPUnit\Framework\TestCase;
class CompanyMergeEventTest extends TestCase
{
public function testConstructGettersSetters(): void
{
$victor = new Company();
$loser = new Company();
$event = new CompanyMergeEvent($victor, $loser);
$this->assertEquals($victor, $event->getVictor());
$this->assertEquals($loser, $event->getLoser());
}
}

View File

@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\FieldOperatorsEvent;
final class FieldOperatorsEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$type = 'select';
$field = 'country';
$allOperators = [
'=' => [
'label' => 'equals',
'expr' => 'eq',
'negate_expr' => 'neq',
],
'!=' => [
'label' => 'not equal',
'expr' => 'neq',
'negate_expr' => 'eq',
],
];
$defaultOperators = [
'equals' => '=',
];
$event = new FieldOperatorsEvent($type, $field, $allOperators, $defaultOperators);
$this->assertSame($type, $event->getType());
$this->assertSame($field, $event->getField());
$this->assertSame($defaultOperators, $event->getOperators());
$event->addOperator('!=');
$this->assertSame(['equals' => '=', 'not equal' => '!='], $event->getOperators());
}
}

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\FormAdjustmentEvent;
use Mautic\LeadBundle\Segment\OperatorOptions;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\Form\FormInterface;
final class FormAdjustmentEventTest extends \PHPUnit\Framework\TestCase
{
/**
* @var MockObject&FormInterface<FormInterface<mixed>>
*/
private MockObject $form;
protected function setUp(): void
{
parent::setUp();
$this->form = $this->createMock(FormInterface::class);
}
public function testConstructGettersSetters(): void
{
$alias = 'email';
$object = 'lead';
$operator = OperatorOptions::EQUAL_TO;
$fieldDetails = [
'properties' => [
'type' => 'text',
'list' => ['one', 'two'],
],
];
$event = new FormAdjustmentEvent($this->form, $alias, $object, $operator, $fieldDetails);
$this->assertSame($this->form, $event->getForm());
$this->assertSame($alias, $event->getFieldAlias());
$this->assertSame($object, $event->getFieldObject());
$this->assertSame($operator, $event->getOperator());
$this->assertSame($fieldDetails, $event->getFieldDetails());
$this->assertSame('text', $event->getFieldType());
$this->assertSame(['one', 'two'], $event->getFieldChoices());
$this->assertFalse($event->filterShouldBeDisabled());
$this->assertFalse($event->operatorIsOneOf(OperatorOptions::LESS_THAN));
$this->assertFalse($event->operatorIsOneOf(OperatorOptions::LESS_THAN, OperatorOptions::NOT_EQUAL_TO));
$this->assertTrue($event->operatorIsOneOf(OperatorOptions::LESS_THAN, OperatorOptions::EQUAL_TO));
$this->assertFalse($event->fieldTypeIsOneOf('select'));
$this->assertTrue($event->fieldTypeIsOneOf('select', 'text'));
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Event\LeadEvent;
class LeadEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$lead = new Lead();
$event = new LeadEvent($lead);
$this->assertEquals($lead, $event->getLead());
$this->assertFalse($event->isNew());
$event = new LeadEvent($lead, false);
$this->assertFalse($event->isNew());
$event = new LeadEvent($lead, true);
$this->assertTrue($event->isNew());
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\CategoryBundle\Entity\Category;
use Mautic\LeadBundle\Entity\LeadList;
use Mautic\LeadBundle\Event\LeadListEvent;
class LeadListEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$segment = new LeadList();
$event = new LeadListEvent($segment);
$this->assertEquals($segment, $event->getList());
$this->assertEquals(false, $event->isNew());
$isNew = false;
$event = new LeadListEvent($segment, $isNew);
$this->assertEquals($isNew, $event->isNew());
$isNew = true;
$event = new LeadListEvent($segment, $isNew);
$this->assertEquals($isNew, $event->isNew());
$segment2 = new LeadList();
$segment2->setName('otherSegmentName');
$event->setList($segment2);
$this->assertEquals($segment2, $event->getList());
$isNew = true;
$event = new LeadListEvent($segment, $isNew);
$category = new Category();
$category->setTitle('Segment Category 1');
$category->setAlias('segment-category-1');
$category->setBundle('segment');
$segment3 = new LeadList();
$segment3->setName('Segment 1');
$segment3->setCategory($category);
$event->setList($segment3);
$this->assertEquals($segment3, $event->getList());
}
}

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\LeadListFiltersChoicesEvent;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
class LeadListFiltersChoicesEventTest extends TestCase
{
public function testGetters(): void
{
$operators = [
'text' => [
'equals' => '=',
'not equal' => '!=',
'empty' => 'empty',
'not empty' => '!empty',
'like' => 'like',
'not like' => '!like',
'regexp' => 'regexp',
'not regexp' => '!regexp',
'starts with' => 'startsWith',
'ends with' => 'endsWith',
'contains' => 'contains',
],
'select' => [
'equals' => '=',
'not equal' => '!=',
'empty' => 'empty',
'not empty' => '!empty',
'including' => 'in',
'excluding' => '!in',
'regexp' => 'regexp',
'not regexp' => '!regexp',
],
'bool' => [
'equals' => '=',
'not equal' => '!=',
],
];
$choices = [0 => 'Choice1', 1 => 'Choice2'];
$search = 'Test Search';
$translator = $this->createMock(TranslatorInterface::class);
$leadListFiltersChoicesEvent = new LeadListFiltersChoicesEvent($choices, $operators, $translator, new Request(), $search);
$this->assertSame($operators, $leadListFiltersChoicesEvent->getOperators());
$this->assertSame($choices, $leadListFiltersChoicesEvent->getChoices());
$this->assertSame($translator, $leadListFiltersChoicesEvent->getTranslator());
$this->assertSame($search, $leadListFiltersChoicesEvent->getSearch());
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\LeadTimelineEvent;
#[\PHPUnit\Framework\Attributes\CoversClass(LeadTimelineEvent::class)]
class LeadTimelineEventTest extends \PHPUnit\Framework\TestCase
{
#[\PHPUnit\Framework\Attributes\TestDox('Every event in the timeline should have a unique eventId so test that one is generated if the subscriber forgets')]
public function testEventIdIsGeneratedIfNotSetBySubscriber(): void
{
$payload = [
[
'event' => 'foo',
'eventLabel' => 'Foo',
'eventType' => 'foo',
'timestamp' => new \DateTime(),
'extra' => [
'something' => 'something',
],
'icon' => 'ri-speed-up-line',
'contactId' => 1,
],
[
'event' => 'bar',
'eventLabel' => 'Bar',
'eventType' => 'bar',
'timestamp' => new \DateTime(),
'extra' => [
'something' => 'something else',
],
'icon' => 'ri-speed-up-line',
'contactId' => 2,
],
[
'event' => 'foobar',
'eventId' => 'foobar123',
'eventLabel' => 'Foo Bar',
'eventType' => 'foobar',
'timestamp' => new \DateTime(),
'extra' => [
'something' => 'something else',
],
'icon' => 'ri-speed-up-line',
'contactId' => 2,
],
];
$event = new LeadTimelineEvent();
foreach ($payload as $data) {
$event->addEvent($data);
}
$events = $event->getEvents();
$id1 = hash('crc32', json_encode($payload[0]), false);
$this->assertTrue(isset($events[0]['eventId']));
$this->assertEquals('foo'.$id1, $events[0]['eventId']);
$id2 = hash('crc32', json_encode($payload[1]), false);
$this->assertTrue(isset($events[1]['eventId']));
$this->assertEquals('bar'.$id2, $events[1]['eventId']);
$this->assertTrue(isset($events[2]['eventId']));
$this->assertEquals('foobar123', $events[2]['eventId']);
}
}

View File

@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\ListFieldChoicesEvent;
final class ListFieldChoicesEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$event = new ListFieldChoicesEvent();
$this->assertSame([], $event->getChoicesForAllListFieldTypes());
$this->assertSame([], $event->getChoicesForAllListFieldAliases());
$event->setChoicesForFieldType('boolean', ['No' => 0, 'Yes' => 1]);
$event->setChoicesForFieldAlias('campaign', ['Campaign A' => 1, 'Campaign B' => 2]);
$event->setSearchTerm('Test search');
$this->assertSame(['boolean' => ['No' => 0, 'Yes' => 1]], $event->getChoicesForAllListFieldTypes());
$this->assertSame(['campaign' => ['Campaign A' => 1, 'Campaign B' => 2]], $event->getChoicesForAllListFieldAliases());
$this->assertSame('Test search', $event->getSearchTerm());
}
}

View File

@@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\SegmentOperatorQueryBuilderEvent;
use Mautic\LeadBundle\Segment\ContactSegmentFilter;
use Mautic\LeadBundle\Segment\Query\QueryBuilder;
use PHPUnit\Framework\MockObject\MockObject;
final class SegmentOperatorQueryBuilderEventTest extends \PHPUnit\Framework\TestCase
{
/**
* @var MockObject|QueryBuilder
*/
private MockObject $queryBuilder;
/**
* @var MockObject|ContactSegmentFilter
*/
private MockObject $filter;
protected function setUp(): void
{
parent::setUp();
$this->queryBuilder = $this->createMock(QueryBuilder::class);
$this->filter = $this->createMock(ContactSegmentFilter::class);
$this->queryBuilder->method('getTableAlias')
->with(MAUTIC_TABLE_PREFIX.'leads')
->willReturn('leads');
}
public function testConstructGettersSetters(): void
{
$this->filter->method('getOperator')->willReturn('=');
$this->filter->method('getGlue')->willReturn('and');
$event = new SegmentOperatorQueryBuilderEvent($this->queryBuilder, $this->filter, 'parameterHolder1');
$this->assertSame($this->queryBuilder, $event->getQueryBuilder());
$this->assertSame($this->filter, $event->getFilter());
$this->assertSame('parameterHolder1', $event->getParameterHolder());
$this->assertFalse($event->operatorIsOneOf('like'));
$this->assertTrue($event->operatorIsOneOf('=', 'like'));
$this->assertFalse($event->wasOperatorHandled());
$this->queryBuilder->expects($this->once())
->method('addLogic')
->with('a != b', 'and');
$event->addExpression('a != b');
$this->assertTrue($event->wasOperatorHandled());
}
}

View File

@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace Mautic\LeadBundle\Tests\Event;
use Mautic\LeadBundle\Event\TypeOperatorsEvent;
final class TypeOperatorsEventTest extends \PHPUnit\Framework\TestCase
{
public function testConstructGettersSetters(): void
{
$event = new TypeOperatorsEvent();
$this->assertSame([], $event->getOperatorsForAllFieldTypes());
$event->setOperatorsForFieldType('email', ['include' => ['=', 'like']]);
$event->setOperatorsForFieldType('firsname', ['exclude' => ['!=', '!like']]);
$this->assertSame([
'email' => ['include' => ['=', 'like']],
'firsname' => ['exclude' => ['!=', '!like']],
], $event->getOperatorsForAllFieldTypes());
}
}