summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'Tests')
-rw-r--r--Tests/Acl/Dbal/AclProviderTest.php8
-rw-r--r--Tests/Acl/Dbal/MutableAclProviderTest.php6
-rw-r--r--Tests/Acl/Domain/PermissionGrantingStrategyTest.php2
-rw-r--r--Tests/Core/User/InMemoryUserProviderTest.php33
-rw-r--r--Tests/Http/Firewall/SwitchUserListenerTest.php52
-rw-r--r--Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php2
6 files changed, 88 insertions, 15 deletions
diff --git a/Tests/Acl/Dbal/AclProviderTest.php b/Tests/Acl/Dbal/AclProviderTest.php
index ecd53db..7ca493f 100644
--- a/Tests/Acl/Dbal/AclProviderTest.php
+++ b/Tests/Acl/Dbal/AclProviderTest.php
@@ -45,11 +45,11 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase
$this->getProvider()->findAcls($oids);
$this->fail('Provider did not throw an expected exception.');
- } catch (\Exception $ex) {
- $this->assertInstanceOf('Symfony\Component\Security\Acl\Exception\AclNotFoundException', $ex);
- $this->assertInstanceOf('Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException', $ex);
+ } catch (\Exception $e) {
+ $this->assertInstanceOf('Symfony\Component\Security\Acl\Exception\AclNotFoundException', $e);
+ $this->assertInstanceOf('Symfony\Component\Security\Acl\Exception\NotAllAclsFoundException', $e);
- $partialResult = $ex->getPartialResult();
+ $partialResult = $e->getPartialResult();
$this->assertTrue($partialResult->contains($oids[0]));
$this->assertFalse($partialResult->contains($oids[1]));
}
diff --git a/Tests/Acl/Dbal/MutableAclProviderTest.php b/Tests/Acl/Dbal/MutableAclProviderTest.php
index f6d66ef..00500f8 100644
--- a/Tests/Acl/Dbal/MutableAclProviderTest.php
+++ b/Tests/Acl/Dbal/MutableAclProviderTest.php
@@ -88,7 +88,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
try {
$provider->findAcl($oid);
$this->fail('ACL has not been properly deleted.');
- } catch (AclNotFoundException $notFound) {
+ } catch (AclNotFoundException $e) {
}
}
@@ -104,7 +104,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
try {
$provider->findAcl(new ObjectIdentity(1, 'Foo'));
$this->fail('Child-ACLs have not been deleted.');
- } catch (AclNotFoundException $notFound) {
+ } catch (AclNotFoundException $e) {
}
}
@@ -290,7 +290,7 @@ class MutableAclProviderTest extends \PHPUnit_Framework_TestCase
try {
$provider->updateAcl($acl1);
$this->fail('Provider failed to detect a concurrent modification.');
- } catch (ConcurrentModificationException $ex) {
+ } catch (ConcurrentModificationException $e) {
}
}
diff --git a/Tests/Acl/Domain/PermissionGrantingStrategyTest.php b/Tests/Acl/Domain/PermissionGrantingStrategyTest.php
index 4935bff..fd33f8d 100644
--- a/Tests/Acl/Domain/PermissionGrantingStrategyTest.php
+++ b/Tests/Acl/Domain/PermissionGrantingStrategyTest.php
@@ -154,7 +154,7 @@ class PermissionGrantingStrategyTest extends \PHPUnit_Framework_TestCase
try {
$strategy->isGranted($acl, array($requiredMask), array($sid));
$this->fail('The ACE is not supposed to match.');
- } catch (NoAceFoundException $noAce) {
+ } catch (NoAceFoundException $e) {
}
} else {
$this->assertTrue($strategy->isGranted($acl, array($requiredMask), array($sid)));
diff --git a/Tests/Core/User/InMemoryUserProviderTest.php b/Tests/Core/User/InMemoryUserProviderTest.php
index 826e390..266d397 100644
--- a/Tests/Core/User/InMemoryUserProviderTest.php
+++ b/Tests/Core/User/InMemoryUserProviderTest.php
@@ -18,18 +18,39 @@ class InMemoryUserProviderTest extends \PHPUnit_Framework_TestCase
{
public function testConstructor()
{
- $provider = new InMemoryUserProvider(array(
+ $provider = $this->createProvider();
+
+ $user = $provider->loadUserByUsername('fabien');
+ $this->assertEquals('foo', $user->getPassword());
+ $this->assertEquals(array('ROLE_USER'), $user->getRoles());
+ $this->assertFalse($user->isEnabled());
+ }
+
+ public function testRefresh()
+ {
+ $user = new User('fabien', 'bar');
+
+ $provider = $this->createProvider();
+
+ $refreshedUser = $provider->refreshUser($user);
+ $this->assertEquals('foo', $refreshedUser->getPassword());
+ $this->assertEquals(array('ROLE_USER'), $refreshedUser->getRoles());
+ $this->assertFalse($refreshedUser->isEnabled());
+ $this->assertFalse($refreshedUser->isCredentialsNonExpired());
+ }
+
+ /**
+ * @return InMemoryUserProvider
+ */
+ protected function createProvider()
+ {
+ return new InMemoryUserProvider(array(
'fabien' => array(
'password' => 'foo',
'enabled' => false,
'roles' => array('ROLE_USER'),
),
));
-
- $user = $provider->loadUserByUsername('fabien');
- $this->assertEquals('foo', $user->getPassword());
- $this->assertEquals(array('ROLE_USER'), $user->getRoles());
- $this->assertFalse($user->isEnabled());
}
public function testCreateUser()
diff --git a/Tests/Http/Firewall/SwitchUserListenerTest.php b/Tests/Http/Firewall/SwitchUserListenerTest.php
index e86ee83..7ba71d4 100644
--- a/Tests/Http/Firewall/SwitchUserListenerTest.php
+++ b/Tests/Http/Firewall/SwitchUserListenerTest.php
@@ -11,7 +11,9 @@
namespace Symfony\Component\Security\Tests\Http\Firewall;
+use Symfony\Component\Security\Http\Event\SwitchUserEvent;
use Symfony\Component\Security\Http\Firewall\SwitchUserListener;
+use Symfony\Component\Security\Http\SecurityEvents;
class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
{
@@ -97,6 +99,56 @@ class SwitchUserListenerTest extends \PHPUnit_Framework_TestCase
$listener->handle($this->event);
}
+ public function testExitUserDispatchesEventWithRefreshedUser()
+ {
+ $originalUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $refreshedUser = $this->getMock('Symfony\Component\Security\Core\User\UserInterface');
+ $this
+ ->userProvider
+ ->expects($this->any())
+ ->method('refreshUser')
+ ->with($originalUser)
+ ->willReturn($refreshedUser);
+ $originalToken = $this->getToken();
+ $originalToken
+ ->expects($this->any())
+ ->method('getUser')
+ ->willReturn($originalUser);
+ $role = $this
+ ->getMockBuilder('Symfony\Component\Security\Core\Role\SwitchUserRole')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $role->expects($this->any())->method('getSource')->willReturn($originalToken);
+ $this
+ ->securityContext
+ ->expects($this->any())
+ ->method('getToken')
+ ->willReturn($this->getToken(array($role)));
+ $this
+ ->request
+ ->expects($this->any())
+ ->method('get')
+ ->with('_switch_user')
+ ->willReturn('_exit');
+ $this
+ ->request
+ ->expects($this->any())
+ ->method('getUri')
+ ->willReturn('/');
+
+ $dispatcher = $this->getMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
+ $dispatcher
+ ->expects($this->once())
+ ->method('dispatch')
+ ->with(SecurityEvents::SWITCH_USER, $this->callback(function (SwitchUserEvent $event) use ($refreshedUser) {
+ return $event->getTargetUser() === $refreshedUser;
+ }))
+ ;
+
+ $listener = new SwitchUserListener($this->securityContext, $this->userProvider, $this->userChecker, 'provider123', $this->accessDecisionManager, null, '_switch_user', 'ROLE_ALLOWED_TO_SWITCH', $dispatcher);
+ $listener->handle($this->event);
+ }
+
/**
* @expectedException \Symfony\Component\Security\Core\Exception\AccessDeniedException
*/
diff --git a/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php b/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
index 89da09f..fe64abc 100644
--- a/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
+++ b/Tests/Http/RememberMe/PersistentTokenBasedRememberMeServicesTest.php
@@ -115,7 +115,7 @@ class PersistentTokenBasedRememberMeServicesTest extends \PHPUnit_Framework_Test
try {
$service->autoLogin($request);
$this->fail('Expected CookieTheftException was not thrown.');
- } catch (CookieTheftException $theft) {
+ } catch (CookieTheftException $e) {
}
$this->assertTrue($request->attributes->has(RememberMeServicesInterface::COOKIE_ATTR_NAME));