mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Fix unit tests
This commit is contained in:
@@ -17,7 +17,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$this->assertNull($authenticator->getUser());
|
||||
@@ -32,7 +32,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$user = $this->createUserMock();
|
||||
|
||||
@@ -53,7 +53,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$user = $this->createUserMock();
|
||||
$user->expects($this->any())
|
||||
@@ -85,6 +85,20 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
$em->expects($this->at(1))
|
||||
->method('flush');
|
||||
|
||||
$repo = $this->createEntityRepositoryMock();
|
||||
$repo->expects($this->once())
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue($session));
|
||||
$repoUsers = $this->createEntityRepositoryMock();
|
||||
$repoUsers->expects($this->once())
|
||||
->method('find')
|
||||
->with($user->getId())
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$app['repo.sessions'] = $repo;
|
||||
$app['repo.users'] = $repoUsers;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$phsession = $authenticator->openAccount($user);
|
||||
|
||||
@@ -103,7 +117,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $SFsession = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$sessionId = 4224242;
|
||||
|
||||
@@ -119,15 +133,18 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$repo->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['id' => $session->getId()]))
|
||||
$repo->expects($this->exactly(2))
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue($session));
|
||||
$repoUsers = $this->createEntityRepositoryMock();
|
||||
$repoUsers->expects($this->once())
|
||||
->method('find')
|
||||
->with($user->getId())
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$app['repo.sessions'] = $repo;
|
||||
$app['repo.users'] = $repoUsers;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $SFsession, $em);
|
||||
$this->assertEquals($session, $authenticator->refreshAccount($session));
|
||||
@@ -144,7 +161,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $SFsession = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$sessionId = 4224242;
|
||||
|
||||
@@ -161,14 +178,11 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
|
||||
$repo->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['id' => $session->getId()]))
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$app['repo.sessions'] = $repo;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $SFsession, $em);
|
||||
try {
|
||||
@@ -216,12 +230,13 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$app['EM']->expects($this->any())->method('find')->with(
|
||||
$this->equalTo('Phraseanet:Session'),
|
||||
$this->equalTo(1)
|
||||
)->will($this->returnValue($sessionEntity));
|
||||
$app['repo.sessions'] = $this->createEntityRepositoryMock();
|
||||
$app['repo.sessions']->expects($this->any())
|
||||
->method('find')
|
||||
->with(1)
|
||||
->will($this->returnValue($sessionEntity));
|
||||
|
||||
$userRepository = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
@@ -235,7 +250,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$app['manipulator.user']->expects($this->once())->method('getRepository')->will($this->returnValue($userRepository));
|
||||
$app['repo.users'] = $userRepository;
|
||||
|
||||
$session->set('usr_id', self::$DI['user']->getId());
|
||||
$session->set('session_id', 1);
|
||||
@@ -254,26 +269,12 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$this->assertFalse($authenticator->isAuthenticated());
|
||||
}
|
||||
|
||||
private function getEntityManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getRegistryMock()
|
||||
{
|
||||
return $this->getMockBuilder('registryInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getSessionMock()
|
||||
{
|
||||
return new \Symfony\Component\HttpFoundation\Session\Session(new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage());
|
||||
|
@@ -13,7 +13,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testGetSession()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
@@ -25,8 +24,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->method('getPlatform')
|
||||
->will($this->returnValue('Linux'));
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$session = new Session();
|
||||
$session->setNonce('prettyN0nce');
|
||||
|
||||
@@ -39,10 +36,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$encoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -58,7 +52,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testGetSessionReturnFalse()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
@@ -70,8 +63,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->method('getPlatform')
|
||||
->will($this->returnValue('Linux'));
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$session = new Session();
|
||||
$session->setNonce('prettyN0nce');
|
||||
|
||||
@@ -84,10 +75,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$encoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -102,12 +90,9 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testSessionNotFound()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -117,10 +102,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$this->assertFalse($manager->getSession($tokenValue));
|
||||
}
|
||||
@@ -132,13 +114,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getEntityManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getBrowserMock()
|
||||
{
|
||||
return $this->getMockBuilder('Browser')
|
||||
|
@@ -15,7 +15,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testSaveFailure()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
|
||||
$ip = '192.168.16.178';
|
||||
@@ -47,7 +47,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
$catchFailure = $failure;
|
||||
}));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->saveFailure($username, $request);
|
||||
|
||||
$this->assertEquals($ip, $catchFailure->getIp());
|
||||
@@ -61,7 +61,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailures()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -73,7 +73,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresLessThan9()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -97,7 +97,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithoutCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(false);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -121,7 +121,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithCorrectCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, true);
|
||||
|
||||
@@ -150,7 +150,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithIncorrectCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, false);
|
||||
|
||||
@@ -175,14 +175,14 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
public function testCheckFailuresTrialsIsConfigurableUnderThreshold()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -196,19 +196,17 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 2);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
public function testTrialsIsConfigurable()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($this->createEntityRepositoryMock(), $em, $recaptcha, 2);
|
||||
$this->assertEquals(2, $manager->getTrials());
|
||||
}
|
||||
|
||||
@@ -219,7 +217,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresTrialsIsConfigurableOverThreshold()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, false);
|
||||
|
||||
@@ -233,7 +231,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 2);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -255,7 +253,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
$this->assertCount(12, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
|
||||
->findAll());
|
||||
|
||||
$manager = new FailureManager(self::$DI['app']['EM'], $recaptcha, 9);
|
||||
$manager = new FailureManager(self::$DI['app']['repo.auth-failures'], self::$DI['app']['EM'], $recaptcha, 9);
|
||||
$manager->saveFailure($username, $request);
|
||||
|
||||
$this->assertCount(0, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
|
||||
@@ -277,20 +275,6 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
return $failures;
|
||||
}
|
||||
|
||||
private function getEntityManagerMock($repo)
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:AuthFailure'))
|
||||
->will($this->returnValue($repo));
|
||||
|
||||
return $em;
|
||||
}
|
||||
|
||||
private function getReCaptchaMock($isSetup = true, Request $request = null, $isValid = false)
|
||||
{
|
||||
$recaptcha = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
|
||||
|
@@ -17,9 +17,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$specialUser = $this->createUserMock();
|
||||
$specialUser->expects($this->any())->method('isSpecial')->will($this->returnValue(true));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($specialUser);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($specialUser);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
|
||||
}
|
||||
|
||||
@@ -28,9 +29,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$encoder = $this->getEncoderMock();
|
||||
$oldEncoder = $this->getOldEncoderMock();
|
||||
$request = $this->getRequestMock();
|
||||
$manipulator = $this->getUserManipulatorMock(null);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock(null);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
|
||||
}
|
||||
|
||||
@@ -43,9 +45,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$mailLockedUser = $this->createUserMock();
|
||||
$mailLockedUser->expects($this->any())->method('isMailLocked')->will($this->returnValue(true));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($mailLockedUser);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($mailLockedUser);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
try {
|
||||
$auth->getUsrId('a_login', 'a_password', $request);
|
||||
@@ -75,7 +78,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->never())
|
||||
->method('isPasswordValid');
|
||||
@@ -85,7 +89,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -110,7 +114,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->never())
|
||||
->method('isPasswordValid');
|
||||
@@ -120,7 +125,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals(false, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -146,6 +151,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -157,7 +163,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals(false, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -182,7 +188,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$manipulator->expects($this->once())->method('setPassword')->with($this->equalTo($user), $this->equalTo($password));
|
||||
|
||||
@@ -203,7 +210,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
return true;
|
||||
}));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
|
||||
@@ -221,13 +228,6 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getFailureManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Alchemy\Phrasea\Authentication\Phrasea\FailureManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getRequestMock()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
|
||||
@@ -235,14 +235,18 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getUserManipulatorMock(User $user = null)
|
||||
private function getUserManipulatorMock()
|
||||
{
|
||||
$manipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')->disableOriginalConstructor()->getMock();
|
||||
|
||||
return $manipulator;
|
||||
}
|
||||
|
||||
private function getEntityRepositoryMock(User $user = null)
|
||||
{
|
||||
$repoMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')->disableOriginalConstructor()->getMock();
|
||||
$repoMock->expects($this->any())->method('findRealUserByLogin')->will($this->returnValue($user));
|
||||
|
||||
$manipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')->disableOriginalConstructor()->getMock();
|
||||
$manipulator->expects($this->any())->method('getRepository')->will($this->returnValue($repoMock));
|
||||
|
||||
return $manipulator;
|
||||
return $repoMock;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(self::$DI['user']->getEmail());
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$finder = new SuggestionFinder(self::$DI['app']['repo.users']);
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
||||
@@ -22,7 +22,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(sprintf('%srandom%s@%srandom.com', uniqid(mt_rand(), true), uniqid(mt_rand(), true), uniqid(mt_rand(), true)));
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$finder = new SuggestionFinder(self::$DI['app']['repo.users']);
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertNull($user);
|
||||
|
Reference in New Issue
Block a user