]> git.mxchange.org Git - friendica.git/commitdiff
Adapt ProfileField & Fix current PermissionSet Usage at ProfileFields
authorPhilipp <admin@philipp.info>
Sun, 17 Oct 2021 13:32:50 +0000 (15:32 +0200)
committerPhilipp <admin@philipp.info>
Mon, 18 Oct 2021 21:32:44 +0000 (23:32 +0200)
src/Core/UserImport.php
src/Model/Profile.php
src/Module/Settings/Profile/Index.php
src/Profile/ProfileField/Collection/ProfileFields.php
src/Profile/ProfileField/Depository/ProfileField.php
src/Profile/ProfileField/Entity/ProfileField.php
src/Profile/ProfileField/Factory/ProfileField.php
src/Security/PermissionSet/Factory/PermissionSet.php
static/dbview.config.php
tests/src/Profile/ProfileField/Entity/ProfileFieldTest.php
update.php

index 309e5c2a9632426c12ce57955f5feefeeeb34ca2..4ac59d14cb94bb38599f7f07ffc3fefd78692119 100644 (file)
@@ -279,7 +279,7 @@ class UserImport
                                $profile['id'] = DBA::lastInsertId();
                        }
 
-                       Profile::migrateFromLegacyProfile($profile);
+                       Profile::migrate($profile);
                }
 
                $permissionSet = DI::permissionSet()->selectDefaultForUser($newuid);
index 2baf455cfd5e7e0cc02846bdd91466e488fac1b9..d089ada3cd172f87908412237ad2fc42f057bc99 100644 (file)
@@ -945,7 +945,7 @@ class Profile
         * @param array $profile One profile array
         * @throws \Exception
         */
-       public static function migrateFromLegacyProfile(array $profile)
+       public static function migrate(array $profile)
        {
                // Already processed, aborting
                if ($profile['is-default'] === null) {
@@ -999,7 +999,7 @@ class Profile
 
                foreach ($custom_fields as $field => $label) {
                        if (!empty($profile[$field]) && $profile[$field] > DBA::NULL_DATE && $profile[$field] > DBA::NULL_DATETIME) {
-                               DI::profileField()->save(DI::profileFieldFactory()->createFromString(
+                               DI::profileField()->save(DI::profileFieldFactory()->createFromValues(
                                        $profile['uid'],
                                        $order,
                                        trim($label, ':'),
index efb3ac9d3e948ba387abadfed1fc7befa1a9a315..7ebf5b712f33c94c333d3b5b762878acd6b5e9d4 100644 (file)
@@ -274,13 +274,13 @@ class Index extends BaseSettings
                if (!empty($profileFieldInputs['new']['label'])) {
                        $permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString(
                                $uid,
-                               $profileFieldInputs['new']['contact_allow'] ?? '',
-                               $profileFieldInputs['new']['group_allow'] ?? '',
-                               $profileFieldInputs['new']['contact_deny'] ?? '',
-                               $profileFieldInputs['new']['group_deny'] ?? ''
+                               DI::aclFormatter()->toString($profileFieldInputs['new']['contact_allow'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInputs['new']['group_allow'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInputs['new']['contact_deny'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInputs['new']['group_deny'] ?? '')
                        ));
 
-                       $profileFields->append(DI::profileFieldFactory()->createFromString(
+                       $profileFields->append(DI::profileFieldFactory()->createFromValues(
                                $uid,
                                $profileFieldOrder['new'],
                                $profileFieldInputs['new']['label'],
@@ -295,13 +295,13 @@ class Index extends BaseSettings
                foreach ($profileFieldInputs as $id => $profileFieldInput) {
                        $permissionSet = DI::permissionSet()->selectOrCreate(DI::permissionSetFactory()->createFromString(
                                $uid,
-                               $profileFieldInput['contact_allow'] ?? '',
-                               $profileFieldInput['group_allow'] ?? '',
-                               $profileFieldInput['contact_deny'] ?? '',
-                               $profileFieldInput['group_deny'] ?? ''
+                               DI::aclFormatter()->toString($profileFieldInput['contact_allow'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInput['group_allow'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInput['contact_deny'] ?? ''),
+                               DI::aclFormatter()->toString($profileFieldInput['group_deny'] ?? '')
                        ));
 
-                       $profileFields->append(DI::profileFieldFactory()->createFromString(
+                       $profileFields->append(DI::profileFieldFactory()->createFromValues(
                                $uid,
                                $profileFieldOrder[$id],
                                $profileFieldInput['label'],
index b954e3ba37c50a277aed749f1951f5599b1ae4b0..21af7397c9f9bef8c6b85f46f1d85d442691750f 100644 (file)
@@ -35,7 +35,7 @@ class ProfileFields extends BaseCollection
         * @param callable $callback
         * @return ProfileFields
         */
-       public function map(callable $callback): self
+       public function map(callable $callback): ProfileFields
        {
                return parent::map($callback);
        }
@@ -45,7 +45,7 @@ class ProfileFields extends BaseCollection
         * @param int           $flag
         * @return ProfileFields
         */
-       public function filter(callable $callback = null, int $flag = 0): self
+       public function filter(callable $callback = null, int $flag = 0): ProfileFields
        {
                return parent::filter($callback, $flag);
        }
index 590e3f45a877858372df658c00aa927704d7721b..0ca427a1a1995f2afab8ef9541fe9ff5c8975148 100644 (file)
@@ -23,9 +23,10 @@ namespace Friendica\Profile\ProfileField\Depository;
 
 use Friendica\BaseDepository;
 use Friendica\Database\Database;
-use Friendica\Network\HTTPException\NotFoundException;
+use Friendica\Database\DBA;
 use Friendica\Profile\ProfileField\Exception\ProfileFieldNotFoundException;
 use Friendica\Profile\ProfileField\Exception\ProfileFieldPersistenceException;
+use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
 use Friendica\Profile\ProfileField\Factory;
 use Friendica\Profile\ProfileField\Entity;
 use Friendica\Profile\ProfileField\Collection;
@@ -40,6 +41,8 @@ class ProfileField extends BaseDepository
 
        protected static $table_name = 'profile_field';
 
+       protected static $view_name = 'profile_field-view';
+
        /** @var PermissionSetDepository */
        protected $permissionSetDepository;
 
@@ -53,16 +56,20 @@ class ProfileField extends BaseDepository
        /**
         * @param array $condition
         * @param array $params
+        *
         * @return Entity\ProfileField
+        *
         * @throws ProfileFieldNotFoundException
+        * @throws UnexpectedPermissionSetException
         */
        private function selectOne(array $condition, array $params = []): Entity\ProfileField
        {
-               try {
-                       return parent::_selectOne($condition, $params);
-               } catch (NotFoundException $exception) {
-                       throw new ProfileFieldNotFoundException($exception->getMessage());
+               $fields = $this->db->selectFirst(static::$view_name, [], $condition, $params);
+               if (!$this->db->isResult($fields)) {
+                       throw new ProfileFieldNotFoundException();
                }
+
+               return $this->factory->createFromTableRow($fields);
        }
 
        /**
@@ -72,14 +79,19 @@ class ProfileField extends BaseDepository
         * @return Collection\ProfileFields
         *
         * @throws ProfileFieldPersistenceException In case of underlying persistence exceptions
+        * @throws UnexpectedPermissionSetException
         */
        private function select(array $condition, array $params = []): Collection\ProfileFields
        {
-               try {
-                       return new Collection\ProfileFields(parent::_select($condition, $params)->getArrayCopy());
-               } catch (\Exception $exception) {
-                       throw new ProfileFieldPersistenceException('Cannot select ProfileFields', $exception);
+               $rows = $this->db->selectToArray(static::$view_name, [], $condition, $params);
+
+               $Entities = new Collection\ProfileFields();
+               foreach ($rows as $fields) {
+                       $this->logger->warning('row', ['row' => $fields]);
+                       $Entities[] = $this->factory->createFromTableRow($fields);
                }
+
+               return $Entities;
        }
 
        /**
@@ -98,7 +110,7 @@ class ProfileField extends BaseDepository
                        'order'   => $profileField->order,
                        'created' => $profileField->created->format(DateTimeFormat::MYSQL),
                        'edited'  => $profileField->edited->format(DateTimeFormat::MYSQL),
-                       'psid'    => $profileField->permissionSetId
+                       'psid'    => $profileField->permissionSet->id
                ];
        }
 
@@ -170,7 +182,7 @@ class ProfileField extends BaseDepository
         *
         * @ProfileFieldNotFoundException In case there is no ProfileField found
         */
-       public function selectOnyById(int $id): Entity\ProfileField
+       public function selectOneById(int $id): Entity\ProfileField
        {
                try {
                        return $this->selectOne(['id' => $id]);
@@ -212,7 +224,7 @@ class ProfileField extends BaseDepository
                        } else {
                                $this->db->insert(self::$table_name, $fields);
 
-                               $profileField = $this->selectOnyById($this->db->lastInsertId());
+                               $profileField = $this->selectOneById($this->db->lastInsertId());
                        }
                } catch (\Exception $exception) {
                        throw new ProfileFieldPersistenceException(sprintf('Cannot save ProfileField with id "%d" and label "%s"', $profileField->id, $profileField->label), $exception);
index f3cb33ae955592605328d0694b60520441a15e4d..b81437d9a2bf02e82945314eb1c80a6f003c2b7b 100644 (file)
@@ -23,10 +23,7 @@ namespace Friendica\Profile\ProfileField\Entity;
 
 use Friendica\BaseEntity;
 use Friendica\Network\HTTPException\InternalServerErrorException;
-use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Profile\ProfileField\Exception\ProfileFieldNotFoundException;
-use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
-use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository;
 use Friendica\Security\PermissionSet\Entity\PermissionSet;
 
 /**
@@ -38,7 +35,6 @@ use Friendica\Security\PermissionSet\Entity\PermissionSet;
  * @property-read int|null  $id
  * @property-read int       $uid
  * @property-read int       $order
- * @property-read int       $permissionSetId
  * @property-read string    $label
  * @property-read string    $value
  * @property-read \DateTime $created
@@ -51,14 +47,10 @@ class ProfileField extends BaseEntity
        protected $id;
        /** @var PermissionSet */
        protected $permissionSet;
-       /** @var PermissionSetDepository */
-       protected $permissionSetDepository;
        /** @var int */
        protected $uid;
        /** @var int */
        protected $order;
-       /** @var int */
-       protected $permissionSetId;
        /** @var string */
        protected $label;
        /** @var string */
@@ -68,54 +60,28 @@ class ProfileField extends BaseEntity
        /** @var \DateTime */
        protected $edited;
 
-       public function __construct(PermissionSetDepository $permissionSetDepository, int $uid, int $order, int $permissionSetId, string $label, string $value, \DateTime $created, \DateTime $edited, int $id = null, PermissionSet $permissionSet = null)
+       public function __construct(int $uid, int $order, string $label, string $value, \DateTime $created, \DateTime $edited, PermissionSet $permissionSet, int $id = null)
        {
-               $this->permissionSetDepository = $permissionSetDepository;
-               $this->permissionSet           = $permissionSet;
-
-               $this->uid             = $uid;
-               $this->order           = $order;
-               $this->permissionSetId = $permissionSetId;
-               $this->label           = $label;
-               $this->value           = $value;
-               $this->created         = $created;
-               $this->edited          = $edited;
-               $this->id              = $id;
+               $this->permissionSet = $permissionSet;
+               $this->uid           = $uid;
+               $this->order         = $order;
+               $this->label         = $label;
+               $this->value         = $value;
+               $this->created       = $created;
+               $this->edited        = $edited;
+               $this->id            = $id;
        }
 
        /**
         * @throws ProfileFieldNotFoundException
-        * @throws UnexpectedPermissionSetException
         */
        public function __get($name)
        {
-               switch ($name) {
-                       case 'permissionSet':
-                               if (empty($this->permissionSet)) {
-                                       try {
-                                               $permissionSet = $this->permissionSetDepository->selectOneById($this->permissionSetId, $this->uid);
-                                               if ($permissionSet->uid !== $this->uid) {
-                                                       throw new UnexpectedPermissionSetException(sprintf('PermissionSet %d (user-id: %d) for ProfileField %d (user-id: %d) is invalid.', $permissionSet->id, $permissionSet->uid, $this->id, $this->uid));
-                                               }
-
-                                               $this->permissionSet = $permissionSet;
-                                       } catch (NotFoundException $exception) {
-                                               throw new UnexpectedPermissionSetException(sprintf('No PermissionSet found for ProfileField %d (user-id: %d).', $this->id, $this->uid));
-                                       }
-                               }
-
-                               $return = $this->permissionSet;
-                               break;
-                       default:
-                               try {
-                                       $return = parent::__get($name);
-                               } catch (InternalServerErrorException $exception) {
-                                       throw new ProfileFieldNotFoundException($exception->getMessage());
-                               }
-                               break;
+               try {
+                       return parent::__get($name);
+               } catch (InternalServerErrorException $exception) {
+                       throw new ProfileFieldNotFoundException($exception->getMessage());
                }
-
-               return $return;
        }
 
        /**
@@ -127,11 +93,10 @@ class ProfileField extends BaseEntity
         */
        public function update(string $value, int $order, PermissionSet $permissionSet)
        {
-               $this->value           = $value;
-               $this->order           = $order;
-               $this->permissionSet   = $permissionSet;
-               $this->permissionSetId = $permissionSet->id;
-               $this->edited          = new \DateTime('now', new \DateTimeZone('UTC'));
+               $this->value         = $value;
+               $this->order         = $order;
+               $this->permissionSet = $permissionSet;
+               $this->edited        = new \DateTime('now', new \DateTimeZone('UTC'));
        }
 
        /**
index e7016ec280c894cae9fbcb62d375c524cc13b62e..4253d93b936bb02954b5cc82b2007bfeae92bf1e 100644 (file)
@@ -23,7 +23,7 @@ namespace Friendica\Profile\ProfileField\Factory;
 
 use Friendica\BaseFactory;
 use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
-use Friendica\Security\PermissionSet\Depository\PermissionSet as PermissionSetDepository;
+use Friendica\Security\PermissionSet\Factory\PermissionSet as PermissionSetFactory;
 use Friendica\Profile\ProfileField\Entity;
 use Friendica\Capabilities\ICanCreateFromTableRow;
 use Friendica\Security\PermissionSet\Entity\PermissionSet;
@@ -31,45 +31,68 @@ use Psr\Log\LoggerInterface;
 
 class ProfileField extends BaseFactory implements ICanCreateFromTableRow
 {
-       /** @var PermissionSetDepository */
-       private $permissionSetDepository;
+       /** @var PermissionSetFactory */
+       private $permissionSetFactory;
 
-       public function __construct(LoggerInterface $logger, PermissionSetDepository $permissionSetDepository)
+       public function __construct(LoggerInterface $logger, PermissionSetFactory $permissionSetFactory)
        {
                parent::__construct($logger);
 
-               $this->permissionSetDepository = $permissionSetDepository;
+               $this->permissionSetFactory = $permissionSetFactory;
        }
 
        /**
         * @inheritDoc
+        *
+        * @throws UnexpectedPermissionSetException
         */
        public function createFromTableRow(array $row, PermissionSet $permissionSet = null): Entity\ProfileField
        {
-               if (empty($permissionSet) && empty($row['psid'])) {
-                       throw new UnexpectedPermissionSetException('Either set the permission set ID or the permission set itself');
+               if (empty($permissionSet) &&
+                       (empty($row['psid']) || !array_key_exists('allow_cid', $row) || !array_key_exists('allow_gid', $row) || !array_key_exists('deny_cid', $row) || !array_key_exists('deny_gid', $row))
+               ) {
+                       throw new UnexpectedPermissionSetException('Either set the PermissionSet fields (join) or the PermissionSet itself');
                }
 
                return new Entity\ProfileField(
-                       $this->permissionSetDepository,
                        $row['uid'],
                        $row['order'],
-                       $row['psid'] ?? $permissionSet->id,
                        $row['label'],
                        $row['value'],
                        new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
                        new \DateTime($row['edited'] ?? 'now', new \DateTimeZone('UTC')),
-                       $row['id'] ?? null,
-                       $permissionSet
+                       $permissionSet ?? $this->permissionSetFactory->createFromString(
+                               $row['uid'],
+                               $row['allow_cid'],
+                               $row['allow_gid'],
+                               $row['deny_cid'],
+                               $row['deny_gid'],
+                               $row['psid']
+                       ),
+                       $row['id'] ?? null
                );
        }
 
-       public function createFromString(
+       /**
+        * Creates a ProfileField instance based on it's values
+        *
+        * @param int           $uid
+        * @param int           $order
+        * @param string        $label
+        * @param string        $value
+        * @param PermissionSet $permissionSet
+        * @param int|null      $id
+        *
+        * @return Entity\ProfileField
+        * @throws UnexpectedPermissionSetException
+        */
+       public function createFromValues(
                int $uid,
                int $order,
                string $label,
                string $value,
-               PermissionSet $permissionSet
+               PermissionSet $permissionSet,
+               int $id = null
        ): Entity\ProfileField {
                return $this->createFromTableRow([
                        'uid'   => $uid,
@@ -77,6 +100,7 @@ class ProfileField extends BaseFactory implements ICanCreateFromTableRow
                        'psid'  => $permissionSet->id,
                        'label' => $label,
                        'value' => $value,
+                       'id'    => $id,
                ], $permissionSet);
        }
 }
index 84c7d5838d1d6da217869f22d6ee45531ec44c26..bde6cd73f150aa380cde2fa81a8a9323f52da9f8 100644 (file)
@@ -51,7 +51,8 @@ class PermissionSet extends BaseFactory implements ICanCreateFromTableRow
                string $allow_cid = '',
                string $allow_gid = '',
                string $deny_cid = '',
-               string $deny_gid = ''): Entity\PermissionSet
+               string $deny_gid = '',
+               int $id = null): Entity\PermissionSet
        {
                return $this->createFromTableRow([
                        'uid'       => $uid,
@@ -59,6 +60,7 @@ class PermissionSet extends BaseFactory implements ICanCreateFromTableRow
                        'allow_gid' => $allow_gid,
                        'deny_cid'  => $deny_cid,
                        'deny_gid'  => $deny_gid,
+                       'id'        => $id,
                ]);
        }
 }
index 662425b02e7c19dadf4a7ca848f9f4f43cf0477b..a373f4c28581782e5a02b3afc6cb301653207234 100644 (file)
                        INNER JOIN `workerqueue` ON `workerqueue`.`pid` = `process`.`pid`
                        WHERE NOT `workerqueue`.`done`"
        ],
+       "profile_field-view" => [
+               "fields" => [
+                       "id" => ["profile_field", "id"],
+                       "uid" => ["profile_field", "uid"],
+                       "label" => ["profile_field", "label"],
+                       "value" => ["profile_field", "value"],
+                       "order" => ["profile_field", "order"],
+                       "psid"=> ["profile_field", "psid"],
+                       "allow_cid" => ["permissionset", "allow_cid"],
+                       "allow_gid" => ["permissionset", "allow_gid"],
+                       "deny_cid" => ["permissionset", "deny_cid"],
+                       "deny_gid" => ["permissionset", "deny_gid"]
+               ],
+               "query" => "FROM `profile_field`
+                       INNER JOIN `permissionset` ON `permissionset`.`id` = `profile_field`.`psid`"
+       ],
 ];
 
index 845c89cc69635e5e5187fe8933d968281fd359d8..e4f29d686f81221cd2626fcb13542e4e88b98293 100644 (file)
@@ -2,7 +2,6 @@
 
 namespace Friendica\Test\src\Profile\ProfileField\Entity;
 
-use Friendica\Network\HTTPException\NotFoundException;
 use Friendica\Profile\ProfileField\Entity\ProfileField;
 use Friendica\Profile\ProfileField\Exception\ProfileFieldNotFoundException;
 use Friendica\Profile\ProfileField\Exception\UnexpectedPermissionSetException;
@@ -21,7 +20,7 @@ class ProfileFieldTest extends MockedTest
        protected $permissionSetDepository;
        /** @var ProfileFieldFactory */
        protected $profileFieldFactory;
-       /** @var PermissionSetFactory */
+       /** @var MockInterface|PermissionSetFactory */
        protected $permissionSetFactory;
 
        protected function setUp(): void
@@ -29,8 +28,8 @@ class ProfileFieldTest extends MockedTest
                parent::setUp();
 
                $this->permissionSetDepository = \Mockery::mock(PermissionSetDepository::class);
-               $this->profileFieldFactory     = new ProfileFieldFactory(new VoidLogger(), $this->permissionSetDepository);
                $this->permissionSetFactory    = new PermissionSetFactory(new VoidLogger(), new ACLFormatter());
+               $this->profileFieldFactory     = new ProfileFieldFactory(new VoidLogger(), $this->permissionSetFactory);
        }
 
        public function dataEntity()
@@ -44,6 +43,14 @@ class ProfileFieldTest extends MockedTest
                                'value'   => 'more',
                                'created' => new \DateTime('2021-10-10T21:12:00.000000+0000', new \DateTimeZone('UTC')),
                                'edited'  => new \DateTime('2021-10-10T21:12:00.000000+0000', new \DateTimeZone('UTC')),
+                               'permissionSet' => [
+                                       'uid'       => 23,
+                                       'allow_cid' => "<1>",
+                                       'allow_gid' => "<~>",
+                                       'deny_cid'  => '<2>',
+                                       'deny_gid'  => '<3>',
+                                       'id'        => 2,
+                               ]
                        ],
                        'withId' => [
                                'uid'     => 23,
@@ -53,6 +60,14 @@ class ProfileFieldTest extends MockedTest
                                'value'   => 'more',
                                'created' => new \DateTime('2021-10-10T21:12:00.000000+0000', new \DateTimeZone('UTC')),
                                'edited'  => new \DateTime('2021-10-10T21:12:00.000000+0000', new \DateTimeZone('UTC')),
+                               'permissionSet' => [
+                                       'uid'       => 23,
+                                       'allow_cid' => "<1>",
+                                       'allow_gid' => "<~>",
+                                       'deny_cid'  => '<2>',
+                                       'deny_gid'  => '<3>',
+                                       'id'        => 2,
+                               ],
                                'id'      => 54,
                        ],
                ];
@@ -61,13 +76,13 @@ class ProfileFieldTest extends MockedTest
        /**
         * @dataProvider dataEntity
         */
-       public function testEntity(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testEntity(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet, $id = null)
        {
-               $entity = new ProfileField($this->permissionSetDepository, $uid, $order, $psid, $label, $value, $created, $edited, $id);
+               $entity = new ProfileField($uid, $order, $label, $value, $created, $edited, $this->permissionSetFactory->createFromTableRow($permissionSet), $id);
 
                self::assertEquals($uid, $entity->uid);
                self::assertEquals($order, $entity->order);
-               self::assertEquals($psid, $entity->permissionSetId);
+               self::assertEquals($psid, $entity->permissionSet->id);
                self::assertEquals($label, $entity->label);
                self::assertEquals($value, $entity->value);
                self::assertEquals($created, $entity->created);
@@ -78,7 +93,7 @@ class ProfileFieldTest extends MockedTest
        /**
         * @dataProvider dataEntity
         */
-       public function testUpdate(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testUpdate(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet,  $id = null)
        {
                $permissionSet = $this->permissionSetFactory->createFromTableRow(['uid' => 2, 'id' => $psid]);
 
@@ -103,7 +118,7 @@ class ProfileFieldTest extends MockedTest
 
                self::assertEquals($uid, $entity->uid);
                self::assertEquals(2345, $entity->order);
-               self::assertEquals(23, $entity->permissionSetId);
+               self::assertEquals(23, $entity->permissionSet->id);
                self::assertEquals($label, $entity->label);
                self::assertEquals('updatedValue', $entity->value);
                self::assertEquals($created, $entity->created);
@@ -114,7 +129,7 @@ class ProfileFieldTest extends MockedTest
        /**
         * @dataProvider dataEntity
         */
-       public function testSetOrder(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testSetOrder(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet, $id = null)
        {
                $permissionSet = $this->permissionSetFactory->createFromTableRow(['uid' => 2, 'id' => $psid]);
 
@@ -133,7 +148,7 @@ class ProfileFieldTest extends MockedTest
 
                self::assertEquals($uid, $entity->uid);
                self::assertEquals(2345, $entity->order);
-               self::assertEquals($psid, $entity->permissionSetId);
+               self::assertEquals($psid, $entity->permissionSet->id);
                self::assertEquals($label, $entity->label);
                self::assertEquals($value, $entity->value);
                self::assertEquals($created, $entity->created);
@@ -146,9 +161,9 @@ class ProfileFieldTest extends MockedTest
         *
         * @dataProvider dataEntity
         */
-       public function testWrongGet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testWrongGet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet, $id = null)
        {
-               $entity = new ProfileField($this->permissionSetDepository, $uid, $order, $psid, $label, $value, $created, $edited, $id);
+               $entity = new ProfileField($uid, $order, $label, $value, $created, $edited, $this->permissionSetFactory->createFromTableRow($permissionSet), $id);
 
                self::expectException(ProfileFieldNotFoundException::class);
                $entity->wrong;
@@ -159,9 +174,10 @@ class ProfileFieldTest extends MockedTest
         *
         * @dataProvider dataEntity
         */
-       public function testPermissionSet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testPermissionSet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet, $id = null)
        {
-               $entity        = new ProfileField($this->permissionSetDepository, $uid, $order, $psid, $label, $value, $created, $edited, $id);
+               $entity = new ProfileField($uid, $order, $label, $value, $created, $edited, $this->permissionSetFactory->createFromTableRow($permissionSet), $id);
+
                $permissionSet = $this->permissionSetFactory->createFromTableRow(['uid' => $uid, 'id' => $psid]);
 
                $this->permissionSetDepository->shouldReceive('selectOneById')->with($psid, $uid)->andReturns($permissionSet);
@@ -169,49 +185,15 @@ class ProfileFieldTest extends MockedTest
                self::assertEquals($psid, $entity->permissionSet->id);
        }
 
-       /**
-        * Test the exception because of incompatible user id
-        *
-        * @dataProvider dataEntity
-        */
-       public function testWrongPermissionSet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
-       {
-               $entity        = new ProfileField($this->permissionSetDepository, $uid, $order, $psid, $label, $value, $created, $edited, $id);
-               $permissionSet = $this->permissionSetFactory->createFromTableRow(['uid' => 12345, 'id' => $psid]);
-
-               $this->permissionSetDepository->shouldReceive('selectOneById')->with($psid, $uid)->andReturns($permissionSet);
-
-               self::expectException(UnexpectedPermissionSetException::class);
-               self::expectExceptionMessage(sprintf('PermissionSet %d (user-id: %d) for ProfileField %d (user-id: %d) is invalid.', $psid, 12345, $id, $uid));
-               $entity->permissionSet;
-       }
-
-       /**
-        * Test the exception because of missing permission set
-        *
-        * @dataProvider dataEntity
-        */
-       public function testMissingPermissionSet(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
-       {
-               $entity = new ProfileField($this->permissionSetDepository, $uid, $order, $psid, $label, $value, $created, $edited, $id);
-
-               $this->permissionSetDepository->shouldReceive('selectOneById')->with($psid, $uid)
-                                                                         ->andThrow(new NotFoundException('test'));
-
-               self::expectException(UnexpectedPermissionSetException::class);
-               self::expectExceptionMessage(sprintf('No PermissionSet found for ProfileField %d (user-id: %d).', $id, $uid));
-               $entity->permissionSet;
-       }
-
        /**
         * Test the exception because the factory cannot find a permissionSet ID, nor the permissionSet itself
         *
         * @dataProvider dataEntity
         */
-       public function testMissingPermissionFactory(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, $id = null)
+       public function testMissingPermissionFactory(int $uid, int $order, int $psid, string $label, string $value, \DateTime $created, \DateTime $edited, array $permissionSet, $id = null)
        {
                self::expectException(UnexpectedPermissionSetException::class);
-               self::expectExceptionMessage('Either set the permission set ID or the permission set itself');
+               self::expectExceptionMessage('Either set the PermissionSet fields (join) or the PermissionSet itself');
 
                $entity = $this->profileFieldFactory->createFromTableRow([
                        'uid'     => $uid,
index d7598a33f5353e28a89a34c135a270f9cab96b8f..f5d3108300a916420794aac8f54306af669e4f83 100644 (file)
@@ -206,7 +206,7 @@ function update_1332()
        $profiles = DBA::select('profile', [], $condition);
 
        while ($profile = DBA::fetch($profiles)) {
-               Profile::migrateFromLegacyProfile($profile);
+               Profile::migrate($profile);
        }
        DBA::close($profiles);