Spaces:
No application file
No application file
File size: 5,121 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
<?php
declare(strict_types=1);
namespace Mautic\IntegrationsBundle\Tests\Unit\Sync\DAO;
use Mautic\IntegrationsBundle\Exception\InvalidValueException;
use Mautic\IntegrationsBundle\Sync\DAO\Sync\InputOptionsDAO;
use Mautic\IntegrationsBundle\Sync\DAO\Sync\ObjectIdsDAO;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\Internal\Object\Contact;
use Mautic\IntegrationsBundle\Sync\SyncDataExchange\MauticSyncDataExchange;
use PHPUnit\Framework\TestCase;
class InputOptionsDAOTest extends TestCase
{
public function testWorkflowFromCliWithAllValuesSet(): void
{
$inputOptionsDAO = new InputOptionsDAO(
[
'integration' => 'Magento',
'first-time-sync' => true,
'disable-push' => false,
'disable-pull' => true,
'disable-activity-push' => true,
'mautic-object-id' => ['contact:12', 'contact:13', 'company:45'],
'integration-object-id' => ['Lead:hfskjdhf', 'Lead:hfskjdhr'],
'start-datetime' => '2019-09-12T12:01:20',
'end-datetime' => '2019-10-12T12:01:20',
'option' => ['custom1:1', 'custom2:2'],
]
);
$this->assertSame('Magento', $inputOptionsDAO->getIntegration());
$this->assertTrue($inputOptionsDAO->isFirstTimeSync());
$this->assertFalse($inputOptionsDAO->pullIsEnabled());
$this->assertTrue($inputOptionsDAO->pushIsEnabled());
$this->assertFalse($inputOptionsDAO->activityPushIsEnabled());
$this->assertSame(['12', '13'], $inputOptionsDAO->getMauticObjectIds()->getObjectIdsFor(Contact::NAME));
$this->assertSame(['45'], $inputOptionsDAO->getMauticObjectIds()->getObjectIdsFor(MauticSyncDataExchange::OBJECT_COMPANY));
$this->assertSame(['hfskjdhf', 'hfskjdhr'], $inputOptionsDAO->getIntegrationObjectIds()->getObjectIdsFor('Lead'));
$this->assertSame('2019-09-12T12:01:20+00:00', $inputOptionsDAO->getStartDateTime()->format(DATE_ATOM));
$this->assertSame('2019-10-12T12:01:20+00:00', $inputOptionsDAO->getEndDateTime()->format(DATE_ATOM));
$this->assertSame(['custom1' => '1', 'custom2' => '2'], $inputOptionsDAO->getOptions());
}
public function testWorkflowFromCliWithNoValuesSet(): void
{
$this->expectException(InvalidValueException::class);
new InputOptionsDAO([]);
}
public function testWorkflowFromCliWithOnlyIntegrationValuesSet(): void
{
$inputOptionsDAO = new InputOptionsDAO(['integration' => 'Magento']);
$this->assertSame('Magento', $inputOptionsDAO->getIntegration());
$this->assertFalse($inputOptionsDAO->isFirstTimeSync());
$this->assertTrue($inputOptionsDAO->pullIsEnabled());
$this->assertTrue($inputOptionsDAO->pushIsEnabled());
$this->assertTrue($inputOptionsDAO->activityPushIsEnabled());
$this->assertNull($inputOptionsDAO->getMauticObjectIds());
$this->assertNull($inputOptionsDAO->getIntegrationObjectIds());
$this->assertNull($inputOptionsDAO->getStartDateTime());
$this->assertNull($inputOptionsDAO->getEndDateTime());
$this->assertEmpty($inputOptionsDAO->getOptions());
}
public function testWorkflowFromServiceWithAllValuesSet(): void
{
$mauticObjectIds = new ObjectIdsDAO();
$integrationObjectIds = new ObjectIdsDAO();
$start = new \DateTimeImmutable('2019-09-12T12:01:20', new \DateTimeZone('UTC'));
$end = new \DateTimeImmutable('2019-10-12T12:01:20', new \DateTimeZone('UTC'));
$options = ['custom1' => 1, 'custom2' => 2];
$inputOptionsDAO = new InputOptionsDAO(
[
'integration' => 'Magento',
'first-time-sync' => true,
'disable-push' => false,
'disable-pull' => true,
'disable-activity-push' => false,
'mautic-object-id' => $mauticObjectIds,
'integration-object-id' => $integrationObjectIds,
'start-datetime' => $start,
'end-datetime' => $end,
'options' => $options,
]
);
$this->assertSame('Magento', $inputOptionsDAO->getIntegration());
$this->assertTrue($inputOptionsDAO->isFirstTimeSync());
$this->assertFalse($inputOptionsDAO->pullIsEnabled());
$this->assertTrue($inputOptionsDAO->pushIsEnabled());
$this->assertTrue($inputOptionsDAO->activityPushIsEnabled());
$this->assertSame($mauticObjectIds, $inputOptionsDAO->getMauticObjectIds());
$this->assertSame($integrationObjectIds, $inputOptionsDAO->getIntegrationObjectIds());
$this->assertSame($start, $inputOptionsDAO->getStartDateTime());
$this->assertSame($end, $inputOptionsDAO->getEndDateTime());
$this->assertSame($options, $inputOptionsDAO->getOptions());
}
}
|