From 46d3528f9660a887f9e84bbd1e4e4b034e28ee4a Mon Sep 17 00:00:00 2001 From: Brandon Nifong Date: Tue, 31 Jul 2018 18:43:43 -0500 Subject: [PATCH] Add Button Group field. Fixes #65 --- src/FieldsBuilder.php | 11 +++++++++++ tests/FieldsBuilderTest.php | 27 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/FieldsBuilder.php b/src/FieldsBuilder.php index 1c75bb1..6f0e4cf 100644 --- a/src/FieldsBuilder.php +++ b/src/FieldsBuilder.php @@ -371,6 +371,17 @@ public function addCheckbox($name, array $args = []) return $this->addChoiceField($name, 'checkbox', $args); } + /** + * @param string $name + * @param array $args field configuration + * @throws FieldNameCollisionException if name already exists. + * @return FieldBuilder + */ + public function addButtonGroup($name, array $args = []) + { + return $this->addChoiceField($name, 'button_group', $args); + } + /** * @param string $name * @param array $args field configuration diff --git a/tests/FieldsBuilderTest.php b/tests/FieldsBuilderTest.php index 948db86..dc2c43b 100644 --- a/tests/FieldsBuilderTest.php +++ b/tests/FieldsBuilderTest.php @@ -379,6 +379,31 @@ public function testAddCheckbox() $this->assertArraySubset($expectedConfig, $builder->build()); } + public function testAddButtonGroup() + { + $builder = new FieldsBuilder('fields'); + $builder->addButtonGroup('colors') + ->addChoice('red') + ->addChoice('blue') + ->addChoice('green'); + + $expectedConfig = [ + 'fields' => [ + [ + 'name' => 'colors', + 'type' => 'button_group', + 'choices' => [ + 'red' => 'red', + 'blue' => 'blue', + 'green' => 'green', + ], + ], + ], + ]; + + $this->assertArraySubset($expectedConfig, $builder->build()); + } + public function testAddPostObject() { $builder = new FieldsBuilder('fields'); @@ -550,7 +575,7 @@ public function testAddGoogleMap() $this->assertArraySubset($expectedConfig, $builder->build()); } - + public function testAddLink() { $builder = new FieldsBuilder('fields');