summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2020-12-16 21:05:39 +0100
committerDaniel Weipert <code@drogueronin.de>2020-12-16 21:05:39 +0100
commit3195d4785e505f664898b6d5599c844832fa9734 (patch)
treebf6e32f03fcccec6937812d35d33a971c54f381f
parent134f3ac61a191ca1f1c4216057a2af8af274fbc0 (diff)
Fixes field reference in foreach loopv1.0.2
-rw-r--r--composer.json2
-rw-r--r--src/Metabox.php2
-rw-r--r--tests/MetaboxTest.php20
3 files changed, 21 insertions, 3 deletions
diff --git a/composer.json b/composer.json
index 0bea819..c23a035 100644
--- a/composer.json
+++ b/composer.json
@@ -1,6 +1,6 @@
{
"name": "drogueronin/metaboxes",
- "version": "1.0.1",
+ "version": "1.0.2",
"type": "library",
"license": "MIT",
"authors": [
diff --git a/src/Metabox.php b/src/Metabox.php
index 0f4c5d7..b2ae2e4 100644
--- a/src/Metabox.php
+++ b/src/Metabox.php
@@ -83,7 +83,7 @@ class Metabox
$fields = [$fields];
}
- foreach ($fields as $field) {
+ foreach ($fields as &$field) {
// set the field's parent
$field->parent($this->key);
diff --git a/tests/MetaboxTest.php b/tests/MetaboxTest.php
index d5a27a3..1a1353e 100644
--- a/tests/MetaboxTest.php
+++ b/tests/MetaboxTest.php
@@ -22,7 +22,7 @@ class MetaboxTest extends TestCase
protected function setUp(): void
{
$this->metabox = new Metabox('Test Metabox');
- $this->field = new MetaboxField('Test Field');
+ $this->field = new MetaboxField('test_field');
}
/**
@@ -62,4 +62,22 @@ class MetaboxTest extends TestCase
$this->assertEquals($this->field->parent, $this->metabox->key);
$this->assertEquals($this->metabox->fields[$this->field->key], $this->field);
}
+
+ /**
+ * @test
+ */
+ public function addsMultipleFieldsAsArray()
+ {
+ $fields = [
+ $this->field,
+ $field2 = (new MetaboxField('field_2')),
+ ];
+ $this->metabox->field($fields);
+
+ $expected = [
+ $this->field->key => $this->field,
+ $field2->key => $field2,
+ ];
+ $this->assertEquals($expected, $this->metabox->fields);
+ }
}