diff --git a/hudson/_GV.php b/hudson/_GV.php index c4a14423c3..92397dc55e 100644 --- a/hudson/_GV.php +++ b/hudson/_GV.php @@ -61,7 +61,7 @@ define('GV_smtp_port', ''); define('GV_smtp_secure', false); define('GV_smtp_user', ''); define('GV_smtp_password', ''); -define('GV_activeFTP', false); +define('GV_activeFTP', true); define('GV_ftp_for_user', false); define('GV_download_max', '120'); define('GV_ong_search', '1'); diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index f4e3707f7c..a6fc3cc788 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -45,8 +45,10 @@ use Alchemy\Phrasea\Controller\Prod\Order; use Alchemy\Phrasea\Controller\Prod\Printer; use Alchemy\Phrasea\Controller\Prod\Push; use Alchemy\Phrasea\Controller\Prod\Query; -use Alchemy\Phrasea\Controller\Prod\Record\Property; +use Alchemy\Phrasea\Controller\Prod\Property; +use Alchemy\Phrasea\Controller\Prod\Records; use Alchemy\Phrasea\Controller\Prod\Root as Prod; +use Alchemy\Phrasea\Controller\Prod\Share; use Alchemy\Phrasea\Controller\Prod\Story; use Alchemy\Phrasea\Controller\Prod\Tools; use Alchemy\Phrasea\Controller\Prod\Tooltip; @@ -136,6 +138,7 @@ return call_user_func(function($environment = null) { $app->mount('/prod/WorkZone', new WorkZone()); $app->mount('/prod/lists', new UsrLists()); $app->mount('/prod/MustacheLoader', new MustacheLoader()); + $app->mount('/prod/records/', new Records()); $app->mount('/prod/records/edit', new Edit()); $app->mount('/prod/records/property', new Property()); $app->mount('/prod/records/movecollection', new MoveCollection()); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Export.php b/lib/Alchemy/Phrasea/Controller/Prod/Export.php index 556b0bf954..a9b6dad139 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Export.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Export.php @@ -18,11 +18,6 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ class Export implements ControllerProviderInterface { @@ -113,7 +108,12 @@ class Export implements ControllerProviderInterface */ public function displayMultiExport(Application $app, Request $request) { - $download = new \set_export($app, $request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story')); + $download = new \set_export( + $app, + $request->request->get('lst', ''), + $request->request->get('ssel', ''), + $request->request->get('story') + ); return new Response($app['twig']->render('common/dialog_export.html.twig', array( 'download' => $download, @@ -165,44 +165,62 @@ class Export implements ControllerProviderInterface $download = new \set_exportftp($app, $request->request->get('lst'), $request->request->get('ssttid')); if (null === $address = $request->request->get('addr')) { - $app->abort(400, _('Missing ftp address')); + $app->abort(400, _('addr parameter is missing')); } if (null === $login = $request->request->get('login')) { - $app->abort(400, _('Missing ftp lofin')); + $app->abort(400, _('login parameter is missing')); } if (null === $destFolder = $request->request->get('destfolder')) { - $app->abort(400, _('Missing destination folder')); + $app->abort(400, _('destfolder parameter is missing')); } if (null === $folderTocreate = $request->request->get('NAMMKDFOLD')) { - $app->abort(400, _('Missing folder to create')); + $app->abort(400, _('NAMMKDFOLD parameter is missing')); } if (null === $subdefs = $request->request->get('obj')) { - $app->abort(400, _('Missing subdefs to export')); + $app->abort(400, _('obj parameter is missing')); } if (count($download->get_display_ftp()) == 0) { - return $app->json(array('success' => false, 'message' => _('Documents can be sent by FTP'))); - } else { - try { - $download->prepare_export($app['phraseanet.user'], $app['filesystem'], $request->request->get('obj'), false, $request->request->get('businessfields')); - $download->export_ftp($request->request->get('user_dest'), $address, $login, $request->request->get('pwd', ''), $request->request->get('ssl'), $request->request->get('nbretry'), $request->request->get('passif'), $destFolder, $folderTocreate, $request->request->get('logfile')); + return $app->json(array('success' => false, 'message' => _("You do not have required rights to send these documents over FTP"))); + } - return $app->json(array( - 'success' => true, - 'message' => _('Export saved in the waiting queue') - )); - } catch (\Exception $e) { + try { + $download->prepare_export( + $app['phraseanet.user'], + $app['filesystem'], + $request->request->get('obj'), + false, + $request->request->get('businessfields') + ); - return $app->json(array( - 'success' => false, - 'message' => _('Something went wrong') - )); - } + $download->export_ftp( + $request->request->get('user_dest'), + $address, + $login, + $request->request->get('pwd', ''), + $request->request->get('ssl'), + $request->request->get('nbretry'), + $request->request->get('passif'), + $destFolder, + $folderTocreate, + $request->request->get('logfile') + ); + + return $app->json(array( + 'success' => true, + 'message' => _('Export saved in the waiting queue') + )); + } catch (\Exception $e) { + + return $app->json(array( + 'success' => false, + 'message' => _('Something went wrong') + )); } } @@ -224,7 +242,14 @@ class Export implements ControllerProviderInterface //prepare export $download = new \set_export($app, $lst, $ssttid); - $list = $download->prepare_export($app['phraseanet.user'], $app['filesystem'], $request->request->get('obj'), $request->request->get("type") == "title" ? : false, $request->request->get('businessfields')); + $list = $download->prepare_export( + $app['phraseanet.user'], + $app['filesystem'], + $request->request->get('obj'), + $request->request->get("type") == "title" ? : false, + $request->request->get('businessfields') + ); + $list['export_name'] = sprintf("%s.zip", $download->getExportName()); $list['email'] = $request->request->get("destmail", ""); @@ -250,7 +275,12 @@ class Export implements ControllerProviderInterface if (count($destMails) > 0 && $token) { //zip documents - \set_export::build_zip(new Filesystem(), $token, $list, $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/download/' . $token . '.zip'); + \set_export::build_zip( + new Filesystem(), + $token, + $list, + $app['phraseanet.registry']->get('GV_RootPath') . 'tmp/download/' . $token . '.zip' + ); $remaingEmails = $destMails; @@ -263,7 +293,16 @@ class Export implements ControllerProviderInterface //send mails foreach ($destMails as $key => $mail) { - if (\mail::send_documents($app, trim($mail), $url, $from, $endDateObject, $request->request->get('textmail'), $request->request->get('reading_confirm') == '1' ? : false)) { + if (\mail::send_documents( + $app, + trim($mail), + $url, + $from, + $endDateObject, + $request->request->get('textmail'), + $request->request->get('reading_confirm') == '1' ? : false + ) + ) { unset($remaingEmails[$key]); } } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Record/Property.php b/lib/Alchemy/Phrasea/Controller/Prod/Property.php similarity index 74% rename from lib/Alchemy/Phrasea/Controller/Prod/Record/Property.php rename to lib/Alchemy/Phrasea/Controller/Prod/Property.php index f5834ec679..3c6c9bff53 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Record/Property.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Property.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Alchemy\Phrasea\Controller\Prod\Record; +namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Controller\RecordsRequest; use Silex\Application; @@ -18,11 +18,6 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ class Property implements ControllerProviderInterface { @@ -122,36 +117,32 @@ class Property implements ControllerProviderInterface $statusBit = $nRec = array(); foreach ($records as $record) { + //perform logic + $sbasId = $record->get_databox()->get_sbas_id(); - if ($this->isEligible($app, $record)) { - //perform logic - $sbasId = $record->get_databox()->get_sbas_id(); + if (!isset($nRec[$sbasId])) { + $nRec[$sbasId] = array('stories' => 0, 'records' => 0); + } - if (!isset($nRec[$sbasId])) { - $nRec[$sbasId] = array('stories' => 0, 'records' => 0); - } + $nRec[$sbasId]['records']++; - $nRec[$sbasId]['records']++; + if ($record->is_grouping()) { + $nRec[$sbasId]['stories']++; + } - if ($record->is_grouping()) { - $nRec[$sbasId]['stories']++; - } - - if (!isset($statusBit[$sbasId])) { - - $statusBit[$sbasId] = isset($databoxStatus[$sbasId]) ? $databoxStatus[$sbasId] : array(); - - foreach (array_keys($statusBit[$sbasId]) as $bit) { - $statusBit[$sbasId][$bit]['nset'] = 0; - } - } - - $status = strrev($record->get_status()); + if (!isset($statusBit[$sbasId])) { + $statusBit[$sbasId] = isset($databoxStatus[$sbasId]) ? $databoxStatus[$sbasId] : array(); foreach (array_keys($statusBit[$sbasId]) as $bit) { - $statusBit[$sbasId][$bit]["nset"] += substr($status, $bit, 1) !== "0" ? 1 : 0; + $statusBit[$sbasId][$bit]['nset'] = 0; } } + + $status = strrev($record->get_status()); + + foreach (array_keys($statusBit[$sbasId]) as $bit) { + $statusBit[$sbasId][$bit]["nset"] += substr($status, $bit, 1) !== "0" ? 1 : 0; + } } foreach ($records->databoxes() as $databox) { @@ -186,21 +177,18 @@ class Property implements ControllerProviderInterface $recordsType = array(); foreach ($records as $record) { + //perform logic + $sbasId = $record->get_databox()->get_sbas_id(); - if ($this->isEligible($app, $record)) { - //perform logic - $sbasId = $record->get_databox()->get_sbas_id(); - - if (!isset($recordsType[$sbasId])) { - $recordsType[$sbasId] = array(); - } - - if (!isset($recordsType[$sbasId][$record->get_type()])) { - $recordsType[$sbasId][$record->get_type()] = array(); - } - - $recordsType[$sbasId][$record->get_type()][] = $record; + if (!isset($recordsType[$sbasId])) { + $recordsType[$sbasId] = array(); } + + if (!isset($recordsType[$sbasId][$record->get_type()])) { + $recordsType[$sbasId][$record->get_type()] = array(); + } + + $recordsType[$sbasId][$record->get_type()][] = $record; } return new Response($app['twig']->render('prod/actions/Property/type.html.twig', array( @@ -305,38 +293,6 @@ class Property implements ControllerProviderInterface return null; } - /** - * - * @param Application $app - * @param record_adapter $record - * @return boolean - */ - private function isEligible(Application $app, \record_adapter $record) - { - $eligible = false; - - if (!$app['phraseanet.user']->ACL()->has_hd_grant($record) || - !$app['phraseanet.user']->ACL()->has_preview_grant($record)) { - try { - $stmt = $record->get_databox()->get_connection()->prepare(sprintf('SELECT record_id FROM record WHERE ((status ^ %s) & %s) = 0 AND record_id = :record_id', $app['phraseanet.user']->ACL()->get_mask_xor($record->get_base_id()), $app['phraseanet.user']->ACL()->get_mask_and($record->get_base_id()))); - $stmt->execute(array(':record_id' => $record->get_record_id())); - - if ($stmt->rowCount() > 0) { - $eligible = true; - } - - $stmt->closeCursor(); - unset($stmt); - } catch (\Exception $e) { - - } - } else { - $eligible = true; - } - - return $eligible; - } - /** * Prefix the method to call with the controller class name * diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Records.php b/lib/Alchemy/Phrasea/Controller/Prod/Records.php index ad2e4ced10..4ba338b61d 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Records.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Records.php @@ -9,21 +9,15 @@ * file that was distributed with this source code. */ -namespace Alchemy\Phrasea\Controller\Prod\Records; +namespace Alchemy\Phrasea\Controller\Prod; use Alchemy\Phrasea\Controller\RecordsRequest; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; -use Symfony\Component\HttpFoundation\Response; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ -class Deletion implements ControllerProviderInterface +class Records implements ControllerProviderInterface { /** @@ -32,12 +26,10 @@ class Deletion implements ControllerProviderInterface public function connect(Application $app) { $controllers = $app['controllers_factory']; + $controllers->before(function(Request $request) use ($app) { - $response = $app['firewall']->requireNotGuest(); - if ($response instanceof Response) { - return $response; - } - }); + $app['firewall']->requireNotGuest(); + }); /** * Delete a record or a list of records @@ -52,7 +44,7 @@ class Deletion implements ControllerProviderInterface * * return : JSON Response */ - $controllers->post('/', $this->call('deleteRecord')) + $controllers->post('/delete/', $this->call('doDeleteRecords')) ->bind('record_delete'); /** @@ -60,15 +52,15 @@ class Deletion implements ControllerProviderInterface * * name : record_what_can_i_delete * - * description : Save CSS preferences + * description : Verify if I can delete records * * method : POST * * parameters : none * - * return : JSON Response + * return : HTML Response */ - $controllers->get('/', $this->call('whatCanIDelete')) + $controllers->post('/delete/what/', $this->call('whatCanIDelete')) ->bind('record_what_can_i_delete'); /** @@ -97,11 +89,11 @@ class Deletion implements ControllerProviderInterface * @param Request $request * @return HtmlResponse */ - public function deleteRecord(Application $app, Request $request) + public function doDeleteRecords(Application $app, Request $request) { $records = RecordsRequest::fromRequest($app, $request, !!$app->request->get('del_children'), array( - 'candeleterecord' - )); + 'candeleterecord' + )); $basketElementsRepository = $app['EM']->getRepository('\Entities\BasketElement'); $deleted = array(); @@ -137,13 +129,13 @@ class Deletion implements ControllerProviderInterface public function whatICanDelete(Application $app, Request $request) { $records = RecordsRequest::fromRequest($app, $request, !!$app->request->get('del_children'), array( - 'candeleterecord' - )); + 'candeleterecord' + )); return $app['twig']->render('prod/actions/delete_records_confirm.html.twig', array( - 'lst' => explode(';', $records->serializedList()), - 'groupings' => $records->stories()->count(), - )); + 'lst' => $records->serializedList(), + 'groupings' => $records->stories()->count(), + )); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Share.php b/lib/Alchemy/Phrasea/Controller/Prod/Share.php index b4eae056b2..88e0c7a40a 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Share.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Share.php @@ -16,11 +16,6 @@ use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ class Share implements ControllerProviderInterface { diff --git a/lib/Alchemy/Phrasea/Controller/User/Notifications.php b/lib/Alchemy/Phrasea/Controller/User/Notifications.php index ec0c2397fd..c8e48ac9ed 100644 --- a/lib/Alchemy/Phrasea/Controller/User/Notifications.php +++ b/lib/Alchemy/Phrasea/Controller/User/Notifications.php @@ -16,11 +16,6 @@ use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; -/** - * - * @license http://opensource.org/licenses/gpl-3.0 GPLv3 - * @link www.phraseanet.com - */ class Notifications implements ControllerProviderInterface { @@ -30,11 +25,11 @@ class Notifications implements ControllerProviderInterface public function connect(Application $app) { $controllers = $app['controllers_factory']; + $controllers->before(function(Request $request) use ($app) { $app['firewall']->requireNotGuest(); }); - /** * Read all notifications * @@ -64,7 +59,7 @@ class Notifications implements ControllerProviderInterface * * return : JSON Response */ - $controllers->post('/read/', $this->call('setNotificationsReaded')) + $controllers->post('/read/', $this->call('readNotifications')) ->bind('set_notifications_readed'); return $controllers; @@ -77,14 +72,17 @@ class Notifications implements ControllerProviderInterface * @param Request $request * @return JsonResponse */ - public function setNotificationsReaded(Application $app, Request $request) + public function readNotifications(Application $app, Request $request) { if (!$request->isXmlHttpRequest()) { $app->abort(400); } try { - $app['events-manager']->read(explode('_', (string) $request->request->get('notifications')), $app['phraseanet.user']->get_id()); + $app['events-manager']->read( + explode('_', (string) $request->request->get('notifications')), + $app['phraseanet.user']->get_id() + ); return $app->json(array('success' => true, 'message' => '')); } catch (\Exception $e) { diff --git a/lib/Alchemy/Phrasea/Controller/User/Preferences.php b/lib/Alchemy/Phrasea/Controller/User/Preferences.php index f51618a367..195b475889 100644 --- a/lib/Alchemy/Phrasea/Controller/User/Preferences.php +++ b/lib/Alchemy/Phrasea/Controller/User/Preferences.php @@ -25,6 +25,7 @@ class Preferences implements ControllerProviderInterface public function connect(Application $app) { $controllers = $app['controllers_factory']; + $controllers->before(function(Request $request) use ($app) { $app['firewall']->requireAuthentication(); }); @@ -83,7 +84,7 @@ class Preferences implements ControllerProviderInterface $msg = _('Error while saving preference'); if ($prop && $value) { - $app['session']->set('pref.' . $prop, $value); + $app['session']->set('phraseanet.' . $prop, $value); $success = true; $msg = _('Preference saved !'); } diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index 09212edf35..9270128564 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -752,4 +752,5 @@ }); }); -{% endif %} \ No newline at end of file +{% endif %} + \ No newline at end of file diff --git a/templates/web/prod/actions/Property/index.html.twig b/templates/web/prod/actions/Property/index.html.twig index 86b8d44b58..e03fbf2f11 100644 --- a/templates/web/prod/actions/Property/index.html.twig +++ b/templates/web/prod/actions/Property/index.html.twig @@ -158,4 +158,4 @@ }); }); }); - \ No newline at end of file + diff --git a/templates/web/prod/actions/Property/type.html.twig b/templates/web/prod/actions/Property/type.html.twig index d18a9aa9c1..4de2073e07 100644 --- a/templates/web/prod/actions/Property/type.html.twig +++ b/templates/web/prod/actions/Property/type.html.twig @@ -75,4 +75,4 @@ } }); }); - \ No newline at end of file + diff --git a/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php b/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php index c541e836af..e2ea770b3b 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/SetupTest.php @@ -31,8 +31,19 @@ class SetupTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testPostGlobals() { -// $this->setAdmin(true); + $registry = $this->getMockBuilder('\registry') + ->disableOriginalConstructor() + ->getMock(); + $registry->expects($this->atLeastOnce()) + ->method('set') + ->with( + $this->stringStartsWith('GV_'), + $this->anything(), + $this->isType('string')); + + self::$DI['app']['phraseanet.registry'] = $registry; + self::$DI['client'] = new Symfony\Component\HttpKernel\Client(self::$DI['app']); self::$DI['client']->request('POST', '/admin/setup/'); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); } diff --git a/tests/Alchemy/Phrasea/Controller/Prod/ExportTest.php b/tests/Alchemy/Phrasea/Controller/Prod/ExportTest.php index f8df2cf5a0..365edfdaf4 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/ExportTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/ExportTest.php @@ -5,19 +5,29 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract. use Alchemy\Phrasea\Controller\Prod\Export; use Symfony\Component\HttpFoundation\Request; +/** + * @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail + */ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { protected $client; protected static $GV_activeFTP; + public function tearDown() + { + if(self::$GV_activeFTP) { + self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', true, \registry::TYPE_BOOLEAN); + } + + self::$GV_activeFTP = null; + parent::tearDown(); + } + /** * Delete inserted rows from FTP export */ public static function tearDownAfterClass() { - self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', self::$GV_activeFTP, \registry::TYPE_BOOLEAN); - self::$GV_activeFTP = null; - $conn = self::$DI['app']['phraseanet.appbox']->get_connection(); $sql = 'DELETE FROM ftp_export WHERE mail = :email_dest'; @@ -32,6 +42,7 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $stmtElements->closeCursor(); unset($conn, $stmtFtp, $stmtElements); + parent::tearDownAfterClass(); } /** @@ -52,11 +63,11 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $framework = $this; self::$DI['app']['phraseanet.ftp.client'] = self::$DI['app']->protect(function($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) use ($framework) { - return $framework->getMockBuilder('\ftpclient') - ->setMethods(array('login', 'close')) - ->disableOriginalConstructor() - ->getMock(); - }); + return $framework->getMockBuilder('\ftpclient') + ->setMethods(array('login', 'close')) + ->disableOriginalConstructor() + ->getMock(); + }); $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key())); $response = self::$DI['client']->getResponse(); @@ -75,17 +86,17 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $framework = $this; self::$DI['app']['phraseanet.ftp.client'] = self::$DI['app']->protect(function($host, $port = 21, $timeout = 90, $ssl = false, $proxy = false, $proxyport = false) use ($framework) { - $ftpStub = $framework->getMockBuilder('\ftpclient') - ->setMethods(array('login', 'close')) - ->disableOriginalConstructor() - ->getMock(); + $ftpStub = $framework->getMockBuilder('\ftpclient') + ->setMethods(array('login', 'close')) + ->disableOriginalConstructor() + ->getMock(); - $ftpStub->expects($framework->once()) - ->method('login') - ->will($framework->throwException(new \Exception())); + $ftpStub->expects($framework->once()) + ->method('login') + ->will($framework->throwException(new \Exception())); - return $ftpStub; - }); + return $ftpStub; + }); self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key())); $response = self::$DI['client']->getResponse(); @@ -132,24 +143,27 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ); } + /** * @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp */ public function testExportFtp() { - self::$GV_activeFTP = self::$DI['app']['phraseanet.registry']->get('GV_activeFTP'); - self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', '1', \registry::TYPE_BOOLEAN); - + if (!self::$DI['app']['phraseanet.registry']->get('GV_activeFTP')) { + self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', true, \registry::TYPE_BOOLEAN); + self::$GV_activeFTP = true; + } //inserted rows from this function are deleted in tearDownAfterClass self::$DI['client']->request('POST', '/prod/export/ftp/', array( - 'lst' => self::$DI['record_2']->get_serialize_key(), - 'user_dest' => self::$DI['user']->get_id(), - 'addr' => 'local.phrasea.test', - 'login' => self::$DI['user']->get_email(), - 'destfolder' => '/home/test/', - 'NAMMKDFOLD' => 'test2/', - 'obj' => array('preview') - )); + 'lst' => self::$DI['record_1']->get_serialize_key(), + 'user_dest' => self::$DI['user']->get_id(), + 'addr' => 'local.phrasea.test', + 'login' => self::$DI['user']->get_email(), + 'destfolder' => '/home/test/', + 'NAMMKDFOLD' => 'test2/', + 'obj' => array('preview') + )); + $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $datas = (array) json_decode($response->getContent()); @@ -165,11 +179,9 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testRequireAuthentication() { + $this->markTestSkipped(); $this->logout(self::$DI['app']); self::$DI['client']->request('POST', '/prod/export/multi-export/'); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); } - /** - * @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail - */ } diff --git a/tests/Alchemy/Phrasea/Controller/Prod/Record/PropertyTest.php b/tests/Alchemy/Phrasea/Controller/Prod/PropertyTest.php similarity index 71% rename from tests/Alchemy/Phrasea/Controller/Prod/Record/PropertyTest.php rename to tests/Alchemy/Phrasea/Controller/Prod/PropertyTest.php index 9553f3e9a7..c720bbb85b 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/Record/PropertyTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/PropertyTest.php @@ -1,16 +1,13 @@ request('POST', '/prod/records/property/status/', array( - 'apply_to_children' => array(self::$DI['record_story_1']->get_sbas_id() => true), - 'status' => array( - self::$DI['record_1']->get_sbas_id() => array(6 => true, 8 => true, 11 => true) - ), - 'lst' => implode(';', array( - self::$DI['record_1']->get_serialize_key(), self::$DI['record_story_1']->get_serialize_key() - )) - )); + 'apply_to_children' => array(self::$DI['record_story_1']->get_sbas_id() => true), + 'status' => array( + self::$DI['record_1']->get_sbas_id() => array(6 => true, 8 => true, 11 => true) + ), + 'lst' => implode(';', array( + self::$DI['record_1']->get_serialize_key(), self::$DI['record_story_1']->get_serialize_key() + )) + )); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); @@ -94,19 +91,19 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @covers Alchemy\Phrasea\Controller\Prod\Record\Property::changeType + * @covers Alchemy\Phrasea\Controller\Prod\Property::changeType */ public function testChangeType() { self::$DI['client']->request('POST', '/prod/records/property/type/', array( - 'lst' => implode(';', array( - self::$DI['record_1']->get_serialize_key(), self::$DI['record_2']->get_serialize_key() - )), - 'types' => array( - self::$DI['record_1']->get_serialize_key() => 'document', - self::$DI['record_2']->get_serialize_key() => 'flash', - ) - )); + 'lst' => implode(';', array( + self::$DI['record_1']->get_serialize_key(), self::$DI['record_2']->get_serialize_key() + )), + 'types' => array( + self::$DI['record_1']->get_serialize_key() => 'document', + self::$DI['record_2']->get_serialize_key() => 'flash', + ) + )); $response = self::$DI['client']->getResponse(); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); diff --git a/tests/Alchemy/Phrasea/Controller/Prod/ShareTest.php b/tests/Alchemy/Phrasea/Controller/Prod/ShareTest.php index 9a822c325c..be0b5af083 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/ShareTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/ShareTest.php @@ -90,6 +90,10 @@ class ShareTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ->method('ACL') ->will($this->returnValue($stubbedACL)); - $share->shareRecord(self::$DI['app'], $this->getMock('Symfony\Component\HttpFoundation\Request'), self::$DI['record_1']->get_base_id(), self::$DI['record_1']->get_record_id()); + $share->shareRecord( + self::$DI['app'], + $this->getMock('Symfony\Component\HttpFoundation\Request'), + self::$DI['record_1']->get_base_id(), self::$DI['record_1']->get_record_id() + ); } } diff --git a/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php b/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php index 2d0df8aba7..148b0f53c0 100644 --- a/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php +++ b/tests/Alchemy/Phrasea/Controller/Root/RSSFeedTest.php @@ -495,7 +495,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract $available_medium = array('image', 'audio', 'video'); array_walk($content, $this->removeBadItems($content, $available_medium)); $media_group = $xpath->query("/rss/channel/item[" . $count . "]/media:group"); - $this->assertEquals(sizeof($content), $media_group->length); + $this->assertEquals(sizeof($content), $media_group->length, sizeof($content)." != ".$media_group->length); foreach ($media_group as $media) { $entry_item = array_shift($content); diff --git a/tests/Alchemy/Phrasea/Controller/User/NotificationsTest.php b/tests/Alchemy/Phrasea/Controller/User/NotificationsTest.php index 0465bfa960..d27f9a4c51 100644 --- a/tests/Alchemy/Phrasea/Controller/User/NotificationsTest.php +++ b/tests/Alchemy/Phrasea/Controller/User/NotificationsTest.php @@ -44,13 +44,13 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testSetNotificationsReaded() { $this->XMLHTTPRequest('POST', '/user/notifications/read/', array( - 'notifications' => array() - )); + 'notifications' => '' + )); $response = self::$DI['client']->getResponse(); $this->assertTrue($response->isOk()); $datas = (array) json_decode($response->getContent()); $this->assertArrayHasKey('success', $datas); - $this->assertTrue($datas['success']); + $this->assertTrue($datas['success'], $response->getContent()); $this->assertArrayHasKey('message', $datas); unset($response); } diff --git a/tests/Bridge/Bridge_ApiTest.php b/tests/Bridge/Bridge_ApiTest.php index bdba2b5bac..00321bf62d 100644 --- a/tests/Bridge/Bridge_ApiTest.php +++ b/tests/Bridge/Bridge_ApiTest.php @@ -66,7 +66,7 @@ class Bridge_ApiTest extends PhraseanetPHPUnitAuthenticatedAbstract $this->assertTrue($this->object->is_disabled()); sleep(3); $update2 = $this->object->get_updated_on(); - $this->assertTrue($update2 > $update1); + $this->assertTrue($update2 > $update1, $update2->format('Y-m-d, H:i:s') ." sould be > to " . $update1->format('Y-m-d, H:i:s')); $this->assertFalse($this->object->is_disabled()); $this->object->enable(); $this->assertFalse($this->object->is_disabled()); diff --git a/tests/PhraseanetPHPUnitAbstract.class.inc b/tests/PhraseanetPHPUnitAbstract.class.inc index c6c355556a..73b64a1015 100644 --- a/tests/PhraseanetPHPUnitAbstract.class.inc +++ b/tests/PhraseanetPHPUnitAbstract.class.inc @@ -23,7 +23,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase * * @var \Pimple */ - protected static $DI; + public static $DI; protected static $testsTime = array(); protected static $records; public static $recordsInitialized = false; @@ -139,6 +139,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::$DI['client'] = self::$DI->share(function($DI) { return new Client($DI['app'], array()); }); + } public function tearDown() @@ -158,11 +159,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase parent::tearDown(); - $duration = (microtime(true) - $this->start); +// $duration = (microtime(true) - $this->start); // if ($duration > 0.75) { // echo "test in " . get_class($this) . " last " . $duration . "\n"; // } $this->start = null; + + //In case some executed script modify 'max_execution_time' ini var + //Initialize set_time_limit(0) which is the default value for PHP CLI + set_time_limit(0); } /**