예제 #1
0
 public function testGetLocale()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->once())->method('getLocale')->will($this->returnValue('en'));
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->exactly(2))->method('isScopeActive')->with('request')->will($this->onConsecutiveCalls(false, true));
     $container->expects($this->once())->method('has')->with('request')->will($this->returnValue(true));
     $container->expects($this->once())->method('get')->with('request')->will($this->returnValue($request));
     $translator = new Translator($container, new MessageSelector());
     $this->assertNull($translator->getLocale());
     $this->assertSame('en', $translator->getLocale());
 }
예제 #2
0
 /**
  * Override the fosuserbundles original sendMessage, to embed template variables etc. into html-emails.
  * @param  string  $templateName
  * @param  array   $context
  * @param  string  $fromEmail
  * @param  string  $toEmail
  * @return boolean true if the mail was sent successfully, else false
  */
 protected function sendMessage($templateName, $context, $fromEmail, $toEmail)
 {
     // get the subject from the template
     // => make sure the subject block exists in your fos-templates (FOSUserBundle:Registration:email.txt.twig & FOSUserBundle:Resetting:email.txt.twig)
     $twigTemplate = $this->loadTemplate($templateName);
     $subject = $twigTemplate->renderBlock('subject', $context);
     return $this->sendSingleEmail($toEmail, null, $subject, $context, $templateName, $this->translator->getLocale());
 }
예제 #3
0
 public function testGetDefaultLocale()
 {
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('getParameter')->with('kernel.default_locale')->will($this->returnValue('en'));
     $translator = new Translator($container, new MessageSelector());
     $this->assertSame('en', $translator->getLocale());
 }
예제 #4
0
 public function testGetLocaleWithInvalidLocale()
 {
     $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
     $request->expects($this->any())->method('getLocale')->will($this->returnValue('foo bar'));
     $request->expects($this->once())->method('getDefaultLocale')->will($this->returnValue('en-US'));
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('get')->with('request_stack')->will($this->returnValue($requestStack));
     $translator = new Translator($container, new MessageSelector());
     $this->assertSame('en-US', $translator->getLocale());
 }
 /**
  * @dataProvider getGetLocaleData
  */
 public function testGetLocale($inRequestScope)
 {
     $requestStack = new RequestStack();
     if ($inRequestScope) {
         $request = $this->getMock('Symfony\\Component\\HttpFoundation\\Request');
         $request->expects($this->once())->method('getLocale')->will($this->returnValue('en'));
         $requestStack->push($request);
     }
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->once())->method('get')->with('request_stack')->will($this->returnValue($requestStack));
     $translator = new Translator($container, new MessageSelector());
     if ($inRequestScope) {
         $this->assertSame('en', $translator->getLocale());
     } else {
         $this->assertNull($translator->getLocale());
     }
 }