|
13 | 13 |
|
14 | 14 | namespace HCaptcha\Tests\Integration; |
15 | 15 |
|
16 | | -use HCaptcha\Admin\Notifications; |
17 | 16 | use HCaptcha\AutoVerify\AutoVerify; |
18 | 17 | use HCaptcha\BBPress\NewTopic; |
19 | 18 | use HCaptcha\BBPress\Reply; |
@@ -582,6 +581,152 @@ static function ( $name ) { |
582 | 581 | self::assertSame( $expected, ob_get_clean() ); |
583 | 582 | } |
584 | 583 |
|
| 584 | + /** |
| 585 | + * Test get_api_url(). |
| 586 | + * |
| 587 | + * @param string $api_host API host. |
| 588 | + * @param string $expected Expected value. |
| 589 | + * |
| 590 | + * @return void |
| 591 | + * @dataProvider dp_test_get_api_url |
| 592 | + */ |
| 593 | + public function test_get_api_url( string $api_host, string $expected ) { |
| 594 | + update_option( |
| 595 | + 'hcaptcha_settings', |
| 596 | + [ |
| 597 | + 'api_host' => $api_host, |
| 598 | + ] |
| 599 | + ); |
| 600 | + |
| 601 | + $subject = new Main(); |
| 602 | + |
| 603 | + $subject->init_hooks(); |
| 604 | + |
| 605 | + self::assertSame( $expected, $subject->get_api_url() ); |
| 606 | + } |
| 607 | + |
| 608 | + /** |
| 609 | + * Data provider for test_get_api_url(). |
| 610 | + * |
| 611 | + * @return array |
| 612 | + */ |
| 613 | + public function dp_test_get_api_url(): array { |
| 614 | + return [ |
| 615 | + [ '', 'https://js.hcaptcha.com/1/api.js' ], |
| 616 | + [ ' ', 'https://js.hcaptcha.com/1/api.js' ], |
| 617 | + [ 'cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/1/api.js' ], |
| 618 | + [ 'http://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/1/api.js' ], |
| 619 | + [ 'https://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/1/api.js' ], |
| 620 | + ]; |
| 621 | + } |
| 622 | + |
| 623 | + /** |
| 624 | + * Test get_api_src(). |
| 625 | + * |
| 626 | + * @return void |
| 627 | + */ |
| 628 | + public function test_get_api_src() { |
| 629 | + update_option( |
| 630 | + 'hcaptcha_settings', |
| 631 | + [ |
| 632 | + 'recaptcha_compat_off' => [ 'on' ], |
| 633 | + 'custom_themes' => [ 'on' ], |
| 634 | + 'asset_host' => 'assets-cn1.hcaptcha.com', |
| 635 | + 'endpoint' => 'cn1.hcaptcha.com', |
| 636 | + 'host' => 'cn1.hcaptcha.com', |
| 637 | + 'image_host' => 'imgs-cn1.hcaptcha.com', |
| 638 | + 'report_api' => 'reportapi-cn1.hcaptcha.com', |
| 639 | + 'sentry' => 'cn1.hcaptcha.com', |
| 640 | + ] |
| 641 | + ); |
| 642 | + |
| 643 | + $expected = 'https://js.hcaptcha.com/1/api.js?onload=hCaptchaOnLoad&render=explicit&recaptchacompat=off&custom=true&assethost=https%3A%2F%2Fassets-cn1.hcaptcha.com&endpoint=https%3A%2F%2Fcn1.hcaptcha.com&host=https%3A%2F%2Fcn1.hcaptcha.com&imghost=https%3A%2F%2Fimgs-cn1.hcaptcha.com&reportapi=https%3A%2F%2Freportapi-cn1.hcaptcha.com&sentry=https%3A%2F%2Fcn1.hcaptcha.com'; |
| 644 | + |
| 645 | + $subject = new Main(); |
| 646 | + |
| 647 | + $subject->init_hooks(); |
| 648 | + |
| 649 | + self::assertSame( $expected, $subject->get_api_src() ); |
| 650 | + } |
| 651 | + |
| 652 | + /** |
| 653 | + * Test get_verify_url(). |
| 654 | + * |
| 655 | + * @param string $backend Backend. |
| 656 | + * @param string $expected Expected value. |
| 657 | + * |
| 658 | + * @return void |
| 659 | + * @dataProvider dp_test_get_verify_url |
| 660 | + */ |
| 661 | + public function test_get_verify_url( string $backend, string $expected ) { |
| 662 | + update_option( |
| 663 | + 'hcaptcha_settings', |
| 664 | + [ |
| 665 | + 'backend' => $backend, |
| 666 | + ] |
| 667 | + ); |
| 668 | + |
| 669 | + $subject = new Main(); |
| 670 | + |
| 671 | + $subject->init_hooks(); |
| 672 | + |
| 673 | + self::assertSame( $expected, $subject->get_verify_url() ); |
| 674 | + } |
| 675 | + |
| 676 | + /** |
| 677 | + * Data provider for test_get_verify_url(). |
| 678 | + * |
| 679 | + * @return array |
| 680 | + */ |
| 681 | + public function dp_test_get_verify_url(): array { |
| 682 | + return [ |
| 683 | + [ '', 'https://api.hcaptcha.com/siteverify' ], |
| 684 | + [ ' ', 'https://api.hcaptcha.com/siteverify' ], |
| 685 | + [ 'cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/siteverify' ], |
| 686 | + [ 'http://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/siteverify' ], |
| 687 | + [ 'https://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/siteverify' ], |
| 688 | + ]; |
| 689 | + } |
| 690 | + |
| 691 | + /** |
| 692 | + * Test get_check_site_config_url(). |
| 693 | + * |
| 694 | + * @param string $backend Backend. |
| 695 | + * @param string $expected Expected value. |
| 696 | + * |
| 697 | + * @return void |
| 698 | + * @dataProvider dp_test_get_check_site_config_url |
| 699 | + */ |
| 700 | + public function test_get_check_site_config_url( string $backend, string $expected ) { |
| 701 | + update_option( |
| 702 | + 'hcaptcha_settings', |
| 703 | + [ |
| 704 | + 'backend' => $backend, |
| 705 | + ] |
| 706 | + ); |
| 707 | + |
| 708 | + $subject = new Main(); |
| 709 | + |
| 710 | + $subject->init_hooks(); |
| 711 | + |
| 712 | + self::assertSame( $expected, $subject->get_check_site_config_url() ); |
| 713 | + } |
| 714 | + |
| 715 | + /** |
| 716 | + * Data provider for test_get_check_site_config_url(). |
| 717 | + * |
| 718 | + * @return array |
| 719 | + */ |
| 720 | + public function dp_test_get_check_site_config_url(): array { |
| 721 | + return [ |
| 722 | + [ '', 'https://api.hcaptcha.com/checksiteconfig' ], |
| 723 | + [ ' ', 'https://api.hcaptcha.com/checksiteconfig' ], |
| 724 | + [ 'cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/checksiteconfig' ], |
| 725 | + [ 'http://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/checksiteconfig' ], |
| 726 | + [ 'https://cn1.hcaptcha.com', 'https://cn1.hcaptcha.com/checksiteconfig' ], |
| 727 | + ]; |
| 728 | + } |
| 729 | + |
585 | 730 | /** |
586 | 731 | * Test print_footer_scripts(). |
587 | 732 | * |
@@ -758,6 +903,29 @@ function delayedLoad() { |
758 | 903 | self::assertNotFalse( strpos( $scripts, $expected_scripts ) ); |
759 | 904 | } |
760 | 905 |
|
| 906 | + /** |
| 907 | + * Test print_footer_scripts when blocked by filter. |
| 908 | + * |
| 909 | + * @return void |
| 910 | + */ |
| 911 | + public function test_print_footer_script_when_blocked_by_filter() { |
| 912 | + add_filter( 'hcap_activate', '__return_true' ); |
| 913 | + add_filter( 'hcap_print_hcaptcha_scripts', '__return_false' ); |
| 914 | + |
| 915 | + $subject = new Main(); |
| 916 | + |
| 917 | + $subject->init_hooks(); |
| 918 | + |
| 919 | + self::assertFalse( wp_script_is( 'hcaptcha' ) ); |
| 920 | + |
| 921 | + ob_start(); |
| 922 | + do_action( 'wp_print_footer_scripts' ); |
| 923 | + $scripts = ob_get_clean(); |
| 924 | + |
| 925 | + self::assertFalse( wp_script_is( 'hcaptcha' ) ); |
| 926 | + self::assertSame( '', $scripts ); |
| 927 | + } |
| 928 | + |
761 | 929 | /** |
762 | 930 | * Data provider for test_print_footer_scripts(). |
763 | 931 | * |
|
0 commit comments