Add missing class declaration

Fix tests

Update tests

Fix CS
This commit is contained in:
Nicolas Le Goff
2012-10-17 15:27:00 +02:00
parent a837ede270
commit ec8d577a41
19 changed files with 227 additions and 213 deletions

View File

@@ -61,7 +61,7 @@ define('GV_smtp_port', '');
define('GV_smtp_secure', false); define('GV_smtp_secure', false);
define('GV_smtp_user', ''); define('GV_smtp_user', '');
define('GV_smtp_password', ''); define('GV_smtp_password', '');
define('GV_activeFTP', false); define('GV_activeFTP', true);
define('GV_ftp_for_user', false); define('GV_ftp_for_user', false);
define('GV_download_max', '120'); define('GV_download_max', '120');
define('GV_ong_search', '1'); define('GV_ong_search', '1');

View File

@@ -45,8 +45,10 @@ use Alchemy\Phrasea\Controller\Prod\Order;
use Alchemy\Phrasea\Controller\Prod\Printer; use Alchemy\Phrasea\Controller\Prod\Printer;
use Alchemy\Phrasea\Controller\Prod\Push; use Alchemy\Phrasea\Controller\Prod\Push;
use Alchemy\Phrasea\Controller\Prod\Query; 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\Root as Prod;
use Alchemy\Phrasea\Controller\Prod\Share;
use Alchemy\Phrasea\Controller\Prod\Story; use Alchemy\Phrasea\Controller\Prod\Story;
use Alchemy\Phrasea\Controller\Prod\Tools; use Alchemy\Phrasea\Controller\Prod\Tools;
use Alchemy\Phrasea\Controller\Prod\Tooltip; 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/WorkZone', new WorkZone());
$app->mount('/prod/lists', new UsrLists()); $app->mount('/prod/lists', new UsrLists());
$app->mount('/prod/MustacheLoader', new MustacheLoader()); $app->mount('/prod/MustacheLoader', new MustacheLoader());
$app->mount('/prod/records/', new Records());
$app->mount('/prod/records/edit', new Edit()); $app->mount('/prod/records/edit', new Edit());
$app->mount('/prod/records/property', new Property()); $app->mount('/prod/records/property', new Property());
$app->mount('/prod/records/movecollection', new MoveCollection()); $app->mount('/prod/records/movecollection', new MoveCollection());

View File

@@ -18,11 +18,6 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Export implements ControllerProviderInterface class Export implements ControllerProviderInterface
{ {
@@ -113,7 +108,12 @@ class Export implements ControllerProviderInterface
*/ */
public function displayMultiExport(Application $app, Request $request) 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( return new Response($app['twig']->render('common/dialog_export.html.twig', array(
'download' => $download, 'download' => $download,
@@ -165,44 +165,62 @@ class Export implements ControllerProviderInterface
$download = new \set_exportftp($app, $request->request->get('lst'), $request->request->get('ssttid')); $download = new \set_exportftp($app, $request->request->get('lst'), $request->request->get('ssttid'));
if (null === $address = $request->request->get('addr')) { 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')) { 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')) { 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')) { 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')) { 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) { if (count($download->get_display_ftp()) == 0) {
return $app->json(array('success' => false, 'message' => _('Documents can be sent by FTP'))); return $app->json(array('success' => false, 'message' => _("You do not have required rights to send these documents over 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( try {
'success' => true, $download->prepare_export(
'message' => _('Export saved in the waiting queue') $app['phraseanet.user'],
)); $app['filesystem'],
} catch (\Exception $e) { $request->request->get('obj'),
false,
$request->request->get('businessfields')
);
return $app->json(array( $download->export_ftp(
'success' => false, $request->request->get('user_dest'),
'message' => _('Something went wrong') $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 //prepare export
$download = new \set_export($app, $lst, $ssttid); $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['export_name'] = sprintf("%s.zip", $download->getExportName());
$list['email'] = $request->request->get("destmail", ""); $list['email'] = $request->request->get("destmail", "");
@@ -250,7 +275,12 @@ class Export implements ControllerProviderInterface
if (count($destMails) > 0 && $token) { if (count($destMails) > 0 && $token) {
//zip documents //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; $remaingEmails = $destMails;
@@ -263,7 +293,16 @@ class Export implements ControllerProviderInterface
//send mails //send mails
foreach ($destMails as $key => $mail) { 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]); unset($remaingEmails[$key]);
} }
} }

View File

@@ -9,7 +9,7 @@
* file that was distributed with this source code. * 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 Alchemy\Phrasea\Controller\RecordsRequest;
use Silex\Application; use Silex\Application;
@@ -18,11 +18,6 @@ use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Property implements ControllerProviderInterface class Property implements ControllerProviderInterface
{ {
@@ -122,36 +117,32 @@ class Property implements ControllerProviderInterface
$statusBit = $nRec = array(); $statusBit = $nRec = array();
foreach ($records as $record) { foreach ($records as $record) {
//perform logic
$sbasId = $record->get_databox()->get_sbas_id();
if ($this->isEligible($app, $record)) { if (!isset($nRec[$sbasId])) {
//perform logic $nRec[$sbasId] = array('stories' => 0, 'records' => 0);
$sbasId = $record->get_databox()->get_sbas_id(); }
if (!isset($nRec[$sbasId])) { $nRec[$sbasId]['records']++;
$nRec[$sbasId] = array('stories' => 0, 'records' => 0);
}
$nRec[$sbasId]['records']++; if ($record->is_grouping()) {
$nRec[$sbasId]['stories']++;
}
if ($record->is_grouping()) { if (!isset($statusBit[$sbasId])) {
$nRec[$sbasId]['stories']++; $statusBit[$sbasId] = isset($databoxStatus[$sbasId]) ? $databoxStatus[$sbasId] : array();
}
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());
foreach (array_keys($statusBit[$sbasId]) as $bit) { 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) { foreach ($records->databoxes() as $databox) {
@@ -186,21 +177,18 @@ class Property implements ControllerProviderInterface
$recordsType = array(); $recordsType = array();
foreach ($records as $record) { foreach ($records as $record) {
//perform logic
$sbasId = $record->get_databox()->get_sbas_id();
if ($this->isEligible($app, $record)) { if (!isset($recordsType[$sbasId])) {
//perform logic $recordsType[$sbasId] = array();
$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][$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( return new Response($app['twig']->render('prod/actions/Property/type.html.twig', array(
@@ -305,38 +293,6 @@ class Property implements ControllerProviderInterface
return null; 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 * Prefix the method to call with the controller class name
* *

View File

@@ -9,21 +9,15 @@
* file that was distributed with this source code. * 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 Alchemy\Phrasea\Controller\RecordsRequest;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
/** class Records implements ControllerProviderInterface
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Deletion implements ControllerProviderInterface
{ {
/** /**
@@ -32,12 +26,10 @@ class Deletion implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
$response = $app['firewall']->requireNotGuest(); $app['firewall']->requireNotGuest();
if ($response instanceof Response) { });
return $response;
}
});
/** /**
* Delete a record or a list of records * Delete a record or a list of records
@@ -52,7 +44,7 @@ class Deletion implements ControllerProviderInterface
* *
* return : JSON Response * return : JSON Response
*/ */
$controllers->post('/', $this->call('deleteRecord')) $controllers->post('/delete/', $this->call('doDeleteRecords'))
->bind('record_delete'); ->bind('record_delete');
/** /**
@@ -60,15 +52,15 @@ class Deletion implements ControllerProviderInterface
* *
* name : record_what_can_i_delete * name : record_what_can_i_delete
* *
* description : Save CSS preferences * description : Verify if I can delete records
* *
* method : POST * method : POST
* *
* parameters : none * 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'); ->bind('record_what_can_i_delete');
/** /**
@@ -97,11 +89,11 @@ class Deletion implements ControllerProviderInterface
* @param Request $request * @param Request $request
* @return HtmlResponse * @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( $records = RecordsRequest::fromRequest($app, $request, !!$app->request->get('del_children'), array(
'candeleterecord' 'candeleterecord'
)); ));
$basketElementsRepository = $app['EM']->getRepository('\Entities\BasketElement'); $basketElementsRepository = $app['EM']->getRepository('\Entities\BasketElement');
$deleted = array(); $deleted = array();
@@ -137,13 +129,13 @@ class Deletion implements ControllerProviderInterface
public function whatICanDelete(Application $app, Request $request) public function whatICanDelete(Application $app, Request $request)
{ {
$records = RecordsRequest::fromRequest($app, $request, !!$app->request->get('del_children'), array( $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( return $app['twig']->render('prod/actions/delete_records_confirm.html.twig', array(
'lst' => explode(';', $records->serializedList()), 'lst' => $records->serializedList(),
'groupings' => $records->stories()->count(), 'groupings' => $records->stories()->count(),
)); ));
} }
/** /**

View File

@@ -16,11 +16,6 @@ use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Share implements ControllerProviderInterface class Share implements ControllerProviderInterface
{ {

View File

@@ -16,11 +16,6 @@ use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Notifications implements ControllerProviderInterface class Notifications implements ControllerProviderInterface
{ {
@@ -30,11 +25,11 @@ class Notifications implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireNotGuest(); $app['firewall']->requireNotGuest();
}); });
/** /**
* Read all notifications * Read all notifications
* *
@@ -64,7 +59,7 @@ class Notifications implements ControllerProviderInterface
* *
* return : JSON Response * return : JSON Response
*/ */
$controllers->post('/read/', $this->call('setNotificationsReaded')) $controllers->post('/read/', $this->call('readNotifications'))
->bind('set_notifications_readed'); ->bind('set_notifications_readed');
return $controllers; return $controllers;
@@ -77,14 +72,17 @@ class Notifications implements ControllerProviderInterface
* @param Request $request * @param Request $request
* @return JsonResponse * @return JsonResponse
*/ */
public function setNotificationsReaded(Application $app, Request $request) public function readNotifications(Application $app, Request $request)
{ {
if (!$request->isXmlHttpRequest()) { if (!$request->isXmlHttpRequest()) {
$app->abort(400); $app->abort(400);
} }
try { 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' => '')); return $app->json(array('success' => true, 'message' => ''));
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -25,6 +25,7 @@ class Preferences implements ControllerProviderInterface
public function connect(Application $app) public function connect(Application $app)
{ {
$controllers = $app['controllers_factory']; $controllers = $app['controllers_factory'];
$controllers->before(function(Request $request) use ($app) { $controllers->before(function(Request $request) use ($app) {
$app['firewall']->requireAuthentication(); $app['firewall']->requireAuthentication();
}); });
@@ -83,7 +84,7 @@ class Preferences implements ControllerProviderInterface
$msg = _('Error while saving preference'); $msg = _('Error while saving preference');
if ($prop && $value) { if ($prop && $value) {
$app['session']->set('pref.' . $prop, $value); $app['session']->set('phraseanet.' . $prop, $value);
$success = true; $success = true;
$msg = _('Preference saved !'); $msg = _('Preference saved !');
} }

View File

@@ -752,4 +752,5 @@
}); });
}); });
</script> </script>
{% endif %} {% endif %}

View File

@@ -158,4 +158,4 @@
}); });
}); });
}); });
</script> </script>

View File

@@ -75,4 +75,4 @@
} }
}); });
}); });
</script> </script>

View File

@@ -31,8 +31,19 @@ class SetupTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testPostGlobals() 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/'); self::$DI['client']->request('POST', '/admin/setup/');
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
} }

View File

@@ -5,19 +5,29 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.
use Alchemy\Phrasea\Controller\Prod\Export; use Alchemy\Phrasea\Controller\Prod\Export;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/**
* @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail
*/
class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client; protected $client;
protected static $GV_activeFTP; 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 * Delete inserted rows from FTP export
*/ */
public static function tearDownAfterClass() 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(); $conn = self::$DI['app']['phraseanet.appbox']->get_connection();
$sql = 'DELETE FROM ftp_export WHERE mail = :email_dest'; $sql = 'DELETE FROM ftp_export WHERE mail = :email_dest';
@@ -32,6 +42,7 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
$stmtElements->closeCursor(); $stmtElements->closeCursor();
unset($conn, $stmtFtp, $stmtElements); unset($conn, $stmtFtp, $stmtElements);
parent::tearDownAfterClass();
} }
/** /**
@@ -52,11 +63,11 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$framework = $this; $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) { 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') return $framework->getMockBuilder('\ftpclient')
->setMethods(array('login', 'close')) ->setMethods(array('login', 'close'))
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
}); });
$this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key())); $this->XMLHTTPRequest('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -75,17 +86,17 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
$framework = $this; $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) { 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') $ftpStub = $framework->getMockBuilder('\ftpclient')
->setMethods(array('login', 'close')) ->setMethods(array('login', 'close'))
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$ftpStub->expects($framework->once()) $ftpStub->expects($framework->once())
->method('login') ->method('login')
->will($framework->throwException(new \Exception())); ->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())); self::$DI['client']->request('POST', '/prod/export/ftp/test/', array('lst' => self::$DI['record_1']->get_serialize_key()));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
@@ -132,24 +143,27 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
); );
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp * @covers Alchemy\Phrasea\Controller\Prod\Export::exportFtp
*/ */
public function testExportFtp() public function testExportFtp()
{ {
self::$GV_activeFTP = self::$DI['app']['phraseanet.registry']->get('GV_activeFTP'); if (!self::$DI['app']['phraseanet.registry']->get('GV_activeFTP')) {
self::$DI['app']['phraseanet.registry']->set('GV_activeFTP', '1', \registry::TYPE_BOOLEAN); 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 //inserted rows from this function are deleted in tearDownAfterClass
self::$DI['client']->request('POST', '/prod/export/ftp/', array( self::$DI['client']->request('POST', '/prod/export/ftp/', array(
'lst' => self::$DI['record_2']->get_serialize_key(), 'lst' => self::$DI['record_1']->get_serialize_key(),
'user_dest' => self::$DI['user']->get_id(), 'user_dest' => self::$DI['user']->get_id(),
'addr' => 'local.phrasea.test', 'addr' => 'local.phrasea.test',
'login' => self::$DI['user']->get_email(), 'login' => self::$DI['user']->get_email(),
'destfolder' => '/home/test/', 'destfolder' => '/home/test/',
'NAMMKDFOLD' => 'test2/', 'NAMMKDFOLD' => 'test2/',
'obj' => array('preview') 'obj' => array('preview')
)); ));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
@@ -165,11 +179,9 @@ class ExportTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
*/ */
public function testRequireAuthentication() public function testRequireAuthentication()
{ {
$this->markTestSkipped();
$this->logout(self::$DI['app']); $this->logout(self::$DI['app']);
self::$DI['client']->request('POST', '/prod/export/multi-export/'); self::$DI['client']->request('POST', '/prod/export/multi-export/');
$this->assertTrue(self::$DI['client']->getResponse()->isRedirect()); $this->assertTrue(self::$DI['client']->getResponse()->isRedirect());
} }
/**
* @todo Test Alchemy\Phrasea\Controller\Prod\Export::exportMail
*/
} }

View File

@@ -1,16 +1,13 @@
<?php <?php
require_once __DIR__ . '/../../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc'; require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract.class.inc';
use Alchemy\Phrasea\Controller\Prod\Record\Property;
use Symfony\Component\HttpFoundation\Request;
class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
{ {
protected $client; protected $client;
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Record\Property::displayStatusProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty
*/ */
public function testDisplayStatusProperty() public function testDisplayStatusProperty()
{ {
@@ -22,7 +19,7 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Record\Property::displayStatusProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayStatusProperty
*/ */
public function testDisplayStatusPropertyNotXMLHTTPRequets() public function testDisplayStatusPropertyNotXMLHTTPRequets()
{ {
@@ -30,7 +27,7 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Record\Property::displayTypeProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayTypeProperty
*/ */
public function testDisplayTypeProperty() public function testDisplayTypeProperty()
{ {
@@ -42,7 +39,7 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
/** /**
* @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException
* @covers Alchemy\Phrasea\Controller\Prod\Record\Property::displayProperty * @covers Alchemy\Phrasea\Controller\Prod\Property::displayProperty
*/ */
public function testDisplayTypePropertyNotXMLHTTPRequets() public function testDisplayTypePropertyNotXMLHTTPRequets()
{ {
@@ -50,19 +47,19 @@ class PropertyTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
} }
/** /**
* @covers Alchemy\Phrasea\Controller\Prod\Record\Property::changeStatus * @covers Alchemy\Phrasea\Controller\Prod\Property::changeStatus
*/ */
public function testChangeStatus() public function testChangeStatus()
{ {
self::$DI['client']->request('POST', '/prod/records/property/status/', array( self::$DI['client']->request('POST', '/prod/records/property/status/', array(
'apply_to_children' => array(self::$DI['record_story_1']->get_sbas_id() => true), 'apply_to_children' => array(self::$DI['record_story_1']->get_sbas_id() => true),
'status' => array( 'status' => array(
self::$DI['record_1']->get_sbas_id() => array(6 => true, 8 => true, 11 => true) self::$DI['record_1']->get_sbas_id() => array(6 => true, 8 => true, 11 => true)
), ),
'lst' => implode(';', array( 'lst' => implode(';', array(
self::$DI['record_1']->get_serialize_key(), self::$DI['record_story_1']->get_serialize_key() self::$DI['record_1']->get_serialize_key(), self::$DI['record_story_1']->get_serialize_key()
)) ))
)); ));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $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() public function testChangeType()
{ {
self::$DI['client']->request('POST', '/prod/records/property/type/', array( self::$DI['client']->request('POST', '/prod/records/property/type/', array(
'lst' => implode(';', array( 'lst' => implode(';', array(
self::$DI['record_1']->get_serialize_key(), self::$DI['record_2']->get_serialize_key() self::$DI['record_1']->get_serialize_key(), self::$DI['record_2']->get_serialize_key()
)), )),
'types' => array( 'types' => array(
self::$DI['record_1']->get_serialize_key() => 'document', self::$DI['record_1']->get_serialize_key() => 'document',
self::$DI['record_2']->get_serialize_key() => 'flash', self::$DI['record_2']->get_serialize_key() => 'flash',
) )
)); ));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);

View File

@@ -90,6 +90,10 @@ class ShareTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
->method('ACL') ->method('ACL')
->will($this->returnValue($stubbedACL)); ->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()
);
} }
} }

View File

@@ -495,7 +495,7 @@ class ControllerRssFeedTest extends \PhraseanetWebTestCaseAbstract
$available_medium = array('image', 'audio', 'video'); $available_medium = array('image', 'audio', 'video');
array_walk($content, $this->removeBadItems($content, $available_medium)); array_walk($content, $this->removeBadItems($content, $available_medium));
$media_group = $xpath->query("/rss/channel/item[" . $count . "]/media:group"); $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) { foreach ($media_group as $media) {
$entry_item = array_shift($content); $entry_item = array_shift($content);

View File

@@ -44,13 +44,13 @@ class NotificationsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract
public function testSetNotificationsReaded() public function testSetNotificationsReaded()
{ {
$this->XMLHTTPRequest('POST', '/user/notifications/read/', array( $this->XMLHTTPRequest('POST', '/user/notifications/read/', array(
'notifications' => array() 'notifications' => ''
)); ));
$response = self::$DI['client']->getResponse(); $response = self::$DI['client']->getResponse();
$this->assertTrue($response->isOk()); $this->assertTrue($response->isOk());
$datas = (array) json_decode($response->getContent()); $datas = (array) json_decode($response->getContent());
$this->assertArrayHasKey('success', $datas); $this->assertArrayHasKey('success', $datas);
$this->assertTrue($datas['success']); $this->assertTrue($datas['success'], $response->getContent());
$this->assertArrayHasKey('message', $datas); $this->assertArrayHasKey('message', $datas);
unset($response); unset($response);
} }

View File

@@ -66,7 +66,7 @@ class Bridge_ApiTest extends PhraseanetPHPUnitAuthenticatedAbstract
$this->assertTrue($this->object->is_disabled()); $this->assertTrue($this->object->is_disabled());
sleep(3); sleep(3);
$update2 = $this->object->get_updated_on(); $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->assertFalse($this->object->is_disabled());
$this->object->enable(); $this->object->enable();
$this->assertFalse($this->object->is_disabled()); $this->assertFalse($this->object->is_disabled());

View File

@@ -23,7 +23,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
* *
* @var \Pimple * @var \Pimple
*/ */
protected static $DI; public static $DI;
protected static $testsTime = array(); protected static $testsTime = array();
protected static $records; protected static $records;
public static $recordsInitialized = false; public static $recordsInitialized = false;
@@ -139,6 +139,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
self::$DI['client'] = self::$DI->share(function($DI) { self::$DI['client'] = self::$DI->share(function($DI) {
return new Client($DI['app'], array()); return new Client($DI['app'], array());
}); });
} }
public function tearDown() public function tearDown()
@@ -158,11 +159,15 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase
parent::tearDown(); parent::tearDown();
$duration = (microtime(true) - $this->start); // $duration = (microtime(true) - $this->start);
// if ($duration > 0.75) { // if ($duration > 0.75) {
// echo "test in " . get_class($this) . " last " . $duration . "\n"; // echo "test in " . get_class($this) . " last " . $duration . "\n";
// } // }
$this->start = null; $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);
} }
/** /**