diff options
-rw-r--r-- | composer.json | 2 | ||||
-rw-r--r-- | src/Metabox.php | 2 | ||||
-rw-r--r-- | tests/MetaboxTest.php | 20 |
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); + } } |