public function testGetEntityName() { $marketingList = new MarketingList(); $marketingList->setEntity('\\stdClass'); $campaign = new EmailCampaign(); $this->assertNull($campaign->getEntityName()); $campaign->setMarketingList($marketingList); $this->assertEquals($marketingList->getEntity(), $campaign->getEntityName()); }
public function testPreSet() { $marketingList = new MarketingList(); $marketingList->setEntity('\\stdClass'); $emailCampaign = new EmailCampaign(); $emailCampaign->setMarketingList($marketingList); $this->form->expects($this->once())->method('getData')->will($this->returnValue($emailCampaign)); $this->form->expects($this->atLeastOnce())->method('add'); $event = new FormEvent($this->form, []); $this->listener->preSet($event); }
/** * @param array $iterable * * @dataProvider sendDataProvider */ public function testSendError($iterable, $to) { $segment = new Segment(); $marketingList = new MarketingList(); $marketingList->setSegment($segment); $campaign = new EmailCampaign(); $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to)); $itCount = count($iterable); $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable)); $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager)); $manager->expects($this->once())->method('persist')->with($campaign); $manager->expects($this->atLeastOnce())->method('flush'); $manager->expects($this->exactly($itCount))->method('beginTransaction'); $manager->expects($this->exactly($itCount))->method('rollback'); if ($itCount) { $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getQueryContactInformationFields')->with($this->equalTo($segment), $this->isType('object'), $this->equalTo(ContactInformationFieldsProvider::CONTACT_INFORMATION_SCOPE_EMAIL))->will($this->returnValue($to)); $this->marketingListConnector->expects($this->exactly($itCount))->method('contact')->with($this->equalTo($marketingList), $this->equalTo(self::ENTITY_ID))->will($this->returnCallback(function () { throw new \Exception('Error'); })); $this->logger->expects($this->exactly($itCount))->method('error'); } $this->transport->expects($this->exactly($itCount))->method('send'); $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport)); $this->sender->setEmailCampaign($campaign); $this->sender->send($campaign); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Sender email and name is empty */ public function testFromEmpty() { $entity = new \stdClass(); $this->helper->expects($this->once())->method('getSingleEntityIdentifier')->will($this->returnValue(1)); $marketingList = new MarketingList(); $marketingList->setEntity($entity); $template = new EmailTemplate(); $template->setType('html'); $settings = new InternalTransportSettings(); $settings->setTemplate($template); $campaign = new EmailCampaign(); $campaign->setMarketingList($marketingList)->setTransportSettings($settings); $this->transport->send($campaign, $entity, [], []); }
/** * @param array $iterable * @param array $to * @param object $type * @dataProvider sendDataProvider */ public function testSendError($iterable, $to, $type) { $segment = new Segment(); $entity = '\\stdClass'; $marketingList = new MarketingList(); $marketingList->setSegment($segment); $marketingList->setType($type); $marketingList->setEntity($entity); $campaign = new EmailCampaign(); $campaign->setMarketingList($marketingList)->setSenderEmail(reset($to)); $itCount = count($iterable); $this->marketingListProvider->expects($this->once())->method('getMarketingListEntitiesIterator')->will($this->returnValue($iterable)); $manager = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->registry->expects($this->once())->method('getManager')->will($this->returnValue($manager)); $manager->expects($this->once())->method('persist')->with($campaign); $manager->expects($this->atLeastOnce())->method('flush'); $manager->expects($this->exactly($itCount))->method('beginTransaction'); $manager->expects($this->exactly($itCount))->method('rollback'); $fields = ['email']; $this->assertFieldsCall($fields, $marketingList); if ($itCount) { $this->contactInformationFieldsProvider->expects($this->exactly($itCount))->method('getTypedFieldsValues')->with($this->equalTo($fields), $this->isType('object'))->will($this->returnValue($to)); $this->statisticsConnector->expects($this->exactly($itCount))->method('getStatisticsRecord')->with($this->equalTo($campaign), $this->isInstanceOf('stdClass'))->willThrowException(new \Exception('Error')); $this->logger->expects($this->exactly($itCount))->method('error'); } $this->transport->expects($this->exactly($itCount))->method('send'); $this->transportProvider->expects($this->once())->method('getTransportByName')->will($this->returnValue($this->transport)); $this->sender->setEmailCampaign($campaign); $this->sender->send($campaign); }