Merge branch '2.3' into 2.6
* 2.3: renamed some confusing tests [2.3] Fix @link annotations Fix javascript [2.3][Translation] test refresh cache when resources File change. [Translator] Cache does not take fallback locales into consideration Conflicts: src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php
This commit is contained in:
commit
234cebd087
@ -12,7 +12,7 @@
|
|||||||
namespace Symfony\Bridge\Twig\Node;
|
namespace Symfony\Bridge\Twig\Node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles a call to {@link FormRendererInterface::renderBlock()}.
|
* Compiles a call to {@link \Symfony\Component\Form\FormRendererInterface::renderBlock()}.
|
||||||
*
|
*
|
||||||
* The function name is used as block name. For example, if the function name
|
* The function name is used as block name. For example, if the function name
|
||||||
* is "foo", the block "foo" will be rendered.
|
* is "foo", the block "foo" will be rendered.
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
|
namespace Symfony\Bundle\FrameworkBundle\Tests\Translation;
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
|
use Symfony\Bundle\FrameworkBundle\Translation\Translator;
|
||||||
|
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||||
use Symfony\Component\Translation\MessageCatalogue;
|
use Symfony\Component\Translation\MessageCatalogue;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
use Symfony\Component\Translation\MessageSelector;
|
use Symfony\Component\Translation\MessageSelector;
|
||||||
@ -77,6 +78,8 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
// do it another time as the cache is primed now
|
// do it another time as the cache is primed now
|
||||||
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||||
|
$loader->expects($this->never())->method('load');
|
||||||
|
|
||||||
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
||||||
$translator->setLocale('fr');
|
$translator->setLocale('fr');
|
||||||
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
$translator->setFallbackLocales(array('en', 'es', 'pt-PT', 'pt_BR', 'fr.UTF-8', 'sr@latin'));
|
||||||
@ -90,6 +93,27 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
$this->assertEquals('other choice 1 (PT-BR)', $translator->transChoice('other choice', 1));
|
||||||
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
$this->assertEquals('foobarbaz (fr.UTF-8)', $translator->trans('foobarbaz'));
|
||||||
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
$this->assertEquals('foobarbax (sr@latin)', $translator->trans('foobarbax'));
|
||||||
|
|
||||||
|
// refresh cache again when resource file resources file change
|
||||||
|
$resource = $this->getMock('Symfony\Component\Config\Resource\ResourceInterface');
|
||||||
|
$resource
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('isFresh')
|
||||||
|
->will($this->returnValue(false))
|
||||||
|
;
|
||||||
|
$catalogue = $this->getCatalogue('fr', array('foo' => 'foo fresh'));
|
||||||
|
$catalogue->addResource($resource);
|
||||||
|
|
||||||
|
$loader = $this->getMock('Symfony\Component\Translation\Loader\LoaderInterface');
|
||||||
|
$loader
|
||||||
|
->expects($this->at(0))
|
||||||
|
->method('load')
|
||||||
|
->will($this->returnValue($catalogue))
|
||||||
|
;
|
||||||
|
|
||||||
|
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir));
|
||||||
|
$translator->setLocale('fr');
|
||||||
|
$this->assertEquals('foo fresh', $translator->trans('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testTransWithCachingWithInvalidLocale()
|
public function testTransWithCachingWithInvalidLocale()
|
||||||
@ -184,12 +208,7 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function getTranslator($loader, $options = array(), $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator')
|
public function getTranslator($loader, $options = array(), $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator')
|
||||||
{
|
{
|
||||||
$translator = new $translatorClass(
|
$translator = $this->createTranslator($loader, $options, $translatorClass);
|
||||||
$this->getContainer($loader),
|
|
||||||
new MessageSelector(),
|
|
||||||
array('loader' => array('loader')),
|
|
||||||
$options
|
|
||||||
);
|
|
||||||
|
|
||||||
$translator->addResource('loader', 'foo', 'fr');
|
$translator->addResource('loader', 'foo', 'fr');
|
||||||
$translator->addResource('loader', 'foo', 'en');
|
$translator->addResource('loader', 'foo', 'en');
|
||||||
@ -201,6 +220,18 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
return $translator;
|
return $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function createTranslator($loader, $options, $translatorClass = '\Symfony\Bundle\FrameworkBundle\Translation\Translator')
|
||||||
|
{
|
||||||
|
$translator = new $translatorClass(
|
||||||
|
$this->getContainer($loader),
|
||||||
|
new MessageSelector(),
|
||||||
|
array('loader' => array('loader')),
|
||||||
|
$options
|
||||||
|
);
|
||||||
|
|
||||||
|
return $translator;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TranslatorWithInvalidLocale extends Translator
|
class TranslatorWithInvalidLocale extends Translator
|
||||||
|
@ -103,13 +103,13 @@
|
|||||||
return dict.hasOwnProperty(key)
|
return dict.hasOwnProperty(key)
|
||||||
? dict[key]
|
? dict[key]
|
||||||
: null;
|
: null;
|
||||||
}
|
};
|
||||||
|
|
||||||
this.set = function(key, value) {
|
this.set = function(key, value) {
|
||||||
dict[key] = value;
|
dict[key] = value;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -383,7 +383,7 @@
|
|||||||
|
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
function canvasAutoUpdateOnResizeAndSubmit(e) {
|
function canvasAutoUpdateOnResizeAndSubmit(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
@ -121,7 +121,7 @@
|
|||||||
for (elem in menuItems) {
|
for (elem in menuItems) {
|
||||||
if (typeof(menuItems[elem].children) !== 'undefined' &&
|
if (typeof(menuItems[elem].children) !== 'undefined' &&
|
||||||
menuItems[elem].children.length > 0) {
|
menuItems[elem].children.length > 0) {
|
||||||
child = menuItems[elem].children[0]
|
child = menuItems[elem].children[0];
|
||||||
|
|
||||||
if ('' === child.getAttribute('title') ||
|
if ('' === child.getAttribute('title') ||
|
||||||
null === child.getAttribute('title')) {
|
null === child.getAttribute('title')) {
|
||||||
|
@ -127,7 +127,7 @@ interface ChoiceListInterface
|
|||||||
* Returns the indices corresponding to the given choices.
|
* Returns the indices corresponding to the given choices.
|
||||||
*
|
*
|
||||||
* The indices must be positive integers or strings accepted by
|
* The indices must be positive integers or strings accepted by
|
||||||
* {@link FormConfigBuilder::validateName()}.
|
* {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
|
||||||
*
|
*
|
||||||
* The index "placeholder" is internally reserved.
|
* The index "placeholder" is internally reserved.
|
||||||
*
|
*
|
||||||
@ -147,7 +147,7 @@ interface ChoiceListInterface
|
|||||||
* Returns the indices corresponding to the given values.
|
* Returns the indices corresponding to the given values.
|
||||||
*
|
*
|
||||||
* The indices must be positive integers or strings accepted by
|
* The indices must be positive integers or strings accepted by
|
||||||
* {@link FormConfigBuilder::validateName()}.
|
* {@link \Symfony\Component\Form\FormConfigBuilder::validateName()}.
|
||||||
*
|
*
|
||||||
* The index "placeholder" is internally reserved.
|
* The index "placeholder" is internally reserved.
|
||||||
*
|
*
|
||||||
|
@ -21,7 +21,7 @@ use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
|||||||
* Encapsulates common logic of {@link FormType} and {@link ButtonType}.
|
* Encapsulates common logic of {@link FormType} and {@link ButtonType}.
|
||||||
*
|
*
|
||||||
* This type does not appear in the form's type inheritance chain and as such
|
* This type does not appear in the form's type inheritance chain and as such
|
||||||
* cannot be extended (via {@link FormTypeExtension}s) nor themed.
|
* cannot be extended (via {@link \Symfony\Component\Form\FormExtensionInterface}) nor themed.
|
||||||
*
|
*
|
||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
@ -20,7 +20,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
* @author Bernhard Schussek <bschussek@gmail.com>
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
||||||
*
|
*
|
||||||
* @deprecated Deprecated since version 2.3, to be removed in 3.0. Pass the
|
* @deprecated Deprecated since version 2.3, to be removed in 3.0. Pass the
|
||||||
* Request instance to {@link Form::handleRequest()} instead.
|
* Request instance to {@link \Symfony\Component\Form\Form::handleRequest()} instead.
|
||||||
*/
|
*/
|
||||||
class BindRequestListener implements EventSubscriberInterface
|
class BindRequestListener implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
|
@ -48,7 +48,7 @@ class ViolationPath implements \IteratorAggregate, PropertyPathInterface
|
|||||||
/**
|
/**
|
||||||
* Creates a new violation path from a string.
|
* Creates a new violation path from a string.
|
||||||
*
|
*
|
||||||
* @param string $violationPath The property path of a {@link ConstraintViolation}
|
* @param string $violationPath The property path of a {@link \Symfony\Component\Validator\ConstraintViolation}
|
||||||
* object.
|
* object.
|
||||||
*/
|
*/
|
||||||
public function __construct($violationPath)
|
public function __construct($violationPath)
|
||||||
|
@ -159,7 +159,7 @@ class NativeRequestHandler implements RequestHandlerInterface
|
|||||||
* It's safe to pass an already converted array, in which case this method
|
* It's safe to pass an already converted array, in which case this method
|
||||||
* just returns the original array unmodified.
|
* just returns the original array unmodified.
|
||||||
*
|
*
|
||||||
* This method is identical to {@link Symfony\Component\HttpFoundation\FileBag::fixPhpFilesArray}
|
* This method is identical to {@link \Symfony\Component\HttpFoundation\FileBag::fixPhpFilesArray}
|
||||||
* and should be kept as such in order to port fixes quickly and easily.
|
* and should be kept as such in order to port fixes quickly and easily.
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
|
@ -26,7 +26,7 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsTrue()
|
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
|
||||||
{
|
{
|
||||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||||
|
|
||||||
@ -36,14 +36,14 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalseAndNoListenerIsRegistered()
|
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered()
|
||||||
{
|
{
|
||||||
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
$kernel = new HttpKernel(new EventDispatcher(), $this->getResolver(function () { throw new \RuntimeException(); }));
|
||||||
|
|
||||||
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
|
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHandleWhenControllerThrowsAnExceptionAndRawIsFalse()
|
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHandlingListener()
|
||||||
{
|
{
|
||||||
$dispatcher = new EventDispatcher();
|
$dispatcher = new EventDispatcher();
|
||||||
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
|
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
|
||||||
@ -51,12 +51,26 @@ class HttpKernelTest extends \PHPUnit_Framework_TestCase
|
|||||||
});
|
});
|
||||||
|
|
||||||
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
|
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
|
||||||
$response = $kernel->handle(new Request());
|
$response = $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||||
|
|
||||||
$this->assertEquals('500', $response->getStatusCode());
|
$this->assertEquals('500', $response->getStatusCode());
|
||||||
$this->assertEquals('foo', $response->getContent());
|
$this->assertEquals('foo', $response->getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \RuntimeException
|
||||||
|
*/
|
||||||
|
public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithANonHandlingListener()
|
||||||
|
{
|
||||||
|
$dispatcher = new EventDispatcher();
|
||||||
|
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) {
|
||||||
|
// should set a response, but does not
|
||||||
|
});
|
||||||
|
|
||||||
|
$kernel = new HttpKernel($dispatcher, $this->getResolver(function () { throw new \RuntimeException('foo'); }));
|
||||||
|
$kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
|
||||||
|
}
|
||||||
|
|
||||||
public function testHandleExceptionWithARedirectionResponse()
|
public function testHandleExceptionWithARedirectionResponse()
|
||||||
{
|
{
|
||||||
$dispatcher = new EventDispatcher();
|
$dispatcher = new EventDispatcher();
|
||||||
|
@ -88,7 +88,7 @@ class DefaultTranslator implements TranslatorInterface
|
|||||||
* have the same expressiveness. While Translator supports intervals in
|
* have the same expressiveness. While Translator supports intervals in
|
||||||
* message translations, which are needed for languages other than English,
|
* message translations, which are needed for languages other than English,
|
||||||
* this translator does not. You should use Translator or a custom
|
* this translator does not. You should use Translator or a custom
|
||||||
* implementation of {@link TranslatorInterface} if you need this or similar
|
* implementation of {@link \Symfony\Component\Translation\TranslatorInterface} if you need this or similar
|
||||||
* functionality.
|
* functionality.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
|
Reference in New Issue
Block a user