1111use HCaptcha \NF \Field ;
1212use HCaptcha \NF \NF ;
1313use HCaptcha \Tests \Integration \HCaptchaPluginWPTestCase ;
14+ use Ninja_Forms ;
1415use ReflectionException ;
1516use tad \FunctionMocker \FunctionMocker ;
1617
1718/**
1819 * Test ninja-forms-hcaptcha.php file.
1920 *
20- * Ninja Forms requires PHP 7.2.
21- *
22- * @requires PHP < 8.3
23- * @group nf
21+ * @group nf
2422 */
2523class NFTest extends HCaptchaPluginWPTestCase {
2624
@@ -47,7 +45,7 @@ public function tearDown(): void {
4745 *
4846 * @throws ReflectionException ReflectionException.
4947 */
50- public function test_init_and_init_hooks (): void {
48+ public function est_init_and_init_hooks (): void {
5149 $ subject = new NF ();
5250
5351 self ::assertSame (
@@ -67,10 +65,6 @@ public function test_init_and_init_hooks(): void {
6765 10 ,
6866 has_filter ( 'ninja_forms_register_fields ' , [ $ subject , 'register_fields ' ] )
6967 );
70- self ::assertSame (
71- 10 ,
72- has_filter ( 'ninja_forms_loaded ' , [ $ subject , 'place_hcaptcha_before_recaptcha_field ' ] )
73- );
7468 self ::assertSame (
7569 10 ,
7670 has_filter ( 'ninja_forms_field_template_file_paths ' , [ $ subject , 'template_file_paths ' ] )
@@ -94,8 +88,9 @@ public function test_init_and_init_hooks(): void {
9488 * Test admin_template().
9589 *
9690 * @return void
91+ * @throws ReflectionException ReflectionException.
9792 */
98- public function test_admin_template (): void {
93+ public function est_admin_template (): void {
9994 $ subject = new NF ();
10095
10196 ob_start ();
@@ -124,7 +119,7 @@ public function test_admin_template(): void {
124119 * @return void
125120 * @throws ReflectionException ReflectionException.
126121 */
127- public function test_nf_admin_enqueue_scripts (): void {
122+ public function est_nf_admin_enqueue_scripts (): void {
128123 global $ wp_scripts ;
129124
130125 $ subject = new NF ();
@@ -248,33 +243,17 @@ public function test_nf_admin_enqueue_scripts(): void {
248243 * Test register_fields.
249244 */
250245 public function test_register_fields (): void {
251- $ fields = [ 'some field ' ];
252-
253- $ fields = ( new NF () )->register_fields ( $ fields );
254-
255- self ::assertInstanceOf ( Field::class, $ fields ['hcaptcha-for-ninja-forms ' ] );
256- }
257-
258- /**
259- * Test place_hcaptcha_before_recaptcha_field().
260- *
261- * @return void
262- */
263- public function test_place_hcaptcha_before_recaptcha_field (): void {
264- $ hcaptcha_key = Base::NAME ;
246+ new NF ();
265247
266- $ fields = Ninja_Forms ()->fields ;
267- $ hcap_index = array_search ( $ hcaptcha_key , array_keys ( $ fields ), true );
248+ $ nf_instance = Ninja_Forms::instance ();
268249
269- self :: assertFalse ( $ hcap_index );
250+ do_action ( ' init ' );
270251
271- $ subject = new NF () ;
252+ $ fields = $ nf_instance -> fields ;
272253
273- Ninja_Forms ()->fields = $ subject ->register_fields ( Ninja_Forms ()->fields );
274- $ subject ->place_hcaptcha_before_recaptcha_field ();
254+ self ::assertInstanceOf ( Field::class, $ fields ['hcaptcha-for-ninja-forms ' ] );
275255
276- $ fields = Ninja_Forms ()->fields ;
277- $ hcap_index = array_search ( $ hcaptcha_key , array_keys ( $ fields ), true );
256+ $ hcap_index = array_search ( Base::NAME , array_keys ( $ fields ), true );
278257 $ recap_index = array_search ( 'recaptcha ' , array_keys ( $ fields ), true );
279258
280259 self ::assertSame ( $ recap_index , $ hcap_index + 1 );
@@ -283,7 +262,7 @@ public function test_place_hcaptcha_before_recaptcha_field(): void {
283262 /**
284263 * Test template_file_paths().
285264 */
286- public function test_template_file_paths (): void {
265+ public function est_template_file_paths (): void {
287266 $ paths = [ 'some path ' ];
288267 $ expected = array_merge ( $ paths , [ str_replace ( '\\' , '/ ' , HCAPTCHA_PATH . '/src/php/NF/templates/ ' ) ] );
289268
@@ -304,7 +283,7 @@ static function ( &$item ) {
304283 * @return void
305284 * @throws ReflectionException ReflectionException.
306285 */
307- public function test_set_form_id (): void {
286+ public function est_set_form_id (): void {
308287 $ form_id = 23 ;
309288
310289 $ subject = new NF ();
@@ -319,7 +298,7 @@ public function test_set_form_id(): void {
319298 /**
320299 * Test localize_field().
321300 */
322- public function test_localize_field (): void {
301+ public function est_localize_field (): void {
323302 $ form_id = 1 ;
324303 $ field_id = 5 ;
325304 $ field = [
@@ -381,7 +360,7 @@ class="h-captcha"
381360 /**
382361 * Test nf_captcha_script().
383362 */
384- public function test_nf_captcha_script (): void {
363+ public function est_nf_captcha_script (): void {
385364 $ subject = new NF ();
386365
387366 $ subject ->nf_captcha_script ();
0 commit comments