mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 23:13:15 +00:00
Fix unit tests
This commit is contained in:
@@ -101,6 +101,7 @@ use Alchemy\Phrasea\Core\Provider\PhraseanetServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\PluginServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\PhraseaVersionServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\RegistrationServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\SearchEngineServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\SerializerServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\SessionHandlerServiceProvider;
|
||||
@@ -281,6 +282,7 @@ class Application extends SilexApplication
|
||||
$this->register(new MP4BoxServiceProvider());
|
||||
$this->register(new NotificationDelivererServiceProvider());
|
||||
$this->register(new ORMServiceProvider());
|
||||
$this->register(new RepositoriesServiceProvider());
|
||||
$this->register(new ManipulatorServiceProvider());
|
||||
$this->register(new InstallerServiceProvider());
|
||||
$this->register(new PhraseanetServiceProvider());
|
||||
|
@@ -100,7 +100,7 @@ class Authenticator
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ class Authenticator
|
||||
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->flush();
|
||||
}
|
||||
@@ -163,7 +163,7 @@ class Authenticator
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@@ -14,18 +14,19 @@ namespace Alchemy\Phrasea\Authentication\PersistentCookie;
|
||||
use Alchemy\Phrasea\Authentication\Phrasea\PasswordEncoder;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Alchemy\Phrasea\Model\Entities\Session;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
class Manager
|
||||
{
|
||||
private $browser;
|
||||
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->encoder = $encoder;
|
||||
$this->em = $em;
|
||||
$this->repository = $repo;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,9 +38,7 @@ class Manager
|
||||
*/
|
||||
public function getSession($cookieValue)
|
||||
{
|
||||
$session = $this->em
|
||||
->getRepository('Phraseanet:Session')
|
||||
->findOneBy(['token' => $cookieValue]);
|
||||
$session = $this->repository->findOneBy(['token' => $cookieValue]);
|
||||
|
||||
if (!$session) {
|
||||
return false;
|
||||
|
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\Phrasea\Authentication\Exception\RequireCaptchaException;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Alchemy\Phrasea\Model\Entities\AuthFailure;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Neutron\ReCaptcha\ReCaptcha;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
@@ -24,13 +25,16 @@ class FailureManager
|
||||
private $captcha;
|
||||
/** @var EntityManager */
|
||||
private $em;
|
||||
/** @var EntityRepository */
|
||||
private $repository;
|
||||
/** @var integer */
|
||||
private $trials;
|
||||
|
||||
public function __construct(EntityManager $em, ReCaptcha $captcha, $trials)
|
||||
public function __construct(EntityRepository $repo, EntityManager $em, ReCaptcha $captcha, $trials)
|
||||
{
|
||||
$this->captcha = $captcha;
|
||||
$this->em = $em;
|
||||
$this->repository = $repo;
|
||||
|
||||
if ($trials < 0) {
|
||||
throw new InvalidArgumentException('Trials number must be a positive integer');
|
||||
@@ -79,9 +83,7 @@ class FailureManager
|
||||
*/
|
||||
public function checkFailures($username, Request $request)
|
||||
{
|
||||
$failures = $this->em
|
||||
->getRepository('Phraseanet:AuthFailure')
|
||||
->findLockedFailuresMatching($username, $request->getClientIp());
|
||||
$failures = $this->repository->findLockedFailuresMatching($username, $request->getClientIp());
|
||||
|
||||
if (0 === count($failures)) {
|
||||
return;
|
||||
@@ -108,9 +110,7 @@ class FailureManager
|
||||
*/
|
||||
private function removeOldFailures()
|
||||
{
|
||||
$failures = $this->em
|
||||
->getRepository('Phraseanet:AuthFailure')
|
||||
->findOldFailures('-2 months');
|
||||
$failures = $this->repository->findOldFailures('-2 months');
|
||||
|
||||
if (0 < count($failures)) {
|
||||
foreach ($failures as $failure) {
|
||||
|
@@ -76,7 +76,7 @@ class Publications implements ControllerProviderInterface
|
||||
})->bind('admin_feeds_create');
|
||||
|
||||
$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']
|
||||
->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");
|
||||
}
|
||||
|
||||
$feed = $app["EM"]->find('Phraseanet:Feed', $id);
|
||||
$feed = $app["repo.feeds"]->find($id);
|
||||
|
||||
try {
|
||||
$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');
|
||||
})->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())) {
|
||||
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,
|
||||
'message' => '',
|
||||
];
|
||||
$feed = $app["EM"]->find('Phraseanet:Feed', $id);
|
||||
$feed = $app["repo.feeds"]->find($id);
|
||||
|
||||
if (null === $feed) {
|
||||
$app->abort(404, "Feed not found");
|
||||
@@ -194,7 +194,7 @@ class Publications implements ControllerProviderInterface
|
||||
try {
|
||||
$request = $app['request'];
|
||||
$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->setUser($user);
|
||||
@@ -219,9 +219,9 @@ class Publications implements ControllerProviderInterface
|
||||
try {
|
||||
$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) {
|
||||
$app->abort(404, "Feed Publisher not found");
|
||||
}
|
||||
@@ -243,7 +243,7 @@ class Publications implements ControllerProviderInterface
|
||||
->assert('id', '\d+');
|
||||
|
||||
$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) {
|
||||
$app->abort(404);
|
||||
|
@@ -805,7 +805,7 @@ class V1 implements ControllerProviderInterface
|
||||
|
||||
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 */
|
||||
if (null === $lazaretFile) {
|
||||
|
@@ -112,7 +112,7 @@ class Lazaret implements ControllerProviderInterface
|
||||
{
|
||||
$ret = ['success' => false, 'message' => '', 'result' => []];
|
||||
|
||||
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id);
|
||||
$lazaretFile = $app['repo.lazaret-files']->find($file_id);
|
||||
|
||||
/* @var $lazaretFile LazaretFile */
|
||||
if (null === $lazaretFile) {
|
||||
@@ -165,7 +165,7 @@ class Lazaret implements ControllerProviderInterface
|
||||
return $app->json($ret);
|
||||
}
|
||||
|
||||
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id);
|
||||
$lazaretFile = $app['repo.lazaret-files']->find($file_id);
|
||||
|
||||
/* @var $lazaretFile LazaretFile */
|
||||
if (null === $lazaretFile) {
|
||||
@@ -274,7 +274,7 @@ class Lazaret implements ControllerProviderInterface
|
||||
{
|
||||
$ret = ['success' => false, 'message' => '', 'result' => []];
|
||||
|
||||
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id);
|
||||
$lazaretFile = $app['repo.lazaret-files']->find($file_id);
|
||||
/* @var $lazaretFile LazaretFile */
|
||||
if (null === $lazaretFile) {
|
||||
$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);
|
||||
}
|
||||
|
||||
$lazaretFile = $app['EM']->find('Phraseanet:LazaretFile', $file_id);
|
||||
$lazaretFile = $app['repo.lazaret-files']->find($file_id);
|
||||
|
||||
/* @var $lazaretFile LazaretFile */
|
||||
if (null === $lazaretFile) {
|
||||
@@ -430,7 +430,7 @@ class Lazaret implements ControllerProviderInterface
|
||||
*/
|
||||
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 */
|
||||
if (null === $lazaretFile) {
|
||||
|
@@ -47,7 +47,7 @@ class RSSFeeds implements ControllerProviderInterface
|
||||
->assert('format', '(rss|atom)');
|
||||
|
||||
$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'];
|
||||
|
||||
|
@@ -81,7 +81,7 @@ class Session implements ControllerProviderInterface
|
||||
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());
|
||||
|
||||
if (!$session->hasModuleId($moduleId)) {
|
||||
@@ -132,7 +132,7 @@ class Session implements ControllerProviderInterface
|
||||
*/
|
||||
public function deleteSession(Application $app, Request $request, $id)
|
||||
{
|
||||
$session = $app['EM']->find('Phraseanet:Session', $id);
|
||||
$session = $app['repo.sessions']->find($id);
|
||||
|
||||
if (null === $session) {
|
||||
$app->abort(404, 'Unknown session');
|
||||
|
@@ -41,7 +41,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
|
||||
});
|
||||
|
||||
$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) {
|
||||
@@ -103,7 +103,7 @@ class AuthenticationManagerServiceProvider implements ServiceProviderInterface
|
||||
$app['auth.native.failure-manager'] = $app->share(function (Application $app) {
|
||||
$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) {
|
||||
|
@@ -183,70 +183,6 @@ class ORMServiceProvider implements ServiceProviderInterface
|
||||
$app['EM.native-query'] = $app->share(function ($app) {
|
||||
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)
|
||||
|
@@ -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)
|
||||
{
|
||||
}
|
||||
}
|
@@ -13,7 +13,6 @@ namespace Alchemy\Phrasea\Model\Manipulator;
|
||||
|
||||
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Alchemy\Phrasea\Exception\LogicException;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
|
||||
class ACLManipulator implements ManipulatorInterface
|
||||
|
@@ -11,8 +11,6 @@
|
||||
|
||||
namespace Alchemy\Phrasea\Model\Manipulator;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
/**
|
||||
* This class is responsible of manipulating entities.
|
||||
*/
|
||||
|
@@ -15,7 +15,6 @@ use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||
use Alchemy\Phrasea\Model\Entities\Registration;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Model\Repositories\RegistrationRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
|
||||
|
@@ -186,7 +186,7 @@ class Session_Logger
|
||||
return;
|
||||
}
|
||||
|
||||
$session = $app['EM']->find('Phraseanet:Session', $app['session']->get('session_id'));
|
||||
$session = $app['repo.sessions']->find($app['session']->get('session_id'));
|
||||
|
||||
if (!$session) {
|
||||
throw new SessionNotFound('No session found');
|
||||
|
@@ -69,7 +69,7 @@ class patch_383alpha1a extends patchAbstract
|
||||
$stmt->closeCursor();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$this->assertNull($authenticator->getUser());
|
||||
@@ -32,7 +32,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$user = $this->createUserMock();
|
||||
|
||||
@@ -53,7 +53,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$user = $this->createUserMock();
|
||||
$user->expects($this->any())
|
||||
@@ -85,6 +85,20 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
$em->expects($this->at(1))
|
||||
->method('flush');
|
||||
|
||||
$repo = $this->createEntityRepositoryMock();
|
||||
$repo->expects($this->once())
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue($session));
|
||||
$repoUsers = $this->createEntityRepositoryMock();
|
||||
$repoUsers->expects($this->once())
|
||||
->method('find')
|
||||
->with($user->getId())
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$app['repo.sessions'] = $repo;
|
||||
$app['repo.users'] = $repoUsers;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$phsession = $authenticator->openAccount($user);
|
||||
|
||||
@@ -103,7 +117,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $SFsession = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$sessionId = 4224242;
|
||||
|
||||
@@ -119,15 +133,18 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$repo->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['id' => $session->getId()]))
|
||||
$repo->expects($this->exactly(2))
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue($session));
|
||||
$repoUsers = $this->createEntityRepositoryMock();
|
||||
$repoUsers->expects($this->once())
|
||||
->method('find')
|
||||
->with($user->getId())
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$app['repo.sessions'] = $repo;
|
||||
$app['repo.users'] = $repoUsers;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $SFsession, $em);
|
||||
$this->assertEquals($session, $authenticator->refreshAccount($session));
|
||||
@@ -144,7 +161,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $SFsession = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$sessionId = 4224242;
|
||||
|
||||
@@ -161,14 +178,11 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
|
||||
$repo->expects($this->once())
|
||||
->method('findOneBy')
|
||||
->with($this->equalTo(['id' => $session->getId()]))
|
||||
->method('find')
|
||||
->with($session->getId())
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$app['repo.sessions'] = $repo;
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $SFsession, $em);
|
||||
try {
|
||||
@@ -216,12 +230,13 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$app['EM']->expects($this->any())->method('find')->with(
|
||||
$this->equalTo('Phraseanet:Session'),
|
||||
$this->equalTo(1)
|
||||
)->will($this->returnValue($sessionEntity));
|
||||
$app['repo.sessions'] = $this->createEntityRepositoryMock();
|
||||
$app['repo.sessions']->expects($this->any())
|
||||
->method('find')
|
||||
->with(1)
|
||||
->will($this->returnValue($sessionEntity));
|
||||
|
||||
$userRepository = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')
|
||||
->disableOriginalConstructor()
|
||||
@@ -235,7 +250,7 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$app['manipulator.user']->expects($this->once())->method('getRepository')->will($this->returnValue($userRepository));
|
||||
$app['repo.users'] = $userRepository;
|
||||
|
||||
$session->set('usr_id', self::$DI['user']->getId());
|
||||
$session->set('session_id', 1);
|
||||
@@ -254,26 +269,12 @@ class AuthenticatorTest extends \PhraseanetTestCase
|
||||
|
||||
$app['browser'] = $browser = $this->getBrowserMock();
|
||||
$app['session'] = $session = $this->getSessionMock();
|
||||
$app['EM'] = $em = $this->getEntityManagerMock();
|
||||
$app['EM'] = $em = $this->createEntityManagerMock();
|
||||
|
||||
$authenticator = new Authenticator($app, $browser, $session, $em);
|
||||
$this->assertFalse($authenticator->isAuthenticated());
|
||||
}
|
||||
|
||||
private function getEntityManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getRegistryMock()
|
||||
{
|
||||
return $this->getMockBuilder('registryInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getSessionMock()
|
||||
{
|
||||
return new \Symfony\Component\HttpFoundation\Session\Session(new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage());
|
||||
|
@@ -13,7 +13,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testGetSession()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
@@ -25,8 +24,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->method('getPlatform')
|
||||
->will($this->returnValue('Linux'));
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$session = new Session();
|
||||
$session->setNonce('prettyN0nce');
|
||||
|
||||
@@ -39,10 +36,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$encoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -58,7 +52,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testGetSessionReturnFalse()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
@@ -70,8 +63,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->method('getPlatform')
|
||||
->will($this->returnValue('Linux'));
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$session = new Session();
|
||||
$session->setNonce('prettyN0nce');
|
||||
|
||||
@@ -84,10 +75,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$encoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -102,12 +90,9 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
public function testSessionNotFound()
|
||||
{
|
||||
$encoder = $this->getPasswordEncoderMock();
|
||||
$em = $this->getEntityManagerMock();
|
||||
$browser = $this->getBrowserMock();
|
||||
$tokenValue = 'encrypted-persistent-value';
|
||||
|
||||
$manager = new Manager($encoder, $em, $browser);
|
||||
|
||||
$repo = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -117,10 +102,7 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo(['token' => $tokenValue]))
|
||||
->will($this->returnValue(null));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:Session'))
|
||||
->will($this->returnValue($repo));
|
||||
$manager = new Manager($encoder, $repo, $browser);
|
||||
|
||||
$this->assertFalse($manager->getSession($tokenValue));
|
||||
}
|
||||
@@ -132,13 +114,6 @@ class ManagerTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getEntityManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getBrowserMock()
|
||||
{
|
||||
return $this->getMockBuilder('Browser')
|
||||
|
@@ -15,7 +15,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testSaveFailure()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
|
||||
$ip = '192.168.16.178';
|
||||
@@ -47,7 +47,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
$catchFailure = $failure;
|
||||
}));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->saveFailure($username, $request);
|
||||
|
||||
$this->assertEquals($ip, $catchFailure->getIp());
|
||||
@@ -61,7 +61,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailures()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -73,7 +73,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresLessThan9()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -97,7 +97,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithoutCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(false);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -121,7 +121,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithCorrectCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, true);
|
||||
|
||||
@@ -150,7 +150,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresMoreThan9WithIncorrectCaptcha()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, false);
|
||||
|
||||
@@ -175,14 +175,14 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 9);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 9);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
public function testCheckFailuresTrialsIsConfigurableUnderThreshold()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
$request = $this->getRequestMock();
|
||||
|
||||
@@ -196,19 +196,17 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 2);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
public function testTrialsIsConfigurable()
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$recaptcha = $this->getReCaptchaMock(null);
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($this->createEntityRepositoryMock(), $em, $recaptcha, 2);
|
||||
$this->assertEquals(2, $manager->getTrials());
|
||||
}
|
||||
|
||||
@@ -219,7 +217,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
public function testCheckFailuresTrialsIsConfigurableOverThreshold()
|
||||
{
|
||||
$repo = $this->getRepo();
|
||||
$em = $this->getEntityManagerMock($repo);
|
||||
$em = $this->createEntityManagerMock();
|
||||
$request = $this->getRequestMock();
|
||||
$recaptcha = $this->getReCaptchaMock(true, $request, false);
|
||||
|
||||
@@ -233,7 +231,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
->method('findLockedFailuresMatching')
|
||||
->will($this->returnValue($oldFailures));
|
||||
|
||||
$manager = new FailureManager($em, $recaptcha, 2);
|
||||
$manager = new FailureManager($repo, $em, $recaptcha, 2);
|
||||
$manager->checkFailures($username, $request);
|
||||
}
|
||||
|
||||
@@ -255,7 +253,7 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
$this->assertCount(12, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
|
||||
->findAll());
|
||||
|
||||
$manager = new FailureManager(self::$DI['app']['EM'], $recaptcha, 9);
|
||||
$manager = new FailureManager(self::$DI['app']['repo.auth-failures'], self::$DI['app']['EM'], $recaptcha, 9);
|
||||
$manager->saveFailure($username, $request);
|
||||
|
||||
$this->assertCount(0, self::$DI['app']['EM']->getRepository('Phraseanet:AuthFailure')
|
||||
@@ -277,20 +275,6 @@ class FailureManagerTest extends \PhraseanetTestCase
|
||||
return $failures;
|
||||
}
|
||||
|
||||
private function getEntityManagerMock($repo)
|
||||
{
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:AuthFailure'))
|
||||
->will($this->returnValue($repo));
|
||||
|
||||
return $em;
|
||||
}
|
||||
|
||||
private function getReCaptchaMock($isSetup = true, Request $request = null, $isValid = false)
|
||||
{
|
||||
$recaptcha = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
|
||||
|
@@ -17,9 +17,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$specialUser = $this->createUserMock();
|
||||
$specialUser->expects($this->any())->method('isSpecial')->will($this->returnValue(true));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($specialUser);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($specialUser);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
|
||||
}
|
||||
|
||||
@@ -28,9 +29,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$encoder = $this->getEncoderMock();
|
||||
$oldEncoder = $this->getOldEncoderMock();
|
||||
$request = $this->getRequestMock();
|
||||
$manipulator = $this->getUserManipulatorMock(null);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock(null);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertNull($auth->getUsrId('a_login', 'a_password', $request));
|
||||
}
|
||||
|
||||
@@ -43,9 +45,10 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$mailLockedUser = $this->createUserMock();
|
||||
$mailLockedUser->expects($this->any())->method('isMailLocked')->will($this->returnValue(true));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($mailLockedUser);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($mailLockedUser);
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
try {
|
||||
$auth->getUsrId('a_login', 'a_password', $request);
|
||||
@@ -75,7 +78,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->never())
|
||||
->method('isPasswordValid');
|
||||
@@ -85,7 +89,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -110,7 +114,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->never())
|
||||
->method('isPasswordValid');
|
||||
@@ -120,7 +125,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals(false, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -146,6 +151,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$oldEncoder->expects($this->once())
|
||||
->method('isPasswordValid')
|
||||
@@ -157,7 +163,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->with($this->equalTo($encoded), $this->equalTo($password), $this->equalTo($nonce))
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
|
||||
$this->assertEquals(false, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
@@ -182,7 +188,8 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
$user->expects($this->any())->method('getPassword')->will($this->returnValue($encoded));
|
||||
$user->expects($this->any())->method('getNonce')->will($this->returnValue($nonce));
|
||||
|
||||
$manipulator = $this->getUserManipulatorMock($user);
|
||||
$manipulator = $this->getUserManipulatorMock();
|
||||
$entityRepo = $this->getEntityRepositoryMock($user);
|
||||
|
||||
$manipulator->expects($this->once())->method('setPassword')->with($this->equalTo($user), $this->equalTo($password));
|
||||
|
||||
@@ -203,7 +210,7 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
return true;
|
||||
}));
|
||||
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $this->createEntityRepositoryMock());
|
||||
$auth = new NativeAuthentication($encoder, $oldEncoder, $manipulator, $entityRepo);
|
||||
$this->assertEquals($userId, $auth->getUsrId('a_login', $password, $request));
|
||||
}
|
||||
|
||||
@@ -221,13 +228,6 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getFailureManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Alchemy\Phrasea\Authentication\Phrasea\FailureManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getRequestMock()
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')
|
||||
@@ -235,14 +235,18 @@ class NativeAuthenticationTest extends \PhraseanetTestCase
|
||||
->getMock();
|
||||
}
|
||||
|
||||
private function getUserManipulatorMock(User $user = null)
|
||||
private function getUserManipulatorMock()
|
||||
{
|
||||
$manipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')->disableOriginalConstructor()->getMock();
|
||||
|
||||
return $manipulator;
|
||||
}
|
||||
|
||||
private function getEntityRepositoryMock(User $user = null)
|
||||
{
|
||||
$repoMock = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\UserRepository')->disableOriginalConstructor()->getMock();
|
||||
$repoMock->expects($this->any())->method('findRealUserByLogin')->will($this->returnValue($user));
|
||||
|
||||
$manipulator = $this->getMockBuilder('Alchemy\Phrasea\Model\Manipulator\UserManipulator')->disableOriginalConstructor()->getMock();
|
||||
$manipulator->expects($this->any())->method('getRepository')->will($this->returnValue($repoMock));
|
||||
|
||||
return $manipulator;
|
||||
return $repoMock;
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(self::$DI['user']->getEmail());
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$finder = new SuggestionFinder(self::$DI['app']['repo.users']);
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user);
|
||||
@@ -22,7 +22,7 @@ class SuggestionFinderTest extends \PhraseanetTestCase
|
||||
{
|
||||
$token = $this->getToken(sprintf('%srandom%s@%srandom.com', uniqid(mt_rand(), true), uniqid(mt_rand(), true), uniqid(mt_rand(), true)));
|
||||
|
||||
$finder = new SuggestionFinder(self::$DI['app']['manipulator.user']->getRepository());
|
||||
$finder = new SuggestionFinder(self::$DI['app']['repo.users']);
|
||||
$user = $finder->find($token);
|
||||
|
||||
$this->assertNull($user);
|
||||
|
@@ -112,7 +112,7 @@ class AdminDashboardTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$admins = array_map(function (User $user) {
|
||||
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");
|
||||
|
||||
|
@@ -48,7 +48,6 @@ class SetupTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->with('registry',$this->isType('array'));
|
||||
|
||||
self::$DI['app']['conf'] = $registry;
|
||||
self::$DI['client'] = new Client(self::$DI['app']);
|
||||
self::$DI['client']->request('POST', '/admin/setup/', ['_token' => 'token']);
|
||||
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['client']->request('POST', '/admin/users/delete/', ['users' => self::$DI['user']->getId()]);
|
||||
$response = self::$DI['client']->getResponse();
|
||||
$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()
|
||||
@@ -285,7 +285,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertTrue(is_object($datas));
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -308,7 +308,7 @@ class UsersTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertTrue(is_object($datas));
|
||||
$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);
|
||||
}
|
||||
|
||||
|
@@ -245,7 +245,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$this->evaluateMeta200($content);
|
||||
$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']));
|
||||
|
||||
foreach ($response['tasks'] as $task) {
|
||||
@@ -335,7 +335,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
|
||||
public function testGetMonitorTaskById()
|
||||
{
|
||||
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
|
||||
$tasks = self::$DI['app']['repo.tasks']->findAll();
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
@@ -362,7 +362,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
|
||||
public function testPostMonitorTaskById()
|
||||
{
|
||||
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
|
||||
$tasks = self::$DI['app']['repo.tasks']->findAll();
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$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');
|
||||
}
|
||||
|
||||
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
|
||||
$tasks = self::$DI['app']['repo.tasks']->findAll();
|
||||
|
||||
if (!count($tasks)) {
|
||||
$this->markTestSkipped('no tasks created for the current instance');
|
||||
@@ -428,13 +428,13 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$this->assertArrayHasKey('task', $content['response']);
|
||||
$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());
|
||||
}
|
||||
|
||||
public function testPostMonitorStopTask()
|
||||
{
|
||||
$tasks = self::$DI['app']['manipulator.task']->getRepository()->findAll();
|
||||
$tasks = self::$DI['app']['repo.tasks']->findAll();
|
||||
|
||||
if (null === self::$adminToken) {
|
||||
$this->markTestSkipped('there is no user with admin rights');
|
||||
@@ -458,7 +458,7 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
$this->assertArrayHasKey('task', $content['response']);
|
||||
$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());
|
||||
}
|
||||
|
||||
@@ -1173,8 +1173,6 @@ abstract class ApiTestCase extends \PhraseanetWebTestCase
|
||||
|
||||
public function testSearchBaskets()
|
||||
{
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->setToken(self::$adminToken);
|
||||
$route = '/api/v1/baskets/list/';
|
||||
$this->evaluateMethodNotAllowedRoute($route, ['POST', 'PUT', 'DELETE']);
|
||||
|
@@ -26,8 +26,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testListElement()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
$fileLazaret = $this->getMock('Alchemy\Phrasea\Model\Entities\LazaretFile', ['getRecordsToSubstitute', 'getSession', 'getCollection'], [], '', false);
|
||||
|
||||
$fileLazaret
|
||||
@@ -53,30 +51,19 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->will($this->returnValue([$fileLazaret]));
|
||||
|
||||
//mock Doctrine\ORM\EntityManager::getRepository
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', ['getRepository'], [], '', false);
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('getRepository')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'))
|
||||
->will($this->returnValue($repo));
|
||||
self::$DI['app']['repo.lazaret-files'] = $repo;
|
||||
|
||||
$route = '/prod/lazaret/';
|
||||
|
||||
self::$DI['app']['EM'] = $em;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$crawler = self::$DI['client']->request(
|
||||
'GET', $route
|
||||
);
|
||||
|
||||
$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());
|
||||
|
||||
$em = $fileLazaret = $repo = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,31 +71,21 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testGetElement()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', ['find'], [], '', false);
|
||||
|
||||
$lazaretFile = $this->getOneLazaretFile();
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->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 . '/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$content = json_decode($response->getContent());
|
||||
|
||||
$this->assertGoodJsonContent($content);
|
||||
@@ -121,8 +98,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$this->assertObjectHasAttribute('pathname', $content->result);
|
||||
$this->assertObjectHasAttribute('sha256', $content->result);
|
||||
$this->assertObjectHasAttribute('uuid', $content->result);
|
||||
|
||||
$em = $lazaretFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,31 +105,20 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testGetElementException()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', ['find'], [], '', false);
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->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 . '/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertBadJsonContent(json_decode($response->getContent()));
|
||||
|
||||
$em = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,9 +127,7 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
public function testAddElement()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
//mock Doctrine\ORM\EntityManager
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$lazaretFile = $this->getOneLazaretFile();
|
||||
|
||||
@@ -205,10 +167,11 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$lazaretFile->addAttribute($lazaretAttribute);
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->will($this->returnValue($lazaretFile));
|
||||
|
||||
//In any case we expect the deletion of the lazaret file
|
||||
@@ -221,8 +184,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->method('flush');
|
||||
|
||||
self::$DI['app']['EM'] = $em;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [
|
||||
'bas_id' => $lazaretFile->getBaseId(),
|
||||
'keep_attributes' => 1,
|
||||
@@ -231,15 +192,11 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertGoodJsonContent(json_decode($response->getContent()));
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
$story->delete();
|
||||
|
||||
$em = $lazaretFile = $lazaretSession = $lazaretAttribute = $story = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,24 +204,8 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testAddElementBadRequestException()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
//mock Doctrine\ORM\EntityManager
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
|
||||
|
||||
$lazaretFile = $this->getOneLazaretFile();
|
||||
|
||||
$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
|
||||
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/force-add/', [
|
||||
'keep_attributes' => 1,
|
||||
@@ -273,13 +214,8 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertBadJsonContent(json_decode($response->getContent()));
|
||||
|
||||
$em = $lazaretFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,9 +223,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
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/', [
|
||||
'bas_id' => 1,
|
||||
'keep_attributes' => 1,
|
||||
@@ -298,9 +231,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertBadJsonContent(json_decode($response->getContent()));
|
||||
}
|
||||
@@ -372,10 +302,7 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testAcceptElement()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
//mock Doctrine\ORM\EntityManager
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
self::$DI['app']['subdef.substituer'] = $this->getMockBuilder('Alchemy\Phrasea\Media\SubdefSubstituer')
|
||||
->disableOriginalConstructor()
|
||||
@@ -427,10 +354,10 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->will($this->returnValue($lazaretFile));
|
||||
|
||||
//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['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [
|
||||
'record_id' => self::$DI['record_1']->get_record_id()
|
||||
]);
|
||||
@@ -461,14 +386,10 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
$content = json_decode($response->getContent());
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertGoodJsonContent($content);
|
||||
|
||||
$em = $lazaretFile = $collection = $databox = $record = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -476,11 +397,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
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')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -493,30 +409,22 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->will($this->returnValue($lazaretFile));
|
||||
|
||||
$id = 1;
|
||||
|
||||
self::$DI['app']['EM'] = $em;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/', [
|
||||
'record_id' => self::$DI['record_1']->get_record_id()
|
||||
]);
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertBadJsonContent(json_decode($response->getContent()));
|
||||
|
||||
$em = $lazaretFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,36 +447,15 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
public function testAcceptElementBadRequestException()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
//mock Doctrine\ORM\EntityManager
|
||||
$em = $this->getMock('Doctrine\ORM\EntityManager', [], [], '', false);
|
||||
|
||||
$lazaretFile = $this->getOneLazaretFile();
|
||||
|
||||
$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
|
||||
self::$DI['client']->request('POST', '/prod/lazaret/' . $id . '/accept/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
$this->assertBadJsonContent(json_decode($response->getContent()));
|
||||
|
||||
$em = $lazaretFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -576,11 +463,6 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
*/
|
||||
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);
|
||||
|
||||
copy(__DIR__ . '/../../../../../files/cestlafete.jpg', __DIR__ . '/../../../../../../tmp/lazaret/cestlafete.jpg');
|
||||
@@ -595,25 +477,17 @@ class LazaretTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$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')
|
||||
->with($this->equalTo('Phraseanet:LazaretFile'), $this->equalTo($id))
|
||||
->with($this->equalTo($id))
|
||||
->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/');
|
||||
|
||||
$response = self::$DI['client']->getResponse();
|
||||
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$this->assertResponseOk($response);
|
||||
|
||||
$em = $lazaretFile = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -162,8 +162,6 @@ class StoryTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
, $record->get_record_id()
|
||||
);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
if (($n % 2) === 0) {
|
||||
$crawler = self::$DI['client']->request('POST', $route);
|
||||
|
||||
|
@@ -85,7 +85,7 @@ class AccountTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
];
|
||||
|
||||
$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'])
|
||||
->getMock();
|
||||
|
||||
|
@@ -1026,7 +1026,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
self::$DI['client']->request('POST', '/login/register-classic/', $parameters);
|
||||
$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');
|
||||
}
|
||||
|
||||
@@ -1091,7 +1091,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
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->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||
@@ -1197,7 +1197,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
$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']);
|
||||
self::$DI['client']->request('POST', '/login/authenticate/', [
|
||||
'login' => $login,
|
||||
@@ -1236,7 +1235,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||
self::$DI['client']->request('POST', '/login/authenticate/', [
|
||||
'login' => $login,
|
||||
@@ -1285,7 +1283,6 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||
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()]);
|
||||
$this->logout(self::$DI['app']);
|
||||
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
$this->set_user_agent(self::USER_AGENT_FIREFOX8MAC, self::$DI['app']);
|
||||
self::$DI['client']->request('GET', '/login/authenticate/guest/');
|
||||
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
|
||||
@@ -1578,7 +1574,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->method('getEmail')
|
||||
->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();
|
||||
$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)
|
||||
->will($this->returnValue($out));
|
||||
|
||||
self::$DI['app']['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
self::$DI['app']['EM'] = $this->createEntityManagerMock();
|
||||
|
||||
self::$DI['app']['EM']->expects($this->at(0))
|
||||
->method('getRepository')
|
||||
->with('Phraseanet:UsrAuthProvider')
|
||||
->will($this->returnValue($repo));
|
||||
self::$DI['app']['repo.usr-auth-providers'] = $repo;
|
||||
|
||||
if ($participants) {
|
||||
$repo = $this->getMockBuilder('Alchemy\Phrasea\Model\Repositories\ValidationParticipantRepository')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$repo->expects($this->once())
|
||||
$repo->expects($participants ? $this->once() : $this->never())
|
||||
->method('findNotConfirmedAndNotRemindedParticipantsByExpireDate')
|
||||
->will($this->returnValue([]));
|
||||
|
||||
self::$DI['app']['EM']->expects($this->at(1))
|
||||
->method('getRepository')
|
||||
->with('Phraseanet:ValidationParticipant')
|
||||
->will($this->returnValue($repo));
|
||||
}
|
||||
self::$DI['app']['repo.validation-participants'] = $repo;
|
||||
}
|
||||
|
||||
private function mockSuggestionFinder()
|
||||
@@ -1891,7 +1877,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
private function enableRegistration()
|
||||
{
|
||||
$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'])
|
||||
->getMock();
|
||||
|
||||
@@ -1902,7 +1888,7 @@ class LoginTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
private function disableRegistration()
|
||||
{
|
||||
$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'])
|
||||
->getMock();
|
||||
|
||||
|
@@ -87,21 +87,19 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
|
||||
public function testDeleteSession()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
|
||||
|
||||
$session->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue(self::$DI['app']['authentication']->getUser()));
|
||||
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$em->expects($this->once())
|
||||
self::$DI['app']['repo.sessions'] = $this->createEntityRepositoryMock();
|
||||
self::$DI['app']['repo.sessions']->expects($this->exactly(2))
|
||||
->method('find')
|
||||
->will($this->returnValue($session));
|
||||
|
||||
$em->expects($this->once())
|
||||
->method('remove')
|
||||
->will($this->returnValue(null));
|
||||
@@ -110,41 +108,28 @@ class SessionTest extends \PhraseanetAuthenticatedWebTestCase
|
||||
->will($this->returnValue(null));
|
||||
|
||||
self::$DI['app']['EM'] = $em;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
$this->XMLHTTPRequest('POST', '/session/delete/1');
|
||||
$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()
|
||||
{
|
||||
$originalEm = self::$DI['app']['EM'];
|
||||
|
||||
$session = $this->getMock('Alchemy\Phrasea\Model\Entities\Session');
|
||||
|
||||
$session->expects($this->any())
|
||||
->method('getUser')
|
||||
->will($this->returnValue(self::$DI['user_alt1']));
|
||||
|
||||
$em = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$em = $this->createEntityManagerMock();
|
||||
|
||||
$em->expects($this->once())
|
||||
self::$DI['app']['repo.sessions'] = $this->createEntityRepositoryMock();
|
||||
self::$DI['app']['repo.sessions']->expects($this->exactly(2))
|
||||
->method('find')
|
||||
->will($this->returnValue($session));
|
||||
|
||||
self::$DI['app']['EM'] = $em;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
self::$DI['client']->request('POST', '/session/delete/1');
|
||||
$this->assertFalse(self::$DI['client']->getResponse()->isOK());
|
||||
$this->assertEquals(self::$DI['client']->getResponse()->getStatusCode(), 403);
|
||||
self::$DI['app']['EM'] = $originalEm;
|
||||
self::$DI['client'] = new Client(self::$DI['app'], []);
|
||||
|
||||
$em = null;
|
||||
}
|
||||
}
|
||||
|
@@ -90,12 +90,8 @@ class SetupTest extends \PhraseanetWebTestCase
|
||||
|
||||
public function testRouteSetupInstallerInstall()
|
||||
{
|
||||
$emMock = $this->getMock('\Doctrine\ORM\EntityManager',
|
||||
['getRepository', 'find', 'persist', 'flush'], [], '', false);
|
||||
$emMock->expects($this->any())
|
||||
->method('getRepository')
|
||||
->will($this->returnValue($this->getMock('Alchemy\Phrasea\Model\Repository\SessionRepository')));
|
||||
|
||||
$emMock = $this->createEntityManagerMock();
|
||||
$this->app['repo.sessions'] = $this->createEntityRepositoryMock();
|
||||
$this->app['EM'] = $emMock;
|
||||
|
||||
$this->app['phraseanet.configuration-tester']->expects($this->once())
|
||||
|
@@ -33,7 +33,7 @@ class RegistrationManagerTest extends \PhraseanetTestCase
|
||||
$mockDatabox->expects($this->once())->method('get_collections')->will($this->returnValue([$mockColl]));
|
||||
$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());
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\Core\Provider\RepositoriesServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\TokensServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\AuthenticationManagerServiceProvider;
|
||||
use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider;
|
||||
@@ -87,9 +88,7 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
|
||||
|
||||
$app['conf']->set(['authentication', 'captcha', 'trials-before-display'], 42);
|
||||
|
||||
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$app['EM'] = $this->createEntityManagerMock();
|
||||
self::$DI['app']['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -111,13 +110,14 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
|
||||
$app['root.path'] = __DIR__ . '/../../../../../../';
|
||||
$app->register(new AuthenticationManagerServiceProvider());
|
||||
$app->register(new ConfigurationServiceProvider());
|
||||
$app->register(new RepositoriesServiceProvider());
|
||||
$app['phraseanet.appbox'] = self::$DI['app']['phraseanet.appbox'];
|
||||
|
||||
$app['conf']->set(['authentication', 'captcha'], ['enabled' => true]);
|
||||
|
||||
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$app['EM'] = $this->createEntityManagerMock();
|
||||
$app['repo.users'] = $this->createEntityRepositoryMock();
|
||||
$app['repo.auth-failures'] = $this->createEntityRepositoryMock();
|
||||
$app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
@@ -135,9 +135,8 @@ class AuthenticationManagerServiceProviderTest extends ServiceProviderTestCase
|
||||
|
||||
$app['conf']->set(['authentication', 'captcha'], ['enabled' => false]);
|
||||
|
||||
$app['EM'] = $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$app['EM'] = $this->createEntityManagerMock();
|
||||
$app['repo.users'] = $this->createEntityRepositoryMock();
|
||||
$app['recaptcha'] = $this->getMockBuilder('Neutron\ReCaptcha\ReCaptcha')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
@@ -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'],
|
||||
];
|
||||
}
|
||||
}
|
@@ -17,7 +17,7 @@ class UserManagerTest extends \PhraseanetTestCase
|
||||
self::$DI['app']['manipulator.user']->setUserSetting($user, 'setting', false);
|
||||
self::$DI['app']['manipulator.user']->setNotificationSetting($user, 'setting', false);
|
||||
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->getNotificationSettings()->count());
|
||||
$this->assertEquals(0, $user->getQueries()->count());
|
||||
|
@@ -55,7 +55,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
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']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')
|
||||
->where($qb->expr()->eq('r.user', ':user'))
|
||||
->setParameter(':user', self::$DI['user_alt1']->getId())
|
||||
@@ -69,7 +69,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
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']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||
$service->deleteOldRegistrations();
|
||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||
@@ -79,7 +79,7 @@ class RegistrationManipulatorTest extends \PhraseanetTestCase
|
||||
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']);
|
||||
$qb = $service->getRepository()->createQueryBuilder('r');
|
||||
$qb = self::$DI['app']['repo.registrations']->createQueryBuilder('r');
|
||||
$nbRegistrationBefore = $qb->select('COUNT(r)')->getQuery()->getSingleScalarResult();
|
||||
$service->deleteRegistrationsOnCollection(self::$DI['collection']);
|
||||
$nbRegistrationAfter = $qb->getQuery()->getSingleScalarResult();
|
||||
|
@@ -104,12 +104,6 @@ class TaskManipulatorTest extends \PhraseanetTestCase
|
||||
$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()
|
||||
{
|
||||
$collection = $this->getMockBuilder('collection')
|
||||
|
@@ -11,7 +11,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
public function testCreateUser()
|
||||
{
|
||||
$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()
|
||||
@@ -25,7 +25,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
public function testCreateAdminUser()
|
||||
{
|
||||
$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->assertNotNull($user->getEmail());
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
{
|
||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'pass');
|
||||
$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());
|
||||
}
|
||||
|
||||
@@ -87,9 +87,9 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
$user2 = self::$DI['app']['manipulator.user']->createUser('login2', 'toto');
|
||||
$this->assertFalse($user2->isAdmin());
|
||||
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());
|
||||
$user2 = self::$DI['app']['manipulator.user']->getRepository()->findOneByLogin('login');
|
||||
$user2 = self::$DI['app']['repo.users']->findOneByLogin('login');
|
||||
$this->assertTrue($user2->isAdmin());
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'toto', null, true);
|
||||
$this->assertTrue($user->isAdmin());
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
{
|
||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
{
|
||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ class UserManipulatorTest extends \PhraseanetTestCase
|
||||
{
|
||||
$user = self::$DI['app']['manipulator.user']->createUser('login', 'password');
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@@ -99,49 +99,49 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
});
|
||||
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
@@ -663,4 +663,11 @@ abstract class PhraseanetTestCase extends WebTestCase
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
protected function createEntityManagerMock()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\ORM\EntityManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
}
|
||||
|
@@ -8,9 +8,9 @@ class userTest extends \PhraseanetTestCase
|
||||
public function testMail()
|
||||
{
|
||||
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');
|
||||
$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 {
|
||||
self::$DI['user']->setEmail('noonealt1@example.com');
|
||||
$this->fail('A user already got this address');
|
||||
@@ -38,7 +38,7 @@ class userTest extends \PhraseanetTestCase
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user