@@ -1983,4 +1983,43 @@ public function test_validate_radio_form() {
1983
1983
1984
1984
Contact_Form::reset_errors ();
1985
1985
}
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
+
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
+ }
1986
2025
}
0 commit comments