Merge branch '2.8'
* 2.8: [Finder] simplified code Fix tests in 2.8 [Validator] Sync polish translation file Adding a class to make it easier to set custom authentication error messages Readd the correct tests
This commit is contained in:
commit
98287265a3
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Expression class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Glob class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
use Symfony\Component\Finder\Glob as FinderGlob;
|
||||
|
||||
/**
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\Regex class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,6 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Expression;
|
||||
|
||||
@trigger_error('The '.__NAMESPACE__.'\ValueInterface interface is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
||||
|
||||
/**
|
||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||
*/
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
use Symfony\Component\Finder\Glob;
|
||||
|
||||
/**
|
||||
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
|
||||
@ -42,6 +42,6 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
|
||||
*/
|
||||
protected function toRegex($str)
|
||||
{
|
||||
return Expression::create($str)->getRegex()->render();
|
||||
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
|
||||
*
|
||||
@ -87,7 +85,22 @@ abstract class MultiplePcreFilterIterator extends FilterIterator
|
||||
*/
|
||||
protected function isRegex($str)
|
||||
{
|
||||
return Expression::create($str)->isRegex();
|
||||
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
|
||||
$start = substr($m[1], 0, 1);
|
||||
$end = substr($m[1], -1);
|
||||
|
||||
if ($start === $end) {
|
||||
return !preg_match('/[*?[:alnum:] \\\\]/', $start);
|
||||
}
|
||||
|
||||
foreach (array(array('{', '}'), array('(', ')'), array('[', ']'), array('<', '>')) as $delimiters) {
|
||||
if ($start === $delimiters[0] && $end === $delimiters[1]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class ExpressionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class GlobTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -13,6 +13,9 @@ namespace Symfony\Component\Finder\Tests\Expression;
|
||||
|
||||
use Symfony\Component\Finder\Expression\Expression;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class RegexTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
|
@ -38,6 +38,9 @@ class MultiplePcreFilterIteratorTest extends \PHPUnit_Framework_TestCase
|
||||
array('/foo/imsxu', true, 'valid regex with multiple modifiers'),
|
||||
array('#foo#', true, '"#" is a valid delimiter'),
|
||||
array('{foo}', true, '"{,}" is a valid delimiter pair'),
|
||||
array('[foo]', true, '"[,]" is a valid delimiter pair'),
|
||||
array('(foo)', true, '"(,)" is a valid delimiter pair'),
|
||||
array('<foo>', true, '"<,>" is a valid delimiter pair'),
|
||||
array('*foo.*', false, '"*" is not considered as a valid delimiter'),
|
||||
array('?foo.?', false, '"?" is not considered as a valid delimiter'),
|
||||
);
|
||||
|
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Exception;
|
||||
|
||||
/**
|
||||
* An authentication exception where you can control the message shown to the user.
|
||||
*
|
||||
* Be sure that the message passed to this exception is something that
|
||||
* can be shown safely to your user. In other words, avoid catching
|
||||
* other exceptions and passing their message directly to this class.
|
||||
*
|
||||
* @author Ryan Weaver <ryan@knpuniversity.com>
|
||||
*/
|
||||
class CustomUserMessageAuthenticationException extends AuthenticationException
|
||||
{
|
||||
private $messageKey;
|
||||
|
||||
private $messageData = array();
|
||||
|
||||
public function __construct($message = '', array $messageData = array(), $code = 0, \Exception $previous = null)
|
||||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
$this->setSafeMessage($message, $messageData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a message that will be shown to the user.
|
||||
*
|
||||
* @param string $messageKey The message or message key
|
||||
* @param array $messageData Data to be passed into the translator
|
||||
*/
|
||||
public function setSafeMessage($messageKey, array $messageData = array())
|
||||
{
|
||||
$this->messageKey = $messageKey;
|
||||
$this->messageData = $messageData;
|
||||
}
|
||||
|
||||
public function getMessageKey()
|
||||
{
|
||||
return $this->messageKey;
|
||||
}
|
||||
|
||||
public function getMessageData()
|
||||
{
|
||||
return $this->messageData;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return serialize(array(
|
||||
parent::serialize(),
|
||||
$this->messageKey,
|
||||
$this->messageData,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function unserialize($str)
|
||||
{
|
||||
list($parentData, $this->messageKey, $this->messageData) = unserialize($str);
|
||||
|
||||
parent::unserialize($parentData);
|
||||
}
|
||||
}
|
@ -13,42 +13,55 @@ namespace Symfony\Component\Security\Core\Tests\Authorization\Voter;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\AbstractVoter;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface;
|
||||
|
||||
/**
|
||||
* @author Roman Marintšenko <inoryy@gmail.com>
|
||||
*/
|
||||
class AbstractVoterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $token;
|
||||
protected $token;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$tokenMock = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
$tokenMock
|
||||
->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue('user'));
|
||||
$this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
||||
}
|
||||
|
||||
$this->token = $tokenMock;
|
||||
public function getTests()
|
||||
{
|
||||
return array(
|
||||
array(array('EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if attribute and class are supported and attribute grants access'),
|
||||
array(array('CREATE'), VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if attribute and class are supported and attribute does not grant access'),
|
||||
|
||||
array(array('DELETE', 'EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute is supported and grants access'),
|
||||
array(array('DELETE', 'CREATE'), VoterInterface::ACCESS_DENIED, new \stdClass(), 'ACCESS_DENIED if one attribute is supported and denies access'),
|
||||
|
||||
array(array('CREATE', 'EDIT'), VoterInterface::ACCESS_GRANTED, new \stdClass(), 'ACCESS_GRANTED if one attribute grants access'),
|
||||
|
||||
array(array('DELETE'), VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attribute is supported'),
|
||||
|
||||
array(array('EDIT'), VoterInterface::ACCESS_ABSTAIN, $this, 'ACCESS_ABSTAIN if class is not supported'),
|
||||
|
||||
array(array('EDIT'), VoterInterface::ACCESS_ABSTAIN, null, 'ACCESS_ABSTAIN if object is null'),
|
||||
|
||||
array(array(), VoterInterface::ACCESS_ABSTAIN, new \stdClass(), 'ACCESS_ABSTAIN if no attributes were provided'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getData
|
||||
* @dataProvider getTests
|
||||
*/
|
||||
public function testVote($expectedVote, $object, $attributes, $message)
|
||||
public function testVote(array $attributes, $expectedVote, $object, $message)
|
||||
{
|
||||
$voter = new VoterFixture();
|
||||
$voter = new AbstractVoterTest_Voter();
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getData
|
||||
* @dataProvider getTests
|
||||
* @group legacy
|
||||
*/
|
||||
public function testVoteUsingDeprecatedIsGranted($expectedVote, $object, $attributes, $message)
|
||||
public function testVoteLegacy(array $attributes, $expectedVote, $object, $message)
|
||||
{
|
||||
$voter = new DeprecatedVoterFixture();
|
||||
$voter = new AbstractVoterTest_LegacyVoter();
|
||||
|
||||
$this->assertEquals($expectedVote, $voter->vote($this->token, $object, $attributes), $message);
|
||||
}
|
||||
@ -59,86 +72,54 @@ class AbstractVoterTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNoOverriddenMethodsThrowsException()
|
||||
{
|
||||
$voter = new DeprecatedVoterNothingImplementedFixture();
|
||||
$voter->vote($this->token, new ObjectFixture(), array('foo'));
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
return array(
|
||||
array(AbstractVoter::ACCESS_ABSTAIN, null, array(), 'ACCESS_ABSTAIN for null objects'),
|
||||
array(AbstractVoter::ACCESS_ABSTAIN, new UnsupportedObjectFixture(), array(), 'ACCESS_ABSTAIN for objects with unsupported class'),
|
||||
array(AbstractVoter::ACCESS_ABSTAIN, new ObjectFixture(), array(), 'ACCESS_ABSTAIN for no attributes'),
|
||||
array(AbstractVoter::ACCESS_ABSTAIN, new ObjectFixture(), array('foobar'), 'ACCESS_ABSTAIN for unsupported attributes'),
|
||||
array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('foo'), 'ACCESS_GRANTED if attribute grants access'),
|
||||
array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('bar', 'foo'), 'ACCESS_GRANTED if *at least one* attribute grants access'),
|
||||
array(AbstractVoter::ACCESS_GRANTED, new ObjectFixture(), array('foobar', 'foo'), 'ACCESS_GRANTED if *at least one* attribute grants access'),
|
||||
array(AbstractVoter::ACCESS_DENIED, new ObjectFixture(), array('bar', 'baz'), 'ACCESS_DENIED for if no attribute grants access'),
|
||||
);
|
||||
$voter = new AbstractVoterTest_NothingImplementedVoter();
|
||||
$voter->vote($this->token, new \stdClass(), array('EDIT'));
|
||||
}
|
||||
}
|
||||
|
||||
class VoterFixture extends AbstractVoter
|
||||
class AbstractVoterTest_Voter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array(
|
||||
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
|
||||
);
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('foo', 'bar', 'baz');
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $object, TokenInterface $token)
|
||||
{
|
||||
return $attribute === 'foo';
|
||||
return 'EDIT' === $attribute;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $class)
|
||||
{
|
||||
return $this->isClassInstanceOf($class, 'stdClass')
|
||||
&& in_array($attribute, array('EDIT', 'CREATE'));
|
||||
}
|
||||
}
|
||||
|
||||
class DeprecatedVoterFixture extends AbstractVoter
|
||||
class AbstractVoterTest_LegacyVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array(
|
||||
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
|
||||
);
|
||||
return array('AbstractVoterTest_Object');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('foo', 'bar', 'baz');
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
protected function isGranted($attribute, $object, $user = null)
|
||||
{
|
||||
return $attribute === 'foo';
|
||||
return 'EDIT' === $attribute;
|
||||
}
|
||||
}
|
||||
|
||||
class DeprecatedVoterNothingImplementedFixture extends AbstractVoter
|
||||
class AbstractVoterTest_NothingImplementedVoter extends AbstractVoter
|
||||
{
|
||||
protected function getSupportedClasses()
|
||||
{
|
||||
return array(
|
||||
'Symfony\Component\Security\Core\Tests\Authorization\Voter\ObjectFixture',
|
||||
);
|
||||
return array('AbstractVoterTest_Object');
|
||||
}
|
||||
|
||||
protected function getSupportedAttributes()
|
||||
{
|
||||
return array('foo', 'bar', 'baz');
|
||||
return array('EDIT', 'CREATE');
|
||||
}
|
||||
|
||||
// this is a bad voter that hasn't overridden isGranted or voteOnAttribute
|
||||
}
|
||||
|
||||
class ObjectFixture
|
||||
{
|
||||
}
|
||||
|
||||
class UnsupportedObjectFixture
|
||||
{
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Tests\Exception;
|
||||
|
||||
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
|
||||
|
||||
class CustomUserMessageAuthenticationExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testConstructWithSAfeMessage()
|
||||
{
|
||||
$e = new CustomUserMessageAuthenticationException('SAFE MESSAGE', array('foo' => true));
|
||||
|
||||
$this->assertEquals('SAFE MESSAGE', $e->getMessageKey());
|
||||
$this->assertEquals(array('foo' => true), $e->getMessageData());
|
||||
$this->assertEquals('SAFE MESSAGE', $e->getMessage());
|
||||
}
|
||||
}
|
@ -310,6 +310,10 @@
|
||||
<source>This value does not match the expected {{ charset }} charset.</source>
|
||||
<target>Ta wartość nie pasuje do oczekiwanego zestawu znaków {{ charset }}.</target>
|
||||
</trans-unit>
|
||||
<trans-unit id="81">
|
||||
<source>This is not a valid Business Identifier Code (BIC).</source>
|
||||
<target>Ta wartość nie jest poprawnym kodem BIC (Business Identifier Code).</target>
|
||||
</trans-unit>
|
||||
</body>
|
||||
</file>
|
||||
</xliff>
|
||||
|
Reference in New Issue
Block a user