Skip to content

Commit 85c5bc0

Browse files
Add support for defaultDisabled parameter in MetadataField
1 parent ab1b9cb commit 85c5bc0

File tree

3 files changed

+45
-7
lines changed

3 files changed

+45
-7
lines changed

src/Api/Metadata/MetadataField.php

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ abstract class MetadataField extends Metadata
5454
*/
5555
protected $restrictions;
5656

57+
/**
58+
* @var bool
59+
*/
60+
protected $defaultDisabled;
61+
5762
/**
5863
* The MetadataField constructor.
5964
*
@@ -71,7 +76,16 @@ public function __construct($label)
7176
*/
7277
public function getPropertyKeys()
7378
{
74-
return ['externalId', 'label', 'mandatory', 'defaultValue', 'type', 'validation', 'restrictions'];
79+
return [
80+
'externalId',
81+
'label',
82+
'mandatory',
83+
'defaultValue',
84+
'type',
85+
'validation',
86+
'restrictions',
87+
'defaultDisabled',
88+
];
7589
}
7690

7791
/**
@@ -159,7 +173,7 @@ public function getMandatory()
159173
*
160174
* @param bool $mandatory A boolean indicating whether the field should be mandatory.
161175
*/
162-
public function setMandatory($mandatory)
176+
public function setMandatory($mandatory = true)
163177
{
164178
$this->mandatory = $mandatory;
165179
}
@@ -203,4 +217,24 @@ public function setRestrictions($restrictions)
203217
{
204218
$this->restrictions = $restrictions;
205219
}
220+
221+
/**
222+
* Gets the value indicating whether the field should be disabled by default.
223+
*
224+
* @return bool
225+
*/
226+
public function isDefaultDisabled()
227+
{
228+
return $this->defaultDisabled;
229+
}
230+
231+
/**
232+
* Sets the value indicating whether the field should be disabled by default.
233+
*
234+
* @param bool $defaultDisabled The value to set.
235+
*/
236+
public function setDefaultDisabled($defaultDisabled = true)
237+
{
238+
$this->defaultDisabled = $defaultDisabled;
239+
}
206240
}

tests/CloudinaryTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected static function assertArrayContainsArray($haystack, $needle)
101101
$haystack,
102102
static function ($item) use ($needle) {
103103
/** @noinspection TypeUnsafeComparisonInspection */
104-
return $item == $needle;
104+
return array_intersect_key($item, $needle) == $needle;
105105
}
106106
);
107107

tests/Unit/Admin/MetadataFieldsTest.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function testCreateStringMetadataField()
6666
$stringMetadataField = new StringMetadataField(self::EXTERNAL_ID_STRING);
6767
$stringMetadataField->setExternalId(self::EXTERNAL_ID_STRING);
6868
$stringMetadataField->setRestrictions(["readonly_ui" => true]);
69+
$stringMetadataField->setMandatory(false);
70+
$stringMetadataField->setDefaultDisabled();
6971

7072
$mockAdminApi->addMetadataField($stringMetadataField);
7173
$lastRequest = $mockAdminApi->getMockHandler()->getLastRequest();
@@ -75,10 +77,12 @@ public function testCreateStringMetadataField()
7577
self::assertRequestFields(
7678
$lastRequest,
7779
[
78-
'type' => MetadataFieldType::STRING,
79-
'external_id' => self::EXTERNAL_ID_STRING,
80-
'label' => self::EXTERNAL_ID_STRING,
81-
'restrictions' => ["readonly_ui" => true],
80+
'type' => MetadataFieldType::STRING,
81+
'external_id' => self::EXTERNAL_ID_STRING,
82+
'label' => self::EXTERNAL_ID_STRING,
83+
'mandatory' => false,
84+
'restrictions' => ["readonly_ui" => true],
85+
'default_disabled' => true,
8286
]
8387
);
8488
}

0 commit comments

Comments
 (0)