Adapt ProfileField & Fix current PermissionSet Usage at ProfileFields
parent
8a354dac82
commit
5fecc9ecf7
|
@ -279,7 +279,7 @@ class UserImport
|
|||
$profile['id'] = DBA::lastInsertId();
|
||||
}
|
||||
|
||||
Profile::migrateFromLegacyProfile($profile);
|
||||
Profile::migrate($profile);
|
||||
}
|
||||
|
||||
$permissionSet = DI::permissionSet()->selectDefaultForUser($newuid);
|
||||
|
|
|
@ -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, ':'),
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1047,5 +1047,21 @@
|
|||
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`"
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue