Example #1
0
 public function testOnConsoleCommand()
 {
     $this->listener = new LocaleListener($this->localeSettings, $this->transListener, true);
     $event = $this->getMockBuilder('Symfony\\Component\\Console\\Event\\ConsoleCommandEvent')->disableOriginalConstructor()->getMock();
     $input = $this->getMockBuilder('Symfony\\Component\\Console\\Input\\InputInterface')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getInput')->will($this->returnValue($input));
     $input->expects($this->once())->method('hasParameterOption')->will($this->returnValue(false));
     $this->localeSettings->expects($this->once())->method('getLocale');
     $this->localeSettings->expects($this->once())->method('getLanguage');
     $this->transListener->expects($this->once())->method('setTranslatableLocale');
     $this->listener->onConsoleCommand($event);
 }
 /**
  * @param mixed $installed
  * @param bool $isSetLocale
  * @dataProvider onKernelRequestDataProvider
  */
 public function testOnKernelRequest($installed, $isSetLocale)
 {
     $customLanguage = 'ru';
     $customLocale = 'fr';
     $request = new Request();
     $request->setDefaultLocale($this->defaultLocale);
     if ($isSetLocale) {
         $this->localeSettings->expects($this->once())->method('getLanguage')->will($this->returnValue($customLanguage));
         $this->localeSettings->expects($this->once())->method('getLocale')->will($this->returnValue($customLocale));
     } else {
         $this->localeSettings->expects($this->never())->method('getLanguage');
         $this->localeSettings->expects($this->never())->method('getLocale');
     }
     $this->listener = new LocaleListener($this->localeSettings, $installed);
     $this->listener->onKernelRequest($this->createGetResponseEvent($request));
     if ($isSetLocale) {
         $this->assertEquals($customLanguage, $request->getLocale());
         $this->assertEquals($customLocale, \Locale::getDefault());
     } else {
         $this->assertEquals($this->defaultLocale, $request->getLocale());
         $this->assertEquals($this->defaultLocale, \Locale::getDefault());
     }
 }