public function testIndexAction() { $content = 'CONTENT'; $templating = $this->getMockBuilder('Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface')->getMockForAbstractClass(); $templating->expects($this->once())->method('render')->will($this->returnValue($content)); $translator = $this->getMockBuilder('Oro\\Bundle\\TranslationBundle\\Translation\\Translator')->disableOriginalConstructor()->getMock(); $translator->expects($this->once())->method('getTranslations')->will($this->returnValue(array())); $controller = new Controller($translator, $templating, 'OroTranslationBundle:Translation:translation.js.twig', array()); $request = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock(); $request->expects($this->once())->method('getMimeType')->with('js')->will($this->returnValue('JS')); $response = $controller->indexAction($request, 'en'); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $response); $this->assertEquals($content, $response->getContent()); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals('JS', $response->headers->get('Content-Type')); }
/** * @param array $locales * * @return bool * @throws \Symfony\Component\Filesystem\Exception\IOException * @throws \RuntimeException */ public function dumpTranslations($locales = []) { if (empty($locales)) { $locales[] = $this->defaultLocale; } $targetPattern = realpath($this->kernelRootDir . '/../web') . $this->router->getRouteCollection()->get($this->jsTranslationRoute)->getPath(); foreach ($locales as $locale) { $target = strtr($targetPattern, array('{_locale}' => $locale)); $this->logger->info(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), basename($target))); $content = $this->translationController->renderJsTranslationContent($this->translationDomains, $locale); $dirName = dirname($target); if (!is_dir($dirName) && true !== @mkdir($dirName, 0777, true)) { throw new IOException(sprintf('Failed to create %s', $dirName)); } if (false === @file_put_contents($target, $content)) { throw new \RuntimeException('Unable to write file ' . $target); } } return true; }