| 1 |
<?php |
| 2 |
/** |
| 3 |
* Tests for Verify_Setup_Ability. |
| 4 |
* |
| 5 |
* @package cookiebot |
| 6 |
* @subpackage tests |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace cybot\cookiebot\tests\integration\abilities; |
| 10 |
|
| 11 |
use cybot\cookiebot\abilities\Verify_Setup_Ability; |
| 12 |
use WP_UnitTestCase; |
| 13 |
|
| 14 |
/** |
| 15 |
* Test class for Verify_Setup_Ability. |
| 16 |
* |
| 17 |
* @since 4.8.0 |
| 18 |
*/ |
| 19 |
class Test_Verify_Setup_Ability extends WP_UnitTestCase { |
| 20 |
|
| 21 |
/** |
| 22 |
* Set up test fixtures. |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function set_up() { |
| 27 |
parent::set_up(); |
| 28 |
update_option( 'cookiebot-cbid', 'aabbccdd-1111-2222-3333-aabbccddeeff' ); |
| 29 |
update_option( 'cookiebot-gcm', '1' ); |
| 30 |
update_option( 'cookiebot-cookie-blocking-mode', 'auto' ); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Test get_name returns correct ability name. |
| 35 |
* |
| 36 |
* @return void |
| 37 |
*/ |
| 38 |
public function test_get_name() { |
| 39 |
$this->assertSame( 'cookiebot/verify-setup', ( new Verify_Setup_Ability() )->get_name() ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Test no issues when fully configured. |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function test_no_issues_when_fully_configured() { |
| 48 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 49 |
$result = call_user_func( $args['execute_callback'] ); |
| 50 |
$this->assertEmpty( $result['issues'] ); |
| 51 |
$this->assertTrue( $result['cbid_configured'] ); |
| 52 |
$this->assertTrue( $result['gcm_enabled'] ); |
| 53 |
$this->assertTrue( $result['blocking_mode_automatic'] ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Test issue when CBID is missing. |
| 58 |
* |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function test_issue_when_cbid_missing() { |
| 62 |
update_option( 'cookiebot-cbid', '' ); |
| 63 |
delete_site_option( 'cookiebot-cbid' ); |
| 64 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 65 |
$result = call_user_func( $args['execute_callback'] ); |
| 66 |
$this->assertFalse( $result['cbid_configured'] ); |
| 67 |
$this->assertNotEmpty( $result['issues'] ); |
| 68 |
$this->assertStringContainsString( 'Domain Group ID', implode( ' ', $result['issues'] ) ); |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Test issue when blocking mode is manual. |
| 73 |
* |
| 74 |
* @return void |
| 75 |
*/ |
| 76 |
public function test_issue_when_blocking_mode_manual() { |
| 77 |
update_option( 'cookiebot-cookie-blocking-mode', 'manual' ); |
| 78 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 79 |
$result = call_user_func( $args['execute_callback'] ); |
| 80 |
$this->assertFalse( $result['blocking_mode_automatic'] ); |
| 81 |
$this->assertNotEmpty( $result['issues'] ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Test output has all required keys. |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
public function test_output_has_all_required_keys() { |
| 90 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 91 |
$result = call_user_func( $args['execute_callback'] ); |
| 92 |
foreach ( array( 'cbid_configured', 'configured_domain', 'gcm_enabled', 'blocking_mode_automatic', 'issues' ) as $key ) { |
| 93 |
$this->assertArrayHasKey( $key, $result ); |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
/** |
| 98 |
* Test configured_domain is a string. |
| 99 |
* |
| 100 |
* @return void |
| 101 |
*/ |
| 102 |
public function test_configured_domain_is_string() { |
| 103 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 104 |
$result = call_user_func( $args['execute_callback'] ); |
| 105 |
$this->assertIsString( $result['configured_domain'] ); |
| 106 |
$this->assertNotEmpty( $result['configured_domain'] ); |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Test issue when GCM is disabled. |
| 111 |
* |
| 112 |
* @return void |
| 113 |
*/ |
| 114 |
public function test_issue_when_gcm_disabled() { |
| 115 |
update_option( 'cookiebot-gcm', '0' ); |
| 116 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 117 |
$result = call_user_func( $args['execute_callback'] ); |
| 118 |
$this->assertFalse( $result['gcm_enabled'] ); |
| 119 |
$this->assertNotEmpty( $result['issues'] ); |
| 120 |
$this->assertStringContainsString( 'Google Consent Mode', implode( ' ', $result['issues'] ) ); |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Test show_in_rest is true. |
| 125 |
* |
| 126 |
* @return void |
| 127 |
*/ |
| 128 |
public function test_show_in_rest_true() { |
| 129 |
$args = ( new Verify_Setup_Ability() )->get_args(); |
| 130 |
$this->assertTrue( $args['meta']['show_in_rest'] ); |
| 131 |
} |
| 132 |
} |
| 133 |
|