Merge branch '2.3' into 2.5

* 2.3:
  [FrameworkBundle] Fixed Translation loader and update translation command.
  [Console] remove « use » statement for PHP built-in exception classes.
  [SecurityBundle] adds unit tests suite for SecurityDataCollector class.

Conflicts:
	src/Symfony/Component/Console/Helper/TableHelper.php
This commit is contained in:
Fabien Potencier 2014-12-22 17:16:14 +01:00
commit 442c633af4
6 changed files with 110 additions and 3 deletions

View File

@ -121,6 +121,13 @@ EOF
? new DiffOperation($currentCatalogue, $extractedCatalogue)
: new MergeOperation($currentCatalogue, $extractedCatalogue);
// Exit if no messages found.
if (!count($operation->getDomains())) {
$output->writeln("\n<comment>No translation found.</comment>");
return;
}
// show compiled list of messages
if ($input->getOption('dump-messages') === true) {
foreach ($operation->getDomains() as $domain) {

View File

@ -47,6 +47,10 @@ class TranslationLoader
*/
public function loadMessages($directory, MessageCatalogue $catalogue)
{
if (!is_dir($directory)) {
return;
}
foreach ($this->loaders as $format => $loader) {
// load any existing translation files
$finder = new Finder();

View File

@ -11,6 +11,7 @@
namespace Symfony\Bundle\SecurityBundle\DataCollector;
use Symfony\Component\Security\Core\Role\RoleInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@ -25,6 +26,11 @@ class SecurityDataCollector extends DataCollector
{
private $context;
/**
* Constructor.
*
* @param SecurityContextInterface|null $context
*/
public function __construct(SecurityContextInterface $context = null)
{
$this->context = $context;
@ -57,7 +63,7 @@ class SecurityDataCollector extends DataCollector
'authenticated' => $token->isAuthenticated(),
'token_class' => get_class($token),
'user' => $token->getUsername(),
'roles' => array_map(function ($role) { return $role->getRole();}, $token->getRoles()),
'roles' => array_map(function (RoleInterface $role) { return $role->getRole(); }, $token->getRoles()),
);
}
}

View File

@ -0,0 +1,87 @@
<?php
namespace Symfony\Bundle\SecurityBundle\Tests\DataCollector;
use Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Symfony\Component\Security\Core\Role\Role;
class SecurityDataCollectorTest extends \PHPUnit_Framework_TestCase
{
public function testCollectWhenSecurityIsDisabled()
{
$collector = new SecurityDataCollector();
$collector->collect($this->getRequest(), $this->getResponse());
$this->assertSame('security', $collector->getName());
$this->assertFalse($collector->isEnabled());
$this->assertFalse($collector->isAuthenticated());
$this->assertNull($collector->getTokenClass());
$this->assertCount(0, $collector->getRoles());
$this->assertEmpty($collector->getUser());
}
public function testCollectWhenAuthenticationTokenIsNull()
{
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
$securityContext->expects($this->once())->method('getToken')->willReturn(null);
$collector = new SecurityDataCollector($securityContext);
$collector->collect($this->getRequest(), $this->getResponse());
$this->assertTrue($collector->isEnabled());
$this->assertFalse($collector->isAuthenticated());
$this->assertNull($collector->getTokenClass());
$this->assertCount(0, $collector->getRoles());
$this->assertEmpty($collector->getUser());
}
/** @dataProvider provideRoles */
public function testCollectAuthenticationTokenAndRoles(array $roles, array $normalizedRoles)
{
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
$securityContext
->expects($this->once())
->method('getToken')
->willReturn(new UsernamePasswordToken('hhamon', 'P4$$w0rD', 'provider', $roles));
$collector = new SecurityDataCollector($securityContext);
$collector->collect($this->getRequest(), $this->getResponse());
$this->assertTrue($collector->isEnabled());
$this->assertTrue($collector->isAuthenticated());
$this->assertSame('Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken', $collector->getTokenClass());
$this->assertSame($normalizedRoles, $collector->getRoles());
$this->assertSame('hhamon', $collector->getUser());
}
public function provideRoles()
{
return array(
array(
array('ROLE_USER'),
array('ROLE_USER'),
),
array(
array(new Role('ROLE_USER')),
array('ROLE_USER'),
),
);
}
private function getRequest()
{
return $this
->getMockBuilder('Symfony\Component\HttpFoundation\Request')
->disableOriginalConstructor()
->getMock();
}
private function getResponse()
{
return $this
->getMockBuilder('Symfony\Component\HttpFoundation\Response')
->disableOriginalConstructor()
->getMock();
}
}

View File

@ -45,7 +45,7 @@ class TableHelper extends Helper
*
* @return TableHelper
*
* @throws InvalidArgumentException when the table layout is not known
* @throws \InvalidArgumentException when the table layout is not known
*/
public function setLayout($layout)
{
@ -64,7 +64,6 @@ class TableHelper extends Helper
default:
throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
break;
};
return $this;

View File

@ -77,6 +77,10 @@ class TranslationWriter
// get the right dumper
$dumper = $this->dumpers[$format];
if (isset($options['path']) && !is_dir($options['path'])) {
mkdir($options['path'], 0777, true);
}
// save
$dumper->dump($catalogue, $options);
}