Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for defaultDisabled parameter in MetadataField #403

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/Api/Metadata/MetadataField.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ abstract class MetadataField extends Metadata
*/
protected $restrictions;

/**
* @var bool
*/
protected $defaultDisabled;

/**
* The MetadataField constructor.
*
Expand All @@ -71,7 +76,16 @@ public function __construct($label)
*/
public function getPropertyKeys()
{
return ['externalId', 'label', 'mandatory', 'defaultValue', 'type', 'validation', 'restrictions'];
return [
'externalId',
'label',
'mandatory',
'defaultValue',
'type',
'validation',
'restrictions',
'defaultDisabled',
];
}

/**
Expand Down Expand Up @@ -159,7 +173,7 @@ public function getMandatory()
*
* @param bool $mandatory A boolean indicating whether the field should be mandatory.
*/
public function setMandatory($mandatory)
public function setMandatory($mandatory = true)
{
$this->mandatory = $mandatory;
}
Expand Down Expand Up @@ -203,4 +217,24 @@ public function setRestrictions($restrictions)
{
$this->restrictions = $restrictions;
}

/**
* Gets the value indicating whether the field should be disabled by default.
*
* @return bool
*/
public function isDefaultDisabled()
{
return $this->defaultDisabled;
}

/**
* Sets the value indicating whether the field should be disabled by default.
*
* @param bool $defaultDisabled The value to set.
*/
public function setDefaultDisabled($defaultDisabled = true)
{
$this->defaultDisabled = $defaultDisabled;
}
}
2 changes: 1 addition & 1 deletion tests/CloudinaryTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected static function assertArrayContainsArray($haystack, $needle)
$haystack,
static function ($item) use ($needle) {
/** @noinspection TypeUnsafeComparisonInspection */
return $item == $needle;
return array_intersect_key($item, $needle) == $needle;
}
);

Expand Down
12 changes: 8 additions & 4 deletions tests/Unit/Admin/MetadataFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function testCreateStringMetadataField()
$stringMetadataField = new StringMetadataField(self::EXTERNAL_ID_STRING);
$stringMetadataField->setExternalId(self::EXTERNAL_ID_STRING);
$stringMetadataField->setRestrictions(["readonly_ui" => true]);
$stringMetadataField->setMandatory(false);
$stringMetadataField->setDefaultDisabled();

$mockAdminApi->addMetadataField($stringMetadataField);
$lastRequest = $mockAdminApi->getMockHandler()->getLastRequest();
Expand All @@ -75,10 +77,12 @@ public function testCreateStringMetadataField()
self::assertRequestFields(
$lastRequest,
[
'type' => MetadataFieldType::STRING,
'external_id' => self::EXTERNAL_ID_STRING,
'label' => self::EXTERNAL_ID_STRING,
'restrictions' => ["readonly_ui" => true],
'type' => MetadataFieldType::STRING,
'external_id' => self::EXTERNAL_ID_STRING,
'label' => self::EXTERNAL_ID_STRING,
'mandatory' => false,
'restrictions' => ["readonly_ui" => true],
'default_disabled' => true,
]
);
}
Expand Down