diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index 1ee962e211..5899044b9e 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -29,7 +29,9 @@ return call_user_func(function() if (!\setup::is_installed()) { - return $app->redirect("/setup/")->send(); + $response = new \Symfony\Component\HttpFoundation\RedirectResponse('/setup/'); + + return $response->send(); } $app->get('/', function() use ($app) @@ -46,9 +48,8 @@ return call_user_func(function() return $app->redirect("/login/?redirect=/client"); }); - $app->get('robots.txt', function() use ($app) + $app->get('/robots.txt', function() use ($app) { - require __DIR__ . "/../lib/bootstrap.php"; $appbox = \appbox::get_instance(); $registry = $appbox->get_registry(); @@ -64,7 +65,7 @@ return call_user_func(function() . "Disallow: /\n"; } - $response = new Response($buffer, 200, array('Content-Type: text/plain')); + $response = new Response($buffer, 200, array('Content-Type' => 'text/plain')); $response->setCharset('UTF-8'); return $response; diff --git a/lib/Alchemy/Phrasea/Application/Setup.php b/lib/Alchemy/Phrasea/Application/Setup.php index 8f1020c953..9fea1063bb 100644 --- a/lib/Alchemy/Phrasea/Application/Setup.php +++ b/lib/Alchemy/Phrasea/Application/Setup.php @@ -198,19 +198,12 @@ return call_user_func(function() $app->error(function($e) use ($app) { - if ($e instanceof Exception_Setup_PhraseaAlreadyInstalled) + if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled) + { + return $app->redirect('/login/'); + } - return $app->redirect('/login'); - - return new Response( - sprintf( - 'Error %s @%s:%s' - , $e->getFile() - , $e->getLine() - , $e->getMessage() - ) - , 500 - ); + return new Response('Internal Server Error', 500); }); return $app; diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 3202510f16..94a961fa81 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -136,7 +136,7 @@ class Installer implements ControllerProviderInterface $servername = $request->getScheme() . '://' . $request->getHttpHost() . '/'; $setupRegistry = new \Setup_Registry(); - $setupRegistry->set('GV_ServerName', $servername); + $setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING); $conn = $connbas = null; @@ -174,7 +174,7 @@ class Installer implements ControllerProviderInterface try { $setupRegistry = new \Setup_Registry(); - $setupRegistry->set('GV_ServerName', $servername); + $setupRegistry->set('GV_ServerName', $servername, \registry::TYPE_STRING); $appbox = \appbox::create($setupRegistry, $conn, $appbox_name, true); @@ -221,22 +221,22 @@ class Installer implements ControllerProviderInterface $appbox->set_registry($registry); - $registry->set('GV_base_datapath_noweb', \p4string::addEndSlash($request->get('datapath_noweb'))); - $registry->set('GV_base_datapath_web', \p4string::addEndSlash($request->get('datapath_web'))); - $registry->set('GV_base_dataurl', \p4string::addEndSlash($request->get('mount_point_web'))); - $registry->set('GV_ServerName', $servername); - $registry->set('GV_cli', $request->get('binary_php')); - $registry->set('GV_imagick', $request->get('binary_convert')); - $registry->set('GV_pathcomposite', $request->get('binary_composite')); - $registry->set('GV_exiftool', $request->get('binary_exiftool')); - $registry->set('GV_swf_extract', $request->get('binary_swfextract')); - $registry->set('GV_pdf2swf', $request->get('binary_pdf2swf')); - $registry->set('GV_swf_render', $request->get('binary_swfrender')); - $registry->set('GV_unoconv', $request->get('binary_unoconv')); - $registry->set('GV_ffmpeg', $request->get('binary_ffmpeg')); - $registry->set('GV_mp4box', $request->get('binary_MP4Box')); - $registry->set('GV_mplayer', $request->get('binary_mplayer')); - $registry->set('GV_pdftotext', $request->get('binary_xpdf')); + $registry->set('GV_base_datapath_noweb', \p4string::addEndSlash($request->get('datapath_noweb')), \registry::TYPE_STRING); + $registry->set('GV_base_datapath_web', \p4string::addEndSlash($request->get('datapath_web')), \registry::TYPE_STRING); + $registry->set('GV_base_dataurl', \p4string::addEndSlash($request->get('mount_point_web')), \registry::TYPE_STRING); + $registry->set('GV_ServerName', $servername, \registry::TYPE_STRING); + $registry->set('GV_cli', $request->get('binary_php'), \registry::TYPE_STRING); + $registry->set('GV_imagick', $request->get('binary_convert'), \registry::TYPE_STRING); + $registry->set('GV_pathcomposite', $request->get('binary_composite'), \registry::TYPE_STRING); + $registry->set('GV_exiftool', $request->get('binary_exiftool'), \registry::TYPE_STRING); + $registry->set('GV_swf_extract', $request->get('binary_swfextract'), \registry::TYPE_STRING); + $registry->set('GV_pdf2swf', $request->get('binary_pdf2swf'), \registry::TYPE_STRING); + $registry->set('GV_swf_render', $request->get('binary_swfrender'), \registry::TYPE_STRING); + $registry->set('GV_unoconv', $request->get('binary_unoconv'), \registry::TYPE_STRING); + $registry->set('GV_ffmpeg', $request->get('binary_ffmpeg'), \registry::TYPE_STRING); + $registry->set('GV_mp4box', $request->get('binary_MP4Box'), \registry::TYPE_STRING); + $registry->set('GV_mplayer', $request->get('binary_mplayer'), \registry::TYPE_STRING); + $registry->set('GV_pdftotext', $request->get('binary_xpdf'), \registry::TYPE_STRING); $user = \User_Adapter::create($appbox, $request->get('email'), $request->get('password'), $request->get('email'), true); diff --git a/lib/Alchemy/Phrasea/Out/Module/PDF.php b/lib/Alchemy/Phrasea/Out/Module/PDF.php index 5e84e26027..b1dbcf9787 100644 --- a/lib/Alchemy/Phrasea/Out/Module/PDF.php +++ b/lib/Alchemy/Phrasea/Out/Module/PDF.php @@ -106,10 +106,10 @@ class PDF switch ($layout) { case "preview": - $this->print_preview(); + $this->print_preview(false); break; case "previewCaption": - $this->print_preview(); + $this->print_preview(false); break; case "previewCaptionTdm": $this->print_preview(true); @@ -329,7 +329,7 @@ class PDF $this->pdf->SetLeftMargin($lmargin); } - protected function print_preview($withtdm=false) + protected function print_preview($withtdm) { $appbox = \appbox::get_instance(); $registry = \registry::get_instance(); diff --git a/lib/classes/Setup/Registry.class.php b/lib/classes/Setup/Registry.class.php index cef6827c56..a7117f7c20 100644 --- a/lib/classes/Setup/Registry.class.php +++ b/lib/classes/Setup/Registry.class.php @@ -26,7 +26,7 @@ class Setup_Registry implements registryInterface return isset($this->datas[$key]) ? $this->datas[$key] : $defaultvalue; } - public function set($key, $value) + public function set($key, $value, $type) { $this->datas[$key] = $value; } diff --git a/lib/classes/registry.class.php b/lib/classes/registry.class.php index d6345477d8..ca98869192 100644 --- a/lib/classes/registry.class.php +++ b/lib/classes/registry.class.php @@ -153,7 +153,7 @@ class registry implements registryInterface * @param mixed $value * @return registry */ - public function set($key, $value, $type = 'string') + public function set($key, $value, $type) { $this->load(); $delete_cache = false; diff --git a/lib/classes/registryInterface.class.php b/lib/classes/registryInterface.class.php index a51833fefb..3b0dfecc8e 100644 --- a/lib/classes/registryInterface.class.php +++ b/lib/classes/registryInterface.class.php @@ -19,7 +19,7 @@ interface registryInterface { public function get($key, $defaultvalue = null); - public function set($key, $value); + public function set($key, $value, $type); public function is_set($key); diff --git a/lib/classes/task/period/upgradetov32.class.php b/lib/classes/task/period/upgradetov32.class.php index c3d1138b6c..93452561f6 100644 --- a/lib/classes/task/period/upgradetov32.class.php +++ b/lib/classes/task/period/upgradetov32.class.php @@ -61,8 +61,8 @@ class task_period_upgradetov32 extends task_abstract printf("taskid %s starting." . PHP_EOL, $this->get_task_id()); $registry = registry::get_instance(); - $registry->set('GV_cache_server_type', 'nocache'); - $registry->set('GV_sphinx', false); + $registry->set('GV_cache_server_type', 'nocache', \registry::TYPE_STRING); + $registry->set('GV_sphinx', false, \registry::TYPE_BOOLEAN); if (!$this->sbas_id) { diff --git a/lib/unitTest/Alchemy/Phrasea/Application/OverviewTest.php b/lib/unitTest/Alchemy/Phrasea/Application/OverviewTest.php index f7db0476ee..cb3647fdb6 100644 --- a/lib/unitTest/Alchemy/Phrasea/Application/OverviewTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Application/OverviewTest.php @@ -50,13 +50,8 @@ class ApplicationOverviewTest extends PhraseanetWebTestCaseAuthenticatedAbstract return require __DIR__ . '/../../../../Alchemy/Phrasea/Application/Overview.php'; } -//$deliver_content = function(session $session, record_adapter $record, $subdef, $watermark, $stamp, $app) -// -//$app->get('/datafiles/{sbas_id}/{record_id}/{subdef}/' - function testDatafilesRouteAuthenticated() { -// $this->client->followRedirects(); $registry = registry::get_instance(); $crawler = $this->client->request('GET', '/datafiles/' . self::$record_1->get_sbas_id() . '/' . self::$record_1->get_record_id() . '/preview/'); $response = $this->client->getResponse(); diff --git a/lib/unitTest/Alchemy/Phrasea/Application/RootTest.php b/lib/unitTest/Alchemy/Phrasea/Application/RootTest.php index 697a28fa6d..971f7e9944 100644 --- a/lib/unitTest/Alchemy/Phrasea/Application/RootTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Application/RootTest.php @@ -26,9 +26,40 @@ class ApplicationRootTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteSlash() { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $crawler = $this->client->request('GET', '/'); + $response = $this->client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertRegExp('/^\/login\/\?redirect=[\/a-zA-Z]+/', $response->headers->get('location')); + } + + public function testRouteRobots() + { + $registry = \registry::get_instance(); + + $original_value = $registry->get('GV_allow_search_engine'); + + $registry->set('GV_allow_search_engine', false, \registry::TYPE_BOOLEAN); + + $crawler = $this->client->request('GET', '/robots.txt'); + $response = $this->client->getResponse(); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type')); + $this->assertEquals('UTF-8', $response->getCharset()); + + $this->assertRegExp('/^Disallow: \/$/m', $response->getContent()); + + $registry = \registry::get_instance(); + $registry->set('GV_allow_search_engine', true, \registry::TYPE_BOOLEAN); + + $crawler = $this->client->request('GET', '/robots.txt'); + $response = $this->client->getResponse(); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('text/plain; charset=UTF-8', $response->headers->get('Content-Type')); + $this->assertEquals('UTF-8', $response->getCharset()); + + $this->assertRegExp('/^Allow: \/$/m', $response->getContent()); + + $registry->set('GV_allow_search_engine', $original_value, \registry::TYPE_BOOLEAN); } } diff --git a/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php b/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php index 9ad795b963..5a1b51acd6 100644 --- a/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Application/SetupTest.php @@ -26,9 +26,10 @@ class ApplicationSetupTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteSlash() { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $crawler = $this->client->request('GET', '/'); + $response = $this->client->getResponse(); + $this->assertEquals(302, $response->getStatusCode()); + $this->assertEquals('/login/', $response->headers->get('location')); } } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php index 36faaabb98..46f666b578 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/DescriptionTest.php @@ -45,18 +45,18 @@ class DescriptionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testRouteSlash() { $this->markTestIncomplete(); - + $appbox = appbox::get_instance(); $databox = array_shift($appbox->get_databoxes()); $fields = $databox->get_meta_structure(); - + $fieldIds = array(); - + foreach($fields as $field) { $fieldIds[] = $field->get_id(); } - + $this->client->request("POST", "/description/" . $databox->get_sbas_id()); } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/RootTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/RootTest.php index 0a159f9f0d..ae6ed50484 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/RootTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/RootTest.php @@ -46,7 +46,7 @@ class RootTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $this->client->request('GET', '/', array('section' => 'base:featured')); $this->assertTrue($this->client->getResponse()->isOk()); - + $this->client->request('GET', '/'); $this->assertTrue($this->client->getResponse()->isOk()); } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php index caaebeea2b..ff586db044 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Admin/UsersTest.php @@ -207,7 +207,7 @@ class ControllerUsersTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->client->request('POST', '/users/search/export/'); $response = $this->client->getResponse(); $this->assertTrue($response->isOK()); - $this->assertRegexp("#text/plain#", $response->headers->get("content-type")); + $this->assertEquals("text/plain; charset=UTF-8", $response->headers->get("Content-type")); $this->assertEquals("attachment; filename=export.txt", $response->headers->get("content-disposition")); } diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/PrinterTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/PrinterTest.php index e97c65f366..b4878ea80c 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/PrinterTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/PrinterTest.php @@ -23,7 +23,7 @@ class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract * $need_records = 2; * */ - protected static $need_records = 2; + protected static $need_records = 4; /** * The application loader @@ -62,7 +62,9 @@ class ControllerPrinterTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $records = array( self::$record_1->get_serialize_key(), - self::$record_2->get_serialize_key() + self::$record_2->get_serialize_key(), + self::$record_3->get_serialize_key(), + self::$record_4->get_serialize_key(), ); $lst = implode(';', $records);