', $html );
+ }
+
+ public function test_radio_form_data() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][0];
+ $pdf_field = new Field_Image_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $form_data = $pdf_field->form_data();
+
+ $this->assertSame( 'o3', $form_data['field'][1] );
+ $this->assertSame( 'o3', $form_data['field']['1.Radio Multi Choice'] );
+ $this->assertSame( 'o3', $form_data['field']['Radio Multi Choice'] );
+
+ $this->assertSame( '
3', $form_data['field']['Radio Multi Choice_name'] );
+
+ foreach ( [ '1_image', '1.Radio Multi Choice_image', 'Radio Multi Choice_image' ] as $id ) {
+ $this->assertArrayHasKey( 'attachment_id', $form_data['field'][ $id ][0] );
+ $this->assertArrayHasKey( 'url', $form_data['field'][ $id ][0] );
+ $this->assertArrayHasKey( 'path', $form_data['field'][ $id ][0] );
+ $this->assertArrayHasKey( 'alt', $form_data['field'][ $id ][0] );
+
+ $this->assertIsInt( $form_data['field'][ $id ][0]['attachment_id'] );
+ $this->assertStringStartsWith( 'http://', $form_data['field'][ $id ][0]['url'] );
+ $this->assertStringStartsWith( '/', $form_data['field'][ $id ][0]['path'] );
+ }
+ }
+
+ public function test_checkbox_html() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '2.1' => 'o1',
+ '2.2' => '',
+ '2.3' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][1];
+ $pdf_field = new Field_Image_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Checkbox Multi Choice
', $html );
+ }
+
+ public function test_checkbox_form_data() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '2.1' => 'o1',
+ '2.2' => '',
+ '2.3' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][1];
+ $pdf_field = new Field_Image_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $form_data = $pdf_field->form_data();
+
+ $this->assertSame( 'o1', $form_data['field'][2][0] );
+ $this->assertSame( 'o3', $form_data['field'][2][1] );
+ $this->assertSame( 'o1', $form_data['field']['2.Checkbox Multi Choice'][0] );
+ $this->assertSame( 'o3', $form_data['field']['2.Checkbox Multi Choice'][1] );
+ $this->assertSame( 'o1', $form_data['field']['Checkbox Multi Choice'][0] );
+ $this->assertSame( 'o3', $form_data['field']['Checkbox Multi Choice'][1] );
+
+ $this->assertSame( 'Option 1', $form_data['field']['2_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['2_name'][1] );
+ $this->assertSame( 'Option 1', $form_data['field']['2.Checkbox Multi Choice_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['2.Checkbox Multi Choice_name'][1] );
+ $this->assertSame( 'Option 1', $form_data['field']['Checkbox Multi Choice_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['Checkbox Multi Choice_name'][1] );
+
+ foreach ( [ '2_image', '2.Checkbox Multi Choice_image', 'Checkbox Multi Choice_image' ] as $id ) {
+ for ( $i = 0; $i <= 1; $i++ ) {
+ $this->assertArrayHasKey( 'attachment_id', $form_data['field'][ $id ][ $i ] );
+ $this->assertArrayHasKey( 'url', $form_data['field'][ $id ][ $i ] );
+ $this->assertArrayHasKey( 'path', $form_data['field'][ $id ][ $i ] );
+ $this->assertArrayHasKey( 'alt', $form_data['field'][ $id ][ $i ] );
+
+ $this->assertIsInt( $form_data['field'][ $id ][ $i ]['attachment_id'] );
+ $this->assertStringStartsWith( 'http://', $form_data['field'][ $id ][ $i ]['url'] );
+ $this->assertStringStartsWith( '/', $form_data['field'][ $id ][ $i ]['path'] );
+ }
+ }
+ }
+}
diff --git a/tests/phpunit/unit-tests/Helper/Fields/Test_Field_Multi_Choice.php b/tests/phpunit/unit-tests/Helper/Fields/Test_Field_Multi_Choice.php
new file mode 100644
index 000000000..fdb6c52e0
--- /dev/null
+++ b/tests/phpunit/unit-tests/Helper/Fields/Test_Field_Multi_Choice.php
@@ -0,0 +1,241 @@
+factory = new GF_UnitTest_Factory();
+
+ /* Create a form with checkbox and radio Multi Choice fields */
+ $options1 = $this->get_choices( 1 );
+ $options2 = $this->get_choices( 2 );
+
+ $this->form = $this->factory->form->create_and_get( [
+ 'fields' => [
+ [
+ 'id' => 1,
+ 'label' => 'Radio Multi Choice',
+ 'type' => 'multi_choice',
+ 'inputType' => 'radio',
+ 'choices' => $options1['choices'],
+ 'inputs' => $options1['inputs'],
+ 'enableOtherChoice' => true,
+ ],
+
+ [
+ 'id' => 2,
+ 'label' => 'Checkbox Multi Choice',
+ 'type' => 'multi_choice',
+ 'inputType' => 'checkbox',
+ 'choices' => $options2['choices'],
+ 'inputs' => $options2['inputs'],
+ 'enableOtherChoice' => true,
+ ],
+ ],
+ ] );
+ }
+
+ protected function get_choices( $id ) {
+ $choices = [
+ [
+ 'text' => 'Option 1',
+ 'value' => 'o1',
+ 'key' => 'abc',
+ ],
+
+ [
+ 'text' => 'Option 2',
+ 'value' => 'o2',
+ 'key' => 'def',
+ ],
+
+ [
+ 'text' => '
Option 3',
+ 'value' => 'o3',
+ 'key' => 'ghi',
+ ],
+
+ [
+ 'text' => 'Select an option',
+ 'value' => '',
+ 'key' => 'jkl',
+ ],
+ ];
+
+ $inputs = [
+ [
+ 'id' => $id . '.1',
+ 'label' => 'Option 1',
+ 'key' => 'abc',
+ ],
+
+ [
+ 'id' => $id . '.2',
+ 'label' => 'Option 2',
+ 'key' => 'def',
+ ],
+
+ [
+ 'id' => $id . '.3',
+ 'label' => 'Option 3',
+ 'key' => 'ghi',
+ ],
+
+ [
+ 'id' => $id . '.4',
+ 'label' => 'Select an option',
+ 'key' => 'jkl',
+ ],
+ ];
+
+ return [
+ 'choices' => $choices,
+ 'inputs' => $inputs,
+ ];
+ }
+
+ public function test_radio_html() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => 'o2',
+ ] );
+
+ $field = $this->form['fields'][0];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Radio Multi Choice
Option 2
', $html );
+ }
+
+ public function test_radio_html_with_markup() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][0];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Radio Multi Choice
Option 3
', $html );
+
+ /* pass user-defined string and verify response is escaped in the PDF */
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => '
My answer',
+ ] );
+
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Radio Multi Choice
<em>My answer</em>
', $html );
+ }
+
+ public function test_radio_html_with_empty_value_but_not_label() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => '',
+ ] );
+
+ $field = $this->form['fields'][0];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Radio Multi Choice
Select an option
', $html );
+ }
+
+ public function test_radio_form_data() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '1' => 'o2',
+ ] );
+
+ $field = $this->form['fields'][0];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $form_data = $pdf_field->form_data();
+
+ $this->assertSame( 'o2', $form_data['field'][1] );
+ $this->assertSame( 'o2', $form_data['field']['1.Radio Multi Choice'] );
+ $this->assertSame( 'o2', $form_data['field']['Radio Multi Choice'] );
+
+ $this->assertSame( 'Option 2', $form_data['field']['1_name'] );
+ $this->assertSame( 'Option 2', $form_data['field']['1.Radio Multi Choice_name'] );
+ $this->assertSame( 'Option 2', $form_data['field']['Radio Multi Choice_name'] );
+ }
+
+ public function test_checkbox_html() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '2.1' => 'o1',
+ '2.2' => '',
+ '2.3' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][1];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $html = $pdf_field->html();
+ $this->assertStringContainsString( '
', $html );
+ $this->assertStringContainsString( '
Checkbox Multi Choice
', $html );
+ }
+
+ public function test_checkbox_form_data() {
+ $entry = $this->factory->entry->create_and_get( [
+ 'form_id' => $this->form['id'],
+ '2.1' => 'o1',
+ '2.2' => '',
+ '2.3' => 'o3',
+ ] );
+
+ $field = $this->form['fields'][1];
+ $pdf_field = new Field_Multi_Choice( $field, $entry, \GPDFAPI::get_form_class(), \GPDFAPI::get_misc_class() );
+
+ $form_data = $pdf_field->form_data();
+
+ $this->assertSame( 'o1', $form_data['field'][2][0] );
+ $this->assertSame( 'o3', $form_data['field'][2][1] );
+ $this->assertSame( 'o1', $form_data['field']['2.Checkbox Multi Choice'][0] );
+ $this->assertSame( 'o3', $form_data['field']['2.Checkbox Multi Choice'][1] );
+ $this->assertSame( 'o1', $form_data['field']['Checkbox Multi Choice'][0] );
+ $this->assertSame( 'o3', $form_data['field']['Checkbox Multi Choice'][1] );
+
+ $this->assertSame( 'Option 1', $form_data['field']['2_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['2_name'][1] );
+ $this->assertSame( 'Option 1', $form_data['field']['2.Checkbox Multi Choice_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['2.Checkbox Multi Choice_name'][1] );
+ $this->assertSame( 'Option 1', $form_data['field']['Checkbox Multi Choice_name'][0] );
+ $this->assertSame( '
Option 3', $form_data['field']['Checkbox Multi Choice_name'][1] );
+ }
+}