diff --git a/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php b/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php new file mode 100644 index 0000000000..8de1c25f7b --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/AbstractDelivery.php @@ -0,0 +1,70 @@ +get_subdef($subdef); + + $pathIn = $pathOut = $file->get_pathfile(); + + if ($watermark === true && $file->get_type() === \media_subdef::TYPE_IMAGE) { + $pathOut = \recordutils_image::watermark($app, $file); + } elseif ($stamp === true && $file->get_type() === \media_subdef::TYPE_IMAGE) { + $pathOut = \recordutils_image::stamp($app, $file); + } + + $log_id = null; + try { + $registry = $app['phraseanet.registry']; + $logger = $session->get_logger($record->get_databox()); + $log_id = $logger->get_id(); + + $referrer = 'NO REFERRER'; + + if (isset($_SERVER['HTTP_REFERER'])) { + $referrer = $_SERVER['HTTP_REFERER']; + } + + $record->log_view($log_id, $referrer, $registry->get('GV_sit')); + } catch (\Exception $e) { + + } + + $response = \set_export::stream_file($app['phraseanet.registry'], $pathOut, $file->get_file(), $file->get_mime(), 'inline'); + $response->setPrivate(); + + /* @var $response \Symfony\Component\HttpFoundation\Response */ + if ($file->getEtag()) { + $response->setEtag($file->getEtag()); + $response->setLastModified($file->get_modification_date()); + } + + $response->headers->addCacheControlDirective('must-revalidate', true); + $response->isNotModified($request); + + return $response; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Datafiles.php b/lib/Alchemy/Phrasea/Controller/Datafiles.php new file mode 100644 index 0000000000..4c4fbb5acf --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Datafiles.php @@ -0,0 +1,98 @@ +get('/{sbas_id}/{record_id}/{subdef}/', function($sbas_id, $record_id, $subdef, PhraseaApplication $app) use ($that) { + + $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); + $record = new \record_adapter($app, $sbas_id, $record_id); + + if (!$app['phraseanet.session']->is_authenticated()) { + throw new \Exception_Session_NotAuthenticated(); + } + + $all_access = false; + $subdefStruct = $databox->get_subdef_structure(); + + if ($subdefStruct->getSubdefGroup($record->get_type())) { + foreach ($subdefStruct->getSubdefGroup($record->get_type()) as $subdefObj) { + if ($subdefObj->get_name() == $subdef) { + if ($subdefObj->get_class() == 'thumbnail') { + $all_access = true; + } + break; + } + } + } + + $user = $app['phraseanet.user']; + + if (!$user->ACL()->has_access_to_subdef($record, $subdef)) { + throw new \Exception_UnauthorizedAction(); + } + + $stamp = false; + $watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark'); + + if ($watermark && !$all_access) { + $subdef_class = $databox + ->get_subdef_structure() + ->get_subdef($record->get_type(), $subdef) + ->get_class(); + + if ($subdef_class == \databox_subdef::CLASS_PREVIEW && $user->ACL()->has_preview_grant($record)) { + $watermark = false; + } elseif ($subdef_class == \databox_subdef::CLASS_DOCUMENT && $user->ACL()->has_hd_grant($record)) { + $watermark = false; + } + } + + if ($watermark && !$all_access) { + + $repository = $app['EM']->getRepository('\Entities\BasketElement'); + + /* @var $repository \Repositories\BasketElementRepository */ + + $ValidationByRecord = $repository->findReceivedValidationElementsByRecord($record, $user); + $ReceptionByRecord = $repository->findReceivedElementsByRecord($record, $user); + + if ($ValidationByRecord && count($ValidationByRecord) > 0) { + $watermark = false; + } elseif ($ReceptionByRecord && count($ReceptionByRecord) > 0) { + $watermark = false; + } + } + + return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app); + })->assert('sbas_id', '\d+')->assert('record_id', '\d+'); + + + return $controllers; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Permalink.php b/lib/Alchemy/Phrasea/Controller/Permalink.php new file mode 100644 index 0000000000..891c891cae --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Permalink.php @@ -0,0 +1,104 @@ +get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/view/' + , function($label, $sbas_id, $record_id, $key, $subdef, PhraseaApplication $app) { + + $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); + + $record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef); + + if (!$record instanceof \record_adapter) { + throw new \Exception_NotFound('bad luck'); + } + + $params = array( + 'subdef_name' => $subdef + , 'module_name' => 'overview' + , 'module' => 'overview' + , 'view' => 'overview' + , 'record' => $record + ); + + return new Response($app['twig']->render('overview.html.twig', $params)); + })->assert('sbas_id', '\d+')->assert('record_id', '\d+'); + + $controllers->get('/v1/{label}/{sbas_id}/{record_id}/{key}/{subdef}/', function(Application $app, $label, $sbas_id, $record_id, $key, $subdef) use ($that) { + $databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id); + $record = \media_Permalink_Adapter::challenge_token($app, $databox, $key, $record_id, $subdef); + + if (!($record instanceof \record_adapter)) { + throw new \Exception_NotFound('bad luck'); + } + + $watermark = $stamp = false; + + if ($app['phraseanet.session']->is_authenticated()) { + $user = \User_Adapter::getInstance($app['phraseanet.session']->get_usr_id(), $app); + + $watermark = !$user->ACL()->has_right_on_base($record->get_base_id(), 'nowatermark'); + + if ($watermark) { + + $repository = $app['EM']->getRepository('\Entities\BasketElement'); + + if (count($repository->findReceivedValidationElementsByRecord($record, $user)) > 0) { + $watermark = false; + } elseif (count($repository->findReceivedElementsByRecord($record, $user)) > 0) { + $watermark = false; + } + } + + return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app); + } else { + $collection = \collection::get_from_base_id($app, $record->get_base_id()); + switch ($collection->get_pub_wm()) { + default: + case 'none': + $watermark = false; + break; + case 'stamp': + $stamp = true; + break; + case 'wm': + $watermark = false; + break; + } + } + + return $that->deliverContent($app['request'], $app['phraseanet.session'], $record, $subdef, $watermark, $stamp, $app); + } + ) + ->assert('sbas_id', '\d+')->assert('record_id', '\d+'); + + return $controllers; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/RecordsRequest.php b/lib/Alchemy/Phrasea/Controller/RecordsRequest.php index 41344d9471..53843d4768 100644 --- a/lib/Alchemy/Phrasea/Controller/RecordsRequest.php +++ b/lib/Alchemy/Phrasea/Controller/RecordsRequest.php @@ -197,22 +197,23 @@ class RecordsRequest extends ArrayCollection $basket = null; if ($request->get('ssel')) { - $repository = $app['phraseanet.core']['EM']->getRepository('\Entities\Basket'); + $repository = $app['EM']->getRepository('\Entities\Basket'); - $basket = $repository->findUserBasket($request->get('ssel'), $app['phraseanet.core']->getAuthenticatedUser(), false); + $basket = $repository->findUserBasket($app, $request->get('ssel'), $app['phraseanet.user'], false); foreach ($basket->getElements() as $basket_element) { - $received[$basket_element->getRecord()->get_serialize_key()] = $basket_element->getRecord(); + $received[$basket_element->getRecord($app)->get_serialize_key()] = $basket_element->getRecord($app); } } elseif ($request->get('story')) { - $repository = $app['phraseanet.core']['EM']->getRepository('\Entities\StoryWZ'); + $repository = $app['EM']->getRepository('\Entities\StoryWZ'); $storyWZ = $repository->findByUserAndId( - $app['phraseanet.core']->getAuthenticatedUser() + $app, + $app['phraseanet.user'] , $request->get('story') ); - $received[$storyWZ->getRecord()->get_serialize_key()] = $storyWZ->getRecord(); + $received[$storyWZ->getRecord($app)->get_serialize_key()] = $storyWZ->getRecord($app); } else { foreach (explode(";", $request->get('lst')) as $bas_rec) { $basrec = explode('_', $bas_rec); @@ -220,7 +221,7 @@ class RecordsRequest extends ArrayCollection continue; } try { - $record = new \record_adapter((int) $basrec[0], (int) $basrec[1]); + $record = new \record_adapter($app, (int) $basrec[0], (int) $basrec[1]); $received[$record->get_serialize_key()] = $record; unset($record); } catch (\Exception_NotFound $e) { @@ -233,7 +234,7 @@ class RecordsRequest extends ArrayCollection $to_remove = array(); - $user = $app['phraseanet.core']->getAuthenticatedUser(); + $user = $app['phraseanet.user']; foreach ($elements as $id => $record) { diff --git a/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php b/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php index b9ad8b4820..d36bd74950 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/AdminCollectionTest.php @@ -6,6 +6,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { protected $client; public static $createdCollections = array(); + protected static $useExceptionHandler = true; public static function tearDownAfterClass() { @@ -109,7 +110,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::submitSuggestedValues */ public function testPostSuggestedValueUnauthorized() @@ -117,6 +117,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(false); $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$collection->get_base_id() . '/suggested-values/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** @@ -289,7 +290,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::setPublicationDisplay */ public function testPublicationDisplayBadRequestMissingArguments() @@ -297,6 +297,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(true); $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$collection->get_base_id() . '/publication/display/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** @@ -345,7 +346,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::rename */ public function testPostNameBadRequestMissingArguments() @@ -353,6 +353,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(true); $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$collection->get_base_id() . '/rename/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** @@ -390,7 +391,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::emptyCollection */ public function testPostEmptyCollectionUnauthorizedException() @@ -398,6 +398,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(false); $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$collection->get_base_id() . '/empty/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** @@ -542,7 +543,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract ); $this->client->request('POST', '/admin/collection/' . self::$collection->get_base_id() . '/picture/mini-logo/', array(), $files); $this->checkRedirection($this->client->getResponse(), '/admin/collection/' . self::$collection->get_base_id() . '/?success=1'); - $this->assertEquals(1, count(\collection::getLogo(self::$application, self::$collection->get_base_id()))); + $this->assertEquals(1, count(\collection::getLogo(self::$collection->get_base_id(), self::$application))); } /** @@ -564,7 +565,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testDeleteMiniLogo() { - if (count(\collection::getLogo(self::$application, self::$collection->get_base_id())) === 0) { + if (count(\collection::getLogo(self::$collection->get_base_id(), self::$application)) === 0) { $this->markTestSkipped('No logo setted'); } @@ -835,7 +836,6 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers Alchemy\Phrasea\Controller\Admin\Bas::unmount */ public function testPostUnmountCollectionUnauthorizedException() @@ -843,6 +843,7 @@ class AdminCollectionTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(false); $this->XMLHTTPRequest('POST', '/admin/collection/' . self::$collection->get_base_id() . '/unmount/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** diff --git a/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php b/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php index 3f488636c5..42748a6861 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/AdminDashboardTest.php @@ -92,7 +92,7 @@ class AdminDashboardTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $admins = array_keys(\User_Adapter::get_sys_admins(self::$application)); - $user = \User_Adapter::create($this->app, uniqid('unit_test_user'), uniqid('unit_test_user'), uniqid('unit_test_user') ."@email.com", false); + $user = \User_Adapter::create(self::$application, uniqid('unit_test_user'), uniqid('unit_test_user'), uniqid('unit_test_user') ."@email.com", false); $admins[] = $user->get_id(); diff --git a/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php b/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php index 85e4a1dc31..75fe389d01 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/DataboxTest.php @@ -343,7 +343,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::getDetails * */ @@ -352,6 +351,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(false); $this->XMLHTTPRequest('GET', '/admin/databox/' . self::$collection->get_sbas_id() . '/informations/documents/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** @@ -487,7 +487,6 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract } /** - * @expectedException \Symfony\Component\HttpKernel\Exception\HttpException * @covers \Alchemy\Phrasea\Controller\Admin\Database::changeViewName */ public function testPostViewNameBadRequestArguments() @@ -495,6 +494,7 @@ class DataboxTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->setAdmin(true); $this->XMLHTTPRequest('POST', '/admin/databox/' . self::$collection->get_sbas_id() . '/view-name/'); + $this->assertXMLHTTPBadJsonResponse($this->client->getResponse()); } /** diff --git a/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php b/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php index 0cdbc2b8b5..e9002ca1ad 100644 --- a/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php +++ b/tests/Alchemy/Phrasea/Controller/Admin/SubdefsTest.php @@ -11,7 +11,7 @@ class ControllerSubdefsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function setUp() { parent::setUp(); - $this->databox = array_shift($this->app['phraseanet.appbox']->get_databoxes()); + $this->databox = array_shift(self::$application['phraseanet.appbox']->get_databoxes()); } public function getSubdefName() diff --git a/tests/Alchemy/Phrasea/Controller/BoilerPlate.php b/tests/Alchemy/Phrasea/Controller/BoilerPlate.php index 5ee51572a9..a5b38690db 100644 --- a/tests/Alchemy/Phrasea/Controller/BoilerPlate.php +++ b/tests/Alchemy/Phrasea/Controller/BoilerPlate.php @@ -21,34 +21,6 @@ use Symfony\Component\HttpFoundation\Response; */ class BoilerPlate extends \PhraseanetWebTestCaseAbstract { - /** - * As controllers use WebTestCase, it requires a client - */ - protected $client; - - /** - * The application loader - */ - public function createApplication() - { - $app = require __DIR__ . '/../../../../Path/To/Application.php'; - - $app['debug'] = true; - unset($app['exception_handler']); - - return $app; - } - - public function setUp() - { - parent::setUp(); - $this->client = $this->createClient(); - } - - public function tearDown() - { - parent::tearDown(); - } /** * Default route test diff --git a/tests/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php b/tests/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php index 67d93eac33..816b3c5289 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/MustacheLoaderTest.php @@ -5,37 +5,32 @@ require_once __DIR__ . '/../../../../PhraseanetWebTestCaseAuthenticatedAbstract. class MustacheLoaderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { protected $client; + protected static $useExceptionHandler = false; - /** - * @expectedException \Exception_BadRequest - */ public function testRouteSlash() { $this->client->request('GET', '/prod/MustacheLoader/'); $response = $this->client->getResponse(); /* @var $response \Symfony\Component\HttpFoundation\Response */ + $this->assertEquals(400, $response->getStatusCode()); } - /** - * @expectedException \Exception_BadRequest - */ public function testRouteSlashWrongUrl() { $this->client->request('GET', '/prod/MustacheLoader/', array('template' => '/../../../../config/config.yml')); $response = $this->client->getResponse(); + $this->assertEquals(400, $response->getStatusCode()); /* @var $response \Symfony\Component\HttpFoundation\Response */ } - /** - * @expectedException \Exception_NotFound - */ public function testRouteSlashWrongFile() { $this->client->request('GET', '/prod/MustacheLoader/', array('template' => 'patator_lala')); $response = $this->client->getResponse(); + $this->assertEquals(404, $response->getStatusCode()); } public function testRouteGood() diff --git a/tests/Alchemy/Phrasea/Controller/Prod/OrderTest.php b/tests/Alchemy/Phrasea/Controller/Prod/OrderTest.php index 30024987cc..6c7f4f8593 100644 --- a/tests/Alchemy/Phrasea/Controller/Prod/OrderTest.php +++ b/tests/Alchemy/Phrasea/Controller/Prod/OrderTest.php @@ -81,7 +81,7 @@ class OrderTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->assertTrue($this->client->getResponse()->isRedirect()); $url = parse_url($this->client->getResponse()->headers->get('location')); parse_str($url['query']); - $this->assertTrue( ! ! $success); + $this->assertTrue( strpos($url['query'], 'success=1') === 0); } /** diff --git a/tests/Alchemy/Phrasea/Controller/RecordsRequestTest.php b/tests/Alchemy/Phrasea/Controller/RecordsRequestTest.php index 4330161e73..50eeddde07 100644 --- a/tests/Alchemy/Phrasea/Controller/RecordsRequestTest.php +++ b/tests/Alchemy/Phrasea/Controller/RecordsRequestTest.php @@ -10,14 +10,6 @@ require_once __DIR__ . '/../../../PhraseanetPHPUnitAuthenticatedAbstract.class.i class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract { - public function getApplication() - { - $application = new Application(); - $application['phraseanet.core'] = self::$core; - - return $application; - } - public function testSimple() { $request = new Request(array( @@ -36,7 +28,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract )) )); - $records = RecordsRequest::fromRequest($this->getApplication(), $request); + $records = RecordsRequest::fromRequest(self::$application, $request); $this->assertEquals(3, count($records)); $this->assertEquals(5, count($records->received())); @@ -65,7 +57,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract )) )); - $records = RecordsRequest::fromRequest($this->getApplication(), $request); + $records = RecordsRequest::fromRequest(self::$application, $request); $this->assertEquals(1, count($records)); $this->assertEquals(1, count($records->received())); @@ -84,7 +76,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract public function testSimpleWithoutSbasRights() { - self::$core->getAuthenticatedUser()->ACL() + self::$application['phraseanet.user']->ACL() ->update_rights_to_sbas(self::$records['record_2']->get_sbas_id(), array('bas_chupub' => 0)); $request = new Request(array( @@ -93,7 +85,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract )) )); - $records = RecordsRequest::fromRequest($this->getApplication(), $request, false, array(), array('bas_chupub')); + $records = RecordsRequest::fromRequest(self::$application, $request, false, array(), array('bas_chupub')); $this->assertEquals(0, count($records)); $this->assertEquals(1, count($records->received())); @@ -110,7 +102,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract public function testSimpleWithoutBasRights() { - self::$core->getAuthenticatedUser()->ACL() + self::$application['phraseanet.user']->ACL() ->update_rights_to_base(self::$records['record_2']->get_base_id(), array('chgstatus' => 0)); $request = new Request(array( @@ -119,7 +111,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract )) )); - $records = RecordsRequest::fromRequest($this->getApplication(), $request, false, array('chgstatus')); + $records = RecordsRequest::fromRequest(self::$application, $request, false, array('chgstatus')); $this->assertEquals(0, count($records)); $this->assertEquals(1, count($records->received())); @@ -147,7 +139,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract )) )); - $records = RecordsRequest::fromRequest($this->getApplication(), $request, true); + $records = RecordsRequest::fromRequest(self::$application, $request, true); $this->assertEquals(2, count($records)); $this->assertEquals(5, count($records->received())); @@ -172,7 +164,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $basketElement = $this->insertOneBasketElement(); $request = new Request(array('ssel' => $basketElement->getBasket()->getId())); - $records = RecordsRequest::fromRequest($this->getApplication(), $request); + $records = RecordsRequest::fromRequest(self::$application, $request); $this->assertEquals(1, count($records)); $this->assertEquals(1, count($records->received())); @@ -185,7 +177,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $exploded = explode(';', $serialized); $this->assertEquals(1, count($exploded)); - $this->assertContains($basketElement->getRecord()->get_serialize_key(), $exploded); + $this->assertContains($basketElement->getRecord(self::$application)->get_serialize_key(), $exploded); } public function getBasket() @@ -199,18 +191,18 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $basket = new \Entities\Basket(); $basket->setName('test'); - $basket->setOwner(self::$core->getAuthenticatedUser()); + $basket->setOwner(self::$application['phraseanet.user']); - self::$core['EM']->persist($basket); - self::$core['EM']->flush(); + self::$application['EM']->persist($basket); + self::$application['EM']->flush(); foreach ($elements as $element) { $basket_element = new \Entities\BasketElement(); $basket_element->setRecord($element); $basket_element->setBasket($basket); $basket->addBasketElement($basket_element); - self::$core['EM']->persist($basket_element); - self::$core['EM']->flush(); + self::$application['EM']->persist($basket_element); + self::$application['EM']->flush(); } return $basket; @@ -221,20 +213,20 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $story = $this->getStoryWZ(); $request = new Request(array('story' => $story->getId())); - $records = RecordsRequest::fromRequest($this->getApplication(), $request); + $records = RecordsRequest::fromRequest(self::$application, $request); $this->assertEquals(1, count($records)); $this->assertEquals(1, count($records->received())); $this->assertEquals(1, count($records->stories())); $this->assertInstanceOf('record_adapter', $records->singleStory()); $this->assertTrue($records->isSingleStory()); - $this->assertEquals(array($story->getRecord()->get_databox()), $records->databoxes()); + $this->assertEquals(array($story->getRecord(self::$application)->get_databox()), $records->databoxes()); $serialized = $records->serializedList(); $exploded = explode(';', $serialized); $this->assertEquals(1, count($exploded)); - $this->assertContains($story->getRecord()->get_serialize_key(), $exploded); + $this->assertContains($story->getRecord(self::$application)->get_serialize_key(), $exploded); } public function testSimpleStoryFlatten() @@ -242,7 +234,7 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $story = $this->getStoryWZ(); $request = new Request(array('story' => $story->getId())); - $records = RecordsRequest::fromRequest($this->getApplication(), $request, true); + $records = RecordsRequest::fromRequest(self::$application, $request, true); $this->assertEquals(0, count($records)); $this->assertEquals(1, count($records->received())); @@ -255,17 +247,17 @@ class RecordsRequestTest extends \PhraseanetPHPUnitAuthenticatedAbstract $exploded = explode(';', $serialized); $this->assertEquals('', $serialized); - $this->assertNotContains($story->getRecord()->get_serialize_key(), $exploded); + $this->assertNotContains($story->getRecord(self::$application)->get_serialize_key(), $exploded); } protected function getStoryWZ() { $story = new \Entities\StoryWZ(); $story->setRecord(self::$records['record_story_2']); - $story->setUser(self::$core->getAuthenticatedUser()); + $story->setUser(self::$application['phraseanet.user']); - self::$core['EM']->persist($story); - self::$core['EM']->flush(); + self::$application['EM']->persist($story); + self::$application['EM']->flush(); return $story; } diff --git a/tests/Alchemy/Phrasea/Controller/Root/AccountTest.php b/tests/Alchemy/Phrasea/Controller/Root/AccountTest.php index 2f93dd6a49..4ec35f9240 100644 --- a/tests/Alchemy/Phrasea/Controller/Root/AccountTest.php +++ b/tests/Alchemy/Phrasea/Controller/Root/AccountTest.php @@ -149,7 +149,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostResetMailBadEmail() { $password = \random::generatePassword(); - self::$user->set_password($password); + self::$application['phraseanet.user']->set_password($password); $this->client->request('POST', '/account/reset-email/', array( 'form_password' => $password, 'form_email' => "invalid#!&&@@email.x", @@ -167,7 +167,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostResetMailEmailNotIdentical() { $password = \random::generatePassword(); - self::$user->set_password($password); + self::$application['phraseanet.user']->set_password($password); $this->client->request('POST', '/account/reset-email/', array( 'form_password' => $password, 'form_email' => 'email1@email.com', @@ -185,7 +185,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract public function testPostResetMailEmail() { $password = \random::generatePassword(); - self::$user->set_password($password); + self::$application['phraseanet.user']->set_password($password); $this->client->request('POST', '/account/reset-email/', array( 'form_password' => $password, 'form_email' => 'email1@email.com', @@ -432,7 +432,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract */ public function testPostRenewPasswordBadArguments($oldPassword, $password, $passwordConfirm, $redirect) { - self::$user->set_password($oldPassword); + self::$application['phraseanet.user']->set_password($oldPassword); $this->client->request('POST', '/account/reset-password/', array( 'form_password' => $password, @@ -464,7 +464,7 @@ class AccountTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { $password = \random::generatePassword(); - self::$user->set_password($password); + self::$application['phraseanet.user']->set_password($password); $this->client->request('POST', '/account/reset-password/', array( 'form_password' => 'password', diff --git a/tests/Alchemy/Phrasea/Controller/Root/LoginTest.php b/tests/Alchemy/Phrasea/Controller/Root/LoginTest.php index 61ef9cfcaa..1d7ba47559 100644 --- a/tests/Alchemy/Phrasea/Controller/Root/LoginTest.php +++ b/tests/Alchemy/Phrasea/Controller/Root/LoginTest.php @@ -634,7 +634,7 @@ class LoginTest extends \PhraseanetWebTestCaseAuthenticatedAbstract { self::$application['phraseanet.appbox']->get_session()->logout(); $password = \random::generatePassword(); - self::$user->set_password($password); + self::$application['phraseanet.user']->set_password($password); $this->client->request('POST', '/login/authenticate/', array( 'login' => self::$user->get_login(), 'pwd' => $password