| 1 |
<?php |
| 2 |
/** |
| 3 |
* Tests for Get_Compliance_Summary_Ability. |
| 4 |
* |
| 5 |
* @package cookiebot |
| 6 |
* @subpackage tests |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace cybot\cookiebot\tests\integration\abilities; |
| 10 |
|
| 11 |
use cybot\cookiebot\abilities\Get_Compliance_Summary_Ability; |
| 12 |
use WP_UnitTestCase; |
| 13 |
|
| 14 |
/** |
| 15 |
* Test class for Get_Compliance_Summary_Ability. |
| 16 |
* |
| 17 |
* @since 4.8.0 |
| 18 |
*/ |
| 19 |
class Test_Get_Compliance_Summary_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-scan-status', 'completed' ); |
| 29 |
update_option( 'cookiebot-user-data', '' ); |
| 30 |
update_option( 'cookiebot-cbid', '' ); |
| 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/get-compliance-summary', ( new Get_Compliance_Summary_Ability() )->get_name() ); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Test output has all required keys. |
| 44 |
* |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function test_output_has_all_required_keys() { |
| 48 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 49 |
$result = call_user_func( $args['execute_callback'] ); |
| 50 |
foreach ( array( 'regulations_covered', 'scan_status', 'consent_log_available', 'plan_type' ) as $key ) { |
| 51 |
$this->assertArrayHasKey( $key, $result ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Test regulations_covered includes key standards. |
| 57 |
* |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public function test_regulations_covered_includes_key_standards() { |
| 61 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 62 |
$result = call_user_func( $args['execute_callback'] ); |
| 63 |
foreach ( array( 'GDPR', 'CCPA/CPRA', 'LGPD', 'IAB TCF 2.2', 'Google Consent Mode v2' ) as $reg ) { |
| 64 |
$this->assertContains( $reg, $result['regulations_covered'] ); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Test scan_status reflects option. |
| 70 |
* |
| 71 |
* @return void |
| 72 |
*/ |
| 73 |
public function test_scan_status_reflects_option() { |
| 74 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 75 |
$result = call_user_func( $args['execute_callback'] ); |
| 76 |
$this->assertSame( 'completed', $result['scan_status'] ); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Test consent_log_available is true when CBID is set. |
| 81 |
* |
| 82 |
* @return void |
| 83 |
*/ |
| 84 |
public function test_consent_log_available_true_when_cbid_set() { |
| 85 |
update_option( 'cookiebot-cbid', 'aabbccdd-1111-2222-3333-aabbccddeeff' ); |
| 86 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 87 |
$result = call_user_func( $args['execute_callback'] ); |
| 88 |
$this->assertTrue( $result['consent_log_available'] ); |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* Test consent_log_available is false when CBID is empty. |
| 93 |
* |
| 94 |
* @return void |
| 95 |
*/ |
| 96 |
public function test_consent_log_available_false_when_cbid_empty() { |
| 97 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 98 |
$result = call_user_func( $args['execute_callback'] ); |
| 99 |
$this->assertFalse( $result['consent_log_available'] ); |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Test plan_type is unknown with no user data. |
| 104 |
* |
| 105 |
* @return void |
| 106 |
*/ |
| 107 |
public function test_plan_type_unknown_with_no_user_data() { |
| 108 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 109 |
$result = call_user_func( $args['execute_callback'] ); |
| 110 |
$this->assertSame( 'unknown', $result['plan_type'] ); |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* Test plan_type detects free plan. |
| 115 |
* |
| 116 |
* @return void |
| 117 |
*/ |
| 118 |
public function test_plan_type_free_detected() { |
| 119 |
update_option( 'cookiebot-user-data', json_encode( array( 'subscription' => array( 'plan' => 'Free Plan' ) ) ) ); |
| 120 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 121 |
$result = call_user_func( $args['execute_callback'] ); |
| 122 |
$this->assertSame( 'free', $result['plan_type'] ); |
| 123 |
} |
| 124 |
|
| 125 |
/** |
| 126 |
* Test plan_type detects premium plan. |
| 127 |
* |
| 128 |
* @return void |
| 129 |
*/ |
| 130 |
public function test_plan_type_premium_detected() { |
| 131 |
update_option( 'cookiebot-user-data', json_encode( array( 'subscription' => array( 'plan' => 'Premium' ) ) ) ); |
| 132 |
$args = ( new Get_Compliance_Summary_Ability() )->get_args(); |
| 133 |
$result = call_user_func( $args['execute_callback'] ); |
| 134 |
$this->assertSame( 'premium', $result['plan_type'] ); |
| 135 |
} |
| 136 |
} |
| 137 |
|