-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAUT-11515 : Custom object date segment filters should have have same…
… operators than date custom field filters (#358) * added all date/datetime filters to custom oject date fields * check if getcontext is exist * Added new function instead changing old one * change if condition sequence * increase code coverage * skip test case if mrunning on mautic 4.4
- Loading branch information
Showing
4 changed files
with
160 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,29 +6,25 @@ | |
|
||
use Mautic\CoreBundle\Test\MauticMysqlTestCase; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\LeadBundle\Entity\LeadField; | ||
use Mautic\LeadBundle\Entity\LeadList; | ||
use Mautic\LeadBundle\Entity\ListLead; | ||
use MauticPlugin\CustomObjectsBundle\CustomFieldType\CustomFieldTypeInterface; | ||
use MauticPlugin\CustomObjectsBundle\Entity\CustomField; | ||
use MauticPlugin\CustomObjectsBundle\Entity\CustomItem; | ||
use MauticPlugin\CustomObjectsBundle\Entity\CustomObject; | ||
use MauticPlugin\CustomObjectsBundle\Provider\CustomFieldTypeProvider; | ||
use MauticPlugin\CustomObjectsBundle\Tests\ProjectVersionTrait; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class FilterOperatorSubscriberTest extends MauticMysqlTestCase | ||
{ | ||
use ProjectVersionTrait; | ||
|
||
public function testIfNewOperatorNotInCustomObjectsAddedinSegmentFilter() | ||
{ | ||
// Create a segment | ||
$segment = new LeadList(); | ||
$segment->setName('Test Segment A'); | ||
$segment->setPublicName('Test Segment A'); | ||
$segment->setAlias('test-segment-a'); | ||
|
||
$this->em->persist($segment); | ||
$this->em->flush(); | ||
|
||
$crawler = $this->client->request(Request::METHOD_GET, '/s/segments/edit/'.$segment->getId()); | ||
|
||
$crawler = $this->client->request(Request::METHOD_GET, '/s/segments/new/'); | ||
$segment_filters = $crawler->filter('#available_segment_filters')->html(); | ||
|
||
$this->assertStringContainsString('not in custom objects', $segment_filters); | ||
} | ||
|
||
|
@@ -44,13 +40,7 @@ public function testIfProperContactsAreAddedinSegmentWithNotInCustomObjectsFilte | |
$this->em->persist($contact2); | ||
|
||
// 2) create custom object "Email List" with "[email protected]" and "[email protected]" as items | ||
$customObject = new CustomObject(); | ||
$customObject->setNameSingular('Email List'); | ||
$customObject->setNamePlural('Emai List'); | ||
$customObject->setAlias('emails'); | ||
$customObject->setType(CustomObject::TYPE_MASTER); | ||
$this->em->persist($customObject); | ||
|
||
$customObject = $this->createCustomObject('emails'); | ||
$customItem1 = new CustomItem($customObject); | ||
$customItem1->setName('[email protected]'); | ||
$this->em->persist($customItem1); | ||
|
@@ -94,4 +84,69 @@ public function testIfProperContactsAreAddedinSegmentWithNotInCustomObjectsFilte | |
$this->assertSame($contact2->getLastname(), $leads[0]->getLead()->getLastname()); | ||
$this->assertSame($contact2->getEmail(), $leads[0]->getLead()->getEmail()); | ||
} | ||
|
||
public function testCustomObjectSegmentFilterOperatorForDateField(): void | ||
{ | ||
if (!$this->isCloudProject()) { | ||
$this->markTestSkipped('As context is not available for segment only in 4.4'); | ||
} | ||
|
||
$leadField = $this->createField('date_field', 'date'); | ||
|
||
$fieldTypeProvider = self::$container->get('custom_field.type.provider'); | ||
\assert($fieldTypeProvider instanceof CustomFieldTypeProvider); | ||
$objectType = $fieldTypeProvider->getType('date'); | ||
$dateField = $this->createCustomField('co_date_field', $objectType); | ||
|
||
$this->createCustomObject('obj', $dateField); | ||
|
||
$this->em->flush(); | ||
$crawler = $this->client->request(Request::METHOD_GET, '/s/segments/new/'); | ||
|
||
$coDateFilterOperators = $crawler | ||
->filter('#available_segment_filters option[id="available_custom_object_cmf_'.$dateField->getId().'"]') | ||
->attr('data-field-operators'); | ||
|
||
$leadDateFilterOperators = $crawler | ||
->filter('#available_segment_filters option[id="available_lead_'.$leadField->getAlias().'"]') | ||
->attr('data-field-operators'); | ||
|
||
$this->assertSame($coDateFilterOperators, $leadDateFilterOperators); | ||
} | ||
|
||
private function createField(string $alias, string $type): LeadField | ||
{ | ||
$field = new LeadField(); | ||
$field->setName($alias); | ||
$field->setAlias($alias); | ||
$field->setType($type); | ||
$this->em->persist($field); | ||
|
||
return $field; | ||
} | ||
|
||
private function createCustomObject(string $alias, ?CustomField $dateField = null): CustomObject | ||
{ | ||
$customObject = new CustomObject(); | ||
$customObject->setNameSingular($alias); | ||
$customObject->setNamePlural($alias.'s'); | ||
$customObject->setAlias($alias); | ||
if ($dateField) { | ||
$customObject->addCustomField($dateField); | ||
} | ||
$this->em->persist($customObject); | ||
|
||
return $customObject; | ||
} | ||
|
||
private function createCustomField(string $alias, CustomFieldTypeInterface $objectType): CustomField | ||
{ | ||
$dateField = new CustomField(); | ||
$dateField->setTypeObject($objectType); | ||
$dateField->setType($objectType->getKey()); | ||
$dateField->setLabel($alias); | ||
$dateField->setAlias($alias); | ||
|
||
return $dateField; | ||
} | ||
} |
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