diff --git a/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php b/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php index c712bda75bf..bf80e0082a5 100644 --- a/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php +++ b/app/bundles/CampaignBundle/Tests/Command/AbstractCampaignCommand.php @@ -39,7 +39,7 @@ class AbstractCampaignCommand extends MauticMysqlTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { // Everything needs to happen anonymously $this->defaultClientServer = $this->clientServer; diff --git a/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php b/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php index 5fddb2c61e8..d4bcdd2ec4e 100644 --- a/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php +++ b/app/bundles/CampaignBundle/Tests/Command/TriggerCampaignCommandTest.php @@ -13,7 +13,7 @@ class TriggerCampaignCommandTest extends AbstractCampaignCommand { - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php b/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php index 3cea7953849..a007b4840f8 100644 --- a/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php +++ b/app/bundles/CampaignBundle/Tests/Membership/Action/AdderTest.php @@ -31,7 +31,7 @@ class AdderTest extends \PHPUnit_Framework_TestCase */ private $leadEventLogRepository; - public function setUp() + protected function setUp() { $this->leadRepository = $this->createMock(LeadRepository::class); $this->leadEventLogRepository = $this->createMock(LeadEventLogRepository::class); diff --git a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php b/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php deleted file mode 100644 index 1a85c305d47..00000000000 --- a/app/bundles/CoreBundle/DependencyInjection/Compiler/IntegrationPass.php +++ /dev/null @@ -1,61 +0,0 @@ -findTaggedServiceIds('mautic.integration') as $id => $tags) { - $definition = $container->findDefinition($id); - - /* - * @deprecated: To be removed in 3.0. Set dependencies on Integration constructor instead, - * using the service container config.php to pass those dependencies in. - */ - $definition->addMethodCall('setFactory', [new Reference('mautic.factory')]); - - $definition->addMethodCall('setDispatcher', [new Reference('event_dispatcher')]); - $definition->addMethodCall('setCache', [new Reference('mautic.helper.cache_storage')]); - $definition->addMethodCall('setEntityManager', [new Reference('doctrine.orm.entity_manager')]); - $definition->addMethodCall('setSession', [new Reference('session')]); - $definition->addMethodCall('setRequest', [new Reference('request_stack')]); - $definition->addMethodCall('setRouter', [new Reference('router')]); - $definition->addMethodCall('setTranslator', [new Reference('translator')]); - $definition->addMethodCall('setLogger', [new Reference('monolog.logger.mautic')]); - $definition->addMethodCall('setEncryptionHelper', [new Reference('mautic.helper.encryption')]); - $definition->addMethodCall('setLeadModel', [new Reference('mautic.lead.model.lead')]); - $definition->addMethodCall('setCompanyModel', [new Reference('mautic.lead.model.company')]); - $definition->addMethodCall('setPathsHelper', [new Reference('mautic.helper.paths')]); - $definition->addMethodCall('setNotificationModel', [new Reference('mautic.core.model.notification')]); - $definition->addMethodCall('setFieldModel', [new Reference('mautic.lead.model.field')]); - $definition->addMethodCall('setIntegrationEntityModel', [new Reference('mautic.plugin.model.integration_entity')]); - - $class = $definition->getClass(); - $reflected = new \ReflectionClass($class); - - if ($reflected->hasMethod('setIntegrationHelper')) { - $definition->addMethodCall('setIntegrationHelper', [new Reference('mautic.helper.integration')]); - } - } - } -} diff --git a/app/bundles/CoreBundle/MauticCoreBundle.php b/app/bundles/CoreBundle/MauticCoreBundle.php index b782010a107..f2a67cc6c52 100644 --- a/app/bundles/CoreBundle/MauticCoreBundle.php +++ b/app/bundles/CoreBundle/MauticCoreBundle.php @@ -26,6 +26,5 @@ public function build(ContainerBuilder $container) $container->addCompilerPass(new Compiler\TemplatingPass()); $container->addCompilerPass(new Compiler\TranslationsPass()); $container->addCompilerPass(new Compiler\ModelPass()); - $container->addCompilerPass(new Compiler\IntegrationPass()); } } diff --git a/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php b/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php index 85b577db1ce..1773e4370f2 100644 --- a/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php +++ b/app/bundles/CoreBundle/Test/AbstractMauticTestCase.php @@ -45,7 +45,7 @@ abstract class AbstractMauticTestCase extends WebTestCase 'PHP_AUTH_PW' => 'mautic', ]; - public function setUp() + protected function setUp() { \Mautic\CoreBundle\ErrorHandler\ErrorHandler::register('prod'); diff --git a/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php b/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php index 9d4c218f9b9..51650797057 100644 --- a/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php +++ b/app/bundles/CoreBundle/Test/EventListener/MaintenanceSubscriberTest.php @@ -27,7 +27,7 @@ class MaintenanceSubscriberTest extends \PHPUnit_Framework_TestCase */ private $subscriber; - public function setUp() + protected function setUp() { $connection = $this->createMock(Connection::class); $userTokenRepository = $this->createMock(UserTokenRepositoryInterface::class); diff --git a/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php b/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php index 22ad7fd8748..5341e72c7b2 100644 --- a/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticMysqlTestCase.php @@ -12,7 +12,7 @@ abstract class MauticMysqlTestCase extends AbstractMauticTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php b/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php index 9c8b0a4c251..bd41147c735 100644 --- a/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticSqliteTestCase.php @@ -8,7 +8,7 @@ abstract class MauticSqliteTestCase extends AbstractMauticTestCase { - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/app/bundles/CoreBundle/Test/MauticWebTestCase.php b/app/bundles/CoreBundle/Test/MauticWebTestCase.php index 014ec234329..e06e5fa5906 100644 --- a/app/bundles/CoreBundle/Test/MauticWebTestCase.php +++ b/app/bundles/CoreBundle/Test/MauticWebTestCase.php @@ -15,7 +15,6 @@ use Doctrine\Common\DataFixtures\ReferenceRepository; use Liip\FunctionalTestBundle\Test\WebTestCase; -use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Finder\Finder; use Symfony\Component\HttpFoundation\Request; @@ -202,7 +201,7 @@ protected function assertNoError($response, $crawler, $fullOutput = false) /** * {@inheritdoc} */ - public function setUp() + protected function setUp() { static::$kernel = static::createKernel(); static::$kernel->boot(); diff --git a/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php b/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php index 87803b6429c..aef0d5aef39 100644 --- a/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php +++ b/app/bundles/CoreBundle/Tests/Unit/Helper/IpLookupHelperTest.php @@ -28,7 +28,7 @@ public function __construct($name = null, array $data = [], $dataName = '') parent::__construct($name, $data, $dataName); } - public function setUp() + protected function setUp() { defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } diff --git a/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php b/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php index f0fa3db471f..5e334d05614 100644 --- a/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php +++ b/app/bundles/CoreBundle/Tests/Unit/IpLookup/MaxmindLookupTest.php @@ -25,7 +25,7 @@ class MaxmindLookupTest extends \PHPUnit_Framework_TestCase { protected $mockHttp; - public function setUp() + protected function setUp() { // Mock http connector $this->mockHttp = $this->getMockBuilder('Joomla\Http\Http') diff --git a/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php b/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php index 80c24c9d9e9..9f06c79048a 100644 --- a/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php +++ b/app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php @@ -56,7 +56,7 @@ class MailHelperTest extends \PHPUnit_Framework_TestCase ], ]; - public function setUp() + protected function setUp() { defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } diff --git a/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php b/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php index ecebc22df15..231acec158f 100644 --- a/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php +++ b/app/bundles/EmailBundle/Tests/Transport/AmazonTransportTest.php @@ -32,7 +32,7 @@ class AmazonTransportTest extends \PHPUnit_Framework_TestCase */ private $translator; - public function setUp() + protected function setUp() { $this->logger = $this->getMockBuilder(Logger::class) ->disableOriginalConstructor() diff --git a/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php b/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php index dfcc1eef9be..12e3204b09f 100644 --- a/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php +++ b/app/bundles/EmailBundle/Tests/Transport/ElasticemailTransportTest.php @@ -24,7 +24,7 @@ class ElasticemailTransportTest extends \PHPUnit_Framework_TestCase private $transportCallback; private $logger; - public function setUp() + protected function setUp() { $this->translator = $this->getMockBuilder(Translator::class) ->disableOriginalConstructor() diff --git a/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php b/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php index 9990b5bb073..9051db946ef 100644 --- a/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php +++ b/app/bundles/FormBundle/Tests/Helper/FormFieldHelperTest.php @@ -14,7 +14,7 @@ class FormFieldHelperTest extends \PHPUnit_Framework_TestCase */ protected $fixture; - public function setUp() + protected function setUp() { $translatorMock = $this->getMockBuilder(TranslatorInterface::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php index ac78dcf290f..a39f58df111 100644 --- a/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php +++ b/app/bundles/LeadBundle/Tests/Controller/Api/LeadApiControllerFunctionalTest.php @@ -198,7 +198,7 @@ public function testBachdDncAddAndRemove() $clientResponse = $this->client->getResponse(); $response = json_decode($clientResponse->getContent(), true); - $this->assertFalse(isset($response['contacts'][0]['doNotContact'][0])); + $this->assertEmpty($response['contacts'][0]['doNotContact']); // Remove contact $this->client->request('DELETE', "/api/contacts/$contactId/delete"); diff --git a/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php b/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php index 11aa3fec134..5a927e355ac 100644 --- a/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php +++ b/app/bundles/LeadBundle/Tests/Helper/TokenHelperTest.php @@ -28,7 +28,7 @@ class TokenHelperTest extends \PHPUnit_Framework_TestCase ], ]; - public function setUp() + protected function setUp() { $reflectionProperty = new ReflectionProperty(TokenHelper::class, 'parameters'); $reflectionProperty->setAccessible(true); diff --git a/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php b/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php index 116631295b2..7ab51d7c957 100644 --- a/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php +++ b/app/bundles/LeadBundle/Tests/Model/CompanyReportDataTest.php @@ -25,7 +25,7 @@ class CompanyReportDataTest extends \PHPUnit_Framework_TestCase */ private $translator; - public function setUp() + protected function setUp() { $this->translator = $this->getMockBuilder(Translator::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php b/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php index d2fc0e582e4..8324de104de 100644 --- a/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php +++ b/app/bundles/LeadBundle/Tests/Model/LeadListModelTest.php @@ -10,7 +10,7 @@ class LeadListModelTest extends \PHPUnit_Framework_TestCase { protected $fixture; - public function setUp() + protected function setUp() { $mockListModel = $this->getMockBuilder(ListModel::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php index ae5da5ddd10..89df6957068 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/BaseDecoratorTest.php @@ -17,7 +17,7 @@ class BaseDecoratorTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php index e8d700bf206..c7b24a9a562 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/CustomMappedDecoratorTest.php @@ -18,7 +18,7 @@ class CustomMappedDecoratorTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php b/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php index a1a1ab28dee..a9306bae517 100644 --- a/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php +++ b/app/bundles/LeadBundle/Tests/Segment/Decorator/DecoratorFactoryTest.php @@ -22,7 +22,7 @@ class DecoratorFactoryTest extends \PHPUnit_Framework_TestCase { - public function setUp() + protected function setUp() { parent::setUp(); defined('MAUTIC_TABLE_PREFIX') or define('MAUTIC_TABLE_PREFIX', ''); diff --git a/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php b/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php index 5bdc4e0c9ac..648836c8c02 100644 --- a/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php +++ b/app/bundles/LeadBundle/Tests/Tracker/ContactTrackerTest.php @@ -80,7 +80,7 @@ class ContactTrackerTest extends \PHPUnit_Framework_TestCase */ private $leadFieldModelMock; - public function setUp() + protected function setUp() { $this->leadRepositoryMock = $this->getMockBuilder(LeadRepository::class) ->disableOriginalConstructor() diff --git a/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php b/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php index 76fd3aeda75..32169375c71 100644 --- a/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php +++ b/app/bundles/LeadBundle/Tests/Tracker/DeviceTrackerTest.php @@ -46,7 +46,7 @@ class DeviceTrackerTest extends \PHPUnit_Framework_TestCase */ private $userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36'; - public function setUp() + protected function setUp() { $this->deviceCreatorService = new DeviceCreatorService(); diff --git a/app/bundles/NotificationBundle/Config/config.php b/app/bundles/NotificationBundle/Config/config.php index 4d4047033ab..9a855bdcdb9 100644 --- a/app/bundles/NotificationBundle/Config/config.php +++ b/app/bundles/NotificationBundle/Config/config.php @@ -158,7 +158,24 @@ ], 'integrations' => [ 'mautic.integration.onesignal' => [ - 'class' => \Mautic\NotificationBundle\Integration\OneSignalIntegration::class, + 'class' => \Mautic\NotificationBundle\Integration\OneSignalIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], ], diff --git a/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php b/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php index 7fc528cba03..d0bfa930780 100644 --- a/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php +++ b/app/bundles/PageBundle/Tests/Controller/PageControllerTest.php @@ -22,7 +22,7 @@ class PageControllerTest extends MauticMysqlTestCase /** * @throws \Exception */ - public function setUp() + protected function setUp() { parent::setUp(); $this->db = $this->container->get('doctrine.dbal.default_connection'); diff --git a/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php b/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php index 6528e91f8fc..6b9208ee84d 100644 --- a/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php +++ b/app/bundles/PluginBundle/Command/PushLeadActivityCommand.php @@ -11,6 +11,7 @@ namespace Mautic\PluginBundle\Command; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Integration\AbstractIntegration; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputInterface; @@ -67,10 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); - /** @var \Mautic\CoreBundle\Factory\MauticFactory $factory */ - $factory = $container->get('mautic.factory'); - - $translator = $factory->getTranslator(); + $translator = $container->get('translator'); $integration = $input->getOption('integration'); $startDate = $input->getOption('start-date'); $endDate = $input->getOption('end-date'); @@ -88,8 +86,8 @@ protected function execute(InputInterface $input, OutputInterface $output) } if ($integration && $startDate && $endDate) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ - $integrationHelper = $factory->getHelper('integration'); + /** @var IntegrationHelper $integrationHelper */ + $integrationHelper = $container->get('mautic.helper.integration'); /** @var AbstractIntegration $integrationObject */ $integrationObject = $integrationHelper->getIntegrationObject($integration); diff --git a/app/bundles/PluginBundle/Config/config.php b/app/bundles/PluginBundle/Config/config.php index 934883e03ee..84821936d2b 100644 --- a/app/bundles/PluginBundle/Config/config.php +++ b/app/bundles/PluginBundle/Config/config.php @@ -102,44 +102,36 @@ ], 'forms' => [ 'mautic.form.type.integration.details' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\DetailsType', - 'alias' => 'integration_details', + 'class' => \Mautic\PluginBundle\Form\Type\DetailsType::class, ], 'mautic.form.type.integration.settings' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\FeatureSettingsType', + 'class' => \Mautic\PluginBundle\Form\Type\FeatureSettingsType::class, 'arguments' => [ 'session', 'mautic.helper.core_parameters', 'monolog.logger.mautic', ], - 'alias' => 'integration_featuresettings', ], 'mautic.form.type.integration.fields' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\FieldsType', - 'alias' => 'integration_fields', - 'arguments' => 'translator', + 'class' => \Mautic\PluginBundle\Form\Type\FieldsType::class, ], 'mautic.form.type.integration.company.fields' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\CompanyFieldsType', - 'alias' => 'integration_company_fields', - 'arguments' => 'translator', + 'class' => \Mautic\PluginBundle\Form\Type\CompanyFieldsType::class, ], 'mautic.form.type.integration.keys' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\KeysType', - 'alias' => 'integration_keys', + 'class' => \Mautic\PluginBundle\Form\Type\KeysType::class, ], 'mautic.form.type.integration.list' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationsListType', - 'arguments' => 'mautic.factory', - 'alias' => 'integration_list', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationsListType::class, + 'arguments' => [ + 'mautic.helper.integration', + ], ], 'mautic.form.type.integration.config' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationConfigType', - 'alias' => 'integration_config', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationConfigType::class, ], 'mautic.form.type.integration.campaign' => [ - 'class' => 'Mautic\PluginBundle\Form\Type\IntegrationCampaignsType', - 'alias' => 'integration_campaign_status', + 'class' => \Mautic\PluginBundle\Form\Type\IntegrationCampaignsType::class, ], ], 'other' => [ diff --git a/app/bundles/PluginBundle/Controller/AjaxController.php b/app/bundles/PluginBundle/Controller/AjaxController.php index ba494d6373c..5bc5e625f43 100644 --- a/app/bundles/PluginBundle/Controller/AjaxController.php +++ b/app/bundles/PluginBundle/Controller/AjaxController.php @@ -13,6 +13,10 @@ use Mautic\CoreBundle\Controller\AjaxController as CommonAjaxController; use Mautic\CoreBundle\Helper\InputHelper; +use Mautic\PluginBundle\Form\Type\CompanyFieldsType; +use Mautic\PluginBundle\Form\Type\FieldsType; +use Mautic\PluginBundle\Form\Type\IntegrationCampaignsType; +use Mautic\PluginBundle\Form\Type\IntegrationConfigType; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\HttpFoundation\Request; @@ -79,7 +83,7 @@ protected function getIntegrationFieldsAction(Request $request) $mauticFields = ($isLead) ? $pluginModel->getLeadFields() : $pluginModel->getCompanyFields(); $featureSettings = $integrationObject->getIntegrationSettings()->getFeatureSettings(); $enableDataPriority = $integrationObject->getDataPriority(); - $formType = $isLead ? 'integration_fields' : 'integration_company_fields'; + $formType = $isLead ? FieldsType::class : CompanyFieldsType::class; $form = $this->createForm( $formType, isset($featureSettings[$object.'Fields']) ? $featureSettings[$object.'Fields'] : [], @@ -130,36 +134,6 @@ protected function getIntegrationFieldsAction(Request $request) return $this->sendJsonResponse($dataArray); } - /** - * Get the HTML for list of fields. - * - * @deprecated 2.8.0 to be removed in 3.0 - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationLeadFieldsAction(Request $request) - { - $request->attributes->set('object', 'lead'); - - return $this->getIntegrationFieldsAction($request); - } - - /** - * Get the HTML for list of fields. - * - * @deprecated 2.8.0 to be removed in 3.0 - * - * @param Request $request - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - */ - protected function getIntegrationCompanyFieldsAction(Request $request) - { - $request->attributes->set('object', 'company'); - - return $this->getIntegrationFieldsAction($request); - } - /** * Get the HTML for integration properties. * @@ -191,7 +165,7 @@ protected function getIntegrationConfigAction(Request $request) } } } - $form = $this->createForm('integration_config', $defaults, [ + $form = $this->createForm(IntegrationConfigType::class, $defaults, [ 'integration' => $object, 'csrf_protection' => false, 'campaigns' => $data, @@ -246,7 +220,7 @@ protected function getIntegrationCampaignStatusAction(Request $request) } } } - $form = $this->createForm('integration_campaign_status', $statusData, [ + $form = $this->createForm(IntegrationCampaignsType::class, $statusData, [ 'csrf_protection' => false, 'campaignContactStatus' => $statusData, ]); diff --git a/app/bundles/PluginBundle/Controller/PluginController.php b/app/bundles/PluginBundle/Controller/PluginController.php index 2c762649169..0235de0beeb 100644 --- a/app/bundles/PluginBundle/Controller/PluginController.php +++ b/app/bundles/PluginBundle/Controller/PluginController.php @@ -13,10 +13,9 @@ use Mautic\CoreBundle\Controller\FormController; use Mautic\CoreBundle\Helper\InputHelper; -use Mautic\PluginBundle\Entity\Integration; -use Mautic\PluginBundle\Entity\Plugin; use Mautic\PluginBundle\Event\PluginIntegrationAuthRedirectEvent; use Mautic\PluginBundle\Event\PluginIntegrationEvent; +use Mautic\PluginBundle\Form\Type\DetailsType; use Mautic\PluginBundle\Integration\AbstractIntegration; use Mautic\PluginBundle\Model\PluginModel; use Mautic\PluginBundle\PluginEvents; @@ -181,7 +180,7 @@ public function configAction($name, $activeTab = 'details-container', $page = 1) $entity = $integrationObject->getIntegrationSettings(); $form = $this->createForm( - 'integration_details', + DetailsType::class, $entity, [ 'integration' => $entity->getName(), diff --git a/app/bundles/PluginBundle/Entity/IntegrationEntity.php b/app/bundles/PluginBundle/Entity/IntegrationEntity.php index 48530352524..7e08c95b1d5 100644 --- a/app/bundles/PluginBundle/Entity/IntegrationEntity.php +++ b/app/bundles/PluginBundle/Entity/IntegrationEntity.php @@ -82,7 +82,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) $builder = new ClassMetadataBuilder($metadata); $builder->setTable('integration_entity') - ->setCustomRepositoryClass('Mautic\PluginBundle\Entity\IntegrationEntityRepository') + ->setCustomRepositoryClass(IntegrationEntityRepository::class) ->addIndex(['integration', 'integration_entity', 'integration_entity_id'], 'integration_external_entity') ->addIndex(['integration', 'internal_entity', 'internal_entity_id'], 'integration_internal_entity') ->addIndex(['integration', 'internal_entity', 'integration_entity'], 'integration_entity_match') diff --git a/app/bundles/PluginBundle/Entity/Plugin.php b/app/bundles/PluginBundle/Entity/Plugin.php index 1d97c05c7ce..49bf244031b 100644 --- a/app/bundles/PluginBundle/Entity/Plugin.php +++ b/app/bundles/PluginBundle/Entity/Plugin.php @@ -86,7 +86,7 @@ public static function loadMetadata(ORM\ClassMetadata $metadata) $builder = new ClassMetadataBuilder($metadata); $builder->setTable('plugins') - ->setCustomRepositoryClass('Mautic\PluginBundle\Entity\PluginRepository') + ->setCustomRepositoryClass(PluginRepository::class) ->addUniqueConstraint(['bundle'], 'unique_bundle'); $builder->addIdColumns(); diff --git a/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php b/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php index f8667759c4d..03f9561d7af 100644 --- a/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/CampaignSubscriber.php @@ -14,6 +14,7 @@ use Mautic\CampaignBundle\CampaignEvents; use Mautic\CampaignBundle\Event\CampaignBuilderEvent; use Mautic\CampaignBundle\Event\CampaignExecutionEvent; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; use Mautic\PluginBundle\PluginEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -40,7 +41,7 @@ public function onCampaignBuild(CampaignBuilderEvent $event) $action = [ 'label' => 'mautic.plugin.actions.push_lead', 'description' => 'mautic.plugin.actions.tooltip', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', 'eventName' => PluginEvents::ON_CAMPAIGN_TRIGGER_ACTION, ]; diff --git a/app/bundles/PluginBundle/EventListener/FormSubscriber.php b/app/bundles/PluginBundle/EventListener/FormSubscriber.php index d418b3426ef..04cc7c950fe 100644 --- a/app/bundles/PluginBundle/EventListener/FormSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/FormSubscriber.php @@ -14,6 +14,7 @@ use Mautic\FormBundle\Event\FormBuilderEvent; use Mautic\FormBundle\Event\SubmissionEvent; use Mautic\FormBundle\FormEvents; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; use Mautic\PluginBundle\PluginEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -41,7 +42,7 @@ public function onFormBuild(FormBuilderEvent $event) 'group' => 'mautic.plugin.actions', 'description' => 'mautic.plugin.actions.tooltip', 'label' => 'mautic.plugin.actions.push_lead', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', 'eventName' => PluginEvents::ON_FORM_SUBMIT_ACTION_TRIGGERED, ]; diff --git a/app/bundles/PluginBundle/EventListener/PointSubscriber.php b/app/bundles/PluginBundle/EventListener/PointSubscriber.php index 4186687abab..e3f9ff2a38d 100644 --- a/app/bundles/PluginBundle/EventListener/PointSubscriber.php +++ b/app/bundles/PluginBundle/EventListener/PointSubscriber.php @@ -11,6 +11,8 @@ namespace Mautic\PluginBundle\EventListener; +use Mautic\PluginBundle\Form\Type\IntegrationsListType; +use Mautic\PluginBundle\Helper\EventHelper; use Mautic\PointBundle\Event\TriggerBuilderEvent; use Mautic\PointBundle\PointEvents; use Symfony\Component\EventDispatcher\EventSubscriberInterface; @@ -35,9 +37,9 @@ public function onTriggerBuild(TriggerBuilderEvent $event) $action = [ 'group' => 'mautic.plugin.point.action', 'label' => 'mautic.plugin.actions.push_lead', - 'formType' => 'integration_list', + 'formType' => IntegrationsListType::class, 'formTheme' => 'MauticPluginBundle:FormTheme\Integration', - 'callback' => ['\\Mautic\\PluginBundle\\Helper\\EventHelper', 'pushLead'], + 'callback' => [EventHelper::class, 'pushLead'], ]; $event->addEvent('plugin.leadpush', $action); diff --git a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php index 876c7d75171..95b12c758f6 100644 --- a/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/CompanyFieldsType.php @@ -16,7 +16,6 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; /** * Class SocialMediaServiceType. @@ -25,23 +24,13 @@ class CompanyFieldsType extends AbstractType { use FieldsTypeTrait; - private $translator; - - /** - * @param TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { - $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], 'company', $options['limit'], $options['start'], $this->translator); + $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], 'company', $options['limit'], $options['start']); } /** @@ -55,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_company_fields'; } diff --git a/app/bundles/PluginBundle/Form/Type/DetailsType.php b/app/bundles/PluginBundle/Form/Type/DetailsType.php index ceec85416dc..c156574d3f7 100644 --- a/app/bundles/PluginBundle/Form/Type/DetailsType.php +++ b/app/bundles/PluginBundle/Form/Type/DetailsType.php @@ -14,11 +14,14 @@ use Mautic\CoreBundle\Form\Type\FormButtonsType; use Mautic\CoreBundle\Form\Type\StandAloneButtonType; use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; +use Mautic\PluginBundle\Entity\Integration; use Symfony\Component\Form\AbstractType; +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\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class DetailsType. @@ -42,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } } - $builder->add('apiKeys', 'integration_keys', [ + $builder->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -53,7 +56,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $data = $event->getData(); $form = $event->getForm(); - $form->add('apiKeys', 'integration_keys', [ + $form->add('apiKeys', KeysType::class, [ 'label' => false, 'integration_keys' => $keys, 'data' => $decryptedKeys, @@ -87,18 +90,19 @@ public function buildForm(FormBuilderInterface $builder, array $options) $choices = []; foreach ($features as $f) { - $choices[$f] = 'mautic.integration.form.feature.'.$f; + $choices['mautic.integration.form.feature.'.$f] = $f; } - $builder->add('supportedFeatures', 'choice', [ - 'choices' => $choices, - 'expanded' => true, - 'label_attr' => ['class' => 'control-label'], - 'multiple' => true, - 'label' => 'mautic.integration.form.features', - 'required' => false, - 'data' => $data, - 'choice_attr' => function ($val, $key, $index) use ($tooltips) { + $builder->add('supportedFeatures', ChoiceType::class, [ + 'choices' => $choices, + 'expanded' => true, + 'label_attr' => ['class' => 'control-label'], + 'multiple' => true, + 'label' => 'mautic.integration.form.features', + 'required' => false, + 'data' => $data, + 'choices_as_values' => true, + 'choice_attr' => function ($val, $key, $index) use ($tooltips) { if (array_key_exists($val, $tooltips)) { return [ 'data-toggle' => 'tooltip', @@ -111,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]); } - $builder->add('featureSettings', 'integration_featuresettings', [ + $builder->add('featureSettings', FeatureSettingsType::class, [ 'label' => 'mautic.integration.form.feature.settings', 'required' => true, 'data' => $options['data']->getFeatureSettings(), @@ -122,9 +126,9 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'company_fields' => $options['company_fields'], ]); - $builder->add('name', 'hidden', ['data' => $options['integration']]); + $builder->add('name', HiddenType::class, ['data' => $options['integration']]); - $builder->add('in_auth', 'hidden', ['mapped' => false]); + $builder->add('in_auth', HiddenType::class, ['mapped' => false]); $builder->add('buttons', FormButtonsType::class); @@ -138,10 +142,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'data_class' => 'Mautic\PluginBundle\Entity\Integration', + 'data_class' => Integration::class, ]); $resolver->setRequired(['integration', 'integration_object', 'lead_fields', 'company_fields']); @@ -150,7 +154,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_details'; } diff --git a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php index 8211afb0321..63564ac8234 100644 --- a/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php +++ b/app/bundles/PluginBundle/Form/Type/FeatureSettingsType.php @@ -47,6 +47,7 @@ class FeatureSettingsType extends AbstractType * * @param Session $session * @param CoreParametersHelper $coreParametersHelper + * @param LoggerInterface $logger */ public function __construct( Session $session, @@ -120,7 +121,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $form->add( 'leadFields', - 'integration_fields', + FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, @@ -140,7 +141,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!empty($integrationCompanyFields)) { $form->add( 'companyFields', - 'integration_company_fields', + CompanyFieldsType::class, [ 'label' => 'mautic.integration.companyfield_matches', 'required' => true, @@ -190,7 +191,7 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_featuresettings'; } diff --git a/app/bundles/PluginBundle/Form/Type/FieldsType.php b/app/bundles/PluginBundle/Form/Type/FieldsType.php index db0e2bbcd53..32b516d10fd 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsType.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsType.php @@ -16,7 +16,6 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; /** * Class FieldsType. @@ -25,23 +24,13 @@ class FieldsType extends AbstractType { use FieldsTypeTrait; - private $translator; - - /** - * @param TranslatorInterface $translator - */ - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - /** * @param FormBuilderInterface $builder * @param array $options */ public function buildForm(FormBuilderInterface $builder, array $options) { - $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], '', $options['limit'], $options['start'], $this->translator); + $this->buildFormFields($builder, $options, $options['integration_fields'], $options['mautic_fields'], '', $options['limit'], $options['start']); } /** @@ -55,7 +44,7 @@ public function configureOptions(OptionsResolver $resolver) /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_fields'; } diff --git a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php index aa44181cd3e..15063f6035e 100644 --- a/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php +++ b/app/bundles/PluginBundle/Form/Type/FieldsTypeTrait.php @@ -12,14 +12,15 @@ namespace Mautic\PluginBundle\Form\Type; use Mautic\CoreBundle\Form\Type\ButtonGroupType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\Options; use Symfony\Component\OptionsResolver\OptionsResolver; -use Symfony\Component\Translation\TranslatorInterface; trait FieldsTypeTrait { @@ -29,6 +30,8 @@ trait FieldsTypeTrait * @param array $integrationFields * @param array $mauticFields * @param string $fieldObject + * @param $limit + * @param $start */ protected function buildFormFields( FormBuilderInterface $builder, @@ -37,12 +40,11 @@ protected function buildFormFields( array $mauticFields, $fieldObject, $limit, - $start, - TranslatorInterface $translator + $start ) { $builder->addEventListener( FormEvents::PRE_SET_DATA, - function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $fieldObject, $limit, $start, $translator) { + function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $fieldObject, $limit, $start) { $form = $event->getForm(); $index = 0; $choices = []; @@ -50,6 +52,13 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f $optionalFields = []; $group = []; $fieldData = $event->getData(); + + foreach ($mauticFields as $key => $value) { + if (is_array($mauticFields)) { + $mauticFields[$key] = array_flip($value); + } + } + // First loop to build options foreach ($integrationFields as $field => $details) { $groupName = '0default'; @@ -132,7 +141,7 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f ++$index; $form->add( 'label_'.$index, - 'text', + TextType::class, [ 'label' => false, 'data' => $choices[$field], @@ -185,16 +194,16 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f ] ); } + if (!$fieldObject) { - $contactId['mauticContactId'] = $this->translator->trans('mautic.lead.report.contact_id'); - $contactLink['mauticContactTimelineLink'] = $this->translator->trans('mautic.plugin.integration.contact.timeline.link'); - $isContactable['mauticContactIsContactableByEmail'] = $this->translator->trans('mautic.plugin.integration.contact.donotcontact.email'); - $mauticFields = array_merge($mauticFields, $contactLink, $isContactable, $contactId); + $mauticFields['mautic.lead.report.contact_id'] = 'mauticContactId'; + $mauticFields['mautic.plugin.integration.contact.timeline.link'] = 'mauticContactTimelineLink'; + $mauticFields['mautic.plugin.integration.contact.donotcontact.email'] = 'mauticContactIsContactableByEmail'; } $form->add( 'm_'.$index, - 'choice', + ChoiceType::class, [ 'choices' => $mauticFields, 'label' => false, @@ -207,6 +216,7 @@ function (FormEvent $event) use ($options, $integrationFields, $mauticFields, $f 'data-value' => $matched && isset($fieldData[$fieldsName][$field]) ? $fieldData[$fieldsName][$field] : '', 'data-choices' => $mauticFields, ], + 'choices_as_values' => true, ] ); $form->add( diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php index e5951cbc5ea..3fec573599a 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationCampaignsType.php @@ -12,8 +12,9 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class IntegrationCampaignsType. @@ -28,10 +29,11 @@ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add( 'campaign_member_status', - 'choice', + ChoiceType::class, [ - 'choices' => $options['campaignContactStatus'], - 'attr' => [ + 'choices' => array_flip($options['campaignContactStatus']), + 'choices_as_values' => true, + 'attr' => [ 'class' => 'form-control', ], 'label' => 'mautic.plugin.integration.campaigns.member.status', 'required' => false, @@ -42,7 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults( ['campaignContactStatus' => []]); @@ -51,7 +53,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_campaign_status'; } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php index a8e36a6d94e..8cdfe143834 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationConfigType.php @@ -12,8 +12,9 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; /** * Class IntegrationConfigType. @@ -32,14 +33,15 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!empty($options['campaigns'])) { $builder->add( 'campaigns', - 'choice', + ChoiceType::class, [ - 'choices' => $options['campaigns'], + 'choices' => array_flip($options['campaigns']), 'attr' => [ 'class' => 'form-control', 'onchange' => 'Mautic.getIntegrationCampaignStatus(this);', ], - 'label' => 'mautic.plugin.integration.campaigns', - 'empty_value' => 'mautic.plugin.config.campaign.member.chooseone', - 'required' => false, + 'label' => 'mautic.plugin.integration.campaigns', + 'empty_value' => 'mautic.plugin.config.campaign.member.chooseone', + 'required' => false, + 'choices_as_values' => true, ] ); } @@ -48,7 +50,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['integration']); $resolver->setDefaults([ @@ -60,7 +62,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_config'; } diff --git a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php index 2f9f143501c..db6a7f5068f 100644 --- a/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php +++ b/app/bundles/PluginBundle/Form/Type/IntegrationsListType.php @@ -11,13 +11,14 @@ namespace Mautic\PluginBundle\Form\Type; -use Mautic\CoreBundle\Factory\MauticFactory; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -26,13 +27,16 @@ class IntegrationsListType extends AbstractType { /** - * @var MauticFactory + * @var IntegrationHelper */ - private $factory; + private $integrationHelper; - public function __construct(MauticFactory $factory) + /** + * @param IntegrationHelper $integrationHelper + */ + public function __construct(IntegrationHelper $integrationHelper) { - $this->factory = $factory; + $this->integrationHelper = $integrationHelper; } /** @@ -40,9 +44,7 @@ public function __construct(MauticFactory $factory) */ public function buildForm(FormBuilderInterface $builder, array $options) { - /** @var \Mautic\PluginBundle\Helper\IntegrationHelper $integrationHelper */ - $integrationHelper = $this->factory->getHelper('integration'); - $integrationObjects = $integrationHelper->getIntegrationObjects(null, $options['supported_features'], true); + $integrationObjects = $this->integrationHelper->getIntegrationObjects(null, $options['supported_features'], true); $integrations = ['' => '']; foreach ($integrationObjects as $name => $object) { @@ -52,13 +54,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) if (!isset($integrations[$settings->getPlugin()->getName()])) { $integrations[$settings->getPlugin()->getName()] = []; } - $integrations[$settings->getPlugin()->getName()][$object->getName()] = $object->getDisplayName(); + $integrations[$settings->getPlugin()->getName()][$object->getDisplayName()] = $object->getName(); } } $builder->add( 'integration', - 'choice', + ChoiceType::class, [ 'choices' => $integrations, 'expanded' => false, @@ -76,6 +78,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ['message' => 'mautic.core.value.required'] ), ], + 'choices_as_values' => true, ] ); @@ -84,8 +87,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $campaignChoices = []; if (isset($data['integration'])) { - $integration = $data['integration']; - $integrationObject = $integrationHelper->getIntegrationObject($data['integration']); + $integrationObject = $this->integrationHelper->getIntegrationObject($data['integration']); if (method_exists($integrationObject, 'getCampaigns')) { $campaigns = $integrationObject->getCampaigns(); @@ -107,7 +109,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } $form->add( 'config', - 'integration_config', + IntegrationConfigType::class, [ 'label' => false, 'attr' => [ @@ -122,7 +124,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $hideClass = (isset($data['campaign_member_status']) && !empty($data['campaign_member_status']['campaign_member_status'])) ? '' : ' hide'; $form->add( 'campaign_member_status', - 'integration_campaign_status', + IntegrationCampaignsType::class, [ 'label' => false, 'attr' => [ @@ -154,9 +156,9 @@ function (FormEvent $event) use ($formModifier) { /** * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { - $resolver->setOptional(['supported_features']); + $resolver->setDefined(['supported_features']); $resolver->setDefaults( [ 'supported_features' => 'push_lead', @@ -167,7 +169,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver) /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'integration_list'; } diff --git a/app/bundles/PluginBundle/Form/Type/KeysType.php b/app/bundles/PluginBundle/Form/Type/KeysType.php index 2df37f04a10..3c73b169e21 100644 --- a/app/bundles/PluginBundle/Form/Type/KeysType.php +++ b/app/bundles/PluginBundle/Form/Type/KeysType.php @@ -12,8 +12,10 @@ namespace Mautic\PluginBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\PasswordType; +use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\OptionsResolver\OptionsResolverInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Callback; use Symfony\Component\Validator\Context\ExecutionContextInterface; @@ -52,7 +54,7 @@ function ($validateMe, ExecutionContextInterface $context) use ($options) { ), ] : []; - $type = ($isSecret) ? 'password' : 'text'; + $type = ($isSecret) ? PasswordType::class : TextType::class; $builder->add( $key, @@ -75,19 +77,19 @@ function ($validateMe, ExecutionContextInterface $context) use ($options) { } /** - * @param OptionsResolverInterface $resolver + * {@inheritdoc} */ - public function setDefaultOptions(OptionsResolverInterface $resolver) + public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(['integration_object', 'integration_keys']); - $resolver->setOptional(['secret_keys']); + $resolver->setDefined(['secret_keys']); $resolver->setDefaults(['secret_keys' => [], 'is_published' => true]); } /** * @return string */ - public function getName() + public function getBlockPrefix() { return 'integration_keys'; } diff --git a/app/bundles/PluginBundle/Helper/IntegrationHelper.php b/app/bundles/PluginBundle/Helper/IntegrationHelper.php index 2e571903e1f..42c6d62e8b5 100644 --- a/app/bundles/PluginBundle/Helper/IntegrationHelper.php +++ b/app/bundles/PluginBundle/Helper/IntegrationHelper.php @@ -12,7 +12,6 @@ namespace Mautic\PluginBundle\Helper; use Doctrine\ORM\EntityManager; -use Mautic\CoreBundle\Factory\MauticFactory; use Mautic\CoreBundle\Helper\BundleHelper; use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\DateTimeHelper; @@ -66,13 +65,6 @@ class IntegrationHelper */ protected $pluginModel; - /** - * @deprecated 2.8.2 To be removed in 3.0 - * - * @var MauticFactory - */ - protected $factory; - private $integrations = []; private $available = []; @@ -82,8 +74,6 @@ class IntegrationHelper private $byPlugin = []; /** - * IntegrationHelper constructor. - * * @param Kernel $kernel * @param EntityManager $em * @param PathsHelper $pathsHelper @@ -91,9 +81,18 @@ class IntegrationHelper * @param CoreParametersHelper $coreParametersHelper * @param TemplatingHelper $templatingHelper * @param PluginModel $pluginModel + * + * @throws \Exception */ - public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $pathsHelper, BundleHelper $bundleHelper, CoreParametersHelper $coreParametersHelper, TemplatingHelper $templatingHelper, PluginModel $pluginModel) - { + public function __construct( + Kernel $kernel, + EntityManager $em, + PathsHelper $pathsHelper, + BundleHelper $bundleHelper, + CoreParametersHelper $coreParametersHelper, + TemplatingHelper $templatingHelper, + PluginModel $pluginModel + ) { $this->container = $kernel->getContainer(); $this->em = $em; $this->pathsHelper = $pathsHelper; @@ -101,7 +100,6 @@ public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $path $this->pluginModel = $pluginModel; $this->coreParametersHelper = $coreParametersHelper; $this->templatingHelper = $templatingHelper; - $this->factory = $this->container->get('mautic.factory'); } /** @@ -114,6 +112,8 @@ public function __construct(Kernel $kernel, EntityManager $em, PathsHelper $path * @param bool|false $publishedOnly * * @return mixed + * + * @throws \Doctrine\ORM\ORMException */ public function getIntegrationObjects($specificIntegrations = null, $withFeatures = null, $alphabetical = false, $pluginFilter = null, $publishedOnly = false) { @@ -178,30 +178,6 @@ public function getIntegrationObjects($specificIntegrations = null, $withFeature $newIntegrations[] = $newIntegration; unset($newIntegration); - } else { - /** - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC for 3rd party plugins - */ - $class = '\\MauticPlugin\\'.$pluginNamespace.'\\Integration\\'.$integrationName.'Integration'; - $refClass = new \ReflectionClass($class); - - if ($refClass->isInstantiable()) { - $this->integrations[$integrationName] = new $class($this->factory); - $features = $this->integrations[$integrationName]->getSupportedFeatures(); - - $newIntegration->setSupportedFeatures($features); - - // Go ahead and stash it since it's built already - $this->integrations[$integrationName]->setIntegrationSettings($newIntegration); - - $newIntegrations[] = $newIntegration; - - unset($newIntegration); - } else { - // Something is bad so ignore - continue; - } } } @@ -334,27 +310,12 @@ public function getIntegrationObjects($specificIntegrations = null, $withFeature if ($this->container->has($integrationContainerKey)) { $this->integrations[$integrationName] = $this->container->get($integrationContainerKey); $this->integrations[$integrationName]->setIntegrationSettings($integration['settings']); - } else { - /** - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC for 3rd party plugins - */ - $rootNamespace = $integration['isPlugin'] ? '\\MauticPlugin\\' : '\\Mautic\\'; - $class = $rootNamespace.$integration['namespace'].'\\Integration\\'.$integrationName.'Integration'; - $refClass = new \ReflectionClass($class); - - if ($refClass->isInstantiable()) { - $this->integrations[$integrationName] = new $class($this->factory); - - $this->integrations[$integrationName]->setIntegrationSettings($integration['settings']); - } else { - // Something is bad so ignore - continue; - } } } - $returnServices[$integrationName] = $this->integrations[$integrationName]; + if (isset($this->integrations[$integrationName])) { + $returnServices[$integrationName] = $this->integrations[$integrationName]; + } } foreach ($returnServices as $key => $value) { diff --git a/app/bundles/PluginBundle/Integration/AbstractIntegration.php b/app/bundles/PluginBundle/Integration/AbstractIntegration.php index 0156b978e32..ddb37ef7cfb 100644 --- a/app/bundles/PluginBundle/Integration/AbstractIntegration.php +++ b/app/bundles/PluginBundle/Integration/AbstractIntegration.php @@ -14,7 +14,6 @@ use Doctrine\ORM\EntityManager; use Joomla\Http\HttpFactory; use Mautic\CoreBundle\Entity\FormEntity; -use Mautic\CoreBundle\Factory\MauticFactory; use Mautic\CoreBundle\Helper\CacheStorageHelper; use Mautic\CoreBundle\Helper\EncryptionHelper; use Mautic\CoreBundle\Helper\PathsHelper; @@ -38,6 +37,7 @@ use Mautic\PluginBundle\Helper\oAuthHelper; use Mautic\PluginBundle\Model\IntegrationEntityModel; use Mautic\PluginBundle\PluginEvents; +use Monolog\Logger; use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormBuilder; @@ -70,11 +70,6 @@ abstract class AbstractIntegration */ protected $coreIntegration = false; - /** - * @var MauticFactory - */ - protected $factory; - /** * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface */ @@ -203,166 +198,53 @@ abstract class AbstractIntegration protected $commandParameters = []; /** - * AbstractIntegration constructor. - */ - public function __construct(MauticFactory $factory = null) - { - /* - * @deprecated: 2.8.2 To be removed in 3.0 - * This keeps BC with 3rd party plugins that - * don't use the container for the - * integration pass to set all of these properties - */ - if ($factory) { - $this->factory = $factory; - $this->dispatcher = $factory->getDispatcher(); - $this->cache = $factory->getHelper('cache_storage')->getCache($this->getName()); - $this->em = $factory->getEntityManager(); - $this->session = (!defined('IN_MAUTIC_CONSOLE')) ? $factory->getSession() : null; - $this->request = $factory->getRequest(); - $this->router = $factory->getRouter(); - $this->translator = $factory->getTranslator(); - $this->logger = $factory->getLogger(); - $this->encryptionHelper = $factory->getHelper('encryption'); - $this->leadModel = $factory->getModel('lead'); - $this->companyModel = $factory->getModel('lead.company'); - $this->pathsHelper = $factory->getHelper('paths'); - $this->notificationModel = $factory->getModel('core.notification'); - $this->fieldModel = $factory->getModel('lead.field'); - $this->integrationEntityModel = $factory->getModel('plugin.integration_entity'); - } - - $this->init(); - } - - /** - * @param MauticFactory $factory - * - * @deprecated 2.8.2 To be removed in 3.0. Use constructor arguments - * to set dependencies instead - */ - public function setFactory(MauticFactory $factory) - { - $this->factory = $factory; - } - - /** - * @param FieldModel $fieldModel - */ - public function setFieldModel(FieldModel $fieldModel) - { - $this->fieldModel = $fieldModel; - } - - /** - * @param NotificationModel $notificationModel - */ - public function setNotificationModel(NotificationModel $notificationModel) - { - $this->notificationModel = $notificationModel; - } - - /** - * @param PathsHelper $pathsHelper - */ - public function setPathsHelper(PathsHelper $pathsHelper) - { - $this->pathsHelper = $pathsHelper; - } - - /** - * @param CompanyModel $companyModel - */ - public function setCompanyModel(CompanyModel $companyModel) - { - $this->companyModel = $companyModel; - } - - /** - * @param LeadModel $leadModel - */ - public function setLeadModel(LeadModel $leadModel) - { - $this->leadModel = $leadModel; - } - - /** - * @param EncryptionHelper $encryptionHelper - */ - public function setEncryptionHelper(EncryptionHelper $encryptionHelper) - { - $this->encryptionHelper = $encryptionHelper; - } - - /** - * @param LoggerInterface $logger - */ - public function setLogger(LoggerInterface $logger) - { - $this->logger = $logger; - } - - /** - * @param TranslatorInterface $translator - */ - public function setTranslator(TranslatorInterface $translator) - { - $this->translator = $translator; - } - - /** - * @param Router $router - */ - public function setRouter(Router $router) - { - $this->router = $router; - } - - /** - * @param RequestStack $requestStack - */ - public function setRequest(RequestStack $requestStack) - { - $this->request = !defined('IN_MAUTIC_CONSOLE') ? $requestStack->getCurrentRequest() : null; - } - - /** - * @param Session|null $session - */ - public function setSession(Session $session = null) - { - $this->session = !defined('IN_MAUTIC_CONSOLE') ? $session : null; - } - - /** - * @param EntityManager $em - */ - public function setEntityManager(EntityManager $em) - { - $this->em = $em; - } - - /** - * @param CacheStorageHelper $cacheStorageHelper - */ - public function setCache(CacheStorageHelper $cacheStorageHelper) - { - $this->cache = $cacheStorageHelper->getCache($this->getName()); - } - - /** - * @param EventDispatcherInterface $dispatcher - */ - public function setDispatcher(EventDispatcherInterface $dispatcher) - { - $this->dispatcher = $dispatcher; - } - - /** - * @param IntegrationEntityModel $integrationModel - */ - public function setIntegrationEntityModel(IntegrationEntityModel $integrationEntityModel) - { + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param TranslatorInterface $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + */ + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + TranslatorInterface $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel + ) { + $this->dispatcher = $eventDispatcher; + $this->cache = $cacheStorageHelper->getCache($this->getName()); + $this->em = $entityManager; + $this->session = (!defined('IN_MAUTIC_CONSOLE')) ? $session : null; + $this->request = (!defined('IN_MAUTIC_CONSOLE')) ? $requestStack->getCurrentRequest() : null; + $this->router = $router; + $this->translator = $translator; + $this->logger = $logger; + $this->encryptionHelper = $encryptionHelper; + $this->leadModel = $leadModel; + $this->companyModel = $companyModel; + $this->pathsHelper = $pathsHelper; + $this->notificationModel = $notificationModel; + $this->fieldModel = $fieldModel; $this->integrationEntityModel = $integrationEntityModel; } @@ -387,16 +269,6 @@ public function getTranslator() return $this->translator; } - /** - * Called on construct. - * - * @deprecated 2.8.2 To be removed in 3.0 - * Setup your integration in the class constructor instead - */ - public function init() - { - } - /** * @return bool */ @@ -1600,25 +1472,6 @@ public function getBearerToken($inAuthorization = false) return ''; } - /** - * Gets the ID of the user for the integration. - * - * @param $identifier - * @param array $socialCache - * - * @deprecated To be removed 2.0 - * - * @return mixed - */ - public function getUserId($identifier, &$socialCache) - { - if (!empty($socialCache['id'])) { - return $socialCache['id']; - } - - return false; - } - /** * Get an array of public activity. * diff --git a/app/bundles/PluginBundle/Tests/ConfigFormTest.php b/app/bundles/PluginBundle/Tests/ConfigFormTest.php index eec9c530632..ff82cf387f9 100644 --- a/app/bundles/PluginBundle/Tests/ConfigFormTest.php +++ b/app/bundles/PluginBundle/Tests/ConfigFormTest.php @@ -16,7 +16,6 @@ use Mautic\CoreBundle\Helper\CoreParametersHelper; use Mautic\CoreBundle\Helper\PathsHelper; use Mautic\CoreBundle\Helper\TemplatingHelper; -use Mautic\CoreBundle\Translation\Translator; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; use Mautic\PluginBundle\Entity\IntegrationRepository; use Mautic\PluginBundle\Entity\PluginRepository; @@ -36,14 +35,9 @@ protected function setUp() public function testConfigForm() { - $plugins = $this->getIntegrationObject()->getIntegrationObjects(); - $mockTranslator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); + $plugins = $this->getIntegrationObject()->getIntegrationObjects(); foreach ($plugins as $name => $s) { - $s->setTranslator($mockTranslator); - $featureSettings = $s->getFormSettings(); $this->assertArrayHasKey('requires_callback', $featureSettings); diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php index be57eaf0e86..d80284ee558 100644 --- a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTest.php @@ -11,29 +11,33 @@ namespace Mautic\PluginBundle\Tests\Integration; -use Mautic\CoreBundle\Translation\Translator; -use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Integration\AbstractIntegration; -class AbstractIntegrationTest extends \PHPUnit_Framework_TestCase +class AbstractIntegrationTest extends AbstractIntegrationTestCase { public function testPopulatedLeadDataReturnsIntAndNotDncEntityForMauticContactIsContactableByEmail() { $integration = $this->getMockBuilder(AbstractIntegration::class) - ->disableOriginalConstructor() + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) ->setMethodsExcept(['convertLeadFieldKey', 'getLeadDoNotContact', 'populateLeadData', 'setTranslator', 'setLeadModel']) ->getMock(); - $translator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setTranslator($translator); - - $leadModel = $this->getMockBuilder(LeadModel::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setLeadModel($leadModel); - $config = [ 'leadFields' => [ 'dnc' => 'mauticContactIsContactableByEmail', diff --git a/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php new file mode 100644 index 00000000000..e19affd6fe4 --- /dev/null +++ b/app/bundles/PluginBundle/Tests/Integration/AbstractIntegrationTestCase.php @@ -0,0 +1,127 @@ +dispatcher = $this->createMock(EventDispatcherInterface::class); + $this->cache = $this->createMock(CacheStorageHelper::class); + $this->em = $this->createMock(EntityManager::class); + $this->session = $this->createMock(Session::class); + $this->request = $this->createMock(RequestStack::class); + $this->router = $this->createMock(Router::class); + $this->translator = $this->createMock(TranslatorInterface::class); + $this->logger = $this->createMock(Logger::class); + $this->encryptionHelper = $this->createMock(EncryptionHelper::class); + $this->leadModel = $this->createMock(LeadModel::class); + $this->companyModel = $this->createMock(CompanyModel::class); + $this->pathsHelper = $this->createMock(PathsHelper::class); + $this->notificationModel = $this->createMock(NotificationModel::class); + $this->fieldModel = $this->createMock(FieldModel::class); + $this->integrationEntityModel = $this->createMock(IntegrationEntityModel::class); + } +} diff --git a/app/bundles/SmsBundle/Config/config.php b/app/bundles/SmsBundle/Config/config.php index fe8c617a937..124aac66581 100644 --- a/app/bundles/SmsBundle/Config/config.php +++ b/app/bundles/SmsBundle/Config/config.php @@ -137,7 +137,24 @@ ], 'integrations' => [ 'mautic.integration.twilio' => [ - 'class' => \Mautic\SmsBundle\Integration\TwilioIntegration::class, + 'class' => \Mautic\SmsBundle\Integration\TwilioIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], 'repositories' => [ diff --git a/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php b/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php index 76ed0ea67e4..92f82d8768d 100644 --- a/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php +++ b/app/bundles/SmsBundle/Tests/Sms/TransportChainTest.php @@ -44,7 +44,7 @@ public function invokeMethod(&$object, $methodName, array $parameters = []) return $method->invokeArgs($object, $parameters); } - public function setUp() + protected function setUp() { parent::setUp(); diff --git a/plugins/MauticCitrixBundle/Config/config.php b/plugins/MauticCitrixBundle/Config/config.php index 5dc33ab648f..081b8fe5387 100644 --- a/plugins/MauticCitrixBundle/Config/config.php +++ b/plugins/MauticCitrixBundle/Config/config.php @@ -118,21 +118,81 @@ 'mautic.integration.gotoassist' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotoassistIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gotomeeting' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotomeetingIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gototraining' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GototrainingIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.gotowebinar' => [ 'class' => \MauticPlugin\MauticCitrixBundle\Integration\GotowebinarIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticClearbitBundle/Config/config.php b/plugins/MauticClearbitBundle/Config/config.php index 98a784849fa..2b728a42f3b 100644 --- a/plugins/MauticClearbitBundle/Config/config.php +++ b/plugins/MauticClearbitBundle/Config/config.php @@ -71,6 +71,21 @@ 'mautic.integration.clearbit' => [ 'class' => \MauticPlugin\MauticClearbitBundle\Integration\ClearbitIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticCloudStorageBundle/Config/config.php b/plugins/MauticCloudStorageBundle/Config/config.php index f1422d80671..1e17a3d3c0e 100644 --- a/plugins/MauticCloudStorageBundle/Config/config.php +++ b/plugins/MauticCloudStorageBundle/Config/config.php @@ -32,12 +32,63 @@ 'integrations' => [ 'mautic.integration.amazons3' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\AmazonS3Integration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], 'mautic.integration.openstack' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\OpenStackIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], 'mautic.integration.rackspace' => [ 'class' => \MauticPlugin\MauticCloudStorageBundle\Integration\RackspaceIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], ], ], ], diff --git a/plugins/MauticCrmBundle/Config/config.php b/plugins/MauticCrmBundle/Config/config.php index 12a852a7006..90530ffcd35 100644 --- a/plugins/MauticCrmBundle/Config/config.php +++ b/plugins/MauticCrmBundle/Config/config.php @@ -66,38 +66,165 @@ 'mautic.integration.hubspot' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\HubspotIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', 'mautic.helper.user', ], ], 'mautic.integration.salesforce' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\SalesforceIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.sugarcrm' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\SugarcrmIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', 'mautic.lead.model.dnc', ], ], 'mautic.integration.vtiger' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\VtigerIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.zoho' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\ZohoIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.dynamics' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.connectwise' => [ 'class' => \MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + ], + ], + 'mautic.integration.pipedrive' => [ + 'class' => \MauticPlugin\MauticCrmBundle\Integration\PipedriveIntegration::class, + 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic_integration.service.transport', + 'mautic_integration.pipedrive.export.lead', ], ], ], diff --git a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php index 1ba0c4fe365..85d2aee94d5 100644 --- a/plugins/MauticCrmBundle/Integration/HubspotIntegration.php +++ b/plugins/MauticCrmBundle/Integration/HubspotIntegration.php @@ -12,14 +12,29 @@ namespace MauticPlugin\MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; use Mautic\CoreBundle\Helper\UserHelper; +use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\DataObject\LeadManipulator; use Mautic\LeadBundle\Entity\Lead; use Mautic\LeadBundle\Entity\StagesChangeLog; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; +use Mautic\PluginBundle\Model\IntegrationEntityModel; use Mautic\StageBundle\Entity\Stage; use MauticPlugin\MauticCrmBundle\Api\HubspotApi; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\TranslatorInterface; /** * Class HubspotIntegration. @@ -36,13 +51,60 @@ class HubspotIntegration extends CrmAbstractIntegration /** * HubspotIntegration constructor. * - * @param UserHelper $userHelper + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param TranslatorInterface $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param UserHelper $userHelper */ - public function __construct(UserHelper $userHelper) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + TranslatorInterface $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + UserHelper $userHelper + ) { $this->userHelper = $userHelper; - parent::__construct(); + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /** diff --git a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php index a5f2ef447f7..e620824e5dc 100644 --- a/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php +++ b/plugins/MauticCrmBundle/Integration/PipedriveIntegration.php @@ -3,9 +3,25 @@ namespace MauticPlugin\MauticCrmBundle\Integration; use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; +use Mautic\PluginBundle\Model\IntegrationEntityModel; +use MauticPlugin\MauticCrmBundle\Api\CrmApi; use MauticPlugin\MauticCrmBundle\Integration\Pipedrive\Export\LeadExport; +use MauticPlugin\MauticCrmBundle\Services\Transport; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\TranslatorInterface; class PipedriveIntegration extends CrmAbstractIntegration { @@ -15,6 +31,19 @@ class PipedriveIntegration extends CrmAbstractIntegration const ORGANIZATION_ENTITY_TYPE = 'organization'; const COMPANY_ENTITY_TYPE = 'company'; + /** + * @var Transport + */ + private $transport; + + /** + * @var LeadExport + */ + private $leadExport; + + /** + * @var CrmApi + */ private $apiHelper; private $requiredFields = [ @@ -22,6 +51,66 @@ class PipedriveIntegration extends CrmAbstractIntegration 'organization' => ['name'], ]; + /** + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param TranslatorInterface $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param Transport $transport + * @param LeadExport $leadExport + */ + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + TranslatorInterface $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + Transport $transport, + LeadExport $leadExport + ) { + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); + + $this->transport = $transport; + $this->leadExport = $leadExport; + } + /** * @return string */ @@ -203,9 +292,8 @@ public function getAvailableLeadFields($object = null) public function getApiHelper() { if (empty($this->apiHelper)) { - $client = $this->factory->get('mautic_integration.service.transport'); $class = '\\MauticPlugin\\MauticCrmBundle\\Api\\'.$this->getName().'Api'; //TODO replace with service - $this->apiHelper = new $class($this, $client); + $this->apiHelper = new $class($this, $this->transport); } return $this->apiHelper; @@ -263,11 +351,9 @@ public function appendToForm(&$builder, $data, $formArea) */ public function pushLead($lead, $config = []) { - /** @var LeadExport $leadExport */ - $leadExport = $this->factory->get('mautic_integration.pipedrive.export.lead'); - $leadExport->setIntegration($this); + $this->leadExport->setIntegration($this); - return $leadExport->create($lead); + return $this->leadExport->create($lead); } /** @@ -279,7 +365,7 @@ public function pushLead($lead, $config = []) */ public function getFormNotes($section) { - $router = $this->factory->get('router'); + $router = $this->router; $translator = $this->getTranslator(); if ($section == 'authorization') { @@ -323,9 +409,7 @@ public function shouldImportDataToPipedrive() */ public function removeIntegrationEntities() { - /** @var EntityManager $em */ - $em = $this->factory->get('doctrine.orm.entity_manager'); - $qb = $em->getConnection()->createQueryBuilder(); + $qb = $this->em->getConnection()->createQueryBuilder(); return $qb->delete(MAUTIC_TABLE_PREFIX.'integration_entity') ->where( diff --git a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php index 4ad718b598f..2b193078bd4 100644 --- a/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php +++ b/plugins/MauticCrmBundle/Integration/SugarcrmIntegration.php @@ -11,16 +11,31 @@ namespace MauticPlugin\MauticCrmBundle\Integration; +use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Form\Type\ButtonGroupType; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; use Mautic\LeadBundle\Entity\Company; use Mautic\LeadBundle\Entity\Lead; +use Mautic\LeadBundle\Model\CompanyModel; use Mautic\LeadBundle\Model\DoNotContact; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; use Mautic\PluginBundle\Exception\ApiErrorException; +use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Constraints\NotBlank; /** @@ -45,12 +60,60 @@ class SugarcrmIntegration extends CrmAbstractIntegration /** * SugarcrmIntegration constructor. * - * @param DoNotContact $doNotContactModel + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param TranslatorInterface $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param DoNotContact $doNotContactModel */ - public function __construct(DoNotContact $doNotContactModel) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + TranslatorInterface $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + DoNotContact $doNotContactModel + ) { $this->doNotContactModel = $doNotContactModel; - parent::__construct(); + + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /** diff --git a/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php b/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php index 91b9657e2ac..9feacd18ca7 100644 --- a/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/CrmAbstractIntegrationTest.php @@ -13,11 +13,10 @@ use Mautic\EmailBundle\Helper\EmailValidator; use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Tests\Stubs\StubIntegration; -use Symfony\Component\HttpFoundation\Session\Session; -class CrmAbstractIntegrationTest extends \PHPUnit_Framework_TestCase +class CrmAbstractIntegrationTest extends AbstractIntegrationTestCase { public function testFieldMatchingPriority() { @@ -63,33 +62,18 @@ public function testFieldMatchingPriority() public function testCompanyDataIsMappedForNewCompanies() { - $integration = $this->getMockBuilder(StubIntegration::class) - ->disableOriginalConstructor() - ->setMethodsExcept(['getMauticCompany', 'setCompanyModel', 'setFieldModel', 'hydrateCompanyName']) - ->getMock(); - $data = [ 'custom_company_name' => 'Some Business', 'some_custom_field' => 'some value', ]; - $integration->expects($this->once()) - ->method('populateMauticLeadData') - ->willReturn($data); - - $fieldModel = $this->getMockBuilder(FieldModel::class) - ->disableOriginalConstructor() - ->getMock(); - $session = $this->getMockBuilder(Session::class) - ->disableOriginalConstructor() - ->getMock(); $emailValidator = $this->getMockBuilder(EmailValidator::class) ->disableOriginalConstructor() ->getMock(); $companyModel = $this->getMockBuilder(CompanyModel::class) ->setMethodsExcept(['setFieldValues']) - ->setConstructorArgs([$fieldModel, $session, $emailValidator]) + ->setConstructorArgs([$this->fieldModel, $this->session, $emailValidator]) ->getMock(); $companyModel->expects($this->once()) ->method('organizeFieldsByGroup') @@ -109,9 +93,31 @@ public function testCompanyDataIsMappedForNewCompanies() ], ], ]); - $integration->setCompanyModel($companyModel); - $integration->setFieldModel($fieldModel); + $integration = $this->getMockBuilder(StubIntegration::class) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) + ->setMethodsExcept(['getMauticCompany', 'setCompanyModel', 'setFieldModel', 'hydrateCompanyName']) + ->getMock(); + + $integration->expects($this->once()) + ->method('populateMauticLeadData') + ->willReturn($data); $company = $integration->getMauticCompany($data); diff --git a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php index 7ee230d1dd9..68382bca6e0 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsApiTest.php @@ -8,10 +8,11 @@ namespace MauticCrmBundle\Api; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\DynamicsApi; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; -class DynamicsApiTest extends \PHPUnit_Framework_TestCase +class DynamicsApiTest extends AbstractIntegrationTestCase { /** @var DynamicsApi */ private $api; @@ -23,7 +24,24 @@ protected function setUp() { parent::setUp(); - $this->integration = new DynamicsIntegration(); + $this->integration = new DynamicsIntegration( + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel + ); + $this->api = new DynamicsApi($this->integration); } diff --git a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php index 51ed1911002..6afc41cf4da 100644 --- a/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/DynamicsIntegrationTest.php @@ -8,9 +8,10 @@ namespace MauticCrmBundle\Integration; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Integration\DynamicsIntegration; -class DynamicsIntegrationTest extends \PHPUnit_Framework_TestCase +class DynamicsIntegrationTest extends AbstractIntegrationTestCase { /** @var DynamicsIntegration */ private $integration; @@ -19,7 +20,23 @@ protected function setUp() { parent::setUp(); - $this->integration = new DynamicsIntegration(); + $this->integration = new DynamicsIntegration( + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel + ); } public function testIntegration() diff --git a/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php index eafac0d85cc..0aae44b81c3 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/ConnectwiseIntegrationTest.php @@ -12,10 +12,11 @@ namespace MauticPlugin\MauticCrmBundle\Tests\Integration; use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\ConnectwiseApi; use MauticPlugin\MauticCrmBundle\Integration\ConnectwiseIntegration; -class ConnectwiseIntegrationTest extends \PHPUnit_Framework_TestCase +class ConnectwiseIntegrationTest extends AbstractIntegrationTestCase { use DataGeneratorTrait; @@ -75,8 +76,28 @@ function () { } ); - $integration = $this->getMockBuilder(ConnectwiseIntegration::class) + $integrationEntityModel = $this->getMockBuilder(IntegrationEntityModel::class) ->disableOriginalConstructor() + ->getMock(); + + $integration = $this->getMockBuilder(ConnectwiseIntegration::class) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $integrationEntityModel, + ]) ->setMethodsExcept(['getCampaignMembers', 'getRecordList', 'setIntegrationEntityModel']) ->getMock(); @@ -88,11 +109,6 @@ function () { ->method('getApiHelper') ->willReturn($apiHelper); - $integrationEntityModel = $this->getMockBuilder(IntegrationEntityModel::class) - ->disableOriginalConstructor() - ->getMock(); - $integration->setIntegrationEntityModel($integrationEntityModel); - $integration->getCampaignMembers(1); } } diff --git a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php index b6ac0cdad21..17ed848b35b 100644 --- a/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/Integration/SalesforceIntegrationTest.php @@ -11,34 +11,22 @@ namespace MauticPlugin\MauticCrmBundle\Tests\Integration; -use Doctrine\ORM\EntityManager; use Mautic\CoreBundle\Entity\AuditLogRepository; -use Mautic\CoreBundle\Factory\MauticFactory; -use Mautic\CoreBundle\Helper\CacheStorageHelper; -use Mautic\CoreBundle\Helper\EncryptionHelper; -use Mautic\CoreBundle\Helper\PathsHelper; -use Mautic\CoreBundle\Model\NotificationModel; -use Mautic\CoreBundle\Translation\Translator; use Mautic\LeadBundle\Entity\Company; use Mautic\LeadBundle\Entity\Lead; -use Mautic\LeadBundle\Model\CompanyModel; -use Mautic\LeadBundle\Model\FieldModel; -use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Entity\Integration; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\IntegrationEntityRepository; use Mautic\PluginBundle\Event\PluginIntegrationKeyEvent; use Mautic\PluginBundle\Exception\ApiErrorException; use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Integration\SalesforceIntegration; -use Monolog\Logger; -use Symfony\Component\EventDispatcher\EventDispatcher; -use Symfony\Component\Routing\Router; /** * Class SalesforceIntegrationTest. */ -class SalesforceIntegrationTest extends \PHPUnit_Framework_TestCase +class SalesforceIntegrationTest extends AbstractIntegrationTestCase { const SC_MULTIPLE_SF_LEADS = 'multiple_sf_leads'; const SC_MULTIPLE_SF_CONTACTS = 'multiple_sf_contacts'; @@ -124,8 +112,10 @@ class SalesforceIntegrationTest extends \PHPUnit_Framework_TestCase */ protected $leadsCreatedCounter = 0; - public function setUp() + protected function setUp() { + parent::setUp(); + defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test'); } @@ -746,31 +736,21 @@ protected function getMaxInvocations($name) return 1; } - /** - * @return \PHPUnit_Framework_MockObject_MockObject - */ - protected function getMockFactory() + protected function setMocks() { - $mockFactory = $this->getMockBuilder(MauticFactory::class) - ->disableOriginalConstructor() - ->getMock(); - - $mockEntityManager = $this->getMockBuilder(EntityManager::class) - ->disableOriginalConstructor() - ->getMock(); - $mockIntegrationEntityRepository = $this->getMockBuilder(IntegrationEntityRepository::class) + $integrationEntityRepository = $this->getMockBuilder(IntegrationEntityRepository::class) ->disableOriginalConstructor() ->getMock(); // we need insight into the entities persisted - $mockIntegrationEntityRepository->method('saveEntities') + $integrationEntityRepository->method('saveEntities') ->willReturnCallback( function () { $this->persistedIntegrationEntities = array_merge($this->persistedIntegrationEntities, func_get_arg(0)); } ); - $mockIntegrationEntityRepository + $integrationEntityRepository ->expects($spy = $this->any()) ->method('getIntegrationsEntityId') ->willReturnCallback( @@ -783,11 +763,11 @@ function () use ($spy) { return $this->getLeadsToUpdate('Lead', 2, 2, 'Lead')['Lead']; } ); - $mockAuditLogRepo = $this->getMockBuilder(AuditLogRepository::class) + $auditLogRepo = $this->getMockBuilder(AuditLogRepository::class) ->disableOriginalConstructor() ->getMock(); - $mockAuditLogRepo + $auditLogRepo ->expects($this->any()) ->method('getAuditLogsForLeads') ->willReturn( @@ -817,17 +797,15 @@ function () use ($spy) { ] ); - $mockEntityManager->method('getRepository') - ->will( - $this->returnValueMap( - [ - ['MauticPluginBundle:IntegrationEntity', $mockIntegrationEntityRepository], - ['MauticCoreBundle:AuditLog', $mockAuditLogRepo], - ] - ) + $this->em->method('getRepository') + ->willReturnMap( + [ + ['MauticPluginBundle:IntegrationEntity', $integrationEntityRepository], + ['MauticCoreBundle:AuditLog', $auditLogRepo], + ] ); - $mockEntityManager->method('getReference') + $this->em->method('getReference') ->willReturnCallback( function () { switch (func_get_arg(0)) { @@ -837,74 +815,16 @@ function () { } ); - $mockFactory->method('getEntityManager') - ->willReturn($mockEntityManager); - - $mockTranslator = $this->getMockBuilder(Translator::class) - ->disableOriginalConstructor() - ->getMock(); - $mockFactory->method('getTranslator') - ->willReturn($mockTranslator); - - $mockRouter = $this->getMockBuilder(Router::class) - ->disableOriginalConstructor() - ->setMethods(['generate']) - ->getMock(); - - $mockRouter->method('generate') + $this->router->method('generate') ->willReturnArgument(0); - $mockFactory->method('getRouter') - ->willReturn($mockRouter); - - $mockLeadModel = $this->getMockBuilder(LeadModel::class) - ->disableOriginalConstructor() - ->getMock(); - $mockLeadModel->method('getEntity') + $this->leadModel->method('getEntity') ->willReturn(new Lead()); - $mockCompanyModel = $this->getMockBuilder(CompanyModel::class) - ->disableOriginalConstructor() - ->getMock(); - $mockCompanyModel->method('getEntity') + + $this->companyModel->method('getEntity') ->willReturn(new Company()); - $mockCompanyModel->method('getEntities') + $this->companyModel->method('getEntities') ->willReturn([]); - $mockFieldModel = $this->getMockBuilder(FieldModel::class) - ->disableOriginalConstructor() - ->getMock(); - $mockNotificationModel = $this->getMockBuilder(NotificationModel::class) - ->disableOriginalConstructor() - ->getMock(); - - $mockFactory->method('getModel') - ->will( - $this->returnValueMap( - [ - ['lead', $mockLeadModel], - ['lead.company', $mockCompanyModel], - ['lead.field', $mockFieldModel], - ['core.notification', $mockNotificationModel], - ] - ) - ); - - $mockLogger = $this->getMockBuilder(Logger::class) - ->disableOriginalConstructor() - ->getMock(); - $mockFactory->method('getLogger') - ->willReturn($mockLogger); - - $mockDispatcher = $this->getMockBuilder(EventDispatcher::class) - ->disableOriginalConstructor() - ->getMock(); - $mockFactory->method('getDispatcher') - ->willReturn($mockDispatcher); - - $mockCacheHelper = $this->getMockBuilder(CacheStorageHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $mockCacheHelper->method('getCache') - ->willReturn($mockCacheHelper); $leadFields = [ 'Id__Lead' => [ @@ -974,34 +894,17 @@ function () { ], ]; - $mockCacheHelper->method('get') - ->will( - $this->returnValueMap( - [ - ['leadFields.Lead', null, $leadFields], - ['leadFields.Contact', null, $contactFields], - ] - ) - ); - - $mockEncryptionHelper = $this->getMockBuilder(EncryptionHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $mockPathsHelper = $this->getMockBuilder(PathsHelper::class) - ->disableOriginalConstructor() - ->getMock(); - $mockFactory->method('getHelper') - ->will( - $this->returnValueMap( - [ - ['cache_storage', $mockCacheHelper], - ['encryption', $mockEncryptionHelper], - ['paths', $mockPathsHelper], - ] - ) + $this->cache + ->method('get') + ->willReturnMap( + [ + ['leadFields.Lead', null, $leadFields], + ['leadFields.Contact', null, $contactFields], + ] ); - return $mockFactory; + $this->cache->method('getCache') + ->willReturn($this->cache); } /** @@ -1015,7 +918,7 @@ function () { */ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, $maxSfLeads = 25, $maxSfContacts = 25, $updateObject = null) { - $mockFactory = $this->getMockFactory(); + $this->setMocks(); $featureSettings = [ 'sandbox' => [ @@ -1069,11 +972,6 @@ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, ] ); - $sf = $this->getMockBuilder(SalesforceIntegration::class) - ->setConstructorArgs([$mockFactory]) - ->setMethods($this->sfMockMethods) - ->getMock(); - $integrationEntityModelMock = $this->getMockBuilder(IntegrationEntityModel::class) ->disableOriginalConstructor() ->getMock(); @@ -1081,7 +979,26 @@ protected function getSalesforceIntegration($maxUpdate = 100, $maxCreate = 200, $integrationEntityModelMock->method('getEntityByIdAndSetSyncDate') ->willReturn(new IntegrationEntity()); - $sf->setIntegrationEntityModel($integrationEntityModelMock); + $sf = $this->getMockBuilder(SalesforceIntegration::class) + ->setConstructorArgs([ + $this->dispatcher, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $this->translator, + $this->logger, + $this->encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $integrationEntityModelMock, + ]) + ->setMethods($this->sfMockMethods) + ->getMock(); $sf->method('makeRequest') ->will( @@ -1129,9 +1046,8 @@ function () use ($maxSfContacts, $maxSfLeads, $updateObject) { ) ); - /** @var \PHPUnit_Framework_MockObject_MockObject $mockDispatcher */ - $mockDispatcher = $mockFactory->getDispatcher(); - $mockDispatcher->method('dispatch') + /* @var \PHPUnit_Framework_MockObject_MockObject $this->>dispatcher */ + $this->dispatcher->method('dispatch') ->will( $this->returnCallback( function () use ($sf, $integration) { diff --git a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php index 9f58304fe11..d426711d7dc 100644 --- a/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php +++ b/plugins/MauticCrmBundle/Tests/Pipedrive/PipedriveTest.php @@ -9,6 +9,7 @@ use Mautic\PluginBundle\Entity\Integration; use Mautic\PluginBundle\Entity\IntegrationEntity; use Mautic\PluginBundle\Entity\Plugin; +use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\UserBundle\Entity\Role; use Mautic\UserBundle\Entity\User; use MauticPlugin\MauticCrmBundle\Entity\PipedriveOwner; @@ -19,7 +20,7 @@ abstract class PipedriveTest extends MauticMysqlTestCase const WEBHOOK_USER = 'user'; const WEBHOOK_PASSWORD = 'pa$$word'; - public function setUp() + protected function setUp() { parent::setUp(); @@ -220,6 +221,7 @@ protected function createCompanyIntegrationEntity($integrationEntityId, $interna protected function getIntegrationObject() { + /** @var IntegrationHelper $integrationHelper */ $integrationHelper = $this->container->get('mautic.helper.integration'); /** @var Integration $integration */ diff --git a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php index 9ff2a37c5ff..74c9552e318 100644 --- a/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php +++ b/plugins/MauticCrmBundle/Tests/ZohoIntegrationTest.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Helper\EncryptionHelper; use Mautic\LeadBundle\Entity\Lead; use Mautic\PluginBundle\Entity\Integration; +use Mautic\PluginBundle\Tests\Integration\AbstractIntegrationTestCase; use MauticPlugin\MauticCrmBundle\Api\CrmApi; use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcher; @@ -21,7 +22,7 @@ /** * Class ZohoIntegrationTest. */ -class ZohoIntegrationTest extends \PHPUnit_Framework_TestCase +class ZohoIntegrationTest extends AbstractIntegrationTestCase { /** @var ZohoIntegration */ private $integration; @@ -47,16 +48,11 @@ protected function setUp() $translator->expects($this->any()) ->method('trans') ->willReturnArgument(0); - $this->integration = $this->getMockBuilder(ZohoIntegration::class) - ->setMethods(['getApiHelper']) - ->getMock(); - $this->integration->setTranslator($translator); - $this->integration->setEncryptionHelper($encryptionHelper); $eventMock = $this->getMockBuilder(Event::class) - ->disableOriginalConstructor() - ->setMethods(['getKeys']) - ->getMock(); + ->disableOriginalConstructor() + ->setMethods(['getKeys']) + ->getMock(); $apiKeys = [ 'EMAIL_ID' => 'test', 'PASSWORD' => 'test', @@ -66,16 +62,37 @@ protected function setUp() 'RESULT' => 'test', ]; $eventMock->expects($this->any()) - ->method('getKeys') - ->willReturn($apiKeys); + ->method('getKeys') + ->willReturn($apiKeys); $dispatcherMock = $this->getMockBuilder(EventDispatcher::class) - ->disableOriginalConstructor() - ->setMethods(['dispatch']) - ->getMock(); - $dispatcherMock->expects($this->any()) - ->method('dispatch') - ->willReturn($eventMock); - $this->integration->setDispatcher($dispatcherMock); + ->disableOriginalConstructor() + ->setMethods(['dispatch']) + ->getMock(); + $dispatcherMock + ->method('dispatch') + ->willReturn($eventMock); + + $this->integration = $this->getMockBuilder(ZohoIntegration::class) + ->setMethods(['getApiHelper']) + ->setConstructorArgs([ + $dispatcherMock, + $this->cache, + $this->em, + $this->session, + $this->request, + $this->router, + $translator, + $this->logger, + $encryptionHelper, + $this->leadModel, + $this->companyModel, + $this->pathsHelper, + $this->notificationModel, + $this->fieldModel, + $this->integrationEntityModel, + ]) + ->getMock(); + $settings = new Integration(); $featureSettings = [ 'update_mautic' => [ @@ -123,9 +140,9 @@ protected function setUp() ->disableOriginalConstructor() ->setMethods(['getLeadFields']) ->getMock(); - $apiHelper->expects($this->any()) - ->method('getLeadFields') - ->willReturn($leadFields); + $apiHelper + ->method('getLeadFields') + ->willReturn($leadFields); $this->integration->method('getApiHelper') ->willReturn($apiHelper); $this->integration->setIntegrationSettings($settings); diff --git a/plugins/MauticEmailMarketingBundle/Config/config.php b/plugins/MauticEmailMarketingBundle/Config/config.php index e59f058f964..0a4e593acc6 100644 --- a/plugins/MauticEmailMarketingBundle/Config/config.php +++ b/plugins/MauticEmailMarketingBundle/Config/config.php @@ -34,16 +34,61 @@ 'mautic.integration.constantcontact' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\ConstantContactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.icontact' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\IcontactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], 'mautic.integration.mailchimp' => [ 'class' => \MauticPlugin\MauticEmailMarketingBundle\Integration\MailchimpIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php b/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php index 39d6d2e2467..0f6afd6bc96 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/ConstantContactType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -120,7 +121,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $fields = $object->getFormLeadFields(); list($specialInstructions, $alertType) = $object->getFormNotes('leadfield_match'); - $builder->add('leadFields', 'integration_fields', [ + $builder->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php b/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php index 85b12960bd1..331176e51dd 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/IcontactType.php @@ -12,6 +12,7 @@ namespace MauticPlugin\MauticEmailMarketingBundle\Form\Type; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -114,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) $fields = $object->getFormLeadFields(); list($specialInstructions, $alertType) = $object->getFormNotes('leadfield_match'); - $builder->add('leadFields', 'integration_fields', [ + $builder->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, diff --git a/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php b/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php index 56f595e55c6..2b1a1e253f4 100644 --- a/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php +++ b/plugins/MauticEmailMarketingBundle/Form/Type/MailchimpType.php @@ -13,6 +13,7 @@ use Mautic\CoreBundle\Form\Type\YesNoButtonGroupType; use Mautic\CoreBundle\Helper\CoreParametersHelper; +use Mautic\PluginBundle\Form\Type\FieldsType; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Model\PluginModel; use Symfony\Component\Form\AbstractType; @@ -146,7 +147,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) } list($specialInstructions) = $mailchimp->getFormNotes('leadfield_match'); - $form->add('leadFields', 'integration_fields', [ + $form->add('leadFields', FieldsType::class, [ 'label' => 'mautic.integration.leadfield_matches', 'required' => true, 'mautic_fields' => $leadFields, diff --git a/plugins/MauticFullContactBundle/Config/config.php b/plugins/MauticFullContactBundle/Config/config.php index b84bf10ff67..de9b6d4f3ce 100644 --- a/plugins/MauticFullContactBundle/Config/config.php +++ b/plugins/MauticFullContactBundle/Config/config.php @@ -71,6 +71,21 @@ 'mautic.integration.fullcontact' => [ 'class' => \MauticPlugin\MauticFullContactBundle\Integration\FullContactIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticGmailBundle/Config/config.php b/plugins/MauticGmailBundle/Config/config.php index 5169cab7e55..9b777e4d8fa 100644 --- a/plugins/MauticGmailBundle/Config/config.php +++ b/plugins/MauticGmailBundle/Config/config.php @@ -19,6 +19,21 @@ 'mautic.integration.gmail' => [ 'class' => \MauticPlugin\MauticGmailBundle\Integration\GmailIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticOutlookBundle/Config/config.php b/plugins/MauticOutlookBundle/Config/config.php index a0b6481e308..8c65fd25cf2 100644 --- a/plugins/MauticOutlookBundle/Config/config.php +++ b/plugins/MauticOutlookBundle/Config/config.php @@ -19,6 +19,21 @@ 'mautic.integration.outlook' => [ 'class' => \MauticPlugin\MauticOutlookBundle\Integration\OutlookIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', ], ], ], diff --git a/plugins/MauticSocialBundle/Config/config.php b/plugins/MauticSocialBundle/Config/config.php index 94167159b51..d443210cb97 100644 --- a/plugins/MauticSocialBundle/Config/config.php +++ b/plugins/MauticSocialBundle/Config/config.php @@ -179,31 +179,127 @@ 'mautic.integration.facebook' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\FacebookIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.foursquare' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\FoursquareIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.googleplus' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\GooglePlusIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.instagram' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\InstagramIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.linkedin' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\LinkedInIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], 'mautic.integration.twitter' => [ 'class' => \MauticPlugin\MauticSocialBundle\Integration\TwitterIntegration::class, 'arguments' => [ + 'event_dispatcher', + 'mautic.helper.cache_storage', + 'doctrine.orm.entity_manager', + 'session', + 'request_stack', + 'router', + 'translator', + 'logger', + 'mautic.helper.encryption', + 'mautic.lead.model.lead', + 'mautic.lead.model.company', + 'mautic.helper.paths', + 'mautic.core.model.notification', + 'mautic.lead.model.field', + 'mautic.plugin.model.integration_entity', + 'mautic.helper.integration', ], ], ], diff --git a/plugins/MauticSocialBundle/Integration/SocialIntegration.php b/plugins/MauticSocialBundle/Integration/SocialIntegration.php index 0f90b8fada3..3152b61d0b0 100644 --- a/plugins/MauticSocialBundle/Integration/SocialIntegration.php +++ b/plugins/MauticSocialBundle/Integration/SocialIntegration.php @@ -11,10 +11,24 @@ namespace MauticPlugin\MauticSocialBundle\Integration; +use Doctrine\ORM\EntityManager; +use Mautic\CoreBundle\Helper\CacheStorageHelper; +use Mautic\CoreBundle\Helper\EncryptionHelper; +use Mautic\CoreBundle\Helper\PathsHelper; +use Mautic\CoreBundle\Model\NotificationModel; +use Mautic\LeadBundle\Model\CompanyModel; +use Mautic\LeadBundle\Model\FieldModel; +use Mautic\LeadBundle\Model\LeadModel; use Mautic\PluginBundle\Helper\IntegrationHelper; use Mautic\PluginBundle\Integration\AbstractIntegration; -use Symfony\Component\Form\Form; +use Mautic\PluginBundle\Model\IntegrationEntityModel; +use Monolog\Logger; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\FormBuilder; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\Routing\Router; +use Symfony\Component\Translation\TranslatorInterface; abstract class SocialIntegration extends AbstractIntegration { @@ -26,11 +40,60 @@ abstract class SocialIntegration extends AbstractIntegration protected $integrationHelper; /** - * @param IntegrationHelper $integrationHelper + * @param EventDispatcherInterface $eventDispatcher + * @param CacheStorageHelper $cacheStorageHelper + * @param EntityManager $entityManager + * @param Session $session + * @param RequestStack $requestStack + * @param Router $router + * @param TranslatorInterface $translator + * @param Logger $logger + * @param EncryptionHelper $encryptionHelper + * @param LeadModel $leadModel + * @param CompanyModel $companyModel + * @param PathsHelper $pathsHelper + * @param NotificationModel $notificationModel + * @param FieldModel $fieldModel + * @param IntegrationEntityModel $integrationEntityModel + * @param IntegrationHelper $integrationHelper */ - public function setIntegrationHelper(IntegrationHelper $integrationHelper) - { + public function __construct( + EventDispatcherInterface $eventDispatcher, + CacheStorageHelper $cacheStorageHelper, + EntityManager $entityManager, + Session $session, + RequestStack $requestStack, + Router $router, + TranslatorInterface $translator, + Logger $logger, + EncryptionHelper $encryptionHelper, + LeadModel $leadModel, + CompanyModel $companyModel, + PathsHelper $pathsHelper, + NotificationModel $notificationModel, + FieldModel $fieldModel, + IntegrationEntityModel $integrationEntityModel, + IntegrationHelper $integrationHelper + ) { $this->integrationHelper = $integrationHelper; + + parent::__construct( + $eventDispatcher, + $cacheStorageHelper, + $entityManager, + $session, + $requestStack, + $router, + $translator, + $logger, + $encryptionHelper, + $leadModel, + $companyModel, + $pathsHelper, + $notificationModel, + $fieldModel, + $integrationEntityModel + ); } /**