diff --git a/composer.json b/composer.json index 3c549bdaa4..56089ec723 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,6 @@ "doctrine/migrations" : "1.0.x-dev@dev" }, "require-dev": { - "doctrine/data-fixtures" : "1.0.x@dev", "phpunit/phpunit" : "~3.7", "behat/behat" : "2.5.x-dev@dev", "behat/gherkin" : "2.3.x-dev@dev", @@ -69,8 +68,7 @@ "autoload": { "psr-0": { "" : "lib/classes", - "Alchemy" : "lib", - "PhraseaFixture" : "lib/conf.d" + "Alchemy" : "lib" } }, "include-path": ["vendor/zend/gdata/library"], diff --git a/lib/conf.d/PhraseaFixture/AbstractWZ.php b/lib/conf.d/PhraseaFixture/AbstractWZ.php deleted file mode 100644 index 5aa21cc300..0000000000 --- a/lib/conf.d/PhraseaFixture/AbstractWZ.php +++ /dev/null @@ -1,40 +0,0 @@ -user; - } - - public function setUser(\User_Adapter $user) - { - $this->user = $user; - } - - public function getRecord() - { - return $this->record; - } - - public function setRecord(\record_adapter $record) - { - $this->record = $record; - } -} diff --git a/lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php b/lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php deleted file mode 100644 index cfe482b7c0..0000000000 --- a/lib/conf.d/PhraseaFixture/Basket/LoadFiveBaskets.php +++ /dev/null @@ -1,47 +0,0 @@ -setName('test ' . $i); - $basket->setDescription('description'); - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new basket'); - } - - $basket->setOwner($this->user); - - $manager->persist($basket); - - $this->baskets[] = $basket; - } - $this->addReference('five-basket', $basket); - $manager->flush(); - } -} diff --git a/lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php b/lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php deleted file mode 100644 index 019e24e566..0000000000 --- a/lib/conf.d/PhraseaFixture/Basket/LoadOneBasket.php +++ /dev/null @@ -1,45 +0,0 @@ -setName('test'); - $basket->setDescription('description'); - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new basket'); - } - - $basket->setOwner($this->user); - - $manager->persist($basket); - $manager->flush(); - - $this->basket = $basket; - - $this->addReference('one-basket', $basket); - } -} diff --git a/lib/conf.d/PhraseaFixture/Basket/LoadOneBasketEnv.php b/lib/conf.d/PhraseaFixture/Basket/LoadOneBasketEnv.php deleted file mode 100644 index 16c128ef47..0000000000 --- a/lib/conf.d/PhraseaFixture/Basket/LoadOneBasketEnv.php +++ /dev/null @@ -1,120 +0,0 @@ -participants[] = $user; - } - - public function addElement(\record_adapter $record) - { - $this->basketElements[] = $record; - } - - public function load(ObjectManager $manager) - { - $basket = new Basket(); - - $basket->setName('test'); - $basket->setDescription('description'); - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new basket'); - } - - $basket->setOwner($this->user); - - $this->addElementToBasket($manager, $basket); - - $validationSession = new ValidationSession(); - $validationSession->setBasket($basket); - - $expires = new \DateTime(); - $expires->modify('+1 week'); - - $validationSession->setExpires($expires); - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new validation Session'); - } - - $validationSession->setInitiator($this->user); - - $this->addParticipantsToSession($manager, $validationSession); - - $this->basket = $basket; - } - - private function addParticipantsToSession(EntityManager $manager, ValidationSession $validationSession) - { - if (0 === count($this->participants)) { - throw new \LogicException('Add new participants to validation session'); - } - - foreach ($this->participants as $participant) { - $validationParticipant = new ValidationParticipant(); - - $validationParticipant->setUser($participant); - - $validationParticipant->setSession($validationSession); - - $manager->persist($validationParticipant); - } - - $manager->flush(); - } - - private function addElementToBasket(EntityManager $manager, Basket $basket) - { - if (0 === count($this->basketElements)) { - throw new \LogicException('Add new elements to basket'); - } - - foreach ($this->basketElements as $record) { - $basketElement = new BasketElement(); - - $basketElement->setRecord($record); - - $basketElement->setBasket($basket); - - $manager->persist($basketElement); - } - - $manager->flush(); - } -} diff --git a/lib/conf.d/PhraseaFixture/Feed/LoadOneFeed.php b/lib/conf.d/PhraseaFixture/Feed/LoadOneFeed.php deleted file mode 100644 index 4db8fbf574..0000000000 --- a/lib/conf.d/PhraseaFixture/Feed/LoadOneFeed.php +++ /dev/null @@ -1,93 +0,0 @@ -user) { - throw new \LogicException('Fill a user to store a new feed'); - } - - $feed = new Feed(); - - $publisher = new FeedPublisher(); - $publisher->setUsrId($this->user->get_id()); - $publisher->setIsOwner(true); - $publisher->setFeed($feed); - - $feed->addPublisher($publisher); - if (isset($this->title) && $this->title !== null) { - $feed->setTitle($this->title); - } else { - $feed->setTitle("test"); - } - - $feed->setIsPublic((Boolean) $this->public); - - $feed->setSubtitle("description"); - - $manager->persist($feed); - $manager->persist($publisher); - $manager->flush(); - - $this->feed = $feed; - - $this->addReference('one-feed', $feed); - } - - public function setUser(\User_Adapter $user) - { - $this->user = $user; - } - - public function getUser() - { - return $this->user; - } - - public function setTitle($title) - { - $this->title = $title; - } - - public function getTitle() - { - return $this->title; - } - - public function setPublic($public) - { - $this->public = $public; - } - - public function getPublic() - { - return $this->public; - } -} diff --git a/lib/conf.d/PhraseaFixture/Lazaret/LoadOneFile.php b/lib/conf.d/PhraseaFixture/Lazaret/LoadOneFile.php deleted file mode 100644 index 4f2983bf70..0000000000 --- a/lib/conf.d/PhraseaFixture/Lazaret/LoadOneFile.php +++ /dev/null @@ -1,61 +0,0 @@ -user) { - throw new \LogicException('Fill a user to store a new basket'); - } - - $lazaretSession = new LazaretSession(); - $lazaretSession->setUsrId($this->user->get_id()); - $lazaretSession->setUpdated(new \DateTime('now')); - $lazaretSession->setCreated(new \DateTime('-1 day')); - - $lazaretFile = new LazaretFile(); - $lazaretFile->setOriginalName('test'); - $lazaretFile->setFilename('test.jpg'); - $lazaretFile->setThumbFilename('thumb_test.jpg'); - $lazaretFile->setBaseId($this->collectionId); - $lazaretFile->setSession($lazaretSession); - $lazaretFile->setSha256('3191af52748620e0d0da50a7b8020e118bd8b8a0845120b0bb'); - $lazaretFile->setUuid('7b8ef0e3-dc8f-4b66-9e2f-bd049d175124'); - $lazaretFile->setCreated(new \DateTime('now')); - $lazaretFile->setUpdated(new \DateTime('-1 day')); - - $manager->persist($lazaretFile); - $manager->flush(); - - $this->file = $lazaretFile; - - $this->addReference('one-lazaret-file', $lazaretFile); - } - - public function setCollectionId($collectionId) - { - $this->collectionId = (int) $collectionId; - } -} diff --git a/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php b/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php deleted file mode 100644 index c8615db09c..0000000000 --- a/lib/conf.d/PhraseaFixture/Story/LoadOneStory.php +++ /dev/null @@ -1,48 +0,0 @@ -record) { - throw new \LogicException('Fill a record to store a new story'); - } - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new story'); - } - - $story->setRecord($this->record); - $story->setUser($this->user); - - $manager->persist($story); - $manager->flush(); - - $this->story = $story; - - $this->addReference('one-story', $story); - } -} diff --git a/lib/conf.d/PhraseaFixture/User/LoadOneUser.php b/lib/conf.d/PhraseaFixture/User/LoadOneUser.php deleted file mode 100644 index 7121b4adaa..0000000000 --- a/lib/conf.d/PhraseaFixture/User/LoadOneUser.php +++ /dev/null @@ -1,48 +0,0 @@ -user) { - throw new \Exception('Please set a user to persist'); - } - - $manager->persist($this->user); - $manager->flush(); - - $this->addReference('one-user', $this->user); - } - - public function getUser() - { - return $this->user; - } - - public function setUser(User $user) - { - $this->user = $user; - } -} diff --git a/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php b/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php deleted file mode 100644 index 3b9c757a4e..0000000000 --- a/lib/conf.d/PhraseaFixture/UsrLists/ListAbstract.php +++ /dev/null @@ -1,41 +0,0 @@ -user; - } - - public function setUser(\User_Adapter $user) - { - $this->user = $user; - } - - public function getList() - { - return $this->list; - } - - public function setList(UsrList $list) - { - $this->list = $list; - } -} diff --git a/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php b/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php deleted file mode 100644 index f985296bb5..0000000000 --- a/lib/conf.d/PhraseaFixture/UsrLists/UsrList.php +++ /dev/null @@ -1,47 +0,0 @@ -getReference('one-listowner'); - - $list->setName('new list'); - $list->addOwner($owner); - - /* @var $owner UsrListOwnerEntity */ - $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 deleted file mode 100644 index a51e72cf3d..0000000000 --- a/lib/conf.d/PhraseaFixture/UsrLists/UsrListEntry.php +++ /dev/null @@ -1,49 +0,0 @@ -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 UsrListEntity */ - $list->addEntrie($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 deleted file mode 100644 index 79f2dead90..0000000000 --- a/lib/conf.d/PhraseaFixture/UsrLists/UsrListOwner.php +++ /dev/null @@ -1,45 +0,0 @@ -setRole(UsrListOwnerEntity::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/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php deleted file mode 100644 index a9de5a783f..0000000000 --- a/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadOneParticipant.php +++ /dev/null @@ -1,46 +0,0 @@ -user) { - throw new \LogicException('Fill a user to store a new validation Session'); - } - $validationParticipant->setParticipant($this->user); - - $validationParticipant->setSession( - $this->getReference('one-validation-session') - ); - - $manager->persist($validationParticipant); - $manager->flush(); - - $this->validationParticipant = $validationParticipant; - - $this->addReference('one-validation-participant', $validationParticipant); - } -} diff --git a/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php b/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php deleted file mode 100644 index 6af7577cde..0000000000 --- a/lib/conf.d/PhraseaFixture/ValidationParticipant/LoadParticipantWithSession.php +++ /dev/null @@ -1,56 +0,0 @@ -user) { - throw new \LogicException('Fill a user to store a new validation Session'); - } - $validationParticipant->setUser($this->user); - - if (null === $this->session) { - throw new \LogicException('Attach a session to the current participant'); - } - $validationParticipant->setSession($this->session); - - $manager->persist($validationParticipant); - $manager->flush(); - - $this->validationParticipant = $validationParticipant; - } - - public function setSession(ValidationSession $session) - { - $this->session = $session; - } -} diff --git a/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php b/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php deleted file mode 100644 index e3eb01221b..0000000000 --- a/lib/conf.d/PhraseaFixture/ValidationSession/LoadOneValidationSession.php +++ /dev/null @@ -1,50 +0,0 @@ -setBasket( - $this->getReference('one-basket') // load the one-basket stored reference - ); - - $expires = new \DateTime(); - $expires->modify('+1 week'); - $validationSession->setExpires($expires); - - if (null === $this->user) { - throw new \LogicException('Fill a user to store a new validation Session'); - } - $validationSession->setInitiator($this->user); - - $manager->persist($validationSession); - $manager->flush(); - - $this->validationSession = $validationSession; - - $this->addReference('one-validation-session', $validationSession); - } -} diff --git a/tests/Alchemy/Tests/Phrasea/Model/Entities/UserTest.php b/tests/Alchemy/Tests/Phrasea/Model/Entities/UserTest.php index 653e4f495e..f64c4ef417 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Entities/UserTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Entities/UserTest.php @@ -98,10 +98,7 @@ class UserTest extends \PhraseanetPHPUnitAbstract public function testIsTemplate() { $this->assertFalse($this->user->isTemplate()); - $template = new User(); - $template->setLogin('login2'); - $template->setPassword('toto'); - $this->insertOneUser($template); + $template = $this->insertOneUser('login2'); $this->user->setModelOf($template); $this->assertTrue($this->user->isTemplate()); } @@ -120,15 +117,10 @@ class UserTest extends \PhraseanetPHPUnitAbstract public function testSetModelOf() { - $this->user->setLogin('login'); - $this->user->setPassword('toto'); - $user = new User(); - $user->setLogin('login2'); - $user->setPassword('toto'); - $this->insertOneUser($this->user); - $this->insertOneUser($user); - $this->user->setModelOf($user); - $this->assertEquals('login2', $this->user->getModelOf()->getLogin()); + $user1 = $this->insertOneUser('login'); + $user2 = $this->insertOneUser('login2'); + $user1->setModelOf($user2); + $this->assertEquals('login3', $user1->getModelOf()->getLogin()); } public function genderProvider() diff --git a/tests/Alchemy/Tests/Phrasea/Model/Repositories/UserRepositoryTest.php b/tests/Alchemy/Tests/Phrasea/Model/Repositories/UserRepositoryTest.php index 77f6ac2e33..ead90b6978 100644 --- a/tests/Alchemy/Tests/Phrasea/Model/Repositories/UserRepositoryTest.php +++ b/tests/Alchemy/Tests/Phrasea/Model/Repositories/UserRepositoryTest.php @@ -8,37 +8,27 @@ class UserRepositoryTest extends \PhraseanetPHPUnitAbstract { public function testFindAdminsWithNoAdmins() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $this->insertOneUser($user); + $this->insertOneUser('login'); $users = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findAdmins(); $this->assertEquals(0, count($users)); } public function testFindAdminsWithOneAdmin() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setAdmin(true); - $this->insertOneUser($user); + $this->insertOneUser('login', null, true); $users = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findAdmins(); $this->assertEquals(1, count($users)); } public function testFindAdminsWithOneAdminButTemplate() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setAdmin(true); + $user = $this->insertOneUser('login'); + $template = $this->insertOneUser('login', null, true); - $template = new User(); - $template->setLogin('logint'); - $template->setPassword('totot'); + $template->setModelOf($user); - $user->setModelOf($template); + self::$DI['app']['EM']->persist($template); + self::$DI['app']['EM']->flush(); $users = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findAdmins(); $this->assertEquals(0, count($users)); @@ -46,22 +36,19 @@ class UserRepositoryTest extends \PhraseanetPHPUnitAbstract public function testFindAdminsWithOneAdminButDeleted() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setAdmin(true); + $user = $this->insertOneUser('login', null, true); $user->setDeleted(true); + self::$DI['app']['EM']->persist($user); + self::$DI['app']['EM']->flush(); + $users = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findAdmins(); $this->assertEquals(0, count($users)); } public function testFindByLogin() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $this->insertOneUser($user); + $this->insertOneUser('login'); $user = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByLogin('login'); $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); $this->assertNull(self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByLogin('wrong-login')); @@ -69,36 +56,30 @@ class UserRepositoryTest extends \PhraseanetPHPUnitAbstract public function testFindUserByEmail() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setEmail('toto@toto.to'); - $this->insertOneUser($user); + $this->insertOneUser('login', 'toto@toto.to'); $user = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByEmail('toto@toto.to'); $this->assertInstanceOf('Alchemy\Phrasea\Model\Entities\User', $user); } public function testFindUserByEmailButDeleted() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setEmail('toto@toto.to'); + $user = $this->insertOneUser('login', 'toto@toto.to'); $user->setDeleted(true); - $this->insertOneUser($user); - $user = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByEmail('toto@toto.to'); - $this->assertNull($user); + + self::$DI['app']['EM']->persist($user); + self::$DI['app']['EM']->flush(); + + $this->assertNull(self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByEmail('toto@toto.to')); } public function testFindUserByEmailButNullEmail() { - $user = new User(); - $user->setLogin('login'); - $user->setPassword('toto'); - $user->setEmail(null); + $user = $this->insertOneUser('login'); $user->setDeleted(true); - $this->insertOneUser($user); - $user = self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByEmail('toto@toto.to'); - $this->assertNull($user); + + self::$DI['app']['EM']->persist($user); + self::$DI['app']['EM']->flush(); + + $this->assertNull(self::$DI['app']['EM']->getRepository('Alchemy\Phrasea\Model\Entities\User')->findByEmail('toto@toto.to')); } } diff --git a/tests/classes/PhraseanetPHPUnitAbstract.php b/tests/classes/PhraseanetPHPUnitAbstract.php index 30657b307c..60b61d1c48 100644 --- a/tests/classes/PhraseanetPHPUnitAbstract.php +++ b/tests/classes/PhraseanetPHPUnitAbstract.php @@ -3,19 +3,25 @@ use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Border\File; -use Doctrine\Common\DataFixtures\Loader; use Alchemy\Phrasea\Model\Entities\AggregateToken; use Alchemy\Phrasea\Model\Entities\Basket; use Alchemy\Phrasea\Model\Entities\BasketElement; use Alchemy\Phrasea\Model\Entities\Feed; use Alchemy\Phrasea\Model\Entities\FeedEntry; use Alchemy\Phrasea\Model\Entities\FeedItem; +use Alchemy\Phrasea\Model\Entities\FeedPublisher; use Alchemy\Phrasea\Model\Entities\FeedToken; +use Alchemy\Phrasea\Model\Entities\LazaretFile; +use Alchemy\Phrasea\Model\Entities\LazaretSession; use Alchemy\Phrasea\Model\Entities\Session; use Alchemy\Phrasea\Model\Entities\Task; use Alchemy\Phrasea\Model\Entities\User; +use Alchemy\Phrasea\Model\Entities\ValidationData; use Alchemy\Phrasea\Model\Entities\ValidationSession; use Alchemy\Phrasea\Model\Entities\ValidationParticipant; +use Alchemy\Phrasea\Model\Entities\UsrListOwner; +use Alchemy\Phrasea\Model\Entities\UsrList; +use Alchemy\Phrasea\Model\Entities\UsrListEntry; use Silex\WebTestCase; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Client; @@ -113,7 +119,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase */ public function __destruct() { - self::deleteRessources(); + self::deleteResources(); if (self::$time_start) { self::$time_start = null; @@ -270,6 +276,26 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $this->assertTrue(false !== stripos($response->getContent(), 'Sorry, the page you are looking for could not be found')); } + protected function assertDateAtom($date) + { + return $this->assertRegExp('/\d{4}[-]\d{2}[-]\d{2}[T]\d{2}[:]\d{2}[:]\d{2}[+]\d{2}[:]\d{2}/', $date); + } + + protected function set_user_agent($user_agent, Application $app) + { + $app['browser']->setUserAgent($user_agent); + $app->register(new \Silex\Provider\TwigServiceProvider()); + $app->setupTwig(); + self::$DI['client'] = self::$DI->share(function ($DI) use ($app) { + return new Client($app, []); + }); + } + + /** + * Inserts two tasks. + * + * @return Task[] + */ public function insertTwoTasks() { $task1 = new Task(); @@ -285,61 +311,23 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::$DI['app']['EM']->persist($task1); self::$DI['app']['EM']->persist($task2); self::$DI['app']['EM']->flush(); + + return [$task1, $task2]; } /** - * Insert fixture contained in the specified fixtureLoader - * into sqlLite test temporary database + * Inserts one basket. * - * @param 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::$DI['app']['EM'], $purger); - $executor->execute($fixtureLoader->getFixtures(), $append); - self::$DI['client'] = self::$DI->share(function ($DI) { - return new Client($DI['app'], []); - }); - } - - /** - * Purge sqlLite test temporary database by truncate all existing tables - */ - protected static function purgeDatabase() - { - $purger = new Doctrine\Common\DataFixtures\Purger\ORMPurger(); - $executor = new Doctrine\Common\DataFixtures\Executor\ORMExecutor(self::$DI['app']['EM'], $purger); - $executor->execute([]); - self::$DI['app']["phraseanet.cache-service"]->flushAll(); - } - - protected function assertDateAtom($date) - { - return $this->assertRegExp('/\d{4}[-]\d{2}[-]\d{2}[T]\d{2}[:]\d{2}[:]\d{2}[+]\d{2}[:]\d{2}/', $date); - } - - protected function set_user_agent($user_agent, Alchemy\Phrasea\Application $app) - { - $app['browser']->setUserAgent($user_agent); - $app->register(new \Silex\Provider\TwigServiceProvider()); - $app->setupTwig(); - self::$DI['client'] = self::$DI->share(function ($DI) use ($app) { - return new Client($app, []); - }); - } - - /** - * Insert one basket entry ans set current authenticated user as owner + * @param User_Adapter $user * - * @return \Alchemy\Phrasea\Model\Entities\Basket + * @return Basket */ protected function insertOneBasket(\User_Adapter $user = null) { $basket = new Basket(); $basket->setOwner($user ?: self::$DI['user']); $basket->setName('test'); - $basket->setName('description test'); + $basket->setDescription('description test'); self::$DI['app']['EM']->persist($basket); self::$DI['app']['EM']->flush(); @@ -348,250 +336,274 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Insert one feed + * Inserts one feed. * - * @return \Alchemy\Phrasea\Model\Entities\Feed + * @param User_Adapter $user + * @param string|null $title + * @param bool $public + * + * @return Feed */ - protected function insertOneFeed(\User_Adapter $user, $title = null, $public = null) + protected function insertOneFeed(\User_Adapter $user = null , $title = null, $public = false) { - try { - $feedFixture = new PhraseaFixture\Feed\LoadOneFeed(); - $feedFixture->setUser($user); + $feed = new Feed(); + $publisher = new FeedPublisher(); - if ($title !== null) { - $feedFixture->setTitle($title); - } + $user = $user ?: self::$DI['user']; - if ($public !== null) { - $feedFixture->setPublic($public); - } + $publisher->setUsrId($user->get_id()); + $publisher->setIsOwner(true); + $publisher->setFeed($feed); - $loader = new Loader(); - $loader->addFixture($feedFixture); + $feed->addPublisher($publisher); + $feed->setTitle($title ?: "test"); + $feed->setIsPublic($public); + $feed->setSubtitle("description"); - $this->insertFixtureInDatabase($loader); + self::$DI['app']['EM']->persist($feed); + self::$DI['app']['EM']->persist($publisher); + self::$DI['app']['EM']->flush(); - return $feedFixture->feed; - } catch (\Exception $e) { - $this->fail('Fail to load one Feed : ' . $e->getMessage()); - } + return $feed; } /** + * Inserts one feed entry. * - * @return \Alchemy\Phrasea\Model\Entities\FeedEntry + * @param User_Adapter $user + * @param bool $public + * + * @return FeedEntry */ - protected function insertOneFeedEntry(\User_Adapter $user, $public = false) + protected function insertOneFeedEntry(\User_Adapter $user = null, $public = false) { - try { - $feed = $this->insertOneFeed($user, '', $public); + $feed = $this->insertOneFeed($user, null, $public); - $em = self::$DI['app']['EM']; + $entry = new FeedEntry(); + $entry->setFeed($feed); + $entry->setTitle("test"); + $entry->setSubtitle("description"); + $entry->setAuthorName('user'); + $entry->setAuthorEmail('user@email.com'); - $entry = new \Alchemy\Phrasea\Model\Entities\FeedEntry(); - $entry->setFeed($feed); - $entry->setTitle("test"); - $entry->setSubtitle("description"); - $entry->setAuthorName('user'); - $entry->setAuthorEmail('user@email.com'); + $publisher = $feed->getPublisher($user ?: self::$DI['user']); - $publisher = $feed->getPublisher($user); - - if ($publisher !== null) { - $entry->setPublisher($publisher); - } - - $feed->addEntry($entry); - - $em->persist($entry); - $em->persist($feed); - - $em->flush(); - - return $entry; - } catch (\Exception $e) { - $this->fail('Fail to load one FeedEntry : ' . $e->getMessage()); + if ($publisher !== null) { + $entry->setPublisher($publisher); } + + $feed->addEntry($entry); + + self::$DI['app']['EM']->persist($entry); + self::$DI['app']['EM']->persist($feed); + self::$DI['app']['EM']->flush(); + + return $entry; } - protected function insertOneFeedToken(Feed $feed, \User_Adapter $user) + /** + * Inserts one feed token. + * + * @param Feed $feed + * @param User_Adapter $user + * + * @return FeedToken + */ + protected function insertOneFeedToken(Feed $feed, \User_Adapter $user = null) { - try { - $token = new FeedToken(); - $token->setValue(self::$DI['app']['tokens']->generatePassword(12)); - $token->setFeed($feed); - $token->setUsrId($user->get_id()); + $user = $user ?: self::$DI['user']; - $feed->addToken($token); + $token = new FeedToken(); + $token->setValue(self::$DI['app']['tokens']->generatePassword(12)); + $token->setFeed($feed); + $token->setUsrId($user->get_id()); - self::$DI['app']['EM']->persist($token); - self::$DI['app']['EM']->persist($feed); - self::$DI['app']['EM']->flush(); - } catch (\Exception $e) { - $this->fail('Fail to load one FeedToken : ' . $e->getMessage()); - } + $feed->addToken($token); - return $token; - } - - protected function insertOneAggregateToken(\User_Adapter $user) - { - try { - $token = new AggregateToken(); - $token->setValue(self::$DI['app']['tokens']->generatePassword(12)); - $token->setUsrId($user->get_id()); - - self::$DI['app']['EM']->persist($token); - self::$DI['app']['EM']->flush(); - } catch (\Exception $e) { - $this->fail('Fail to load one AggregateToken : ' . $e->getMessage()); - } + self::$DI['app']['EM']->persist($token); + self::$DI['app']['EM']->persist($feed); + self::$DI['app']['EM']->flush(); return $token; } /** + * Insert one aggregate token. * - * @return \Alchemy\Phrasea\Model\Entities\FeedItem + * @param User_Adapter $user + * + * @return AggregateToken */ - protected function insertOneFeedItem(\User_Adapter $user, $public = false, $qty = 1, \record_adapter $record = null) + protected function insertOneAggregateToken(\User_Adapter $user = null) { - try { - $em = self::$DI['app']['EM']; - $entry = $this->insertOneFeedEntry($user, $public); + $user = $user ?: self::$DI['user']; - for ($i = 0; $i < $qty; $i++) { - $item = new \Alchemy\Phrasea\Model\Entities\FeedItem(); - $item->setEntry($entry); + $token = new AggregateToken(); + $token->setValue(self::$DI['app']['tokens']->generatePassword(12)); + $token->setUsrId($user->get_id()); - if (null === $record) { - $actual = self::$DI['record_'.($i+1)]; - } else { - $actual = $record; - } + self::$DI['app']['EM']->persist($token); + self::$DI['app']['EM']->flush(); - $item->setRecordId($actual->get_record_id()); - $item->setSbasId($actual->get_sbas_id()); - $item->setEntry($entry); + return $token; + } - $entry->addItem($item); - $em->persist($item); + /** + * Inserts one feed item. + * + * @param User_Adapter $user + * @param boolean $public + * @param integer $qty + * @param record_adapter $record + * + * @return FeedItem + */ + protected function insertOneFeedItem(\User_Adapter $user = null, $public = false, $qty = 1, \record_adapter $record = null) + { + $entry = $this->insertOneFeedEntry($user, $public); + + for ($i = 0; $i < $qty; $i++) { + $item = new FeedItem(); + $item->setEntry($entry); + + if (null === $record) { + $actual = self::$DI['record_'.($i+1)]; + } else { + $actual = $record; } - $em->persist($entry); + $item->setRecordId($actual->get_record_id()); + $item->setSbasId($actual->get_sbas_id()); + $item->setEntry($entry); + $entry->addItem($item); - $em->flush(); - } catch (\Exception $e) { - $this->fail('Fail to load one FeedEntry : ' . $e->getMessage()); + self::$DI['app']['EM']->persist($item); } + self::$DI['app']['EM']->persist($entry); + self::$DI['app']['EM']->flush(); + return $item; } /** - * Insert one basket entry ans set current authenticated user as owner + * Inserts one lazaret file. * - * @return \Alchemy\Phrasea\Model\Entities\Basket + * @param User_Adapter $user + * + * @return LazaretFile */ - protected function insertOneLazaretFile() + protected function insertOneLazaretFile(\User_Adapter $user = null) { - try { - $lazaretFixture = new PhraseaFixture\Lazaret\LoadOneFile(); + $user = $user ?: self::$DI['user']; - $lazaretFixture->setUser(self::$DI['user']); - $lazaretFixture->setCollectionId(self::$DI['collection']->get_base_id()); + $lazaretSession = new LazaretSession(); + $lazaretSession->setUsrId($user->get_id()); + $lazaretSession->setUpdated(new \DateTime('now')); + $lazaretSession->setCreated(new \DateTime('-1 day')); - $loader = new Loader(); - $loader->addFixture($lazaretFixture); + $lazaretFile = new LazaretFile(); + $lazaretFile->setOriginalName('test'); + $lazaretFile->setFilename('test.jpg'); + $lazaretFile->setThumbFilename('thumb_test.jpg'); + $lazaretFile->setBaseId(self::$DI['collection']->get_base_id()); + $lazaretFile->setSession($lazaretSession); + $lazaretFile->setSha256('3191af52748620e0d0da50a7b8020e118bd8b8a0845120b0bb'); + $lazaretFile->setUuid('7b8ef0e3-dc8f-4b66-9e2f-bd049d175124'); + $lazaretFile->setCreated(new \DateTime('now')); + $lazaretFile->setUpdated(new \DateTime('-1 day')); - $this->insertFixtureInDatabase($loader); + self::$DI['app']['EM']->persist($lazaretFile); + self::$DI['app']['EM']->flush(); - return $lazaretFixture->file; - } catch (\Exception $e) { - $this->fail('Fail load one Basket : ' . $e->getMessage()); - } - } + return $lazaretFile; - 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()); - } } /** + * Inserts one user list. * - * @param \Alchemy\Phrasea\Model\Entities\UsrList $UsrList - * @return \Alchemy\Phrasea\Model\Entities\UsrListEntry + * @param User_Adapter $user + * + * @return UsrListOwner + */ + protected function insertOneUsrList(\User_Adapter $user = null) + { + $user = $user ?: self::$DI['user']; + + $owner = new UsrListOwner(); + $owner->setRole(UsrListOwner::ROLE_ADMIN); + $owner->setUser($user); + + self::$DI['app']['EM']->persist($owner); + self::$DI['app']['EM']->flush(); + + return $owner; + } + + /** + * Insert one user list entry. + * + * @param User_adapter $owner + * @param User_adapter $user + * + * @return UsrListEntry */ protected function insertOneUsrListEntry(\User_adapter $owner, \User_adapter $user) { - try { - $loader = new Loader(); + $listOwner = new UsrListOwner(); + $listOwner->setRole(UsrListOwner::ROLE_ADMIN); + $listOwner->setUser($owner); - $UsrOwner = new PhraseaFixture\UsrLists\UsrListOwner(); - $UsrOwner->setUser($owner); + $list = new UsrList(); + $list->addOwner($listOwner); - $loader->addFixture($UsrOwner); + $listOwner->setList($list); - $UsrList = new PhraseaFixture\UsrLists\UsrList(); + $entry = new UsrListEntry(); + $entry->setUser($user); + $entry->setList($list); - $loader->addFixture($UsrList); + $list->addEntrie($entry); - $UsrEntry = new PhraseaFixture\UsrLists\UsrListEntry(); + self::$DI['app']['EM']->persist($entry); + self::$DI['app']['EM']->persist($list); + self::$DI['app']['EM']->persist($listOwner); + self::$DI['app']['EM']->flush(); - $UsrEntry->setUser($user); - - $loader->addFixture($UsrEntry); - - $this->insertFixtureInDatabase($loader); - - return $UsrEntry->entry; - } catch (\Exception $e) { - $this->fail('Fail load one UsrListEntry : ' . $e->getMessage()); - } + return $entry; } /** - * Insert five baskets and set current authenticated user as owner + * Inserts five baskets. * - * @return \Alchemy\Phrasea\Model\Entities\Basket + * @return Basket[] */ protected function insertFiveBasket() { - try { - $basketFixture = new PhraseaFixture\Basket\LoadFiveBaskets(); + $baskets = []; - $basketFixture->setUser(self::$DI['user']); + for ($i = 0; $i < 5; $i ++) { + $basket = new Basket(); + $basket->setName('test ' . $i); + $basket->setDescription('description'); + $basket->setOwner(self::$DI['user']); - $loader = new Loader(); - $loader->addFixture($basketFixture); - - $this->insertFixtureInDatabase($loader); - - return $basketFixture->baskets; - } catch (\Exception $e) { - $this->fail('Fail load five Basket : ' . $e->getMessage()); + self::$DI['app']['EM']->persist($basket); + $baskets[] = $basket; } + self::$DI['app']['EM']->flush(); + + return $baskets; } /** - * @return \Alchemy\Phrasea\Model\Entities\BasketElement + * Inserts one basket element. + * + * @param User_Adapter $user + * @param record_adapter $record + * + * @return BasketElement */ protected function insertOneBasketElement(\User_Adapter $user = null, \record_adapter $record = null) { @@ -602,67 +614,66 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $basket->addElement($element); $element->setBasket($basket); - self::$DI['app']['EM']->persist($element); + self::$DI['app']['EM']->persist($basket); self::$DI['app']['EM']->flush(); return $element; } /** + * Inserts one validation basket. * - * @return \Alchemy\Phrasea\Model\Entities\Basket + * @param array $parameters + * + * @return Basket */ protected function insertOneValidationBasket(array $parameters = []) { - $em = self::$DI['app']['EM']; - $basketElement = $this->insertOneBasketElement(); $basket = $basketElement->getBasket(); - $Validation = new Alchemy\Phrasea\Model\Entities\ValidationSession(); - $Validation->setBasket($basket); - $Validation->setInitiator(self::$DI['user']); + $validation = new ValidationSession(); + $validation->setBasket($basket); + $validation->setInitiator(self::$DI['user']); if (isset($parameters['expires']) && $parameters['expires'] instanceof \DateTime) { - $Validation->setExpires($parameters['expires']); + $validation->setExpires($parameters['expires']); } - $basket->setValidation($Validation); - $em->persist($Validation); - $em->merge($basket); + $basket->setValidation($validation); - $Participant = new Alchemy\Phrasea\Model\Entities\ValidationParticipant(); - $Participant->setUser(self::$DI['user']); - $Participant->setCanAgree(true); - $Participant->setCanSeeOthers(true); + $participant = new ValidationParticipant(); + $participant->setUser(self::$DI['user']); + $participant->setCanAgree(true); + $participant->setCanSeeOthers(true); - $Validation->addParticipant($Participant); - $Participant->setSession($Validation); + $validation->addParticipant($participant); + $participant->setSession($validation); - $em->persist($Participant); - $em->merge($Validation); + $data = new ValidationData(); + $data->setBasketElement($basketElement); + $data->setParticipant($participant); + $basketElement->addValidationData($data); - $Data = new Alchemy\Phrasea\Model\Entities\ValidationData(); - $Data->setBasketElement($basketElement); - $Data->setParticipant($Participant); - $basketElement->addValidationData($Data); + self::$DI['app']['EM']->persist($basket); + self::$DI['app']['EM']->persist($validation); + self::$DI['app']['EM']->persist($participant); + self::$DI['app']['EM']->persist($data); + self::$DI['app']['EM']->persist($basketElement); - $em->persist($Data); - $em->merge($basketElement); - - $em->flush(); + self::$DI['app']['EM']->flush(); return $basket; } /** - * Create a new basket with current auhtenticated user as owner - * Create a new sessionValidation with the newly created basket - * Set current authenticated user as sessionValidation initiator - * Add 2 records as elments of the newly created basket - * Add 2 participants to the newly created sessionValidation + * - Creates a new basket with current authenticated user as owner. + * - Creates a new sessionValidation with the newly created basket. + * - Sets current authenticated user as sessionValidation initiator. + * - Adds 2 records as elements of the newly created basket. + * - Adds 2 participants to the newly created sessionValidation. * - * @return \Alchemy\Phrasea\Model\Entities\Basket + * @return Basket */ protected function insertOneBasketEnv() { @@ -670,6 +681,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $basket->setName('test'); $basket->setDescription('description'); $basket->setOwner(self::$DI['user']); + self::$DI['app']['EM']->persist($basket); foreach ([self::$DI['record_1'], self::$DI['record_2']] as $record) { @@ -702,58 +714,72 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Load One WZ with - * One basket - * One story - * One ValidationSession & one participant - * @return + * Inserts one story. + * + * @param User_Adapter $user + * @param record_adapter $record + * + * @return StoryWZ + */ + protected function insertOneStory(User_Adapter $user = null, \record_adapter $record = null) + { + $story = new StoryWZ(); + + $story->setRecord($record ?: self::$DI['record_1']); + $story->setUser($user ?: self::$DI['user']); + + self::$DI['app']['EM']->persist($story); + self::$DI['app']['EM']->flush(); + + return $story; + } + + /** + * Inserts one validation session. + * + * @param Basket $basket + * @param User_Adapter $user + * + * @return ValidationSession + */ + protected function insertOneValidationSession(Basket $basket = null, \User_Adapter $user = null) + { + $validationSession = new ValidationSession(); + + $validationSession->setBasket($basket ?: $this->insertOneBasket()); + + $expires = new \DateTime(); + $expires->modify('+1 week'); + $validationSession->setExpires($expires); + $validationSession->setInitiator($user ?: self::$DI['user']); + + self::$DI['app']['EM']->persist($validationSession); + self::$DI['app']['EM']->flush(); + + return $validationSession; + } + + /** + * Loads One WZ with one basket, one story and one ValidationSession with one participant. */ protected function insertOneWZ() { - try { - $currentUser = self::$DI['user']; - $altUser = self::$DI['user_alt1']; - - // add one basket - $basket = new PhraseaFixture\Basket\LoadOneBasket(); - $basket->setUser($currentUser); - - //add one story - $story = new PhraseaFixture\Story\LoadOneStory(); - $story->setUser($currentUser); - $story->setRecord(self::$DI['record_1']); - - //add a validation session initiated by alt user - $validationSession = new PhraseaFixture\ValidationSession\LoadOneValidationSession(); - $validationSession->setUser($altUser); - - $loader = new Loader(); - $loader->addFixture($basket); - $loader->addFixture($story); - $loader->addFixture($validationSession); - - $this->insertFixtureInDatabase($loader); - } catch (\Exception $e) { - $this->fail('Fail load one WorkingZone : ' . $e->getMessage()); - } - - return; + $this->insertOneStory(); + $this->insertOneValidationSession($this->insertOneBasket(), self::$DI['user_alt1']); } - protected function insertOneUser(User $user) + /** + * Inserts one user. + * + * @param string $login + * @param null $email + * @param bool $admin + * + * @return User + */ + protected function insertOneUser($login, $email = null, $admin = false) { - try { - $userFixture = new PhraseaFixture\User\LoadOneUser(); - $userFixture->setUser($user); - - $loader = new Loader(); - $loader->addFixture($userFixture); - - $this->insertFixtureInDatabase($loader); - - } catch (\Exception $e) { - $this->fail('Fail load one User : ' . $e->getMessage()); - } + return self::$DI['app']['manipulator.user']->create($login, uniqid('pass'), $email, $admin); } /** @@ -762,7 +788,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase * @param string $method The request method * @param string $uri The URI to fetch * @param array $parameters The Request parameters - * @param array $httpAccept Contents of the Accept header + * @param string $httpAccept Contents of the Accept header * * @return Crawler */ @@ -775,13 +801,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Update the sql tables with the current schema - * @return void + * Updates the sql tables with the current schema. */ private static function updateTablesSchema(Application $application) { if (!self::$updated) { - if (file_exists(Setup_Upgrade::get_lock_file())) { unlink(Setup_Upgrade::get_lock_file()); } @@ -800,7 +824,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase throw new \RuntimeException($process->getErrorOutput()); } - self::$updated = true; + self::$updated = true; } catch (\RuntimeException $e) { echo "\033[0;31mUnable to validate ORM schema\033[0;37m\n"; exit(1); @@ -813,12 +837,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Create a set of users for the test suite + * Creates a set of users for the test suite. + * * self::$DI['user'] * self::$DI['user_alt1'] * self::$DI['user_alt2'] - * - * @return void; */ private static function createSetOfUserTests(Application $application) { @@ -870,7 +893,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Give Bases Rights to User + * Gives Bases Rights to User. * * @param \User_Adapter $user */ @@ -923,8 +946,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Set self::$DI['collection'] - * @return void + * Sets self::$DI['collection']. */ private static function setCollection(Application $application) { @@ -998,7 +1020,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Generate a set of records for the current tests suites + * Generates a set of records for the current tests suites. */ private static function generateRecords(Application $app) { @@ -1087,11 +1109,9 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase } /** - * Delete previously created Ressources - * - * @return void + * Deletes previously created Resources. */ - private static function deleteRessources() + private static function deleteResources() { $skipped = \PhraseanetPHPUnitListener::getSkipped(); @@ -1116,6 +1136,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase return; } + /** + * Authenticates self::['user'] against application. + * + * @param Application $app + */ protected function authenticate(Application $app) { $app['session']->clear(); @@ -1131,6 +1156,11 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::$DI['app']['authentication']->reinitUser(); } + /** + * Logout authenticated user from application. + * + * @param Application $app + */ protected function logout(Application $app) { $app['session']->clear();