diff --git a/tests/integration/Espo/LeadCapture/LeadCaptureTest.php b/tests/integration/Espo/LeadCapture/LeadCaptureTest.php new file mode 100644 index 0000000000..7091ca050e --- /dev/null +++ b/tests/integration/Espo/LeadCapture/LeadCaptureTest.php @@ -0,0 +1,76 @@ +getContainer()->get('entityManager'); + + $targetList = $entityManager->getEntity('TargetList'); + $entityManager->saveEntity($targetList); + + $team = $entityManager->getEntity('Team'); + $entityManager->saveEntity($team); + + $leadCaptureService = $this->getContainer()->get('serviceFactory')->create('LeadCapture'); + + $leadCapureData = (object) [ + 'name' => 'test', + 'subscribeToTargetList' => true, + 'targetListId' => $targetList->id, + 'targetTeamId' => $team->id, + 'fieldList' => ['name', 'emailAddress'], + 'leadSource' => 'Web Site' + ]; + $leadCapture = $leadCaptureService->createEntity($leadCapureData); + + $this->assertNotEmpty($leadCapture->get('apiKey')); + + $data = (object) [ + 'firstName' => 'Test', + 'lastName' => 'Tester', + 'emailAddress' => 'test@tester.com' + ]; + + $leadCaptureService->leadCapture($leadCapture->get('apiKey'), $data); + + $lead = $entityManager->getRepository('Lead')->where(['emailAddress' => 'test@tester.com'])->findOne(); + $this->assertNotNull($lead); + + $this->assertEquals('Web Site', $lead->get('source')); + + $this->assertTrue($entityManager->getRepository('Lead')->isRelated($lead, 'teams', $team->id)); + + $this->assertTrue($entityManager->getRepository('Lead')->isRelated($lead, 'targetLists', $targetList->id)); + } +}