Skip to content

Commit f9229c3

Browse files
committed
Add Feedback tests
1 parent e13ebf9 commit f9229c3

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

projects/packages/forms/tests/php/contact-form/Feedback_Test.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,4 +1983,43 @@ public function test_validate_radio_form() {
19831983

19841984
Contact_Form::reset_errors();
19851985
}
1986+
1987+
public function test_get_field_by_id_and_value_by_id_new_submission() {
1988+
$form_id = Utility::get_form_id();
1989+
$_post_data = Utility::get_post_request(
1990+
array(
1991+
'name' => 'John Doe',
1992+
'email' => '[email protected]',
1993+
'message' => 'Hello!',
1994+
),
1995+
'g' . $form_id
1996+
);
1997+
1998+
$form = new Contact_Form(
1999+
array(
2000+
'title' => 'Test Form',
2001+
'description' => 'This is a test form.',
2002+
),
2003+
"[contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Message' type='textarea' required='1'/]"
2004+
);
2005+
2006+
$response = Feedback::from_submission( $_post_data, $form );
2007+
$field_ids = $form->get_field_ids();
2008+
$email_id = $field_ids['email'];
2009+
2010+
$this->assertNotEmpty( $email_id );
2011+
$this->assertEquals( '[email protected]', $response->get_field_value_by_id( $email_id ) );
2012+
2013+
$field = $response->get_field_by_id( $email_id );
2014+
$this->assertInstanceOf( Feedback_Field::class, $field );
2015+
$this->assertEquals( $email_id, $field->get_form_field_id() );
2016+
}
2017+
2018+
public function test_get_field_by_id_and_value_by_id_legacy() {
2019+
$post_id = Utility::create_legacy_feedback( array() );
2020+
$response = Feedback::get( $post_id );
2021+
2022+
$this->assertSame( '', $response->get_field_value_by_id( 'email' ) );
2023+
$this->assertNull( $response->get_field_by_id( 'email' ) );
2024+
}
19862025
}

0 commit comments

Comments
 (0)