forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mautic#1088 from mautic-inc/MAUT-4688
Maut 4688 - Use segment membership as a filter for dynamic content in email
- Loading branch information
Showing
11 changed files
with
483 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
app/bundles/CoreBundle/Test/Event/TokenReplacementEventTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2020 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link https://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\CoreBundle\Test\Event; | ||
|
||
use Mautic\CoreBundle\Event\TokenReplacementEvent; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class TokenReplacementEventTest extends TestCase | ||
{ | ||
public function testGetPassthrough(): void | ||
{ | ||
$passthrough = ['passthrough']; | ||
$event = new TokenReplacementEvent('', null, [], $passthrough); | ||
self::assertSame($passthrough, $event->getPassthrough()); | ||
} | ||
|
||
public function testGetSetContent(): void | ||
{ | ||
$content = 'content'; | ||
$event = new TokenReplacementEvent($content); | ||
self::assertSame($content, $event->getContent()); | ||
} | ||
|
||
public function testAddGetTokens(): void | ||
{ | ||
$token = 'token'; | ||
$value = 'value'; | ||
$token1 = 'token1'; | ||
$value1 = 'value1'; | ||
$event = new TokenReplacementEvent(''); | ||
self::assertSame([], $event->getTokens()); | ||
$event->addToken($token, $value); | ||
self::assertSame([$token => $value], $event->getTokens()); | ||
$event->addToken($token1, $value1); | ||
self::assertSame( | ||
[ | ||
$token => $value, | ||
$token1 => $value1, | ||
], | ||
$event->getTokens() | ||
); | ||
} | ||
|
||
public function testGetClickthrough(): void | ||
{ | ||
$leadId = 1; | ||
$leadEntity['id'] = $leadId; | ||
$clickthrough = ['lead' => $leadEntity]; | ||
$event = new TokenReplacementEvent('', $leadEntity, $clickthrough); | ||
self::assertSame( | ||
['lead' => 1], | ||
$event->getClickthrough() | ||
); | ||
|
||
$leadEntity = new Lead(); | ||
|
||
$clickthrough = ['lead', $leadEntity]; | ||
$event = new TokenReplacementEvent('', $leadEntity, $clickthrough); | ||
self::assertSame( | ||
$clickthrough, | ||
$event->getClickthrough() | ||
); | ||
|
||
$leadEntity->setId($leadId); | ||
$clickthrough = ['lead' => $leadEntity]; | ||
$event = new TokenReplacementEvent('', $leadEntity, $clickthrough); | ||
self::assertSame( | ||
['lead' => 1], | ||
$event->getClickthrough() | ||
); | ||
} | ||
|
||
public function testGetEntity(): void | ||
{ | ||
$lead = new Lead(); | ||
$event = new TokenReplacementEvent($lead); | ||
self::assertSame( | ||
$lead, | ||
$event->getEntity() | ||
); | ||
} | ||
|
||
public function testSetClickthrough(): void | ||
{ | ||
$lead = new Lead(); | ||
$event = new TokenReplacementEvent($lead); | ||
$clickthrough = ['clickthrough']; | ||
$event->setClickthrough($clickthrough); | ||
|
||
self::assertSame($clickthrough, $event->getClickthrough()); | ||
} | ||
|
||
public function testGetLead(): void | ||
{ | ||
$lead = null; | ||
$event = new TokenReplacementEvent('', $lead); | ||
self::assertSame($lead, $event->getLead()); | ||
$lead = new Lead(); | ||
$event = new TokenReplacementEvent('', $lead); | ||
self::assertSame($lead, $event->getLead()); | ||
} | ||
|
||
public function testSetContent(): void | ||
{ | ||
$content1 = 'content1'; | ||
$event = new TokenReplacementEvent(''); | ||
$event->setContent($content1); | ||
self::assertSame($content1, $event->getContent()); | ||
} | ||
} |
132 changes: 132 additions & 0 deletions
132
app/bundles/CoreBundle/Tests/Unit/Form/Type/DynamicContentFilterEntryFiltersTypeTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2020 Mautic Contributors. All rights reserved | ||
* @author Mautic | ||
* | ||
* @link https://mautic.org | ||
* | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\CoreBundle\Tests\Unit\Form\Type; | ||
|
||
use Mautic\CoreBundle\Form\Type\DynamicContentFilterEntryFiltersType; | ||
use Mautic\LeadBundle\Model\ListModel; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Form\FormEvent; | ||
use Symfony\Component\Form\FormEvents; | ||
use Symfony\Component\OptionsResolver\OptionsResolver; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
class DynamicContentFilterEntryFiltersTypeTest extends TestCase | ||
{ | ||
/** | ||
* @var MockObject|TranslatorInterface | ||
*/ | ||
private $translator; | ||
|
||
/** | ||
* @var ListModel|MockObject | ||
*/ | ||
private $listModel; | ||
|
||
/** | ||
* @var DynamicContentFilterEntryFiltersType | ||
*/ | ||
private $form; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->translator = $this->createMock(TranslatorInterface::class); | ||
$this->listModel = $this->createMock(ListModel::class); | ||
|
||
$this->form = new DynamicContentFilterEntryFiltersType($this->translator, $this->listModel); | ||
} | ||
|
||
public function testBuildForm(): void | ||
{ | ||
$builder = $this->createMock(FormBuilderInterface::class); | ||
$builder->expects(self::exactly(4)) | ||
->method('add') | ||
->withConsecutive( | ||
[ | ||
'glue', | ||
ChoiceType::class, | ||
[ | ||
'label' => false, | ||
'choices' => [ | ||
'mautic.lead.list.form.glue.and' => 'and', | ||
'mautic.lead.list.form.glue.or' => 'or', | ||
], | ||
'attr' => [ | ||
'class' => 'form-control not-chosen glue-select', | ||
'onchange' => 'Mautic.updateFilterPositioning(this)', | ||
], | ||
], | ||
], | ||
[ | ||
'field', | ||
HiddenType::class, | ||
], | ||
[ | ||
'object', | ||
HiddenType::class, | ||
], | ||
[ | ||
'type', | ||
HiddenType::class, | ||
] | ||
); | ||
|
||
$builder->expects($this->exactly(2)) | ||
->method('addEventListener') | ||
->withConsecutive( | ||
[ | ||
FormEvents::PRE_SET_DATA, | ||
function (FormEvent $event) use ($formModifier) { | ||
$formModifier($event, FormEvents::PRE_SET_DATA); | ||
}, | ||
], | ||
[ | ||
FormEvents::PRE_SUBMIT, | ||
function (FormEvent $event) use ($formModifier) { | ||
$formModifier($event, FormEvents::PRE_SUBMIT); | ||
}, | ||
] | ||
); | ||
|
||
$this->form->buildForm($builder, []); | ||
} | ||
|
||
public function testGetBlockPrefix(): void | ||
{ | ||
self::assertSame('dynamic_content_filter_entry_filters', $this->form->getBlockPrefix()); | ||
} | ||
|
||
public function testConfigureOptions(): void | ||
{ | ||
$resolver = $this->createMock(OptionsResolver::class); | ||
$resolver->expects(self::once()) | ||
->method('setRequired') | ||
->with([ | ||
'countries', | ||
'regions', | ||
'timezones', | ||
'stages', | ||
'locales', | ||
'fields', | ||
'lists', | ||
]); | ||
|
||
$this->form->configureOptions($resolver); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.