protected function setUp() { $this->renderer = new DataBlockRenderer(); $this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new DataBlockExtension())->getFormFactory(); $this->twig = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock(); $this->twig->expects($this->any())->method('render')->will($this->returnValue(null)); $this->twig->expects($this->any())->method('getLoader')->will($this->returnValue($this->getMockForAbstractClass('\\Twig_LoaderInterface'))); }
public function setUp() { $timezone = new DateTimeZone(date_default_timezone_get()); $coreExtension = $this->getMock('Twig_Extension_Core'); $coreExtension->expects($this->any())->method('getTimezone')->will($this->returnValue($timezone)); $this->env = $this->getMock('Twig_Environment'); $this->env->expects($this->any())->method('getExtension')->with('core')->will($this->returnValue($coreExtension)); }
protected function setUp() { $this->loader = $this->getMockBuilder(MailLoaderInterface::class)->getMock(); $this->twig = $this->getMockBuilder(\Twig_Environment::class)->getMock(); $this->twigTemplate = $this->getMockBuilder(\Twig_Template::class)->disableOriginalConstructor()->getMock(); $this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $this->templater = new MailTemplater($this->loader, $this->twig, $this->dispatcher); $this->twig->expects($this->any())->method('createTemplate')->will($this->returnValue($this->twigTemplate)); $this->twig->expects($this->any())->method('loadTemplate')->will($this->returnValue($this->twigTemplate)); }
public function testItCanWrapATwigTemplateIntoAResponse() { $name = 'template_name'; $context = ['foo' => 'bar']; $status = 400; $headers = ['baz' => 'bim']; $this->twig->expects($this->once())->method('render')->with($name, $context)->willReturn('foo content'); $response = $this->sut->renderResponse($name, $context, $status, $headers); $this->assertInstanceOf(Response::class, $response); $this->assertSame(400, $response->getStatusCode()); $this->assertSame('foo content', $response->getContent()); $this->assertTrue($response->headers->contains('baz', 'bim')); }
protected function mockTwigEnvironment() { $this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->getMock(); $this->twigEnvironment->expects($this->any())->method('loadTemplate')->will($this->returnValue('loadedTemplate')); $this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($this->getMock('\\Twig_LoaderInterface'))); return $this->twigEnvironment; }
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); }
public function testRenderFragmentWithoutUser() { $windowState = $this->createWindowState(); $this->environment->expects($this->never())->method($this->anything()); $this->stateManager->expects($this->once())->method('deleteWindowsState')->willThrowException(new AccessDeniedException()); $this->assertEquals('', $this->extension->renderFragment($this->environment, $windowState)); $this->assertFalse($windowState->isRenderedSuccessfully()); }
public function testSendConfirmationEmail() { $email = '*****@*****.**'; $activationHash = md5(time()); $fromEmail = '*****@*****.**'; $htmlTemplate = 'html.tpl'; $txtTemplate = 'txt.tpl'; $registrationMailer = new RegistrationMailer($this->twig, $this->mailer, $fromEmail, $htmlTemplate, $txtTemplate); $confirmation = new \Swift_Message(); $renderedHtmlTpl = 'rendered html'; $renderedTxtTpl = 'rendered txt'; $this->twig->expects($this->at(0))->method('render')->with($txtTemplate)->will($this->returnValue($renderedTxtTpl)); $this->twig->expects($this->at(1))->method('render')->with($htmlTemplate)->will($this->returnValue($renderedHtmlTpl)); $this->mailer->expects($this->once())->method('createMessage')->will($this->returnValue($confirmation)); $this->mailer->expects($this->once())->method('send')->with($this->logicalAnd($this->isInstanceOf('\\Swift_Message'), $this->callback(function (\Swift_Message $other) use($email, $renderedTxtTpl, $fromEmail) { return $other->getSubject() == 'Confirmation' && $other->getBody() == $renderedTxtTpl && array_key_exists($email, $other->getTo()) && array_key_exists($fromEmail, $other->getReplyTo()); }))); $registrationMailer->sendConfirmationEmail($email, $activationHash); }
protected function mockTwigEnvironment() { $this->twigEnvironment = $this->getMockBuilder('Twig_Environment')->disableOriginalConstructor()->getMock(); $this->twigEnvironment->expects($this->any())->method('loadTemplate')->will($this->returnValue('loadedTemplate')); if (interface_exists('\\Twig_SourceContextLoaderInterface')) { $loader = $this->getMock('\\Twig_SourceContextLoaderInterface'); } else { $loader = $this->getMock('\\Twig_LoaderInterface'); } $this->twigEnvironment->expects($this->any())->method('getLoader')->will($this->returnValue($loader)); return $this->twigEnvironment; }
/** * @dataProvider renderProvider */ public function testRenderGlobalAction($gridTemplate = null, $rendererTemplate = null) { $template = 'global_action'; if ($rendererTemplate !== null) { $this->renderer = new Renderer($this->twig, $this->actionRenderer, $this->columnRenderer, $this->sorterRenderer, [$template => $rendererTemplate]); } $view = $this->createGridViewMock(); $view->expects($this->once())->method('getDefinition')->will($this->returnValue($grid = $this->createGridMock())); $grid->expects($this->once())->method('hasOption')->with($this->identicalTo($option = $template . '_template'))->will($this->returnValue($gridTemplate !== null)); $grid->expects($gridTemplate !== null ? $this->once() : $this->never())->method('getOption')->with($this->identicalTo($option))->will($this->returnValue($gridTemplate)); $this->actionRenderer->expects($this->once())->method('render')->with($this->identicalTo($view), $this->identicalTo($action = $this->createActionMock()), $this->isNull())->will($this->returnValue($value = 'value')); $this->twig->expects($this->once())->method('render')->with($this->identicalTo($gridTemplate ?: ($rendererTemplate ?: '@LugGrid/' . $template . '.html.twig')), $this->identicalTo(['action' => $action, 'value' => $value, 'grid' => $view]))->will($this->returnValue($result = 'result')); $this->assertSame($result, $this->renderer->renderGlobalAction($view, $action)); }
/** * Tests the sendMessage method with no body_html block. */ public function testSendMessageWithNoBodyHtmlBlock() { $this->twig->expects($this->once())->method('loadTemplate')->will($this->returnValue($this->template)); $contact = new Contact(); $this->template->expects($this->exactly(3))->method('renderBlock')->withConsecutive(array($this->equalTo('subject'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_text'), $this->equalTo(array('contact' => $contact))), array($this->equalTo('body_html'), $this->equalTo(array('contact' => $contact))))->willReturnOnConsecutiveCalls('', 'Body text', ''); $message = $this->getMockBuilder('\\Swift_Message')->disableOriginalConstructor()->getMock(); $message->expects($this->once())->method('setSubject')->willReturnSelf(); $message->expects($this->once())->method('setFrom')->willReturnSelf(); $message->expects($this->once())->method('setTo')->willReturnSelf(); $message->expects($this->once())->method('setBody')->with($this->equalTo('Body text')); $message->expects($this->never())->method('addPart'); $this->serviceMailer->expects($this->once())->method('createMessage')->will($this->returnValue($message)); $this->mailer->expects($this->once())->method('send')->with($this->equalTo($message)); $this->serviceMailer->sendMessage($contact); }
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); }
public function testRender() { $this->propertyAccessor->expects($this->once())->method('getValue')->with($this->identicalTo($data = new \stdClass()), $this->identicalTo($path = 'path_value'))->will($this->returnValue($boolean = true)); $this->twig->expects($this->once())->method('render')->with($this->identicalTo($this->template), $this->identicalTo(array_merge($context = ['foo' => 'bar'], ['column' => $column = $this->createColumnMock(), 'data' => $boolean])))->will($this->returnValue($result = 'result')); $this->assertSame($result, $this->type->render($data, ['column' => $column, 'path' => $path, 'template' => $this->template, 'context' => $context])); }