Skip to content

Commit

Permalink
Added new test case and updated existing one
Browse files Browse the repository at this point in the history
  • Loading branch information
shinde-rahul committed Oct 3, 2023
1 parent 504c3a5 commit 0b0a998
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 43 deletions.
7 changes: 7 additions & 0 deletions Config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,12 @@
],
],
],
'fixtures' => [
'mautic.citrix.fixture.test.citrix' => [
'class' => \MauticPlugin\LeuchtfeuerGoToBundle\Tests\DataFixtures\ORM\LoadCitrixData::class,
'tag' => \Doctrine\Bundle\FixturesBundle\DependencyInjection\CompilerPass\FixturesCompilerPass::FIXTURE_TAG,
'optional' => true,
],
]
],
];
69 changes: 69 additions & 0 deletions Tests/CreateEntities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

namespace MauticPlugin\LeuchtfeuerGoToBundle\Tests;

use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Entity\LeadList;
use Mautic\PluginBundle\Entity\Integration;
use Mautic\PluginBundle\Entity\Plugin;
use Mautic\PluginBundle\Helper\IntegrationHelper;

trait CreateEntities
{
protected function createSegment($listConfig): LeadList
{
$list = new LeadList();
$list->setName($listConfig['name']);
$list->setPublicName($listConfig['name']);
$list->setAlias($listConfig['alias']);
$list->setIsGlobal($listConfig['public']);
$list->setFilters($listConfig['filters']);

$this->em->persist($list);

return $list;
}

protected function createIntegration(): void
{
$plugin = new Plugin();
$plugin->setName('GoTo Integration by Leuchtfeuer');
$plugin->setDescription('Enables integration with Mautic supported GoTo collaboration products.');
$plugin->setBundle('LeuchtfeuerGoToBundle');
$plugin->setVersion('1.0');
$plugin->setAuthor('Mautic');

$this->em->persist($plugin);

$webinar = new Integration();
$webinar->setIsPublished(true);
$webinar->setApiKeys([
'app_name' => 'Mautic',
'client_id' => 'client_id',
'client_secret' => 'client_secret',
]);
$webinar->setPlugin($plugin);
$webinar->setName('GoTo Integration by Leuchtfeuer');

$this->em->persist($webinar);
$this->em->flush();

/** @var IntegrationHelper $integrationHelper */
$integrationHelper = self::$container->get('mautic.helper.integration');

/** @var Integration $integration */
$integrationObject = $integrationHelper->getIntegrationObject('Gotowebinar');

$integrationObject->encryptAndSetApiKeys([
'app_name' => 'Mautic',
'client_id' => 'client_id',
'client_secret' => 'client_secret',
], $webinar);

$integrationObject->getIntegrationSettings()->setIsPublished(true);

$this->em->flush();
}
}
57 changes: 29 additions & 28 deletions Tests/DataFixtures/ORM/LoadCitrixData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,18 @@

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectManager;
use Mautic\LeadBundle\Entity\Lead;
use MauticPlugin\LeuchtfeuerGoToBundle\Entity\GoToEvent;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use MauticPlugin\LeuchtfeuerGoToBundle\Entity\GoToProduct;

/**
* Class LoadPageData.
*/
class LoadCitrixData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
class LoadCitrixData extends AbstractFixture implements OrderedFixtureInterface
{
/**
* @var ContainerInterface
*/
private $container;

/**
* {@inheritdoc}
*/
public function setContainer(ContainerInterface $container = null)
public function load(ObjectManager $manager): void
{
$this->container = $container;
}

public function load(ObjectManager $manager)
{
$em = $this->container->get('doctrine')->getManager();
$today = new \DateTime();
$email = 'joe.o\'connor@domain.com';

Expand All @@ -49,23 +34,39 @@ public function load(ObjectManager $manager)
$lead->setEmail($email);
$lead->checkAttributionDate();

$em->persist($lead);
$em->flush();
$manager->persist($lead);
$manager->flush();

$this->setReference('lead-citrix', $lead);

$product = new GoToProduct();
$product->setName('Sample Webinar');
$product->setDate($today->add(new \DateInterval('P1D')));
$product->setDuration(3600);
$product->setProductKey('1234567');
$product->setRecurrenceKey('7654321');
$product->setOrganizerKey('12123434');
$product->setProduct('webinar');
$product->setStatus('active');

$manager->persist($product);
$manager->flush();

$this->setReference('citrix-product', $product);


// create event
$event = new GoToEvent();
$event->setLead($lead);
$event->setContact($lead);
$event->setEventDate($today);
$event->setProduct('webinar');
$event->setEmail($email);
$event->setGoToProduct($product);
$event->setContact($lead);
$event->setEventType('registered');
$event->setEventName('sample-webinar_#0000');
$event->setEventDesc('Sample Webinar');
$event->setJoinUrl('sample-webinar_#0000');
// $event->setEventDesc('Sample Webinar');

$em->persist($event);
$em->flush();
$manager->persist($event);
$manager->flush();

$this->setReference('citrix-event', $event);
}
Expand Down
80 changes: 80 additions & 0 deletions Tests/Functional/GotoSegmentFilterFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace MauticPlugin\LeuchtfeuerGoToBundle\Tests\Functional;

use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\UserBundle\DataFixtures\ORM\LoadRoleData;
use Mautic\UserBundle\DataFixtures\ORM\LoadUserData;
use MauticPlugin\LeuchtfeuerGoToBundle\Tests\CreateEntities;
use MauticPlugin\LeuchtfeuerGoToBundle\Tests\DataFixtures\ORM\LoadCitrixData;

class GotoSegmentFilterFunctionalTest extends MauticMysqlTestCase
{
use CreateEntities;

protected function setUp(): void
{
parent::setUp();

$this->fixtures = $this->loadFixtures(
[
LoadRoleData::class,
LoadUserData::class,
LoadCitrixData::class
],
false
)->getReferenceRepository();

$this->createIntegration();
}

protected function beforeBeginTransaction(): void
{
$this->resetAutoincrement(
[
'leads',
'lead_lists',
'users',
]
);
}

public function testGotoSegments(): void
{
// Create Segment with filters
$segment = $this->createSegment([
'name' => 'Goto: Webinar Registration',
'alias' => 'goto-webinar-registration',
'public' => true,
'filters' => [
[
'glue' => 'and',
'type' => 'email',
'object' => 'lead',
'field' => 'webinar-registration',
'operator' => 'including',
'properties' => ['filter' => 'Any Webinar', 'display' => null],
],
],
]);

$this->em->flush();
$this->em->clear();

// Build segments
$command = $this->testSymfonyCommand(
'mautic:segments:update',
[
'-i' => $segment->getId(),
'--env' => 'test',
]
);

$output = $command->getDisplay();
$this->assertEquals(0, $command->getStatusCode());
$this->assertStringContainsString('1 total contact(s) to be added in batches of 300', $output);
$this->assertStringContainsString('1 contact(s) affected', $output);
}
}
49 changes: 34 additions & 15 deletions Tests/Model/CitrixModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,51 @@

namespace MauticPlugin\LeuchtfeuerGoToBundle\Tests\Model;

use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\UserBundle\DataFixtures\ORM\LoadRoleData;
use Mautic\UserBundle\DataFixtures\ORM\LoadUserData;
use MauticPlugin\LeuchtfeuerGoToBundle\Model\GoToModel;
use PHPUnit\Framework\TestCase;
use MauticPlugin\LeuchtfeuerGoToBundle\Tests\CreateEntities;
use MauticPlugin\LeuchtfeuerGoToBundle\Tests\DataFixtures\ORM\LoadCitrixData;

class CitrixModelTest extends TestCase
class CitrixModelTest extends MauticMysqlTestCase
{
/**
* {@inheritdoc}
*/
protected function getMauticFixtures($returnClassNames = false)
use CreateEntities;

protected function setUp(): void
{
$fixtures = [];
$fixturesDir = __DIR__.'/../DataFixtures/ORM';
parent::setUp();

$this->fixtures = $this->loadFixtures(
[
LoadRoleData::class,
LoadUserData::class,
LoadCitrixData::class
],
false
)->getReferenceRepository();

if (file_exists($fixturesDir)) {
$classPrefix = 'MauticPlugin\\LeuchtfeuerGoToBundle\\Tests\\DataFixtures\\ORM\\';
$this->populateFixturesFromDirectory($fixturesDir, $fixtures, $classPrefix, $returnClassNames);
}
$this->createIntegration();
}

return $fixtures;
protected function beforeBeginTransaction(): void
{
$this->resetAutoincrement(
[
'leads',
'lead_lists',
'users',
]
);
}

public function testCountEventsBy()
{
/** @var GoToModel $model */
$model = $this->container->get(GoToModel::class);
$model = self::$container->get('mautic.citrix.model.citrix');
$count = $model->countEventsBy('webinar', "joe.o'connor@domain.com", 'registered', ['sample-webinar_#0000']);
$this->assertEquals($count, 1);


$this->assertEquals(1, $count);
}
}

0 comments on commit 0b0a998

Please sign in to comment.