diff --git a/config/nginx.rewrite.rules b/config/nginx.rewrite.rules index 739c49df06..91efe0c106 100644 --- a/config/nginx.rewrite.rules +++ b/config/nginx.rewrite.rules @@ -16,6 +16,7 @@ rewrite ^/admin/typeahead/.*$ /admin/router.php last; rewrite ^/prod/records/edit/.*$ /prod/router.php last; rewrite ^/prod/records/movecollection/.*$ /prod/router.php last; rewrite ^/prod/bridge/.*$ /prod/router.php last; +rewrite ^/prod/lists/.*$ /prod/router.php last; rewrite ^/prod/feeds/.*$ /prod/router.php last; rewrite ^/prod/tooltip/.*$ /prod/router.php last; rewrite ^/prod/printer/.*$ /prod/router.php last; diff --git a/lib/Alchemy/Phrasea/Application/Prod.php b/lib/Alchemy/Phrasea/Application/Prod.php index 976240d109..9194fb36d3 100644 --- a/lib/Alchemy/Phrasea/Application/Prod.php +++ b/lib/Alchemy/Phrasea/Application/Prod.php @@ -41,6 +41,7 @@ return call_user_func(function() $app->mount('/baskets', new Controller\Basket()); $app->mount('/story', new Controller\Story()); $app->mount('/WorkZone', new Controller\WorkZone()); + $app->mount('/lists', new Controller\UsrLists()); $app->mount('/records/edit', new Controller\Edit()); $app->mount('/records/movecollection', new Controller\MoveCollection()); $app->mount('/bridge/', new Controller\Bridge()); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php index 02a6cb2692..450174dfab 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/UsrLists.php @@ -15,7 +15,8 @@ use Silex\Application, Silex\ControllerProviderInterface, Silex\ControllerCollection; use Alchemy\Phrasea\Helper\Record as RecordHelper, - Alchemy\Phrasea\Out\Module\PDF as PDFExport; + Alchemy\Phrasea\Out\Module\PDF as PDFExport, + Alchemy\Phrasea\Controller\Exception as ControllerException; use Symfony\Component\HttpFoundation\Response, Symfony\Component\HttpFoundation\RedirectResponse; @@ -35,7 +36,7 @@ class UsrLists implements ControllerProviderInterface /** * Get all lists */ - $controllers->get('/list/all/', function() use ($app) + $controllers->get('/list/all/', function(Application $app) { $em = $app['Core']->getEntityManager(); @@ -47,7 +48,6 @@ class UsrLists implements ControllerProviderInterface foreach ($lists as $list) { - $owners = $entries = array(); foreach ($list->getOwners() as $owner) @@ -63,7 +63,7 @@ class UsrLists implements ControllerProviderInterface ); } - foreach ($list->getUsers() as $entry) + foreach ($list->getEntries() as $entry) { $entries[] = array( 'usr_id' => $owner->getUser()->get_id(), @@ -95,18 +95,26 @@ class UsrLists implements ControllerProviderInterface /** * Creates a list */ - $controllers->post('/list/', function() use ($app) + $controllers->post('/list/', function(Application $app) { $request = $app['request']; - + $list_name = $request->get('name'); + + $datas = array( + 'success' => false + , 'message' => sprintf(_('Unable to create list %s'), $list_name) + ); try { + if(!$list_name) + { + throw new ControllerException(_('List name is required')); + } + $em = $app['Core']->getEntityManager(); - $repository = $em->getRepository('\Entities\Usr'); - $List = new \Entities\UsrList(); $Owner = new \Entities\UsrListOwner(); @@ -123,15 +131,14 @@ class UsrLists implements ControllerProviderInterface $datas = array( 'success' => true - , 'message' => '' + , 'message' => sprintf(_('List %s has been created'), $list_name) ); } - catch (\Exception $e) + catch (ControllerException $e) { - $datas = array( 'success' => false - , 'message' => sprintf(_('Unable to create list %s'), $list_name) + , 'message' => $e->getMessage() ); } @@ -144,7 +151,7 @@ class UsrLists implements ControllerProviderInterface /** * Gets a list */ - $controllers->get('/list/{list_id}/', function() use ($app) + $controllers->get('/list/{list_id}/', function(Application $app, $list_id) { $user = $app['Core']->getAuthenticatedUser(); $em = $app['Core']->getEntityManager(); @@ -152,7 +159,7 @@ class UsrLists implements ControllerProviderInterface $repository = $em->getRepository('\Entities\UsrList'); $list = $repository->findUserListByUserAndId($user, $list_id); - + $owners = $entries = $lists = array(); foreach ($list->getOwners() as $owner) @@ -168,7 +175,7 @@ class UsrLists implements ControllerProviderInterface ); } - foreach ($list->getUsers() as $entry) + foreach ($list->getEntries() as $entry) { $entries[] = array( 'usr_id' => $owner->getUser()->get_id(), @@ -200,35 +207,46 @@ class UsrLists implements ControllerProviderInterface /** * Update a list */ - $controllers->post('/list/{list_id}/update/', function() use ($app) + $controllers->post('/list/{list_id}/update/', function(Application $app, $list_id) { - $user = $app['Core']->getAuthenticatedUser(); - $em = $app['Core']->getEntityManager(); + $request = $app['request']; + $datas = array( + 'success' => false + , 'message' => _('Unable to update list') + ); + try { - $request = $app['request']; + $list_name = $request->get('name'); + + if(!$list_name) + { + throw new ControllerException(_('List name is required')); + } + + $user = $app['Core']->getAuthenticatedUser(); + $em = $app['Core']->getEntityManager(); $repository = $em->getRepository('\Entities\UsrList'); $list = $repository->findUserListByUserAndId($user, $list_id); - $list->setName($request->get('name')); + $list->setName($list_name); $em->merge($list); $em->flush(); $datas = array( 'success' => true - , 'message' => '' + , 'message' => _('List has been updated') ); } - catch (\Exception $e) + catch (ControllerException $e) { - $datas = array( 'success' => false - , 'message' => sprintf(_('Unable to create list %s'), $list_name) + , 'message' => $e->getMessage() ); } @@ -241,16 +259,16 @@ class UsrLists implements ControllerProviderInterface /** * Delete a list */ - $controllers->post('/list/{list_id}/delete/', function() use ($app) + $controllers->post('/list/{list_id}/delete/', function(Application $app, $list_id) { $em = $app['Core']->getEntityManager(); - $repository = $em->getRepository('\Entities\Usr'); - try { $repository = $em->getRepository('\Entities\UsrList'); - + + $user = $app['Core']->getAuthenticatedUser(); + $list = $repository->findUserListByUserAndId($user, $list_id); $em->remove($list); @@ -280,13 +298,15 @@ class UsrLists implements ControllerProviderInterface /** * Remove a usr_id from a list */ - $controllers->post('/list/{list_id}/remove/{entry_id}/', function() use ($app) + $controllers->post('/list/{list_id}/remove/{entry_id}/', function(Application $app, $list_id, $entry_id) { $em = $app['Core']->getEntityManager(); try { $repository = $em->getRepository('\Entities\UsrList'); + + $user = $app['Core']->getAuthenticatedUser(); $list = $repository->findUserListByUserAndId($user, $list_id); /* @var $list \Entities\UsrList */ @@ -299,7 +319,7 @@ class UsrLists implements ControllerProviderInterface $em->flush(); $datas = array( - 'success' => false + 'success' => true , 'message' => _('Entry removed from list') ); } @@ -321,7 +341,7 @@ class UsrLists implements ControllerProviderInterface /** * Adds a usr_id to a list */ - $controllers->post('/list/{list_id}/add/{usr_id}/', function() use ($app) + $controllers->post('/list/{list_id}/add/{usr_id}/', function(Application $app, $list_id, $usr_id) { $em = $app['Core']->getEntityManager(); @@ -345,7 +365,7 @@ class UsrLists implements ControllerProviderInterface $em->flush(); $datas = array( - 'success' => false + 'success' => true , 'message' => _('Usr added to list') ); } @@ -367,7 +387,7 @@ class UsrLists implements ControllerProviderInterface /** * Share a list to a user with an optionnal role */ - $controllers->post('/list/{list_id}/share/{usr_id}/', function() use ($app) + $controllers->post('/list/{list_id}/share/{usr_id}/', function(Application $app, $list_id, $usr_id) { $em = $app['Core']->getEntityManager(); $user = $app['Core']->getAuthenticatedUser(); @@ -410,8 +430,8 @@ class UsrLists implements ControllerProviderInterface $em->flush(); $datas = array( - 'success' => false - , 'message' => _('Usr added to list') + 'success' => true + , 'message' => _('List shared to user') ); } catch (\Exception $e) @@ -419,7 +439,7 @@ class UsrLists implements ControllerProviderInterface $datas = array( 'success' => false - , 'message' => _('Unable to add usr to list') + , 'message' => _('Unable to share the list with the usr') ); } @@ -431,7 +451,7 @@ class UsrLists implements ControllerProviderInterface /** * UnShare a list to a user */ - $controllers->post('/list/{list_id}/unshare/{owner_id}/', function() use ($app) + $controllers->post('/list/{list_id}/unshare/{owner_id}/', function(Application $app, $list_id, $owner_id) { $em = $app['Core']->getEntityManager(); $user = $app['Core']->getAuthenticatedUser(); @@ -456,7 +476,7 @@ class UsrLists implements ControllerProviderInterface $em->flush(); $datas = array( - 'success' => false + 'success' => true , 'message' => _('Owner removed from list') ); } diff --git a/lib/Doctrine/Entities/UsrList.php b/lib/Doctrine/Entities/UsrList.php index 9fc5c8a62b..5d1f5c8edd 100644 --- a/lib/Doctrine/Entities/UsrList.php +++ b/lib/Doctrine/Entities/UsrList.php @@ -47,12 +47,12 @@ class UsrList /** * @var Entities\UsrListEntry */ - private $users; + private $entries; public function __construct() { $this->owners = new \Doctrine\Common\Collections\ArrayCollection(); - $this->users = new \Doctrine\Common\Collections\ArrayCollection(); + $this->entries = new \Doctrine\Common\Collections\ArrayCollection(); } /** @@ -173,23 +173,23 @@ class UsrList } /** - * Add users + * Add entry * - * @param Entities\UsrListContent $users + * @param Entities\UsrListEntry $entry */ - public function addUsrListEntry(\Entities\UsrListEntry $users) + public function addUsrListEntry(\Entities\UsrListEntry $entry) { - $this->users[] = $users; + $this->entries[] = $entry; } /** - * Get users + * Get entries * * @return Doctrine\Common\Collections\Collection */ - public function getUsers() + public function getEntries() { - return $this->users; + return $this->entries; } } \ No newline at end of file diff --git a/lib/Doctrine/Proxies/EntitiesUsrListProxy.php b/lib/Doctrine/Proxies/EntitiesUsrListProxy.php index 7d2270bf23..8826826001 100644 --- a/lib/Doctrine/Proxies/EntitiesUsrListProxy.php +++ b/lib/Doctrine/Proxies/EntitiesUsrListProxy.php @@ -102,22 +102,22 @@ class EntitiesUsrListProxy extends \Entities\UsrList implements \Doctrine\ORM\Pr return parent::getOwner($user); } - public function addUsrListEntry(\Entities\UsrListEntry $users) + public function addUsrListEntry(\Entities\UsrListEntry $entry) { $this->__load(); - return parent::addUsrListEntry($users); + return parent::addUsrListEntry($entry); } - public function getUsers() + public function getEntries() { $this->__load(); - return parent::getUsers(); + return parent::getEntries(); } public function __sleep() { - return array('__isInitialized__', 'id', 'name', 'created', 'updated', 'owners', 'users'); + return array('__isInitialized__', 'id', 'name', 'created', 'updated', 'owners', 'entries'); } public function __clone() diff --git a/lib/classes/ACL.class.php b/lib/classes/ACL.class.php index 2af01f4a12..2bb919e3b2 100644 --- a/lib/classes/ACL.class.php +++ b/lib/classes/ACL.class.php @@ -121,7 +121,7 @@ class ACL implements cache_cacheableInterface $this->load_hd_grant(); - $key = $record->get_base_id() . '_' . $record->get_record_id(); + $key = $record->get_serialize_key(); if (array_key_exists($key, $this->_rights_records_document)) return true; @@ -188,7 +188,7 @@ class ACL implements cache_cacheableInterface $this->load_hd_grant(); - $key = $record->get_base_id() . '_' . $record->get_record_id(); + $key = $record->get_serialize_key(); if (array_key_exists($key, $this->_rights_records_preview)) return true; @@ -230,7 +230,7 @@ class ACL implements cache_cacheableInterface { $granted = true; } - + return $granted; } diff --git a/lib/conf.d/Doctrine/Entities.UsrList.dcm.yml b/lib/conf.d/Doctrine/Entities.UsrList.dcm.yml index 81576c8dfa..6eb3597d9e 100644 --- a/lib/conf.d/Doctrine/Entities.UsrList.dcm.yml +++ b/lib/conf.d/Doctrine/Entities.UsrList.dcm.yml @@ -25,7 +25,7 @@ Entities\UsrList: targetEntity: UsrListOwner mappedBy: list cascade: ["ALL"] - users: + entries: targetEntity: UsrListEntry mappedBy: list cascade: ["ALL"] diff --git a/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php b/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php new file mode 100644 index 0000000000..bebbe353b6 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php @@ -0,0 +1,45 @@ +user; + } + + public function setUser(\User_Adapter $user) + { + $this->user = $user; + } + + public function getList() + { + return $this->list; + } + + public function setList(\Entities\UsrList $list) + { + $this->list = $list; + } + +} diff --git a/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php b/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php new file mode 100644 index 0000000000..9384160f12 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php @@ -0,0 +1,53 @@ +getReference('one-listowner'); + + $list->setName('new list'); + $list->addUsrListOwner($owner); + + /* @var $owner \Entities\UsrListOwner */ + $owner->setList($list); + + $manager->persist($list); + $manager->merge($owner); + $manager->flush(); + + $this->list = $list; + + $this->addReference('one-list', $list); + } + +} diff --git a/lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php b/lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php new file mode 100644 index 0000000000..76dd54ea95 --- /dev/null +++ b/lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php @@ -0,0 +1,64 @@ +user) + { + throw new \LogicException('Fill a user to store a new basket'); + } + + $list = $this->getReference('one-list'); + + $entry->setUser($this->user); + $entry->setList($list); + + /* @var $list \Entities\UsrList */ + $list->addUsrListEntry($entry); + + $manager->persist($entry); + $manager->flush(); + + $this->entry = $entry; + + $this->addReference('one-entry', $entry); + } + +} diff --git a/lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php b/lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php new file mode 100644 index 0000000000..9650c4f21c --- /dev/null +++ b/lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php @@ -0,0 +1,51 @@ +setRole(\Entities\UsrListOwner::ROLE_ADMIN); + + if (null === $this->user) + { + throw new \LogicException('Fill a user to store a new basket'); + } + + $owner->setUser($this->user); + + $manager->persist($owner); + $manager->flush(); + + $this->owner = $owner; + + $this->addReference('one-listowner', $owner); + } + +} diff --git a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/UsrListsTest.php b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/UsrListsTest.php index 331150894a..8fdd4f223e 100644 --- a/lib/unitTest/Alchemy/Phrasea/Controller/Prod/UsrListsTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Controller/Prod/UsrListsTest.php @@ -42,19 +42,286 @@ class ControllerUsrListsTest extends \PhraseanetWebTestCaseAuthenticatedAbstract $this->client = $this->createClient(); } - public function tearDown() - { - parent::tearDown(); - } - /** * Default route test */ public function testRouteSlash() { - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $entry1 = $this->insertOneUsrListEntry(self::$user,self::$user); + $entry2 = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $entry3 = $this->insertOneUsrListEntry(self::$user, self::$user); + $entry4 = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $entry5 = $this->insertOneUsrListEntry(self::$user_alt1,self::$user_alt1); + $entry6 = $this->insertOneUsrListEntry(self::$user_alt1,self::$user_alt2); + + $route = '/lists/list/all/'; + + $this->client->request('GET', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertEquals(4, count($datas['lists'])); + } + + protected function checkList($list, $owners = true, $users = true) + { + $this->assertInstanceOf('stdClass', $list); + $this->assertObjectHasAttribute('name', $list); + $this->assertObjectHasAttribute('created', $list); + $this->assertObjectHasAttribute('updated', $list); + $this->assertObjectHasAttribute('owners', $list); + $this->assertObjectHasAttribute('users', $list); + + if($owners) + $this->assertTrue(count($list->owners) > 0); + + foreach($list->owners as $owner) + { + $this->checkOwner($owner); + } + + if($users) + $this->assertTrue(count($list->users) > 0); + + foreach($list->users as $user) + { + $this->checkUser($user); + } + } + + public function testPostList() + { + $route = '/lists/list/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertFalse($datas['success']); + + $this->client->request('POST', $route, array('name'=>'New List')); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + } + + public function testGetList() + { + $entry = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $list_id = $entry->getList()->getId(); + + $route = '/lists/list/' . $list_id . '/'; + + $this->client->request('GET', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertTrue(is_array($datas)); + $this->assertArrayhasKey('list', $datas); + $this->checkList($datas['list']); + } + + public function testPostUpdate() + { + $entry = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $list_id = $entry->getList()->getId(); + + $route = '/lists/list/' . $list_id . '/update/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertFalse($datas['success']); + + + $this->client->request('POST', $route, array('name'=>'New NAME')); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + } + + + + + public function testPostDelete() + { + $entry = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $list_id = $entry->getList()->getId(); + + $route = '/lists/list/' . $list_id . '/delete/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + + $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); + + $this->assertNull($repository->find($list_id)); + } + + public function testPostRemoveEntry() + { + $entry = $this->insertOneUsrListEntry(self::$user,self::$user_alt1); + $list_id = $entry->getList()->getId(); + $entry_id = $entry->getId(); + + $route = '/lists/list/' . $list_id . '/remove/' . $entry_id . '/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + + $repository = self::$core->getEntityManager()->getRepository('Entities\UsrListEntry'); + + $this->assertNull($repository->find($entry_id)); + } + + public function testPostAddEntry() + { + $list = $this->insertOneUsrList(self::$user); + + $this->assertEquals(0, $list->getEntries()->count()); + + $route = '/lists/list/' . $list->getId() . '/add/' . self::$user->get_id() . '/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + + $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); + + $list = $repository->find($list->getId()); + + $this->assertEquals(1, $list->getEntries()->count()); + } + + public function testPostShareList() + { + $list = $this->insertOneUsrList(self::$user); + + $this->assertEquals(1, $list->getOwners()->count()); + + $route = '/lists/list/' . $list->getId() . '/share/' . self::$user_alt1->get_id() . '/'; + + $this->client->request('POST', $route); + + $response = $this->client->getResponse(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertEquals('UTF-8', $response->getCharset()); + + $datas = (array) json_decode($response->getContent()); + + $this->assertArrayHasKey('success', $datas); + $this->assertArrayHasKey('message', $datas); + + $this->assertTrue($datas['success']); + + $repository = self::$core->getEntityManager()->getRepository('Entities\UsrList'); + + $list = $repository->find($list->getId()); + + $this->assertEquals(2, $list->getOwners()->count()); + } + + + protected function checkOwner($owner) + { + $this->assertInstanceOf('stdClass', $owner); + $this->assertObjectHasAttribute('usr_id', $owner); + $this->assertObjectHasAttribute('display_name', $owner); + $this->assertObjectHasAttribute('position', $owner); + $this->assertObjectHasAttribute('job', $owner); + $this->assertObjectHasAttribute('company', $owner); + $this->assertObjectHasAttribute('email', $owner); + $this->assertObjectHasAttribute('role', $owner); + $this->assertTrue(ctype_digit($owner->role)); + } + + protected function checkUser($user) + { + $this->assertInstanceOf('stdClass', $user); + $this->assertObjectHasAttribute('usr_id', $user); + $this->assertObjectHasAttribute('display_name', $user); + $this->assertObjectHasAttribute('position', $user); + $this->assertObjectHasAttribute('job', $user); + $this->assertObjectHasAttribute('company', $user); + $this->assertObjectHasAttribute('email', $user); } } diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index eee5ad1d4c..2a27dacc52 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -15,7 +15,6 @@ use Silex\WebTestCase; use Symfony\Component\HttpKernel\Client; use Symfony\Component\HttpFoundation\Response; use Doctrine\Common\DataFixtures\Loader; -use PhraseaFixture\Basket as MyFixture; /** * @@ -504,11 +503,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase * * @param Doctrine\Common\DataFixtures\Loader $fixtureLoader */ - public function insertFixtureInDatabase(Doctrine\Common\DataFixtures\Loader $fixtureLoader) + public function insertFixtureInDatabase(Doctrine\Common\DataFixtures\Loader $fixtureLoader, $append = true) { $purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger(); $executor = new Doctrine\Common\DataFixtures\Executor\ORMExecutor(self::$core->getEntityManager(), $purger); - $executor->execute($fixtureLoader->getFixtures(), true); + $executor->execute($fixtureLoader->getFixtures(), $append); } /** @@ -543,7 +542,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase { try { - $basketFixture = new MyFixture\LoadOneBasket(); + $basketFixture = new PhraseaFixture\Basket\LoadOneBasket(); $basketFixture->setUser(self::$user); @@ -559,6 +558,70 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $this->fail('Fail load one Basket : ' . $e->getMessage()); } } + + + protected function insertOneUsrList(\User_Adapter $user) + { + try + { + $loader = new Loader(); + + $UsrOwner = new PhraseaFixture\UsrLists\UsrListOwner(); + $UsrOwner->setUser($user); + + $loader->addFixture($UsrOwner); + + $UsrList = new PhraseaFixture\UsrLists\UsrList(); + + $loader->addFixture($UsrList); + + + $this->insertFixtureInDatabase($loader); + + return $UsrList->list; + } + catch (\Exception $e) + { + $this->fail('Fail load one UsrList : ' . $e->getMessage()); + } + } + + /** + * + * @param \Entities\UsrList $UsrList + * @return \Entities\UsrListEntry + */ + protected function insertOneUsrListEntry(\User_adapter $owner, \User_adapter $user) + { + try + { + $loader = new Loader(); + + $UsrOwner = new PhraseaFixture\UsrLists\UsrListOwner(); + $UsrOwner->setUser($owner); + + $loader->addFixture($UsrOwner); + + $UsrList = new PhraseaFixture\UsrLists\UsrList(); + + $loader->addFixture($UsrList); + + $UsrEntry = new PhraseaFixture\UsrLists\UsrListEntry(); +// $UsrEntry->setList($UsrList); + $UsrEntry->setUser($user); + + $loader->addFixture($UsrEntry); + + + $this->insertFixtureInDatabase($loader); + + return $UsrEntry->entry; + } + catch (\Exception $e) + { + $this->fail('Fail load one UsrListEntry : ' . $e->getMessage()); + } + } /** * Insert five baskets and set current authenticated user as owner @@ -569,7 +632,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase { try { - $basketFixture = new MyFixture\LoadFiveBaskets(); + $basketFixture = new PhraseaFixture\Basket\LoadFiveBaskets(); $basketFixture->setUser(self::$user); @@ -671,7 +734,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $em = self::$core->getEntityManager(); /* @var $em \Doctrine\ORM\EntityManager */ - $basketFixture = new MyFixture\LoadOneBasketEnv(); + $basketFixture = new PhraseaFixture\Basket\LoadOneBasketEnv(); $basketFixture->setUser(self::$user); diff --git a/www/.htaccess b/www/.htaccess index 9150d14cab..e770070c46 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -20,6 +20,7 @@ RewriteRule ^prod/bridge/.*$ /prod/router.php [L] RewriteRule ^prod/feeds/.*$ /prod/router.php [L] RewriteRule ^prod/tooltip/.*$ /prod/router.php [L] + RewriteRule ^prod/lists/.*$ /prod/router.php [L] RewriteRule ^prod/baskets/.*$ /prod/router.php [L] RewriteRule ^prod/push/.*$ /prod/router.php [L] RewriteRule ^prod/printer/.*$ /prod/router.php [L]