Fix unit tests

This commit is contained in:
Romain Neutron
2014-02-27 17:52:49 +01:00
parent 13e661c4b0
commit 894c5fe620
41 changed files with 368 additions and 501 deletions

View File

@@ -101,6 +101,7 @@ use Alchemy\Phrasea\Core\Provider\PhraseanetServiceProvider;
use Alchemy\Phrasea\Core\Provider\PluginServiceProvider; use Alchemy\Phrasea\Core\Provider\PluginServiceProvider;
use Alchemy\Phrasea\Core\Provider\PhraseaVersionServiceProvider; use Alchemy\Phrasea\Core\Provider\PhraseaVersionServiceProvider;
use Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider; use Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider;
use Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider;
use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider; use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider;
use Alchemy\Phrasea\Core\Provider\SerializerServiceProvider; use Alchemy\Phrasea\Core\Provider\SerializerServiceProvider;
use Alchemy\Phrasea\Core\Provider\SessionHandlerServiceProvider; use Alchemy\Phrasea\Core\Provider\SessionHandlerServiceProvider;
@@ -281,6 +282,7 @@ class Application extends SilexApplication
$this->register(new MP4BoxServiceProvider()); $this->register(new MP4BoxServiceProvider());
$this->register(new NotificationDelivererServiceProvider()); $this->register(new NotificationDelivererServiceProvider());
$this->register(new ORMServiceProvider()); $this->register(new ORMServiceProvider());
$this->register(new RepositoriesServiceProvider());
$this->register(new ManipulatorServiceProvider()); $this->register(new ManipulatorServiceProvider());
$this->register(new InstallerServiceProvider()); $this->register(new InstallerServiceProvider());
$this->register(new PhraseanetServiceProvider()); $this->register(new PhraseanetServiceProvider());

View File

@@ -100,7 +100,7 @@ class Authenticator
public function refreshAccount(Session $session) public function refreshAccount(Session $session)
{ {
if (!$this->em->getRepository('Phraseanet:Session')->findOneBy(['id' => $session->getId()])) { if (!$this->app['repo.sessions']->find($session->getId())) {
throw new RuntimeException('Unable to refresh the session, it does not exist anymore'); throw new RuntimeException('Unable to refresh the session, it does not exist anymore');
} }
@@ -129,7 +129,7 @@ class Authenticator
throw new RuntimeException('No session to close.'); throw new RuntimeException('No session to close.');
} }
if (null !== $session = $this->em->find('Phraseanet:Session', $this->session->get('session_id'))) { if (null !== $session = $this->app['repo.sessions']->find($this->session->get('session_id'))) {
$this->em->remove($session); $this->em->remove($session);
$this->em->flush(); $this->em->flush();
} }
@@ -163,7 +163,7 @@ class Authenticator
} }
if ($this->session->has('session_id')) { if ($this->session->has('session_id')) {
if (null !== $this->em->find('Phraseanet:Session', $this->session->get('session_id'))) { if (null !== $this->app['repo.sessions']->find($this->session->get('session_id'))) {
return true; return true;
} }
} }

View File

@@ -14,18 +14,19 @@ namespace Alchemy\Phrasea\Authentication\PersistentCookie;
use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder; use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Session;
use Doctrine\ORM\EntityRepository;
class Manager class Manager
{ {
private $browser; private $browser;
private $encoder; private $encoder;
private $em; private $repository;
public function __construct(PasswordEncoder $encoder, EntityManager $em, \Browser $browser) public function __construct(PasswordEncoder $encoder, EntityRepository $repo, \Browser $browser)
{ {
$this->browser = $browser; $this->browser = $browser;
$this->encoder = $encoder; $this->encoder = $encoder;
$this->em = $em; $this->repository = $repo;
} }
/** /**
@@ -37,9 +38,7 @@ class Manager
*/ */
public function getSession($cookieValue) public function getSession($cookieValue)
{ {
$session = $this->em $session = $this->repository->findOneBy(['token' => $cookieValue]);
->getRepository('Phraseanet:Session')
->findOneBy(['token' => $cookieValue]);
if (!$session) { if (!$session) {
return false; return false;

View File

@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Authentication\Exception\RequireCaptchaException; use Alchemy\Phrasea\Authentication\Exception\RequireCaptchaException;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Alchemy\Phrasea\Model\Entities\AuthFailure; use Alchemy\Phrasea\Model\Entities\AuthFailure;
use Doctrine\ORM\EntityRepository;
use Neutron\ReCaptcha\ReCaptcha; use Neutron\ReCaptcha\ReCaptcha;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -24,13 +25,16 @@ class FailureManager
private $captcha; private $captcha;
/** @var EntityManager */ /** @var EntityManager */
private $em; private $em;
/** @var EntityRepository */
private $repository;
/** @var integer */ /** @var integer */
private $trials; private $trials;
public function __construct(EntityManager $em, ReCaptcha $captcha, $trials) public function __construct(EntityRepository $repo, EntityManager $em, ReCaptcha $captcha, $trials)
{ {
$this->captcha = $captcha; $this->captcha = $captcha;
$this->em = $em; $this->em = $em;
$this->repository = $repo;
if ($trials < 0) { if ($trials < 0) {
throw new InvalidArgumentException('Trials number must be a positive integer'); throw new InvalidArgumentException('Trials number must be a positive integer');
@@ -79,9 +83,7 @@ class FailureManager
*/ */
public function checkFailures($username, Request $request) public function checkFailures($username, Request $request)
{ {
$failures = $this->em $failures = $this->repository->findLockedFailuresMatching($username, $request->getClientIp());
->getRepository('Phraseanet:AuthFailure')
->findLockedFailuresMatching($username, $request->getClientIp());
if (0 === count($failures)) { if (0 === count($failures)) {
return; return;
@@ -108,9 +110,7 @@ class FailureManager
*/ */
private function removeOldFailures() private function removeOldFailures()
{ {
$failures = $this->em $failures = $this->repository->findOldFailures('-2 months');
->getRepository('Phraseanet:AuthFailure')
->findOldFailures('-2 months');
if (0 < count($failures)) { if (0 < count($failures)) {
foreach ($failures as $failure) { foreach ($failures as $failure) {

View File

@@ -76,7 +76,7 @@ class Publications implements ControllerProviderInterface
})->bind('admin_feeds_create'); })->bind('admin_feeds_create');
$controllers->get('/feed/{id}/', function (PhraseaApplication $app, Request $request, $id) { $controllers->get('/feed/{id}/', function (PhraseaApplication $app, Request $request, $id) {
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
return $app['twig'] return $app['twig']
->render('admin/publications/fiche.html.twig', ['feed' => $feed, 'error' => $app['request']->query->get('error')]); ->render('admin/publications/fiche.html.twig', ['feed' => $feed, 'error' => $app['request']->query->get('error')]);
@@ -90,7 +90,7 @@ class Publications implements ControllerProviderInterface
$app->abort(400, "Bad request"); $app->abort(400, "Bad request");
} }
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
try { try {
$collection = \collection::get_from_base_id($app, $request->request->get('base_id')); $collection = \collection::get_from_base_id($app, $request->request->get('base_id'));
@@ -106,7 +106,7 @@ class Publications implements ControllerProviderInterface
return $app->redirectPath('admin_feeds_list'); return $app->redirectPath('admin_feeds_list');
})->before(function (Request $request) use ($app) { })->before(function (Request $request) use ($app) {
$feed = $app["EM"]->find('Phraseanet:Feed', $request->attributes->get('id')); $feed = $app["repo.feeds"]->find($request->attributes->get('id'));
if (!$feed->isOwner($app['authentication']->getUser())) { if (!$feed->isOwner($app['authentication']->getUser())) {
return $app->redirectPath('admin_feeds_feed', ['id' => $request->attributes->get('id'), 'error' => $app->trans('You are not the owner of this feed, you can not edit it')]); return $app->redirectPath('admin_feeds_feed', ['id' => $request->attributes->get('id'), 'error' => $app->trans('You are not the owner of this feed, you can not edit it')]);
@@ -120,7 +120,7 @@ class Publications implements ControllerProviderInterface
'success' => false, 'success' => false,
'message' => '', 'message' => '',
]; ];
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
if (null === $feed) { if (null === $feed) {
$app->abort(404, "Feed not found"); $app->abort(404, "Feed not found");
@@ -194,7 +194,7 @@ class Publications implements ControllerProviderInterface
try { try {
$request = $app['request']; $request = $app['request'];
$user = $app['repo.users']->find($request->request->get('usr_id')); $user = $app['repo.users']->find($request->request->get('usr_id'));
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
$publisher = new FeedPublisher(); $publisher = new FeedPublisher();
$publisher->setUser($user); $publisher->setUser($user);
@@ -219,9 +219,9 @@ class Publications implements ControllerProviderInterface
try { try {
$request = $app['request']; $request = $app['request'];
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
$publisher = $app["EM"]->find('Phraseanet:FeedPublisher', $request->request->get('publisher_id')); $publisher = $app["repo.feed-publishers"]->find($request->request->get('publisher_id'));
if (null === $publisher) { if (null === $publisher) {
$app->abort(404, "Feed Publisher not found"); $app->abort(404, "Feed Publisher not found");
} }
@@ -243,7 +243,7 @@ class Publications implements ControllerProviderInterface
->assert('id', '\d+'); ->assert('id', '\d+');
$controllers->post('/feed/{id}/delete/', function (PhraseaApplication $app, $id) { $controllers->post('/feed/{id}/delete/', function (PhraseaApplication $app, $id) {
$feed = $app["EM"]->find('Phraseanet:Feed', $id); $feed = $app["repo.feeds"]->find($id);
if (null === $feed) { if (null === $feed) {
$app->abort(404); $app->abort(404);

View File

@@ -805,7 +805,7 @@ class V1 implements ControllerProviderInterface
public function list_quarantine_item($lazaret_id, Application $app, Request $request) public function list_quarantine_item($lazaret_id, Application $app, Request $request)
{ {
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $lazaret_id); $lazaretFile = $app['repo.lazaret-files']->find($lazaret_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {

View File

@@ -112,7 +112,7 @@ class Lazaret implements ControllerProviderInterface
{ {
$ret = ['success' => false, 'message' => '', 'result' => []]; $ret = ['success' => false, 'message' => '', 'result' => []];
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id); $lazaretFile = $app['repo.lazaret-files']->find($file_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -165,7 +165,7 @@ class Lazaret implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id); $lazaretFile = $app['repo.lazaret-files']->find($file_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -274,7 +274,7 @@ class Lazaret implements ControllerProviderInterface
{ {
$ret = ['success' => false, 'message' => '', 'result' => []]; $ret = ['success' => false, 'message' => '', 'result' => []];
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id); $lazaretFile = $app['repo.lazaret-files']->find($file_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
$ret['message'] = $app->trans('File is not present in quarantine anymore, please refresh'); $ret['message'] = $app->trans('File is not present in quarantine anymore, please refresh');
@@ -359,7 +359,7 @@ class Lazaret implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id); $lazaretFile = $app['repo.lazaret-files']->find($file_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {
@@ -430,7 +430,7 @@ class Lazaret implements ControllerProviderInterface
*/ */
public function thumbnailElement(Application $app, Request $request, $file_id) public function thumbnailElement(Application $app, Request $request, $file_id)
{ {
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id); $lazaretFile = $app['repo.lazaret-files']->find($file_id);
/* @var $lazaretFile LazaretFile */ /* @var $lazaretFile LazaretFile */
if (null === $lazaretFile) { if (null === $lazaretFile) {

View File

@@ -47,7 +47,7 @@ class RSSFeeds implements ControllerProviderInterface
->assert('format', '(rss|atom)'); ->assert('format', '(rss|atom)');
$controllers->get('/userfeed/{token}/{id}/{format}/', function (Application $app, $token, $id, $format) { $controllers->get('/userfeed/{token}/{id}/{format}/', function (Application $app, $token, $id, $format) {
$token = $app["EM"]->find('Phraseanet:FeedToken', $id); $token = $app["repo.feed-tokens"]->find($id);
$request = $app['request']; $request = $app['request'];

View File

@@ -81,7 +81,7 @@ class Session implements ControllerProviderInterface
return $app->json($ret); return $app->json($ret);
} }
$session = $app['EM']->find('Phraseanet:Session', $app['session']->get('session_id')); $session = $app['repo.sessions']->find($app['session']->get('session_id'));
$session->setUpdated(new \DateTime()); $session->setUpdated(new \DateTime());
if (!$session->hasModuleId($moduleId)) { if (!$session->hasModuleId($moduleId)) {
@@ -132,7 +132,7 @@ class Session implements ControllerProviderInterface
*/ */
public function deleteSession(Application $app, Request $request, $id) public function deleteSession(Application $app, Request $request, $id)
{ {
$session = $app['EM']->find('Phraseanet:Session', $id); $session = $app['repo.sessions']->find($id);
if (null === $session) { if (null === $session) {
$app->abort(404, 'Unknown session'); $app->abort(404, 'Unknown session');

View File

@@ -41,7 +41,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
}); });
$app['authentication.persistent-manager'] = $app->share(function (Application $app) { $app['authentication.persistent-manager'] = $app->share(function (Application $app) {
return new CookieManager($app['auth.password-encoder'], $app['EM'], $app['browser']); return new CookieManager($app['auth.password-encoder'], $app['repo.sessions'], $app['browser']);
}); });
$app['authentication.suggestion-finder'] = $app->share(function (Application $app) { $app['authentication.suggestion-finder'] = $app->share(function (Application $app) {
@@ -103,7 +103,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
$app['auth.native.failure-manager'] = $app->share(function (Application $app) { $app['auth.native.failure-manager'] = $app->share(function (Application $app) {
$authConf = $app['conf']->get(['authentication', 'captcha']); $authConf = $app['conf']->get(['authentication', 'captcha']);
return new FailureManager($app['EM'], $app['recaptcha'], isset($authConf['trials-before-display']) ? $authConf['trials-before-display'] : 9); return new FailureManager($app['repo.auth-failures'], $app['EM'], $app['recaptcha'], isset($authConf['trials-before-display']) ? $authConf['trials-before-display'] : 9);
}); });
$app['auth.password-checker'] = $app->share(function (Application $app) { $app['auth.password-checker'] = $app->share(function (Application $app) {

View File

@@ -183,70 +183,6 @@ class ORMServiceProvider implements ServiceProviderInterface
$app['EM.native-query'] = $app->share(function ($app) { $app['EM.native-query'] = $app->share(function ($app) {
return new NativeQueryProvider($app['EM']); return new NativeQueryProvider($app['EM']);
}); });
$app['repo.users'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:User');
});
$app['repo.tasks'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Task');
});
$app['repo.registrations'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Registration');
});
$app['repo.baskets'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Basket');
});
$app['repo.basket-elements'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:BasketElement');
});
$app['repo.validation-participants'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:ValidationParticipant');
});
$app['repo.story-wz'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:StoryWZ');
});
$app['repo.orders'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Order');
});
$app['repo.order-elements'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:OrderElement');
});
$app['repo.feeds'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Feed');
});
$app['repo.feed-entries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedEntry');
});
$app['repo.feed-items'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedItem');
});
$app['repo.feed-publishers'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedPublisher');
});
$app['repo.aggregate-tokens'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:AggregateTokens');
});
$app['repo.usr-lists'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrList');
});
$app['repo.usr-list-owners'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrListOwner');
});
$app['repo.usr-list-entries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrListEntries');
});
$app['repo.lazaret-files'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:LazaretFile');
});
$app['repo.usr-auth-providers'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrAuthProvider');
});
$app['repo.ftp-exports'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FtpExport');
});
$app['repo.user-queries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UserQuery');
});
} }
public function boot(Application $app) public function boot(Application $app)

View File

@@ -0,0 +1,99 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Core\Provider;
use Alchemy\Phrasea\Application as PhraseaApplication;
use Silex\Application;
use Silex\ServiceProviderInterface;
class RepositoriesServiceProvider implements ServiceProviderInterface
{
public function register(Application $app)
{
$app['repo.users'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:User');
});
$app['repo.auth-failures'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:AuthFailure');
});
$app['repo.sessions'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Session');
});
$app['repo.tasks'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Task');
});
$app['repo.registrations'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Registration');
});
$app['repo.baskets'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Basket');
});
$app['repo.basket-elements'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:BasketElement');
});
$app['repo.validation-participants'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:ValidationParticipant');
});
$app['repo.story-wz'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:StoryWZ');
});
$app['repo.orders'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Order');
});
$app['repo.order-elements'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:OrderElement');
});
$app['repo.feeds'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:Feed');
});
$app['repo.feed-entries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedEntry');
});
$app['repo.feed-items'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedItem');
});
$app['repo.feed-publishers'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedPublisher');
});
$app['repo.feed-tokens'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FeedToken');
});
$app['repo.aggregate-tokens'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:AggregateToken');
});
$app['repo.usr-lists'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrList');
});
$app['repo.usr-list-owners'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrListOwner');
});
$app['repo.usr-list-entries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrListEntry');
});
$app['repo.lazaret-files'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:LazaretFile');
});
$app['repo.usr-auth-providers'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UsrAuthProvider');
});
$app['repo.ftp-exports'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:FtpExport');
});
$app['repo.user-queries'] = $app->share(function (PhraseaApplication $app) {
return $app['EM']->getRepository('Phraseanet:UserQuery');
});
}
public function boot(Application $app)
{
}
}

View File

@@ -13,7 +13,6 @@ namespace Alchemy\Phrasea\Model\Manipulator;
use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Exception\InvalidArgumentException; use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Alchemy\Phrasea\Exception\LogicException;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
class ACLManipulator implements ManipulatorInterface class ACLManipulator implements ManipulatorInterface

View File

@@ -11,8 +11,6 @@
namespace Alchemy\Phrasea\Model\Manipulator; namespace Alchemy\Phrasea\Model\Manipulator;
use Doctrine\ORM\EntityRepository;
/** /**
* This class is responsible of manipulating entities. * This class is responsible of manipulating entities.
*/ */

View File

@@ -15,7 +15,6 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider; use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Model\Entities\Registration; use Alchemy\Phrasea\Model\Entities\Registration;
use Alchemy\Phrasea\Model\Entities\User; use Alchemy\Phrasea\Model\Entities\User;
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository; use Doctrine\ORM\EntityRepository;

View File

@@ -186,7 +186,7 @@ class Session_Logger
return; return;
} }
$session = $app['EM']->find('Phraseanet:Session', $app['session']->get('session_id')); $session = $app['repo.sessions']->find($app['session']->get('session_id'));
if (!$session) { if (!$session) {
throw new SessionNotFound('No session found'); throw new SessionNotFound('No session found');

View File

@@ -69,7 +69,7 @@ class patch_383alpha1a extends patchAbstract
$stmt->closeCursor(); $stmt->closeCursor();
foreach ($rows as $row) { foreach ($rows as $row) {
if (null !== $session = $app['EM']->find('Phraseanet:Session', $row['id'])) { if (null !== $session = $app['repo.sessions']->find($row['id'])) {
$app['EM']->remove($session); $app['EM']->remove($session);
} }
} }

View File

@@ -17,7 +17,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $session = $this->getSessionMock(); $app['session'] = $session = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$authenticator = new Authenticator($app, $browser, $session, $em); $authenticator = new Authenticator($app, $browser, $session, $em);
$this->assertNull($authenticator->getUser()); $this->assertNull($authenticator->getUser());
@@ -32,7 +32,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $session = $this->getSessionMock(); $app['session'] = $session = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$user = $this->createUserMock(); $user = $this->createUserMock();
@@ -53,7 +53,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $session = $this->getSessionMock(); $app['session'] = $session = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$user = $this->createUserMock(); $user = $this->createUserMock();
$user->expects($this->any()) $user->expects($this->any())
@@ -85,6 +85,20 @@ class AuthenticatorTest extends \PhraseanetTestCase
$em->expects($this->at(1)) $em->expects($this->at(1))
->method('flush'); ->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); $authenticator = new Authenticator($app, $browser, $session, $em);
$phsession = $authenticator->openAccount($user); $phsession = $authenticator->openAccount($user);
@@ -103,7 +117,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $SFsession = $this->getSessionMock(); $app['session'] = $SFsession = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$sessionId = 4224242; $sessionId = 4224242;
@@ -119,15 +133,18 @@ class AuthenticatorTest extends \PhraseanetTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$repo->expects($this->once()) $repo->expects($this->exactly(2))
->method('findOneBy') ->method('find')
->with($this->equalTo(['id' => $session->getId()])) ->with($session->getId())
->will($this->returnValue($session));
$repoUsers = $this->createEntityRepositoryMock();
$repoUsers->expects($this->once())
->method('find')
->with($user->getId())
->will($this->returnValue($session)); ->will($this->returnValue($session));
$em->expects($this->once()) $app['repo.sessions'] = $repo;
->method('getRepository') $app['repo.users'] = $repoUsers;
->with($this->equalTo('Phraseanet:Session'))
->will($this->returnValue($repo));
$authenticator = new Authenticator($app, $browser, $SFsession, $em); $authenticator = new Authenticator($app, $browser, $SFsession, $em);
$this->assertEquals($session, $authenticator->refreshAccount($session)); $this->assertEquals($session, $authenticator->refreshAccount($session));
@@ -144,7 +161,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $SFsession = $this->getSessionMock(); $app['session'] = $SFsession = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$sessionId = 4224242; $sessionId = 4224242;
@@ -161,14 +178,11 @@ class AuthenticatorTest extends \PhraseanetTestCase
->getMock(); ->getMock();
$repo->expects($this->once()) $repo->expects($this->once())
->method('findOneBy') ->method('find')
->with($this->equalTo(['id' => $session->getId()])) ->with($session->getId())
->will($this->returnValue(null)); ->will($this->returnValue(null));
$em->expects($this->once()) $app['repo.sessions'] = $repo;
->method('getRepository')
->with($this->equalTo('Phraseanet:Session'))
->will($this->returnValue($repo));
$authenticator = new Authenticator($app, $browser, $SFsession, $em); $authenticator = new Authenticator($app, $browser, $SFsession, $em);
try { try {
@@ -216,12 +230,13 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $session = $this->getSessionMock(); $app['session'] = $session = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$app['EM']->expects($this->any())->method('find')->with( $app['repo.sessions'] = $this->createEntityRepositoryMock();
$this->equalTo('Phraseanet:Session'), $app['repo.sessions']->expects($this->any())
$this->equalTo(1) ->method('find')
)->will($this->returnValue($sessionEntity)); ->with(1)
->will($this->returnValue($sessionEntity));
$userRepository = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository') $userRepository = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
@@ -235,7 +250,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->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('usr_id', self::$DI['user']->getId());
$session->set('session_id', 1); $session->set('session_id', 1);
@@ -254,26 +269,12 @@ class AuthenticatorTest extends \PhraseanetTestCase
$app['browser'] = $browser = $this->getBrowserMock(); $app['browser'] = $browser = $this->getBrowserMock();
$app['session'] = $session = $this->getSessionMock(); $app['session'] = $session = $this->getSessionMock();
$app['EM'] = $em = $this->getEntityManagerMock(); $app['EM'] = $em = $this->createEntityManagerMock();
$authenticator = new Authenticator($app, $browser, $session, $em); $authenticator = new Authenticator($app, $browser, $session, $em);
$this->assertFalse($authenticator->isAuthenticated()); $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() private function getSessionMock()
{ {
return new \Symfony\Component\HttpFoundation\Session\Session(new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage()); return new \Symfony\Component\HttpFoundation\Session\Session(new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage());

View File

@@ -13,7 +13,6 @@ class ManagerTest extends \PhraseanetTestCase
public function testGetSession() public function testGetSession()
{ {
$encoder = $this->getPasswordEncoderMock(); $encoder = $this->getPasswordEncoderMock();
$em = $this->getEntityManagerMock();
$browser = $this->getBrowserMock(); $browser = $this->getBrowserMock();
$tokenValue = 'encrypted-persistent-value'; $tokenValue = 'encrypted-persistent-value';
@@ -25,8 +24,6 @@ class ManagerTest extends \PhraseanetTestCase
->method('getPlatform') ->method('getPlatform')
->will($this->returnValue('Linux')); ->will($this->returnValue('Linux'));
$manager = new Manager($encoder, $em, $browser);
$session = new Session(); $session = new Session();
$session->setNonce('prettyN0nce'); $session->setNonce('prettyN0nce');
@@ -39,10 +36,7 @@ class ManagerTest extends \PhraseanetTestCase
->with($this->equalTo(['token' => $tokenValue])) ->with($this->equalTo(['token' => $tokenValue]))
->will($this->returnValue($session)); ->will($this->returnValue($session));
$em->expects($this->once()) $manager = new Manager($encoder, $repo, $browser);
->method('getRepository')
->with($this->equalTo('Phraseanet:Session'))
->will($this->returnValue($repo));
$encoder->expects($this->once()) $encoder->expects($this->once())
->method('isPasswordValid') ->method('isPasswordValid')
@@ -58,7 +52,6 @@ class ManagerTest extends \PhraseanetTestCase
public function testGetSessionReturnFalse() public function testGetSessionReturnFalse()
{ {
$encoder = $this->getPasswordEncoderMock(); $encoder = $this->getPasswordEncoderMock();
$em = $this->getEntityManagerMock();
$browser = $this->getBrowserMock(); $browser = $this->getBrowserMock();
$tokenValue = 'encrypted-persistent-value'; $tokenValue = 'encrypted-persistent-value';
@@ -70,8 +63,6 @@ class ManagerTest extends \PhraseanetTestCase
->method('getPlatform') ->method('getPlatform')
->will($this->returnValue('Linux')); ->will($this->returnValue('Linux'));
$manager = new Manager($encoder, $em, $browser);
$session = new Session(); $session = new Session();
$session->setNonce('prettyN0nce'); $session->setNonce('prettyN0nce');
@@ -84,10 +75,7 @@ class ManagerTest extends \PhraseanetTestCase
->with($this->equalTo(['token' => $tokenValue])) ->with($this->equalTo(['token' => $tokenValue]))
->will($this->returnValue($session)); ->will($this->returnValue($session));
$em->expects($this->once()) $manager = new Manager($encoder, $repo, $browser);
->method('getRepository')
->with($this->equalTo('Phraseanet:Session'))
->will($this->returnValue($repo));
$encoder->expects($this->once()) $encoder->expects($this->once())
->method('isPasswordValid') ->method('isPasswordValid')
@@ -102,12 +90,9 @@ class ManagerTest extends \PhraseanetTestCase
public function testSessionNotFound() public function testSessionNotFound()
{ {
$encoder = $this->getPasswordEncoderMock(); $encoder = $this->getPasswordEncoderMock();
$em = $this->getEntityManagerMock();
$browser = $this->getBrowserMock(); $browser = $this->getBrowserMock();
$tokenValue = 'encrypted-persistent-value'; $tokenValue = 'encrypted-persistent-value';
$manager = new Manager($encoder, $em, $browser);
$repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository') $repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -117,10 +102,7 @@ class ManagerTest extends \PhraseanetTestCase
->with($this->equalTo(['token' => $tokenValue])) ->with($this->equalTo(['token' => $tokenValue]))
->will($this->returnValue(null)); ->will($this->returnValue(null));
$em->expects($this->once()) $manager = new Manager($encoder, $repo, $browser);
->method('getRepository')
->with($this->equalTo('Phraseanet:Session'))
->will($this->returnValue($repo));
$this->assertFalse($manager->getSession($tokenValue)); $this->assertFalse($manager->getSession($tokenValue));
} }
@@ -132,13 +114,6 @@ class ManagerTest extends \PhraseanetTestCase
->getMock(); ->getMock();
} }
private function getEntityManagerMock()
{
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
->getMock();
}
private function getBrowserMock() private function getBrowserMock()
{ {
return $this->getMockBuilder('Browser') return $this->getMockBuilder('Browser')

View File

@@ -15,7 +15,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testSaveFailure() public function testSaveFailure()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$recaptcha = $this->getReCaptchaMock(null); $recaptcha = $this->getReCaptchaMock(null);
$ip = '192.168.16.178'; $ip = '192.168.16.178';
@@ -47,7 +47,7 @@ class FailureManagerTest extends \PhraseanetTestCase
$catchFailure = $failure; $catchFailure = $failure;
})); }));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->saveFailure($username, $request); $manager->saveFailure($username, $request);
$this->assertEquals($ip, $catchFailure->getIp()); $this->assertEquals($ip, $catchFailure->getIp());
@@ -61,7 +61,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailures() public function testCheckFailures()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$recaptcha = $this->getReCaptchaMock(null); $recaptcha = $this->getReCaptchaMock(null);
$request = $this->getRequestMock(); $request = $this->getRequestMock();
@@ -73,7 +73,7 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
@@ -83,7 +83,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailuresLessThan9() public function testCheckFailuresLessThan9()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$recaptcha = $this->getReCaptchaMock(null); $recaptcha = $this->getReCaptchaMock(null);
$request = $this->getRequestMock(); $request = $this->getRequestMock();
@@ -97,7 +97,7 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
@@ -107,7 +107,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailuresMoreThan9WithoutCaptcha() public function testCheckFailuresMoreThan9WithoutCaptcha()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$recaptcha = $this->getReCaptchaMock(false); $recaptcha = $this->getReCaptchaMock(false);
$request = $this->getRequestMock(); $request = $this->getRequestMock();
@@ -121,7 +121,7 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
@@ -131,7 +131,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailuresMoreThan9WithCorrectCaptcha() public function testCheckFailuresMoreThan9WithCorrectCaptcha()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$request = $this->getRequestMock(); $request = $this->getRequestMock();
$recaptcha = $this->getReCaptchaMock(true, $request, true); $recaptcha = $this->getReCaptchaMock(true, $request, true);
@@ -150,7 +150,7 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
@@ -161,7 +161,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailuresMoreThan9WithIncorrectCaptcha() public function testCheckFailuresMoreThan9WithIncorrectCaptcha()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$request = $this->getRequestMock(); $request = $this->getRequestMock();
$recaptcha = $this->getReCaptchaMock(true, $request, false); $recaptcha = $this->getReCaptchaMock(true, $request, false);
@@ -175,14 +175,14 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 9); $manager = new FailureManager($repo, $em, $recaptcha, 9);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
public function testCheckFailuresTrialsIsConfigurableUnderThreshold() public function testCheckFailuresTrialsIsConfigurableUnderThreshold()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$recaptcha = $this->getReCaptchaMock(null); $recaptcha = $this->getReCaptchaMock(null);
$request = $this->getRequestMock(); $request = $this->getRequestMock();
@@ -196,19 +196,17 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 2); $manager = new FailureManager($repo, $em, $recaptcha, 2);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
public function testTrialsIsConfigurable() public function testTrialsIsConfigurable()
{ {
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager') $em = $this->createEntityManagerMock();
->disableOriginalConstructor()
->getMock();
$recaptcha = $this->getReCaptchaMock(null); $recaptcha = $this->getReCaptchaMock(null);
$manager = new FailureManager($em, $recaptcha, 2); $manager = new FailureManager($this->createEntityRepositoryMock(), $em, $recaptcha, 2);
$this->assertEquals(2, $manager->getTrials()); $this->assertEquals(2, $manager->getTrials());
} }
@@ -219,7 +217,7 @@ class FailureManagerTest extends \PhraseanetTestCase
public function testCheckFailuresTrialsIsConfigurableOverThreshold() public function testCheckFailuresTrialsIsConfigurableOverThreshold()
{ {
$repo = $this->getRepo(); $repo = $this->getRepo();
$em = $this->getEntityManagerMock($repo); $em = $this->createEntityManagerMock();
$request = $this->getRequestMock(); $request = $this->getRequestMock();
$recaptcha = $this->getReCaptchaMock(true, $request, false); $recaptcha = $this->getReCaptchaMock(true, $request, false);
@@ -233,7 +231,7 @@ class FailureManagerTest extends \PhraseanetTestCase
->method('findLockedFailuresMatching') ->method('findLockedFailuresMatching')
->will($this->returnValue($oldFailures)); ->will($this->returnValue($oldFailures));
$manager = new FailureManager($em, $recaptcha, 2); $manager = new FailureManager($repo, $em, $recaptcha, 2);
$manager->checkFailures($username, $request); $manager->checkFailures($username, $request);
} }
@@ -255,7 +253,7 @@ class FailureManagerTest extends \PhraseanetTestCase
$this->assertCount(12, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure') $this->assertCount(12, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
->findAll()); ->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); $manager->saveFailure($username, $request);
$this->assertCount(0, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure') $this->assertCount(0, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
@@ -277,20 +275,6 @@ class FailureManagerTest extends \PhraseanetTestCase
return $failures; 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) private function getReCaptchaMock($isSetup = true, Request $request = null, $isValid = false)
{ {
$recaptcha = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha') $recaptcha = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')

View File

@@ -17,9 +17,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
$specialUser = $this->createUserMock(); $specialUser = $this->createUserMock();
$specialUser->expects($this->any())->method('isSpecial')->will($this->returnValue(true)); $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)); $this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
} }
@@ -28,9 +29,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
$encoder = $this->getEncoderMock(); $encoder = $this->getEncoderMock();
$oldEncoder = $this->getOldEncoderMock(); $oldEncoder = $this->getOldEncoderMock();
$request = $this->getRequestMock(); $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)); $this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
} }
@@ -43,9 +45,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
$mailLockedUser = $this->createUserMock(); $mailLockedUser = $this->createUserMock();
$mailLockedUser->expects($this->any())->method('isMailLocked')->will($this->returnValue(true)); $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 { try {
$auth->getUsrId('a_login', 'a_password', $request); $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('getPassword')->will($this->returnValue($encoded));
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce)); $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()) $oldEncoder->expects($this->never())
->method('isPasswordValid'); ->method('isPasswordValid');
@@ -85,7 +89,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
->will($this->returnValue(true)); ->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)); $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('getPassword')->will($this->returnValue($encoded));
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce)); $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()) $oldEncoder->expects($this->never())
->method('isPasswordValid'); ->method('isPasswordValid');
@@ -120,7 +125,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
->will($this->returnValue(false)); ->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)); $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)); $user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
$manipulator = $this->getUserManipulatorMock($user); $manipulator = $this->getUserManipulatorMock($user);
$entityRepo = $this->getEntityRepositoryMock($user);
$oldEncoder->expects($this->once()) $oldEncoder->expects($this->once())
->method('isPasswordValid') ->method('isPasswordValid')
@@ -157,7 +163,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce)) ->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
->will($this->returnValue(false)); ->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)); $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('getPassword')->will($this->returnValue($encoded));
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce)); $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)); $manipulator->expects($this->once())->method('setPassword')->with($this->equalTo($user), $this->equalTo($password));
@@ -203,7 +210,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
return true; 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)); $this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request));
} }
@@ -221,13 +228,6 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
->getMock(); ->getMock();
} }
private function getFailureManagerMock()
{
return $this->getMockBuilder('Alchemy\Phrasea\Authentication\Phrasea\FailureManager')
->disableOriginalConstructor()
->getMock();
}
private function getRequestMock() private function getRequestMock()
{ {
return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
@@ -235,14 +235,18 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
->getMock(); ->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 = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')->disableOriginalConstructor()->getMock();
$repoMock->expects($this->any())->method('findRealUserByLogin')->will($this->returnValue($user)); $repoMock->expects($this->any())->method('findRealUserByLogin')->will($this->returnValue($user));
$manipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')->disableOriginalConstructor()->getMock(); return $repoMock;
$manipulator->expects($this->any())->method('getRepository')->will($this->returnValue($repoMock));
return $manipulator;
} }
} }

View File

@@ -11,7 +11,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
{ {
$token = $this->getToken(self::$DI['user']->getEmail()); $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); $user = $finder->find($token);
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); $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))); $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); $user = $finder->find($token);
$this->assertNull($user); $this->assertNull($user);

View File

@@ -112,7 +112,7 @@ class AdminDashboardTest extends \PhraseanetAuthenticatedWebTestCase
$admins = array_map(function (User $user) { $admins = array_map(function (User $user) {
return $user->getId(); return $user->getId();
}, self::$DI['app']['manipulator.user']->getRepository()->findAdmins()); }, self::$DI['app']['repo.users']->findAdmins());
$user = self::$DI['app']['manipulator.user']->createUser(uniqid('unit_test_user'), uniqid('unit_test_user'), uniqid('unit_test_user') ."@email.com"); $user = self::$DI['app']['manipulator.user']->createUser(uniqid('unit_test_user'), uniqid('unit_test_user'), uniqid('unit_test_user') ."@email.com");

View File

@@ -48,7 +48,6 @@ class SetupTest extends \PhraseanetAuthenticatedWebTestCase
->with('registry',$this->isType('array')); ->with('registry',$this->isType('array'));
self::$DI['app']['conf'] = $registry; self::$DI['app']['conf'] = $registry;
self::$DI['client'] = new Client(self::$DI['app']);
self::$DI['client']->request('POST', '/admin/setup/', ['_token' => 'token']); self::$DI['client']->request('POST', '/admin/setup/', ['_token' => 'token']);
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
} }

View File

@@ -39,7 +39,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['client']->request('POST', '/admin/users/delete/', ['users' => self::$DI['user']->getId()]); self::$DI['client']->request('POST', '/admin/users/delete/', ['users' => self::$DI['user']->getId()]);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isRedirect()); $this->assertTrue($response->isRedirect());
$this->assertNotNull(self::$DI['app']['manipulator.user']->getRepository()->findByLogin(self::$DI['user']->getLogin())); $this->assertNotNull(self::$DI['app']['repo.users']->findByLogin(self::$DI['user']->getLogin()));
} }
public function testRouteRightsApply() public function testRouteRightsApply()
@@ -285,7 +285,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue(is_object($datas)); $this->assertTrue(is_object($datas));
$this->assertFalse($datas->error); $this->assertFalse($datas->error);
$this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data))); $this->assertNotNull($user = (self::$DI['app']['repo.users']->find((int) $datas->data)));
self::$DI['app']['manipulator.user']->delete($user); self::$DI['app']['manipulator.user']->delete($user);
} }
@@ -308,7 +308,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertTrue(is_object($datas)); $this->assertTrue(is_object($datas));
$this->assertFalse($datas->error); $this->assertFalse($datas->error);
$this->assertNotNull($user = (self::$DI['app']['manipulator.user']->getRepository()->find((int) $datas->data))); $this->assertNotNull($user = (self::$DI['app']['repo.users']->find((int) $datas->data)));
self::$DI['app']['manipulator.user']->delete($user); self::$DI['app']['manipulator.user']->delete($user);
} }

View File

@@ -245,7 +245,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->evaluateMeta200($content); $this->evaluateMeta200($content);
$response = $content['response']; $response = $content['response'];
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $tasks = self::$DI['app']['repo.tasks']->findAll();
$this->assertEquals(count($tasks), count($response['tasks'])); $this->assertEquals(count($tasks), count($response['tasks']));
foreach ($response['tasks'] as $task) { foreach ($response['tasks'] as $task) {
@@ -335,7 +335,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testGetMonitorTaskById() public function testGetMonitorTaskById()
{ {
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $tasks = self::$DI['app']['repo.tasks']->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -362,7 +362,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testPostMonitorTaskById() public function testPostMonitorTaskById()
{ {
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $tasks = self::$DI['app']['repo.tasks']->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -408,7 +408,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
} }
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $tasks = self::$DI['app']['repo.tasks']->findAll();
if (!count($tasks)) { if (!count($tasks)) {
$this->markTestSkipped('no tasks created for the current instance'); $this->markTestSkipped('no tasks created for the current instance');
@@ -428,13 +428,13 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask); $task = self::$DI['app']['repo.tasks']->find($idTask);
$this->assertEquals(Task::STATUS_STARTED, $task->getStatus()); $this->assertEquals(Task::STATUS_STARTED, $task->getStatus());
} }
public function testPostMonitorStopTask() public function testPostMonitorStopTask()
{ {
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll(); $tasks = self::$DI['app']['repo.tasks']->findAll();
if (null === self::$adminToken) { if (null === self::$adminToken) {
$this->markTestSkipped('there is no user with admin rights'); $this->markTestSkipped('there is no user with admin rights');
@@ -458,7 +458,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
$this->assertArrayHasKey('task', $content['response']); $this->assertArrayHasKey('task', $content['response']);
$this->evaluateGoodTask($content['response']['task']); $this->evaluateGoodTask($content['response']['task']);
$task = self::$DI['app']['manipulator.task']->getRepository()->find($idTask); $task = self::$DI['app']['repo.tasks']->find($idTask);
$this->assertEquals(Task::STATUS_STOPPED, $task->getStatus()); $this->assertEquals(Task::STATUS_STOPPED, $task->getStatus());
} }
@@ -1173,8 +1173,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
public function testSearchBaskets() public function testSearchBaskets()
{ {
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->setToken(self::$adminToken); $this->setToken(self::$adminToken);
$route = '/api/v1/baskets/list/'; $route = '/api/v1/baskets/list/';
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']); $this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);

View File

@@ -26,8 +26,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testListElement() public function testListElement()
{ {
$originalEm = self::$DI['app']['EM'];
$fileLazaret = $this->getMock('Alchemy\Phrasea\Model\Entities\LazaretFile', ['getRecordsToSubstitute', 'getSession', 'getCollection'], [], '', false); $fileLazaret = $this->getMock('Alchemy\Phrasea\Model\Entities\LazaretFile', ['getRecordsToSubstitute', 'getSession', 'getCollection'], [], '', false);
$fileLazaret $fileLazaret
@@ -53,30 +51,19 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
->will($this->returnValue([$fileLazaret])); ->will($this->returnValue([$fileLazaret]));
//mock Doctrine\ORM\EntityManager::getRepository //mock Doctrine\ORM\EntityManager::getRepository
$em = $this->getMock('Doctrine\ORM\EntityManager', ['getRepository'], [], '', false); $em = $this->createEntityManagerMock();
$em->expects($this->once()) self::$DI['app']['repo.lazaret-files'] = $repo;
->method('getRepository')
->with($this->equalTo('Phraseanet:LazaretFile'))
->will($this->returnValue($repo));
$route = '/prod/lazaret/'; $route = '/prod/lazaret/';
self::$DI['app']['EM'] = $em; self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
$crawler = self::$DI['client']->request( $crawler = self::$DI['client']->request(
'GET', $route 'GET', $route
); );
$this->assertResponseOk(self::$DI['client']->getResponse()); $this->assertResponseOk(self::$DI['client']->getResponse());
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertEquals(1, $crawler->filter('.records-subititution')->count()); $this->assertEquals(1, $crawler->filter('.records-subititution')->count());
$em = $fileLazaret = $repo = null;
} }
/** /**
@@ -84,31 +71,21 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testGetElement() public function testGetElement()
{ {
$originalEm = self::$DI['app']['EM'];
$em = $this->getMock('Doctrine\ORM\EntityManager', ['find'], [], '', false);
$lazaretFile = $this->getOneLazaretFile(); $lazaretFile = $this->getOneLazaretFile();
$id = 1; $id = 1;
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue($lazaretFile)); ->will($this->returnValue($lazaretFile));
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/'); self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/');
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertResponseOk($response); $this->assertResponseOk($response);
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
$this->assertGoodJsonContent($content); $this->assertGoodJsonContent($content);
@@ -121,8 +98,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertObjectHasAttribute('pathname', $content->result); $this->assertObjectHasAttribute('pathname', $content->result);
$this->assertObjectHasAttribute('sha256', $content->result); $this->assertObjectHasAttribute('sha256', $content->result);
$this->assertObjectHasAttribute('uuid', $content->result); $this->assertObjectHasAttribute('uuid', $content->result);
$em = $lazaretFile = null;
} }
/** /**
@@ -130,31 +105,20 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testGetElementException() public function testGetElementException()
{ {
$originalEm = self::$DI['app']['EM'];
$em = $this->getMock('Doctrine\ORM\EntityManager', ['find'], [], '', false);
$id = 1; $id = 1;
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue(null)); ->will($this->returnValue(null));
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/'); self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/');
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertBadJsonContent(json_decode($response->getContent())); $this->assertBadJsonContent(json_decode($response->getContent()));
$em = null;
} }
/** /**
@@ -163,9 +127,7 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
public function testAddElement() public function testAddElement()
{ {
$originalEm = self::$DI['app']['EM']; $originalEm = self::$DI['app']['EM'];
$em = $this->createEntityManagerMock();
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
$lazaretFile = $this->getOneLazaretFile(); $lazaretFile = $this->getOneLazaretFile();
@@ -205,10 +167,11 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$lazaretFile->addAttribute($lazaretAttribute); $lazaretFile->addAttribute($lazaretAttribute);
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue($lazaretFile)); ->will($this->returnValue($lazaretFile));
//In any case we expect the deletion of the lazaret file //In any case we expect the deletion of the lazaret file
@@ -221,8 +184,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
->method('flush'); ->method('flush');
self::$DI['app']['EM'] = $em; self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [ self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [
'bas_id' => $lazaretFile->getBaseId(), 'bas_id' => $lazaretFile->getBaseId(),
'keep_attributes' => 1, 'keep_attributes' => 1,
@@ -231,15 +192,11 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertGoodJsonContent(json_decode($response->getContent())); $this->assertGoodJsonContent(json_decode($response->getContent()));
self::$DI['app']['EM'] = $originalEm;
$story->delete(); $story->delete();
$em = $lazaretFile = $lazaretSession = $lazaretAttribute = $story = null;
} }
/** /**
@@ -247,24 +204,8 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAddElementBadRequestException() public function testAddElementBadRequestException()
{ {
$originalEm = self::$DI['app']['EM'];
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
$lazaretFile = $this->getOneLazaretFile();
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id
$em->expects($this->any())
->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
->will($this->returnValue($lazaretFile));
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
//Ommit base_id mandatory param //Ommit base_id mandatory param
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [ self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [
'keep_attributes' => 1, 'keep_attributes' => 1,
@@ -273,13 +214,8 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertBadJsonContent(json_decode($response->getContent())); $this->assertBadJsonContent(json_decode($response->getContent()));
$em = $lazaretFile = null;
} }
/** /**
@@ -287,9 +223,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAddElementException() public function testAddElementException()
{ {
$originalEm = self::$DI['app']['EM'];
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('POST', '/prod/lazaret/99999/force-add/', [ self::$DI['client']->request('POST', '/prod/lazaret/99999/force-add/', [
'bas_id' => 1, 'bas_id' => 1,
'keep_attributes' => 1, 'keep_attributes' => 1,
@@ -298,9 +231,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertBadJsonContent(json_decode($response->getContent())); $this->assertBadJsonContent(json_decode($response->getContent()));
} }
@@ -372,10 +302,7 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAcceptElement() public function testAcceptElement()
{ {
$originalEm = self::$DI['app']['EM']; $em = $this->createEntityManagerMock();
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
self::$DI['app']['subdef.substituer'] = $this->getMockBuilder('Alchemy\Phrasea\Media\SubdefSubstituer') self::$DI['app']['subdef.substituer'] = $this->getMockBuilder('Alchemy\Phrasea\Media\SubdefSubstituer')
->disableOriginalConstructor() ->disableOriginalConstructor()
@@ -427,10 +354,10 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue($lazaretFile)); ->will($this->returnValue($lazaretFile));
//In any case we expect the deletion of the lazaret file //In any case we expect the deletion of the lazaret file
@@ -452,8 +379,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
}); });
self::$DI['app']['EM'] = $em; self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [ self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [
'record_id' => self::$DI['record_1']->get_record_id() 'record_id' => self::$DI['record_1']->get_record_id()
]); ]);
@@ -461,14 +386,10 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$content = json_decode($response->getContent()); $content = json_decode($response->getContent());
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertGoodJsonContent($content); $this->assertGoodJsonContent($content);
$em = $lazaretFile = $collection = $databox = $record = null;
} }
/** /**
@@ -476,11 +397,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAcceptElementNoRecordException() public function testAcceptElementNoRecordException()
{ {
$originalEm = self::$DI['app']['EM'];
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
$lazaretFile = $this->getMockBuilder('Alchemy\Phrasea\Model\Entities\LazaretFile') $lazaretFile = $this->getMockBuilder('Alchemy\Phrasea\Model\Entities\LazaretFile')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -493,30 +409,22 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue($lazaretFile)); ->will($this->returnValue($lazaretFile));
$id = 1; $id = 1;
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [ self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [
'record_id' => self::$DI['record_1']->get_record_id() 'record_id' => self::$DI['record_1']->get_record_id()
]); ]);
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertBadJsonContent(json_decode($response->getContent())); $this->assertBadJsonContent(json_decode($response->getContent()));
$em = $lazaretFile = null;
} }
/** /**
@@ -539,36 +447,15 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testAcceptElementBadRequestException() public function testAcceptElementBadRequestException()
{ {
$originalEm = self::$DI['app']['EM'];
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
$lazaretFile = $this->getOneLazaretFile();
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id
$em->expects($this->any())
->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
->will($this->returnValue($lazaretFile));
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
//Ommit record_id mandatory param //Ommit record_id mandatory param
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/'); self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/');
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$this->assertBadJsonContent(json_decode($response->getContent())); $this->assertBadJsonContent(json_decode($response->getContent()));
$em = $lazaretFile = null;
} }
/** /**
@@ -576,11 +463,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
*/ */
public function testThumbnailElement() public function testThumbnailElement()
{ {
$originalEm = self::$DI['app']['EM'];
//mock Doctrine\ORM\EntityManager
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
$lazaretFile = $this->getMock('Alchemy\Phrasea\Model\Entities\LazaretFile', [], [], '', false); $lazaretFile = $this->getMock('Alchemy\Phrasea\Model\Entities\LazaretFile', [], [], '', false);
copy(__DIR__ . '/../../../../../files/cestlafete.jpg', __DIR__ . '/../../../../../../tmp/lazaret/cestlafete.jpg'); copy(__DIR__ . '/../../../../../files/cestlafete.jpg', __DIR__ . '/../../../../../../tmp/lazaret/cestlafete.jpg');
@@ -595,25 +477,17 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
$id = 1; $id = 1;
//Expect the retrieval of the lazaret file with the provided id self::$DI['app']['repo.lazaret-files'] = $this->createEntityRepositoryMock();
$em->expects($this->any()) self::$DI['app']['repo.lazaret-files']->expects($this->once())
->method('find') ->method('find')
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id)) ->with($this->equalTo($id))
->will($this->returnValue($lazaretFile)); ->will($this->returnValue($lazaretFile));
self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/thumbnail/'); self::$DI['client']->request('GET', '/prod/lazaret/' . $id . '/thumbnail/');
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->assertResponseOk($response); $this->assertResponseOk($response);
$em = $lazaretFile = null;
} }
/** /**

View File

@@ -162,8 +162,6 @@ class StoryTest extends \PhraseanetAuthenticatedWebTestCase
, $record->get_record_id() , $record->get_record_id()
); );
self::$DI['client'] = new Client(self::$DI['app'], []);
if (($n % 2) === 0) { if (($n % 2) === 0) {
$crawler = self::$DI['client']->request('POST', $route); $crawler = self::$DI['client']->request('POST', $route);

View File

@@ -85,7 +85,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
]; ];
$service = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager') $service = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']]) ->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations'], self::$DI['app']['locale']])
->setMethods(['getRegistrationSummary']) ->setMethods(['getRegistrationSummary'])
->getMock(); ->getMock();

View File

@@ -1026,7 +1026,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['client']->request('POST', '/login/register-classic/', $parameters); self::$DI['client']->request('POST', '/login/register-classic/', $parameters);
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
if (null === $user = self::$DI['app']['manipulator.user']->getRepository()->findByEmail($parameters['email'])) { if (null === $user = self::$DI['app']['repo.users']->findByEmail($parameters['email'])) {
$this->fail('User not created'); $this->fail('User not created');
} }
@@ -1091,7 +1091,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['client']->request('POST', '/login/register-classic/', $parameters); self::$DI['client']->request('POST', '/login/register-classic/', $parameters);
if (null === $user = self::$DI['app']['manipulator.user']->getRepository()->findByEmail($parameters['email'])) { if (null === $user = self::$DI['app']['repo.users']->findByEmail($parameters['email'])) {
$this->fail('User not created'); $this->fail('User not created');
} }
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
@@ -1197,7 +1197,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
$this->assertEquals($context, $event->getContext()->getContext()); $this->assertEquals($context, $event->getContext()->getContext());
}); });
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
self::$DI['client']->request('POST', '/login/authenticate/', [ self::$DI['client']->request('POST', '/login/authenticate/', [
'login' => $login, 'login' => $login,
@@ -1236,7 +1235,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
$this->logout(self::$DI['app']); $this->logout(self::$DI['app']);
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
self::$DI['client']->request('POST', '/login/authenticate/', [ self::$DI['client']->request('POST', '/login/authenticate/', [
'login' => $login, 'login' => $login,
@@ -1285,7 +1283,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
$this->logout(self::$DI['app']); $this->logout(self::$DI['app']);
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
self::$DI['client']->request('POST', '/login/authenticate/guest/'); self::$DI['client']->request('POST', '/login/authenticate/guest/');
@@ -1300,7 +1297,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
self::$DI['app']['acl']->get(self::$DI['user_guest'])->give_access_to_base([self::$DI['collection']->get_base_id()]); self::$DI['app']['acl']->get(self::$DI['user_guest'])->give_access_to_base([self::$DI['collection']->get_base_id()]);
$this->logout(self::$DI['app']); $this->logout(self::$DI['app']);
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
self::$DI['client']->request('GET', '/login/authenticate/guest/'); self::$DI['client']->request('GET', '/login/authenticate/guest/');
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
@@ -1578,7 +1574,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
->method('getEmail') ->method('getEmail')
->will($this->returnValue('supermail@superprovider.com')); ->will($this->returnValue('supermail@superprovider.com'));
if (null === $user = self::$DI['app']['manipulator.user']->getRepository()->findByEmail('supermail@superprovider.com')) { if (null === $user = self::$DI['app']['repo.users']->findByEmail('supermail@superprovider.com')) {
$random = self::$DI['app']['tokens']->generatePassword(); $random = self::$DI['app']['tokens']->generatePassword();
$user = self::$DI['app']['manipulator.user']->createUser('temporary-'.$random, $random, 'supermail@superprovider.com'); $user = self::$DI['app']['manipulator.user']->createUser('temporary-'.$random, $random, 'supermail@superprovider.com');
} }
@@ -1750,29 +1746,19 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
->with('provider-test', $id) ->with('provider-test', $id)
->will($this->returnValue($out)); ->will($this->returnValue($out));
self::$DI['app']['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager') self::$DI['app']['EM'] = $this->createEntityManagerMock();
->disableOriginalConstructor()
->getMock();
self::$DI['app']['EM']->expects($this->at(0)) self::$DI['app']['repo.usr-auth-providers'] = $repo;
->method('getRepository')
->with('Phraseanet:UsrAuthProvider')
->will($this->returnValue($repo));
if ($participants) {
$repo = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\ValidationParticipantRepository') $repo = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\ValidationParticipantRepository')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$repo->expects($this->once()) $repo->expects($participants ? $this->once() : $this->never())
->method('findNotConfirmedAndNotRemindedParticipantsByExpireDate') ->method('findNotConfirmedAndNotRemindedParticipantsByExpireDate')
->will($this->returnValue([])); ->will($this->returnValue([]));
self::$DI['app']['EM']->expects($this->at(1)) self::$DI['app']['repo.validation-participants'] = $repo;
->method('getRepository')
->with('Phraseanet:ValidationParticipant')
->will($this->returnValue($repo));
}
} }
private function mockSuggestionFinder() private function mockSuggestionFinder()
@@ -1891,7 +1877,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
private function enableRegistration() private function enableRegistration()
{ {
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager') $managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']]) ->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations'], self::$DI['app']['locale']])
->setMethods(['isRegistrationEnabled']) ->setMethods(['isRegistrationEnabled'])
->getMock(); ->getMock();
@@ -1902,7 +1888,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
private function disableRegistration() private function disableRegistration()
{ {
$managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager') $managerMock = $this->getMockBuilder('Alchemy\Phrasea\Core\Configuration\RegistrationManager')
->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']]) ->setConstructorArgs([self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations'], self::$DI['app']['locale']])
->setMethods(['isRegistrationEnabled']) ->setMethods(['isRegistrationEnabled'])
->getMock(); ->getMock();

View File

@@ -87,21 +87,19 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
public function testDeleteSession() public function testDeleteSession()
{ {
$originalEm = self::$DI['app']['EM'];
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session'); $session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
$session->expects($this->any()) $session->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue(self::$DI['app']['authentication']->getUser())); ->will($this->returnValue(self::$DI['app']['authentication']->getUser()));
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager') $em = $this->createEntityManagerMock();
->disableOriginalConstructor()
->getMock();
$em->expects($this->once()) self::$DI['app']['repo.sessions'] = $this->createEntityRepositoryMock();
self::$DI['app']['repo.sessions']->expects($this->exactly(2))
->method('find') ->method('find')
->will($this->returnValue($session)); ->will($this->returnValue($session));
$em->expects($this->once()) $em->expects($this->once())
->method('remove') ->method('remove')
->will($this->returnValue(null)); ->will($this->returnValue(null));
@@ -110,41 +108,28 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
->will($this->returnValue(null)); ->will($this->returnValue(null));
self::$DI['app']['EM'] = $em; self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
$this->XMLHTTPRequest('POST', '/session/delete/1'); $this->XMLHTTPRequest('POST', '/session/delete/1');
$this->assertTrue(self::$DI['client']->getResponse()->isOK()); $this->assertTrue(self::$DI['client']->getResponse()->isOK());
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$em = null;
} }
public function testDeleteSessionUnauthorized() public function testDeleteSessionUnauthorized()
{ {
$originalEm = self::$DI['app']['EM'];
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session'); $session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
$session->expects($this->any()) $session->expects($this->any())
->method('getUser') ->method('getUser')
->will($this->returnValue(self::$DI['user_alt1'])); ->will($this->returnValue(self::$DI['user_alt1']));
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager') $em = $this->createEntityManagerMock();
->disableOriginalConstructor()
->getMock();
$em->expects($this->once()) self::$DI['app']['repo.sessions'] = $this->createEntityRepositoryMock();
self::$DI['app']['repo.sessions']->expects($this->exactly(2))
->method('find') ->method('find')
->will($this->returnValue($session)); ->will($this->returnValue($session));
self::$DI['app']['EM'] = $em; self::$DI['app']['EM'] = $em;
self::$DI['client'] = new Client(self::$DI['app'], []);
self::$DI['client']->request('POST', '/session/delete/1'); self::$DI['client']->request('POST', '/session/delete/1');
$this->assertFalse(self::$DI['client']->getResponse()->isOK()); $this->assertFalse(self::$DI['client']->getResponse()->isOK());
$this->assertEquals(self::$DI['client']->getResponse()->getStatusCode(), 403); $this->assertEquals(self::$DI['client']->getResponse()->getStatusCode(), 403);
self::$DI['app']['EM'] = $originalEm;
self::$DI['client'] = new Client(self::$DI['app'], []);
$em = null;
} }
} }

View File

@@ -90,12 +90,8 @@ class SetupTest extends \PhraseanetWebTestCase
public function testRouteSetupInstallerInstall() public function testRouteSetupInstallerInstall()
{ {
$emMock = $this->getMock('\Doctrine\ORM\EntityManager', $emMock = $this->createEntityManagerMock();
['getRepository', 'find', 'persist', 'flush'], [], '', false); $this->app['repo.sessions'] = $this->createEntityRepositoryMock();
$emMock->expects($this->any())
->method('getRepository')
->will($this->returnValue($this->getMock('Alchemy\Phrasea\Model\Repository\SessionRepository')));
$this->app['EM'] = $emMock; $this->app['EM'] = $emMock;
$this->app['phraseanet.configuration-tester']->expects($this->once()) $this->app['phraseanet.configuration-tester']->expects($this->once())

View File

@@ -33,7 +33,7 @@ class RegistrationManagerTest extends \PhraseanetTestCase
$mockDatabox->expects($this->once())->method('get_collections')->will($this->returnValue([$mockColl])); $mockDatabox->expects($this->once())->method('get_collections')->will($this->returnValue([$mockColl]));
$mockAppbox->expects($this->once())->method('get_databoxes')->will($this->returnValue([$mockDatabox])); $mockAppbox->expects($this->once())->method('get_databoxes')->will($this->returnValue([$mockDatabox]));
$service = new RegistrationManager($mockAppbox, self::$DI['app']['manipulator.registration']->getRepository(), self::$DI['app']['locale']); $service = new RegistrationManager($mockAppbox, self::$DI['app']['repo.registrations'], self::$DI['app']['locale']);
$this->assertEquals($expected, $service->isRegistrationEnabled()); $this->assertEquals($expected, $service->isRegistrationEnabled());
} }

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\Core\Provider; namespace Alchemy\Tests\Phrasea\Core\Provider;
use Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider;
use Alchemy\Phrasea\Core\Provider\TokensServiceProvider; use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider; use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider;
use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider; use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider;
@@ -87,9 +88,7 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42); $app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42);
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager') $app['EM'] = $this->createEntityManagerMock();
->disableOriginalConstructor()
->getMock();
self::$DI['app']['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha') self::$DI['app']['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -111,13 +110,14 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['root.path'] = __DIR__ . '/../../../../../../'; $app['root.path'] = __DIR__ . '/../../../../../../';
$app->register(new AuthenticationManagerServiceProvider()); $app->register(new AuthenticationManagerServiceProvider());
$app->register(new ConfigurationServiceProvider()); $app->register(new ConfigurationServiceProvider());
$app->register(new RepositoriesServiceProvider());
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox']; $app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
$app['conf']->set(['authentication', 'captcha'], ['enabled' => true]); $app['conf']->set(['authentication', 'captcha'], ['enabled' => true]);
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager') $app['EM'] = $this->createEntityManagerMock();
->disableOriginalConstructor() $app['repo.users'] = $this->createEntityRepositoryMock();
->getMock(); $app['repo.auth-failures'] = $this->createEntityRepositoryMock();
$app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha') $app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@@ -135,9 +135,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
$app['conf']->set(['authentication', 'captcha'], ['enabled' => false]); $app['conf']->set(['authentication', 'captcha'], ['enabled' => false]);
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager') $app['EM'] = $this->createEntityManagerMock();
->disableOriginalConstructor() $app['repo.users'] = $this->createEntityRepositoryMock();
->getMock();
$app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha') $app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();

View File

@@ -0,0 +1,35 @@
<?php
namespace Alchemy\Tests\Phrasea\Core\Provider;
class RepositoriesServiceProviderTest extends ServiceProviderTestCase
{
public function provideServiceDescription()
{
return [
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.users', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.tasks', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.registrations', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.baskets', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.basket-elements', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.validation-participants', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.story-wz', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.orders', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.order-elements', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.feeds', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.feed-entries', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.feed-items', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.feed-publishers', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.aggregate-tokens', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.usr-lists', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.usr-list-owners', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.usr-list-entries', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.lazaret-files', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.usr-auth-providers', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.ftp-exports', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.user-queries', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.feed-tokens', 'Doctrine\\ORM\\EntityRepository'],
['Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider', 'repo.sessions', 'Doctrine\\ORM\\EntityRepository'],
];
}
}

View File

@@ -17,7 +17,7 @@ class UserManagerTest extends \PhraseanetTestCase
self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false); self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false);
self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false); self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false);
self::$DI['app']['model.user-manager']->delete($user); self::$DI['app']['model.user-manager']->delete($user);
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertEquals(0, $user->getSettings()->count()); $this->assertEquals(0, $user->getSettings()->count());
$this->assertEquals(0, $user->getNotificationSettings()->count()); $this->assertEquals(0, $user->getNotificationSettings()->count());
$this->assertEquals(0, $user->getQueries()->count()); $this->assertEquals(0, $user->getQueries()->count());

View File

@@ -55,7 +55,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
public function testDeleteRegistrationForUser() public function testDeleteRegistrationForUser()
{ {
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']);
$qb = $service->getRepository()->createQueryBuilder('r'); $qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
$nbRegistrationBefore = $qb->select('COUNT(r)') $nbRegistrationBefore = $qb->select('COUNT(r)')
->where($qb->expr()->eq('r.user', ':user')) ->where($qb->expr()->eq('r.user', ':user'))
->setParameter(':user', self::$DI['user_alt1']->getId()) ->setParameter(':user', self::$DI['user_alt1']->getId())
@@ -69,7 +69,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
public function testDeleteOldRegistrations() public function testDeleteOldRegistrations()
{ {
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']);
$qb = $service->getRepository()->createQueryBuilder('r'); $qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult(); $nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
$service->deleteOldRegistrations(); $service->deleteOldRegistrations();
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult(); $nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
@@ -79,7 +79,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
public function testDeleteRegistrationOnCollection() public function testDeleteRegistrationOnCollection()
{ {
$service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']); $service = new RegistrationManipulator(self::$DI['app'], self::$DI['app']['EM'], self::$DI['app']['acl'], self::$DI['app']['phraseanet.appbox'], self::$DI['app']['repo.registrations']);
$qb = $service->getRepository()->createQueryBuilder('r'); $qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult(); $nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
$service->deleteRegistrationsOnCollection(self::$DI['collection']); $service->deleteRegistrationsOnCollection(self::$DI['collection']);
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult(); $nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();

View File

@@ -104,12 +104,6 @@ class TaskManipulatorTest extends \PhraseanetTestCase
$this->assertEquals(0, $task->getCrashed()); $this->assertEquals(0, $task->getCrashed());
} }
public function testGetRepository()
{
$manipulator = new TaskManipulator(self::$DI['app']['EM'], $this->createNotifierMock(), self::$DI['app']['translator'], self::$DI['app']['repo.tasks']);
$this->assertSame(self::$DI['app']['EM']->getRepository('Phraseanet:Task'), $manipulator->getRepository());
}
public function testCreateEmptyCollection() public function testCreateEmptyCollection()
{ {
$collection = $this->getMockBuilder('collection') $collection = $this->getMockBuilder('collection')

View File

@@ -11,7 +11,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
public function testCreateUser() public function testCreateUser()
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass'); $user = self::$DI['app']['manipulator.user']->createUser('login', 'pass');
$this->assertInstanceOf('\Alchemy\Phrasea\Model\Entities\User', self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login')); $this->assertInstanceOf('\Alchemy\Phrasea\Model\Entities\User', self::$DI['app']['repo.users']->findOneByLogin('login'));
} }
public function testDeleteUser() public function testDeleteUser()
@@ -25,7 +25,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
public function testCreateAdminUser() public function testCreateAdminUser()
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass', 'admin@admin.com', true); $user = self::$DI['app']['manipulator.user']->createUser('login', 'pass', 'admin@admin.com', true);
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertTrue($user->isAdmin()); $this->assertTrue($user->isAdmin());
$this->assertNotNull($user->getEmail()); $this->assertNotNull($user->getEmail());
} }
@@ -34,7 +34,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass'); $user = self::$DI['app']['manipulator.user']->createUser('login', 'pass');
$template = self::$DI['app']['manipulator.user']->createTemplate('test', $user); $template = self::$DI['app']['manipulator.user']->createTemplate('test', $user);
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('test'); $user = self::$DI['app']['repo.users']->findOneByLogin('test');
$this->assertTrue($user->isTemplate()); $this->assertTrue($user->isTemplate());
} }
@@ -87,9 +87,9 @@ class UserManipulatorTest extends \PhraseanetTestCase
$user2 = self::$DI['app']['manipulator.user']->createUser('login2', 'toto'); $user2 = self::$DI['app']['manipulator.user']->createUser('login2', 'toto');
$this->assertFalse($user2->isAdmin()); $this->assertFalse($user2->isAdmin());
self::$DI['app']['manipulator.user']->promote([$user, $user2]); self::$DI['app']['manipulator.user']->promote([$user, $user2]);
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertTrue($user->isAdmin()); $this->assertTrue($user->isAdmin());
$user2 = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user2 = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertTrue($user2->isAdmin()); $this->assertTrue($user2->isAdmin());
} }
@@ -98,7 +98,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
$user = self::$DI['app']['manipulator.user']->createUser('login', 'toto', null, true); $user = self::$DI['app']['manipulator.user']->createUser('login', 'toto', null, true);
$this->assertTrue($user->isAdmin()); $this->assertTrue($user->isAdmin());
self::$DI['app']['manipulator.user']->demote($user); self::$DI['app']['manipulator.user']->demote($user);
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertFalse($user->isAdmin()); $this->assertFalse($user->isAdmin());
} }
@@ -173,7 +173,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); $user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
self::$DI['app']['manipulator.user']->setUserSetting($user, 'name' ,'value'); self::$DI['app']['manipulator.user']->setUserSetting($user, 'name' ,'value');
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertCount(1, $user->getSettings()); $this->assertCount(1, $user->getSettings());
} }
@@ -181,7 +181,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); $user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'name', 'value'); self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'name', 'value');
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertCount(1, $user->getNotificationSettings()); $this->assertCount(1, $user->getNotificationSettings());
} }
@@ -189,7 +189,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
{ {
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password'); $user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
self::$DI['app']['manipulator.user']->logQuery($user, 'query'); self::$DI['app']['manipulator.user']->logQuery($user, 'query');
$user = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login'); $user = self::$DI['app']['repo.users']->findOneByLogin('login');
$this->assertCount(1, $user->getQueries()); $this->assertCount(1, $user->getQueries());
} }
} }

View File

@@ -99,49 +99,49 @@ abstract class PhraseanetTestCase extends WebTestCase
}); });
self::$DI['user'] = self::$DI->share(function ($DI) { self::$DI['user'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['test_phpunit']);
}); });
self::$DI['user_1'] = self::$DI->share(function ($DI) { self::$DI['user_1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_1']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['user_1']);
}); });
self::$DI['user_2'] = self::$DI->share(function ($DI) { self::$DI['user_2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_2']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['user_2']);
}); });
self::$DI['user_3'] = self::$DI->share(function ($DI) { self::$DI['user_3'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_3']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['user_3']);
}); });
self::$DI['user_guest'] = self::$DI->share(function ($DI) { self::$DI['user_guest'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_guest']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['user_guest']);
}); });
self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) { self::$DI['user_notAdmin'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_not_admin']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['test_phpunit_not_admin']);
}); });
self::$DI['user_alt1'] = self::$DI->share(function ($DI) { self::$DI['user_alt1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt1']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['test_phpunit_alt1']);
}); });
self::$DI['user_alt2'] = self::$DI->share(function ($DI) { self::$DI['user_alt2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['test_phpunit_alt2']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['test_phpunit_alt2']);
}); });
self::$DI['user_template'] = self::$DI->share(function ($DI) { self::$DI['user_template'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.user']->getRepository()->find(self::$fixtureIds['user']['user_template']); return $DI['app']['repo.users']->find(self::$fixtureIds['user']['user_template']);
}); });
self::$DI['registration_1'] = self::$DI->share(function ($DI) { self::$DI['registration_1'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_1']); return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_1']);
}); });
self::$DI['registration_2'] = self::$DI->share(function ($DI) { self::$DI['registration_2'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_2']); return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_2']);
}); });
self::$DI['registration_3'] = self::$DI->share(function ($DI) { self::$DI['registration_3'] = self::$DI->share(function ($DI) {
return $DI['app']['manipulator.registration']->getRepository()->find(self::$fixtureIds['registrations']['registration_3']); return $DI['app']['repo.registrations']->find(self::$fixtureIds['registrations']['registration_3']);
}); });
self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) { self::$DI['oauth2-app-user'] = self::$DI->share(function ($DI) {
@@ -663,4 +663,11 @@ abstract class PhraseanetTestCase extends WebTestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
} }
protected function createEntityManagerMock()
{
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
->disableOriginalConstructor()
->getMock();
}
} }

View File

@@ -8,9 +8,9 @@ class userTest extends \PhraseanetTestCase
public function testMail() public function testMail()
{ {
self::$DI['user']->setEmail(''); self::$DI['user']->setEmail('');
$this->assertNull(self::$DI['app']['manipulator.user']->getRepository()->findByEmail(self::$DI['user']->getEmail())); $this->assertNull(self::$DI['app']['repo.users']->findByEmail(self::$DI['user']->getEmail()));
self::$DI['user']->setEmail('noone@example.com'); self::$DI['user']->setEmail('noone@example.com');
$this->assertEquals(self::$DI['user'], self::$DI['app']['manipulator.user']->getRepository()->findByEmail('noone@example.com')); $this->assertEquals(self::$DI['user'], self::$DI['app']['repo.users']->findByEmail('noone@example.com'));
try { try {
self::$DI['user']->setEmail('noonealt1@example.com'); self::$DI['user']->setEmail('noonealt1@example.com');
$this->fail('A user already got this address'); $this->fail('A user already got this address');
@@ -38,7 +38,7 @@ class userTest extends \PhraseanetTestCase
public function testDeleteSetMailToNullAndRemovesSessions() public function testDeleteSetMailToNullAndRemovesSessions()
{ {
if (null === $user = self::$DI['app']['manipulator.user']->getRepository()->findByLogin('test_phpunit_sessions')) { if (null === $user = self::$DI['app']['repo.users']->findByLogin('test_phpunit_sessions')) {
$user = self::$DI['app']['manipulator.user']->createUser('test_phpunit_sessions', \random::generatePassword()); $user = self::$DI['app']['manipulator.user']->createUser('test_phpunit_sessions', \random::generatePassword());
} }