/** * @dataProvider visibilityDataProvider * @param string $visibility * @param bool $expected */ public function testChecksVisibilityFromConfig($visibility, $expected) { $this->configManager->expects($this->once())->method('get')->with('orob2b_product.default_visibility')->willReturn($visibility); $product = $this->getProductMock(); $product->expects($this->once())->method('getVisibility')->willReturn(Product::VISIBILITY_BY_CONFIG); $this->assertEquals($expected, $this->service->isVisible($product)); }
/** * {@inheritdoc} */ protected function setUp() { $this->record = $this->getMock('Oro\\Bundle\\DataGridBundle\\Datasource\\ResultRecordInterface'); $this->configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->configManager->expects($this->any())->method('get')->with('oro_b2b_rfp.default_request_status')->will($this->returnValue(self::CONFIG_DEFAULT_STATUS)); $this->actionPermissionProvider = new ActionPermissionProvider($this->configManager); }
public function testProcessEvent() { $user = new User(); $user->setId(1); $this->configManager->expects($this->once())->method('get')->with('diamante_desk.email_notification')->will($this->returnValue(true)); $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user)); $event = $this->event(); $this->notificationDeliveryManager->expects($this->once())->method('add')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\Notifications\\TicketNotification'), $this->attributeEqualTo('ticketUniqueId', $event->getAggregateId()), $this->attributeEqualTo('author', $user), $this->attributeEqualTo('headerText', $event->getHeaderText()), $this->attributeEqualTo('subject', $event->getSubject()), $this->attributeEqualTo('attachments', $event->attachments()), $this->attribute($this->logicalAnd($this->isInstanceOf('\\ArrayIterator'), $this->arrayHasKey('Description'), $this->contains('New Description')), 'changeList'))); $this->subscriber->processEvent($event); }
/** * @dataProvider isFreshDataProvider * * @param array $configData * @param array $statisticData * @param string $langCode * @param bool $expectedResult */ public function testIsFresh(array $configData, array $statisticData, $langCode, $expectedResult) { $this->cm->expects($this->once())->method('get')->with($this->equalTo(TranslationStatusInterface::META_CONFIG_KEY))->will($this->returnValue($configData)); $this->sp->expects($this->once())->method('get')->will($this->returnValue($statisticData)); $result1 = $this->extension->isFresh($langCode); // second call should not fail expectation above // result should be cached $result2 = $this->extension->isFresh($langCode); $this->assertSame($result1, $result2); $this->assertSame($expectedResult, $result1); }
/** * @dataProvider submitProvider * * @param AccountUser $defaultData * @param array $submittedData * @param AccountUser $expectedData * @param User $owner */ public function testSubmit($defaultData, array $submittedData, $expectedData, User $owner) { $this->configManager->expects($this->once())->method('get')->with('oro_b2b_account.default_account_owner')->willReturn(42); $repository = $this->assertUserRepositoryCall(); $repository->expects($this->once())->method('find')->with(42)->willReturn($owner); $form = $this->factory->create($this->formType, $defaultData, []); $this->assertEquals($defaultData, $form->getData()); $form->submit($submittedData); $this->assertTrue($form->isValid()); $this->assertEquals($expectedData, $form->getData()); }
/** * @param bool $expected * @param [] $data * @param bool $configSyncEnabled * @param int $configSyncMaxSize * * @dataProvider addAttachmentProvider */ public function testAddAttachment($expected, $data, $configSyncEnabled, $configSyncMaxSize) { $this->emailBodyBuilder->setEmailBody('test', true); $this->configManager->expects($this->at(0))->method('get')->with(EmailBodyBuilder::ORO_EMAIL_ATTACHMENT_SYNC_ENABLE)->willReturn($configSyncEnabled); if ($configSyncEnabled) { $this->configManager->expects($this->at(1))->method('get')->with(EmailBodyBuilder::ORO_EMAIL_ATTACHMENT_SYNC_MAX_SIZE)->willReturn($configSyncMaxSize); } $this->emailBodyBuilder->addEmailAttachment('test', 'content', 'ct', $data['contentTransferEncoding'], $data['embeddedContentId'], $data['contentSize']); $body = $this->emailBodyBuilder->getEmailBody(); $this->assertEquals($expected, $body->getHasAttachments()); }
protected function setUp() { $this->logger = $this->getMock('Psr\\Log\\LoggerInterface'); $this->entityManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $this->entityPool = $this->getMockBuilder('Oro\\Bundle\\NotificationBundle\\Doctrine\\EntityPool')->disableOriginalConstructor()->getMock(); $this->emailRenderer = $this->getMockBuilder('Oro\\Bundle\\EmailBundle\\Provider\\EmailRenderer')->disableOriginalConstructor()->getMock(); $this->mailer = $this->getMockBuilder('Swift_Mailer')->disableOriginalConstructor()->getMock(); $this->cm = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->cm->expects($this->any())->method('get')->will($this->returnValueMap([['oro_notification.email_notification_sender_email', false, false, self::TEST_SENDER_EMAIL], ['oro_notification.email_notification_sender_name', false, false, self::TEST_SENDER_NAME]])); $this->processor = new EmailNotificationProcessor($this->logger, $this->entityManager, $this->entityPool, $this->emailRenderer, $this->mailer, $this->cm); $this->processor->setEnv(self::TEST_ENV); $this->processor->setMessageLimit(self::TEST_MESSAGE_LIMIT); }
public function testGetVariableValues() { $organization = new Organization(); $organization->setName('TestOrg'); $user = new User(); $user->setUsername('test'); $user->setFirstName('FirstName'); $user->setLastName('LastName'); $this->securityFacade->expects($this->once())->method('getOrganization')->will($this->returnValue($organization)); $this->securityFacade->expects($this->once())->method('getLoggedUser')->will($this->returnValue($user)); $this->entityNameResolver->expects($this->once())->method('getName')->with($this->identicalTo($user))->will($this->returnValue('FullName')); $this->configManager->expects($this->once())->method('get')->with('oro_email.signature')->will($this->returnValue('Signature')); $result = $this->provider->getVariableValues(); $this->assertEquals(['userName' => 'test', 'userFirstName' => 'FirstName', 'userLastName' => 'LastName', 'userFullName' => 'FullName', 'organizationName' => 'TestOrg', 'userSignature' => 'Signature'], $result); }
protected function setUp() { $this->objectRepository = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Entity\\Repository\\EmailTemplateRepository'); $this->objectManager = $this->getMockForClass('Doctrine\\Common\\Persistence\\ObjectManager'); $this->objectManager->expects($this->any())->method('getRepository')->with('OroEmailBundle:EmailTemplate')->willReturn($this->objectRepository); $this->managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry'); $this->managerRegistry->expects($this->any())->method('getManagerForClass')->with('OroEmailBundle:EmailTemplate')->willReturn($this->objectManager); $this->configManager = $this->getMockForClass('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager'); $this->configManager->expects($this->any())->method('get')->willReturnMap([['oro_notification.email_notification_sender_email', false, false, self::FROM_EMAIL], ['oro_notification.email_notification_sender_name', false, false, self::FROM_NAME]]); $this->renderer = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Provider\\EmailRenderer'); $this->emailHolderHelper = $this->getMockForClass('Oro\\Bundle\\EmailBundle\\Tools\\EmailHolderHelper'); $this->mailer = $this->getMockForClass('\\Swift_Mailer'); $this->mailProcessor = new BaseProcessor($this->managerRegistry, $this->configManager, $this->renderer, $this->emailHolderHelper, $this->mailer); $this->emailTemplate = $this->getMock('Oro\\Bundle\\EmailBundle\\Model\\EmailTemplateInterface'); }
public function testNotifyWithEmptyAuthor() { $ticketUniqueId = UniqueId::generate(); $reporter = new UserAdapter(1, UserAdapter::TYPE_DIAMANTE); $assignee = new User(); $assignee->setId(2); $assignee->setEmail('*****@*****.**'); $author = null; $branch = new Branch('KEY', 'Name', 'Description'); $ticket = new Ticket($ticketUniqueId, new TicketSequenceNumber(1), 'Subject', 'Description', $branch, $reporter, $assignee, new Source(Source::WEB), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::NEW_ONE)); $notification = new TicketNotification((string) $ticketUniqueId, $author, 'Header', 'Subject', new \ArrayIterator(array('key' => 'value')), array('file.ext')); $message = new \Swift_Message(); $this->watchersService->expects($this->once())->method('getWatchers')->will($this->returnValue([new WatcherList($ticket, 'diamante_1')])); $this->diamanteUserRepository->expects($this->exactly(2))->method('get')->with(1)->will($this->returnValue($this->diamanteUser)); $this->configManager->expects($this->once())->method('get')->will($this->returnValue('*****@*****.**')); $this->nameFormatter->expects($this->once())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last')); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->ticketRepository->expects($this->once())->method('getByUniqueId')->with($ticketUniqueId)->will($this->returnValue($ticket)); $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html')))); $optionsConstraint = $this->logicalAnd($this->arrayHasKey('changes'), $this->arrayHasKey('attachments'), $this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains($notification->getChangeList()), $this->contains($notification->getAttachments()), $this->contains('First Last'), $this->contains($notification->getHeaderText())); $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template')); $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template')); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) { $to = $other->getTo(); return false !== strpos($other->getSubject(), $notification->getSubject()) && false !== strpos($other->getSubject(), 'KEY-1') && false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to) && $other->getHeaders()->has('References') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**') && false !== strpos($other->getHeaders()->get('References'), '*****@*****.**'); }))); $this->messageReferenceRepository->expects($this->once())->method('findAllByTicket')->with($ticket)->will($this->returnValue(array(new MessageReference('*****@*****.**', $ticket), new MessageReference('*****@*****.**', $ticket)))); $this->messageReferenceRepository->expects($this->once())->method('store')->with($this->logicalAnd($this->isInstanceOf('\\Diamante\\DeskBundle\\Model\\Ticket\\EmailProcessing\\MessageReference'))); $notifier = new EmailNotifier($this->container, $this->twig, $this->mailer, $this->templateResolver, $this->ticketRepository, $this->messageReferenceRepository, $this->userService, $this->nameFormatter, $this->diamanteUserRepository, $this->configManager, $this->oroUserManager, $this->watchersService, $this->senderHost); $notifier->notify($notification); }
/** * @param $entityClass * @param $entityId * @param $from * @param $subject * @param $parentEmail * @param $helperDecodeClassNameCalls * @param $emGetRepositoryCalls * @param $helperPreciseFullEmailAddressCalls * @param $helperGetUserCalls * @param $helperBuildFullEmailAddress * * @dataProvider createEmailModelProvider * * @SuppressWarnings(PHPMD) */ public function testCreateEmailModel($entityClass, $entityId, $from, $subject, $parentEmail, $helperDecodeClassNameCalls, $emGetRepositoryCalls, $helperPreciseFullEmailAddressCalls, $helperGetUserCalls, $helperBuildFullEmailAddress) { $emailModel = new EmailModel(); $this->request = new Request(); $this->request->setMethod('GET'); if ($entityClass) { $this->request->query->set('entityClass', $entityClass); } if ($entityId) { $this->request->query->set('entityId', $entityId); } if ($from) { $this->request->query->set('from', $from); } if ($subject) { $this->request->query->set('subject', $subject); } $this->emailModelBuilder = new EmailModelBuilder($this->helper, $this->entityManager, $this->configManager, $this->activityListProvider, $this->emailAttachmentProvider, $this->factory); $this->emailModelBuilder->setRequest($this->request); $this->helper->expects($this->exactly($helperDecodeClassNameCalls))->method('decodeClassName')->willReturn($entityClass); $repository = $this->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock(); $this->entityManager->expects($this->exactly($emGetRepositoryCalls))->method('getRepository')->willReturn($repository); $this->helper->expects($this->exactly($helperPreciseFullEmailAddressCalls))->method('preciseFullEmailAddress'); $this->helper->expects($this->exactly($helperGetUserCalls))->method('getUser')->willReturn($this->getMock('Oro\\Bundle\\UserBundle\\Entity\\User')); $this->helper->expects($this->exactly($helperBuildFullEmailAddress))->method('buildFullEmailAddress'); $this->configManager->expects($this->once())->method('get')->with('oro_email.signature'); $result = $this->emailModelBuilder->createEmailModel($emailModel); $this->assertEquals($emailModel, $result); $this->assertEquals($entityClass, $result->getEntityClass()); $this->assertEquals($entityId, $result->getEntityId()); $this->assertEquals($subject, $result->getSubject()); $this->assertEquals($from, $result->getFrom()); }
/** * @dataProvider submitDataProvider * * @param array $allowedCurrencies * @param string $localeCurrency * @param array $inputOptions * @param array $expectedOptions * @param string $submittedData */ public function testSubmit(array $allowedCurrencies, $localeCurrency, array $inputOptions, array $expectedOptions, $submittedData) { $hasCustomCurrencies = isset($inputOptions['currencies_list']) || !empty($inputOptions['full_currency_list']); $this->configManager->expects($hasCustomCurrencies ? $this->never() : $this->once())->method('get')->with('oro_currency.allowed_currencies')->willReturn($allowedCurrencies); $this->localeSettings->expects(count($allowedCurrencies) ? $this->never() : $this->once())->method('getCurrency')->willReturn($localeCurrency); $form = $this->factory->create($this->formType, null, $inputOptions); $formConfig = $form->getConfig(); foreach ($expectedOptions as $key => $value) { $this->assertTrue($formConfig->hasOption($key)); $this->assertEquals($value, $formConfig->getOption($key)); } $this->assertNull($form->getData()); $form->submit($submittedData); $this->assertTrue($form->isValid()); $this->assertEquals($submittedData, $form->getData()); }
public function testProcessWhenMessageWithoutReferenceWithoutDefaultBranch() { $message = new Message(self::DUMMY_UNIQUE_ID, self::DUMMY_MESSAGE_ID, self::DUMMY_SUBJECT, self::DUMMY_CONTENT, $this->getDummyFrom(), self::DUMMY_MESSAGE_TO); $assigneeId = 1; $diamanteUser = $this->getReporter(1); $this->userService->expects($this->once())->method('getUserByEmail')->with($this->equalTo(self::DUMMY_MESSAGE_FROM))->will($this->returnValue($diamanteUser)); $this->configManager->expects($this->once())->method('get')->with($this->equalTo('diamante_desk.default_branch'))->will($this->returnValue(1)); $this->branchService->expects($this->once())->method('getBranch')->with($this->equalTo(1))->will($this->returnValue($this->defaultBranch)); $this->defaultBranch->expects($this->any())->method('getDefaultAssigneeId')->will($this->returnValue($assigneeId)); $reporter = $this->getReporter($diamanteUser->getId()); $this->messageReferenceService->expects($this->once())->method('createTicket')->with($this->equalTo($message->getMessageId()), self::DUMMY_BRANCH_ID, $message->getSubject(), $message->getContent(), $reporter, $assigneeId); $this->ticketStrategy->process($message); }
public function testNotify() { $author = new ApiUser('*****@*****.**', 'password'); $notification = new UserNotification($author, 'Header'); $format = '%prefix% %first_name% %middle_name% %last_name% %suffix%'; $message = new \Swift_Message(); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->configManager->expects($this->once())->method('get')->will($this->returnValue('Mike The Bot')); $this->nameFormatter->expects($this->any())->method('format')->with($this->diamanteUser)->will($this->returnValue('First Last')); $this->userService->expects($this->once())->method('verifyDiamanteUserExists')->with($this->equalTo($author->getEmail()))->will($this->returnValue(1)); $this->userService->expects($this->once())->method('getByUser')->with($this->equalTo(new UserAdapter(1, UserAdapter::TYPE_DIAMANTE)))->will($this->returnValue($this->diamanteUser)); $this->nameFormatter->expects($this->once())->method('getNameFormat')->will($this->returnValue($format)); $this->templateResolver->expects($this->any())->method('resolve')->will($this->returnValueMap(array(array($notification, TemplateResolver::TYPE_TXT, 'txt.template.html'), array($notification, TemplateResolver::TYPE_HTML, 'html.template.html')))); $optionsConstraint = $this->logicalAnd($this->arrayHasKey('user'), $this->arrayHasKey('header'), $this->contains('First Last'), $this->contains($notification->getHeaderText())); $this->twig->expects($this->at(0))->method('render')->with('txt.template.html', $optionsConstraint)->will($this->returnValue('Rendered TXT template')); $this->twig->expects($this->at(1))->method('render')->with('html.template.html', $optionsConstraint)->will($this->returnValue('Rendered HTML template')); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($notification) { $to = $other->getTo(); return false !== strpos($other->getBody(), 'Rendered TXT template') && array_key_exists('*****@*****.**', $to); }))); $notifier = new EmailNotifier($this->twig, $this->mailer, $this->templateResolver, $this->userService, $this->nameFormatter, $this->configManager, $this->senderEmail); $notifier->notify($notification); }
/** * @throws \OroB2B\Bundle\ProductBundle\Exception\InvalidRoundingTypeException */ public function testInvalidRoundingTypeException() { $this->configManager->expects($this->once())->method('get')->with('orob2b_product.unit_rounding_type')->willReturn('test'); $this->setExpectedException('\\OroB2B\\Bundle\\ProductBundle\\Exception\\InvalidRoundingTypeException', 'The type of the rounding is not valid. Allowed the following types: half_up, half_down, ceil, floor.'); $this->service->round(1.15, 1); }
protected function setUp() { $this->cm = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->cm->expects($this->exactly(5))->method('get')->will($this->onConsecutiveCalls('old value', 'default value', 'old value', 'old value', 'pre value')); $this->event = new ConfigUpdateEvent($this->cm, $this->testUpdatedConfigValues, $this->testDeletedConfigValues); }