diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index c115cb5923..83d30aaca7 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -92,6 +92,7 @@ use Alchemy\Phrasea\Core\Provider\JMSSerializerServiceProvider; use Alchemy\Phrasea\Core\Provider\LocaleServiceProvider; use Alchemy\Phrasea\Core\Provider\NotificationDelivererServiceProvider; use Alchemy\Phrasea\Core\Provider\ORMServiceProvider; +use Alchemy\Phrasea\Core\Provider\PhraseaEventServiceProvider; use Alchemy\Phrasea\Core\Provider\PhraseanetServiceProvider; use Alchemy\Phrasea\Core\Provider\PluginServiceProvider; use Alchemy\Phrasea\Core\Provider\PhraseaVersionServiceProvider; @@ -307,6 +308,7 @@ class Application extends SilexApplication $this->register(new XPDFServiceProvider()); $this->register(new FileServeServiceProvider()); $this->register(new PluginServiceProvider()); + $this->register(new PhraseaEventServiceProvider()); $this['phraseanet.exception_handler'] = $this->share(function ($app) { return PhraseaExceptionHandler::register($app['debug']); @@ -399,11 +401,11 @@ class Application extends SilexApplication $this->extend('dispatcher', function ($dispatcher, Application $app) { $dispatcher->addListener(KernelEvents::REQUEST, array($app, 'initSession'), 254); $dispatcher->addListener(KernelEvents::RESPONSE, array($app, 'addUTF8Charset'), -128); - $dispatcher->addSubscriber(new LogoutSubscriber()); - $dispatcher->addSubscriber(new PhraseaLocaleSubscriber($app)); - $dispatcher->addSubscriber(new MaintenanceSubscriber($app)); - $dispatcher->addSubscriber(new CookiesDisablerSubscriber($app)); - $dispatcher->addSubscriber(new SessionManagerSubscriber($app)); + $dispatcher->addSubscriber($app['phraseanet.logout-subscriber']); + $dispatcher->addSubscriber($app['phraseanet.locale-subscriber']); + $dispatcher->addSubscriber($app['phraseanet.maintenance-subscriber']); + $dispatcher->addSubscriber($app['phraseanet.cookie-disabler-subscriber']); + $dispatcher->addSubscriber($app['phraseanet.session-manager-subscriber']); return $dispatcher; }) @@ -792,94 +794,6 @@ class Application extends SilexApplication $this->mount('/datafiles/', new Datafiles()); - // log real human activity on application, to keep session alive - $app = $this; - $this->before(function(Request $request) use ($app) { - - $modulesIds = array( - "prod" => 1, - "client" => 2, - "admin" => 3, - "thesaurus" => 5, - "report" => 10, - "lightbox" => 6, - ); - - $pathInfo = explode('/', $request->getPathInfo()); - - if(count($pathInfo) < 2) { - return; - } - - $moduleName = strtolower($pathInfo[1]); - if(!array_key_exists($moduleName, $modulesIds) ) { - return; - } - - // this route is polled by js in admin/databox to refresh infos (progress bar...) - if(preg_match("#^/admin/databox/[0-9]+/informations/documents/#", $request->getPathInfo()) == 1) { - return; - } - - // this route is polled by js in admin/tasks to refresh tasks status - if($request->getPathInfo() == "/admin/task-manager/tasks/" && $request->getContentType() == 'json') { - return; - } - - // if we are already disconnected (ex. from another window), quit immediatly - if(!($app['authentication']->isAuthenticated())) { - if($request->isXmlHttpRequest()) { - $r = new Response("End-Session", 403); - } - else { - $r = new RedirectResponse($app["url_generator"]->generate("homepage", array("redirect"=>'..' . $request->getPathInfo()))); - } - $r->headers->set('X-Phraseanet-End-Session', '1'); - - return $r; - } - - $session = $app['EM']->find('Entities\Session', $app['session']->get('session_id')); - - $idle = 0; - if(isset($app["phraseanet.configuration"]["session"]["idle"])) { - $idle = (int)($app["phraseanet.configuration"]["session"]["idle"]); - } - $now = new \DateTime(); - $dt = $now->getTimestamp() - $session->getUpdated()->getTimestamp(); - if($idle > 0 && $dt > $idle) { - // we must disconnet due to idletime - $app['authentication']->closeAccount(); - if($request->isXmlHttpRequest()) { - $r = new Response("End-Session", 403); - } - else { - $r = new RedirectResponse($app["url_generator"]->generate("homepage", array("redirect"=>'..' . $request->getPathInfo()))); - } - $r->headers->set('X-Phraseanet-End-Session', '1'); - - return $r; - } - - $moduleId = $modulesIds[$moduleName]; - - $session->setUpdated(new \DateTime()); - - if (!$session->hasModuleId($moduleId)) { - $module = new \Entities\SessionModule(); - $module->setModuleId($moduleId); - $module->setSession($session); - $session->addModule($module); - - $app['EM']->persist($module); - } else { - $app['EM']->persist($session->getModuleById($moduleId)->setUpdated(new \DateTime())); - } - - $app['EM']->persist($session); - $app['EM']->flush(); - }); - $this->mount('/admin/', new AdminRoot()); $this->mount('/admin/dashboard', new Dashboard()); $this->mount('/admin/collection', new Collection()); @@ -893,8 +807,6 @@ class Application extends SilexApplication $this->mount('/admin/fields', new Fields()); $this->mount('/admin/task-manager', new TaskManager()); $this->mount('/admin/subdefs', new Subdefs()); - $this->mount('/admin/tests/connection', new ConnectionTest()); - $this->mount('/admin/tests/pathurl', new PathFileTest()); $this->mount('/client/', new ClientRoot()); $this->mount('/client/baskets', new ClientBasket()); @@ -931,8 +843,6 @@ class Application extends SilexApplication $this->mount('/session/', new Session()); $this->mount('/setup', new SetupController()); - $this->mount('/setup/connection_test/', new ConnectionTest()); - $this->mount('/setup/test/', new PathFileTest()); $this->mount('/report/', new ReportRoot()); $this->mount('/report/activity', new ReportActivity()); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Root.php b/lib/Alchemy/Phrasea/Controller/Admin/Root.php index aaa8218009..b6e544764f 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Root.php @@ -12,13 +12,13 @@ namespace Alchemy\Phrasea\Controller\Admin; use Alchemy\Phrasea\Exception\SessionNotFound; +use Alchemy\Phrasea\Helper\DatabaseHelper; +use Alchemy\Phrasea\Helper\PathHelper; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; -use Alchemy\Phrasea\Controller\Root\Session; - /** * * @license http://opensource.org/licenses/gpl-3.0 GPLv3 @@ -452,6 +452,24 @@ class Root implements ControllerProviderInterface ->assert('bit', '\d+') ->bind('database_submit_statusbit'); + $controllers->get('/tests/connection/mysql/', function (Application $app, Request $request) { + $dbHelper = new DatabaseHelper($app, $request); + + return $app->json($dbHelper->checkConnection()); + }); + + $controllers->get('/tests/pathurl/path/', function (Application $app, Request $request) { + $pathHelper = new PathHelper($app, $request); + + return $app->json($pathHelper->checkPath()); + }); + + $controllers->get('/tests/pathurl/url/', function (Application $app, Request $request) { + $pathHelper = new PathHelper($app, $request); + + return $app->json($pathHelper->checkUrl()); + }); + return $controllers; } } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Language.php b/lib/Alchemy/Phrasea/Controller/Prod/Language.php index 93b58f1ac7..a1ece019fa 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Language.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Language.php @@ -21,13 +21,13 @@ use Silex\ControllerProviderInterface; */ class Language implements ControllerProviderInterface { - public function connect(Application $app) { $controller = $app['controllers_factory']; - $controller->get("/", function (Application $app) { + $app['firewall']->addMandatoryAuthentication($controller); + $controller->get("/", function (Application $app) { $out = array(); $out['thesaurusBasesChanged'] = _('prod::recherche: Attention : la liste des bases selectionnees pour la recherche a ete changee.'); $out['confirmDel'] = _('paniers::Vous etes sur le point de supprimer ce panier. Cette action est irreversible. Souhaitez-vous continuer ?'); diff --git a/lib/Alchemy/Phrasea/Controller/Root/Session.php b/lib/Alchemy/Phrasea/Controller/Root/Session.php index 0ecce7976b..96e88b54e4 100644 --- a/lib/Alchemy/Phrasea/Controller/Root/Session.php +++ b/lib/Alchemy/Phrasea/Controller/Root/Session.php @@ -39,7 +39,7 @@ class Session implements ControllerProviderInterface ->bind('update_session'); $controllers->post('/notifications/', $this->call('getNotifications')) - ->bind('get_notifications'); + ->bind('list_notifications'); $controller = $controllers->post('/delete/{id}', $this->call('deleteSession')) ->bind('delete_session'); diff --git a/lib/Alchemy/Phrasea/Controller/Setup.php b/lib/Alchemy/Phrasea/Controller/Setup.php index ade1de05f8..f1a023491c 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup.php +++ b/lib/Alchemy/Phrasea/Controller/Setup.php @@ -12,6 +12,8 @@ namespace Alchemy\Phrasea\Controller; use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Helper\DatabaseHelper; +use Alchemy\Phrasea\Helper\PathHelper; use Alchemy\Phrasea\Setup\Requirements\BinariesRequirements; use Alchemy\Phrasea\Setup\Requirements\FilesystemRequirements; use Alchemy\Phrasea\Setup\Requirements\LocalesRequirements; @@ -46,6 +48,24 @@ class Setup implements ControllerProviderInterface $controllers->post('/installer/install/', 'controller.setup:doInstall') ->bind('install_do_install'); + $controllers->get('/connection_test/mysql/', function (Application $app, Request $request) { + $dbHelper = new DatabaseHelper($app, $request); + + return $app->json($dbHelper->checkConnection()); + }); + + $controllers->get('/test/path/', function (Application $app, Request $request) { + $pathHelper = new PathHelper($app, $request); + + return $app->json($pathHelper->checkPath()); + }); + + $controllers->get('/test/url/', function (Application $app, Request $request) { + $pathHelper = new PathHelper($app, $request); + + return $app->json($pathHelper->checkUrl()); + }); + return $controllers; } diff --git a/lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php b/lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php deleted file mode 100644 index 6f9073c689..0000000000 --- a/lib/Alchemy/Phrasea/Controller/Utils/ConnectionTest.php +++ /dev/null @@ -1,90 +0,0 @@ -get('/mysql/', function (Application $app) { - - $request = $app['request']; - $hostname = $request->query->get('hostname', '127.0.0.1'); - $port = (int) $request->query->get('port', 3306); - $user = $request->query->get('user'); - $password = $request->query->get('password'); - $dbname = $request->query->get('dbname'); - - $connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false; - - try { - $conn = new \connection_pdo('test', $hostname, $port, $user, $password, null, array(), false); - $connection_ok = true; - } catch (\Exception $e) { - - } - - if ($dbname && $connection_ok === true) { - try { - $conn = new \connection_pdo('test', $hostname, $port, $user, $password, $dbname, array(), false); - $db_ok = true; - - $sql = "SHOW TABLE STATUS"; - $stmt = $conn->prepare($sql); - $stmt->execute(); - - $empty = $stmt->rowCount() === 0; - - $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) { - if ($row["Name"] === 'sitepreff') { - $is_appbox = true; - } - if ($row["Name"] === 'pref') { - $is_databox = true; - } - } - } catch (\Exception $e) { - - } - } - - $datas = array( - 'connection' => $connection_ok - , 'database' => $db_ok - , 'is_empty' => $empty - , 'is_appbox' => $is_appbox - , 'is_databox' => $is_databox - ); - - return $app->json($datas); - }); - - return $controllers; - } -} diff --git a/lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php b/lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php deleted file mode 100644 index 6de61b4887..0000000000 --- a/lib/Alchemy/Phrasea/Controller/Utils/PathFileTest.php +++ /dev/null @@ -1,50 +0,0 @@ -get('/path/', function (Application $app, Request $request) { - return $app->json(array( - 'exists' => file_exists($request->query->get('path')) - , 'file' => is_file($request->query->get('path')) - , 'dir' => is_dir($request->query->get('path')) - , 'readable' => is_readable($request->query->get('path')) - , 'writeable' => is_writable($request->query->get('path')) - , 'executable' => is_executable($request->query->get('path')) - )); - }); - - $controllers->get('/url/', function (Application $app, Request $request) { - return $app->json(array('code' => \http_query::getHttpCodeFromUrl($request->query->get('url')))); - }); - - return $controllers; - } -} diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/SessionManagerSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/SessionManagerSubscriber.php index 049314c33f..1e20a94867 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/SessionManagerSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/SessionManagerSubscriber.php @@ -32,11 +32,11 @@ class SessionManagerSubscriber implements EventSubscriberInterface public static function getSubscribedEvents() { return array( - KernelEvents::REQUEST => array('onKernelRequest', -112), + KernelEvents::REQUEST => array('checkSessionActivity', -112), ); } - public function onKernelRequest(GetResponseEvent $event) + public function checkSessionActivity(GetResponseEvent $event) { $modulesIds = array( "prod" => 1, diff --git a/lib/Alchemy/Phrasea/Core/Provider/PhraseaEventServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/PhraseaEventServiceProvider.php new file mode 100644 index 0000000000..0524371f9b --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Provider/PhraseaEventServiceProvider.php @@ -0,0 +1,46 @@ +share(function(Application $app) { + return new LogoutSubscriber(); + }); + $app['phraseanet.locale-subscriber'] = $app->share(function(Application $app) { + return new PhraseaLocaleSubscriber($app); + }); + $app['phraseanet.maintenance-subscriber'] = $app->share(function(Application $app) { + return new MaintenanceSubscriber($app); + }); + $app['phraseanet.cookie-disabler-subscriber'] = $app->share(function(Application $app) { + return new CookiesDisablerSubscriber($app); + }); + $app['phraseanet.session-manager-subscriber'] = $app->share(function(Application $app) { + return new SessionManagerSubscriber($app); + }); + } + + public function boot(Application $app) + { + } +} diff --git a/lib/Alchemy/Phrasea/Helper/DatabaseHelper.php b/lib/Alchemy/Phrasea/Helper/DatabaseHelper.php new file mode 100644 index 0000000000..244ec4519c --- /dev/null +++ b/lib/Alchemy/Phrasea/Helper/DatabaseHelper.php @@ -0,0 +1,70 @@ +request->query->get('hostname', '127.0.0.1'); + $port = (int) $this->request->query->get('port', 3306); + $user = $this->request->query->get('user'); + $password = $this->request->query->get('password'); + $dbname = $this->request->query->get('dbname'); + + $connection_ok = $db_ok = $is_databox = $is_appbox = $empty = false; + + try { + $conn = new \connection_pdo('test', $hostname, $port, $user, $password, null, array(), false); + $connection_ok = true; + } catch (\Exception $e) { + + } + + if ($dbname && $connection_ok === true) { + try { + $conn = new \connection_pdo('test', $hostname, $port, $user, $password, $dbname, array(), false); + $db_ok = true; + + $sql = "SHOW TABLE STATUS"; + $stmt = $conn->prepare($sql); + $stmt->execute(); + + $empty = $stmt->rowCount() === 0; + + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + foreach ($rs as $row) { + if ($row["Name"] === 'sitepreff') { + $is_appbox = true; + } + if ($row["Name"] === 'pref') { + $is_databox = true; + } + } + } catch (\Exception $e) { + + } + } + + return array( + 'connection' => $connection_ok, + 'database' => $db_ok, + 'is_empty' => $empty, + 'is_appbox' => $is_appbox, + 'is_databox' => $is_databox + ); + } +} diff --git a/lib/Alchemy/Phrasea/Helper/PathHelper.php b/lib/Alchemy/Phrasea/Helper/PathHelper.php new file mode 100644 index 0000000000..2093a5f2fe --- /dev/null +++ b/lib/Alchemy/Phrasea/Helper/PathHelper.php @@ -0,0 +1,34 @@ + file_exists($this->request->query->get('path')), + 'file' => is_file($this->request->query->get('path')), + 'dir' => is_dir($this->request->query->get('path')), + 'readable' => is_readable($this->request->query->get('path')), + 'writeable' => is_writable($this->request->query->get('path')), + 'executable' => is_executable($this->request->query->get('path')), + ); + } + + public function checkUrl() + { + return array('code' => \http_query::getHttpCodeFromUrl($this->request->query->get('url'))); + } +} diff --git a/templates/web/admin/index.html.twig b/templates/web/admin/index.html.twig index e3e0f22ecf..356be5e091 100644 --- a/templates/web/admin/index.html.twig +++ b/templates/web/admin/index.html.twig @@ -48,7 +48,7 @@ function pollNotifications(){ $.ajax({ type: "POST", - url: "{{ path('get_notifications') }}", + url: "{{ path('list_notifications') }}", dataType: 'json', data: { module : 3, diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index 756cfd9939..40aacdca74 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -1025,7 +1025,7 @@ function pollNotifications(){ $.ajax({ type: "POST", - url: "{{ path('get_notifications') }}", + url: "{{ path('list_notifications') }}", dataType: "json", data: { module : 1, diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php index 93df91f20a..4b3dfddda6 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Admin/RootTest.php @@ -19,4 +19,104 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract self::$DI['client']->request('GET', '/admin/'); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); } + + public function testRouteMysql() + { + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; + + $params = array( + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], + "password" => $connexion['password'], + "dbname" => $connexion['dbname'], + ); + + self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); + $response = self::$DI['client']->getResponse(); + $this->assertTrue($response->isOk()); + } + + public function testRouteMysqlFailed() + { + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; + + $params = array( + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], + "password" => "fakepassword", + "dbname" => $connexion['dbname'], + ); + + self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); + $response = self::$DI['client']->getResponse(); + $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); + $this->assertTrue($response->isOk()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('connection', $content); + $this->assertObjectHasAttribute('database', $content); + $this->assertObjectHasAttribute('is_empty', $content); + $this->assertObjectHasAttribute('is_appbox', $content); + $this->assertObjectHasAttribute('is_databox', $content); + $this->assertFalse($content->connection); + } + + public function testRouteMysqlDbFailed() + { + $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; + + $params = array( + "hostname" => $connexion['host'], + "port" => $connexion['port'], + "user" => $connexion['user'], + "password" => $connexion['password'], + "dbname" => "fake-DTABASE-name" + ); + + self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); + $response = self::$DI['client']->getResponse(); + $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); + $this->assertTrue($response->isOk()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('connection', $content); + $this->assertObjectHasAttribute('database', $content); + $this->assertObjectHasAttribute('is_empty', $content); + $this->assertObjectHasAttribute('is_appbox', $content); + $this->assertObjectHasAttribute('is_databox', $content); + $this->assertFalse($content->database); + } + + /** + * Default route test + */ + public function testRoutePath() + { + $file = new \SplFileObject(__DIR__ . '/../../../../../files/cestlafete.jpg'); + self::$DI['client']->request("GET", "/admin/tests/pathurl/path/", array('path' => $file->getPathname())); + + $response = self::$DI['client']->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); + $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue(is_object($content)); + $this->assertObjectHasAttribute('exists', $content); + $this->assertObjectHasAttribute('file', $content); + $this->assertObjectHasAttribute('dir', $content); + $this->assertObjectHasAttribute('readable', $content); + $this->assertObjectHasAttribute('executable', $content); + } + + public function testRouteUrl() + { + self::$DI['client']->request("GET", "/admin/tests/pathurl/url/", array('url' => "www.google.com")); + + $response = self::$DI['client']->getResponse(); + $this->assertTrue($response->isOk()); + $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); + $content = json_decode(self::$DI['client']->getResponse()->getContent()); + $this->assertTrue(is_object($content)); + } } diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php index 77dcbb3ae8..2137a323c9 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LanguageTest.php @@ -2,15 +2,13 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod; -class ControllerLanguageTest extends \PhraseanetWebTestCaseAbstract +class ControllerLanguageTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { protected $client; public function testRootPost() { - $route = '/prod/language/'; - - self::$DI['client']->request("GET", $route); + self::$DI['client']->request("GET", '/prod/language/'); $this->assertTrue(self::$DI['client']->getResponse()->isOk()); $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); $pageContent = json_decode(self::$DI['client']->getResponse()->getContent()); diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php index 28047ed2c1..f05af7292f 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/LazaretTest.php @@ -3,6 +3,7 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod; use Alchemy\Phrasea\Border\Attribute\AttributeInterface; +use Alchemy\Phrasea\Core\Event\Subscriber\SessionManagerSubscriber; use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Response; @@ -15,9 +16,11 @@ class LazaretTest extends \PhraseanetWebTestCaseAuthenticatedAbstract protected $client; protected static $need_records = false; - public function tearDown() + public function setUp() { - parent::tearDown(); + parent::setUp(); + + self::$DI['app']['dispatcher']->removeSubscriber(self::$DI['app']['phraseanet.session-manager-subscriber']); } /** diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php deleted file mode 100644 index c7594c1b1f..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Controller/Utils/ConnectionTestTest.php +++ /dev/null @@ -1,78 +0,0 @@ - $connexion['host'], - "port" => $connexion['port'], - "user" => $connexion['user'], - "password" => $connexion['password'], - "dbname" => $connexion['dbname'], - ); - - self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); - $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); - } - - public function testRouteMysqlFailed() - { - $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; - - $params = array( - "hostname" => $connexion['host'], - "port" => $connexion['port'], - "user" => $connexion['user'], - "password" => "fakepassword", - "dbname" => $connexion['dbname'], - ); - - self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); - $response = self::$DI['client']->getResponse(); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $this->assertTrue($response->isOk()); - $this->assertTrue(is_object($content)); - $this->assertObjectHasAttribute('connection', $content); - $this->assertObjectHasAttribute('database', $content); - $this->assertObjectHasAttribute('is_empty', $content); - $this->assertObjectHasAttribute('is_appbox', $content); - $this->assertObjectHasAttribute('is_databox', $content); - $this->assertFalse($content->connection); - } - - public function testRouteMysqlDbFailed() - { - $connexion = self::$DI['app']['phraseanet.configuration']['main']['database']; - - $params = array( - "hostname" => $connexion['host'], - "port" => $connexion['port'], - "user" => $connexion['user'], - "password" => $connexion['password'], - "dbname" => "fake-DTABASE-name" - ); - - self::$DI['client']->request("GET", "/admin/tests/connection/mysql/", $params); - $response = self::$DI['client']->getResponse(); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $this->assertTrue($response->isOk()); - $this->assertTrue(is_object($content)); - $this->assertObjectHasAttribute('connection', $content); - $this->assertObjectHasAttribute('database', $content); - $this->assertObjectHasAttribute('is_empty', $content); - $this->assertObjectHasAttribute('is_appbox', $content); - $this->assertObjectHasAttribute('is_databox', $content); - $this->assertFalse($content->database); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php deleted file mode 100644 index 80bb5e4262..0000000000 --- a/tests/Alchemy/Tests/Phrasea/Controller/Utils/PathFileTestTest.php +++ /dev/null @@ -1,37 +0,0 @@ -request("GET", "/admin/tests/pathurl/path/", array('path' => $file->getPathname())); - - $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue(is_object($content)); - $this->assertObjectHasAttribute('exists', $content); - $this->assertObjectHasAttribute('file', $content); - $this->assertObjectHasAttribute('dir', $content); - $this->assertObjectHasAttribute('readable', $content); - $this->assertObjectHasAttribute('executable', $content); - } - - public function testRouteUrl() - { - self::$DI['client']->request("GET", "/admin/tests/pathurl/url/", array('url' => "www.google.com")); - - $response = self::$DI['client']->getResponse(); - $this->assertTrue($response->isOk()); - $this->assertEquals("application/json", self::$DI['client']->getResponse()->headers->get("content-type")); - $content = json_decode(self::$DI['client']->getResponse()->getContent()); - $this->assertTrue(is_object($content)); - } -} diff --git a/tests/classes/PhraseanetPHPUnitListener.php b/tests/classes/PhraseanetPHPUnitListener.php index 3e8c0cb2d1..1f914bf202 100644 --- a/tests/classes/PhraseanetPHPUnitListener.php +++ b/tests/classes/PhraseanetPHPUnitListener.php @@ -40,6 +40,7 @@ class PhraseanetPHPUnitListener implements PHPUnit_Framework_TestListener public function startTest(PHPUnit_Framework_Test $test) { + echo $test->getName() . "\n"; return; }