PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / trunk
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode vtrunk
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / tests / integration / abilities / Test_Set_Cbid_Ability.php
cookiebot / tests / integration / abilities Last commit date
Test_Ability_Audit_Logger.php 2 months ago Test_Cookiebot_Abilities_Registrar.php 2 months ago Test_Get_Compliance_Summary_Ability.php 2 months ago Test_Get_Status_Ability.php 2 months ago Test_Install_Ppg_Ability.php 2 months ago Test_Set_Cbid_Ability.php 2 months ago Test_Toggle_Gcm_Ability.php 2 months ago Test_Verify_Setup_Ability.php 2 months ago
Test_Set_Cbid_Ability.php
94 lines
1 <?php
2 /**
3 * Test_Set_Cbid_Ability class.
4 *
5 * @package cookiebot
6 * @subpackage tests
7 */
8
9 namespace cybot\cookiebot\tests\integration\abilities;
10
11 use cybot\cookiebot\abilities\Ability_Audit_Logger;
12 use cybot\cookiebot\abilities\Set_Cbid_Ability;
13 use WP_UnitTestCase;
14
15 /**
16 * Tests for Set_Cbid_Ability.
17 *
18 * @since 4.8.0
19 */
20 class Test_Set_Cbid_Ability extends WP_UnitTestCase {
21
22 /**
23 * @var Ability_Audit_Logger
24 */
25 private $logger;
26
27 public function set_up() {
28 parent::set_up();
29 $this->logger = new Ability_Audit_Logger();
30 delete_option( 'cookiebot-ai-action-log' );
31 update_option( 'cookiebot-cbid', '11111111-1111-1111-1111-111111111111' );
32 }
33
34 public function test_get_name() {
35 $this->assertSame( 'cookiebot/set-cbid', ( new Set_Cbid_Ability( $this->logger ) )->get_name() );
36 }
37
38 public function test_updates_option_on_valid_cbid() {
39 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
40 $result = call_user_func( $args['execute_callback'], array( 'cbid' => 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF' ) );
41 $this->assertTrue( $result['success'] );
42 $this->assertSame( 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF', get_option( 'cookiebot-cbid' ) );
43 }
44
45 public function test_returns_cbid_set_flags_not_raw_values() {
46 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
47 $result = call_user_func( $args['execute_callback'], array( 'cbid' => 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF' ) );
48 // Response must use boolean flags, never the raw CBID value (security: CBID is sensitive).
49 $this->assertTrue( $result['old_cbid_set'] );
50 $this->assertTrue( $result['new_cbid_set'] );
51 $this->assertArrayNotHasKey( 'old_cbid', $result );
52 $this->assertArrayNotHasKey( 'new_cbid', $result );
53 }
54
55 public function test_old_cbid_set_false_when_previously_unset() {
56 update_option( 'cookiebot-cbid', '' );
57 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
58 $result = call_user_func( $args['execute_callback'], array( 'cbid' => 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF' ) );
59 $this->assertFalse( $result['old_cbid_set'] );
60 $this->assertTrue( $result['new_cbid_set'] );
61 }
62
63 public function test_writes_audit_log_on_success() {
64 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
65 call_user_func( $args['execute_callback'], array( 'cbid' => 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF' ) );
66 $log = get_option( 'cookiebot-ai-action-log', array() );
67 $this->assertCount( 1, $log );
68 $this->assertSame( 'cookiebot/set-cbid', $log[0]['ability'] );
69 // Audit log must NOT store raw CBID values.
70 $this->assertNotContains( 'AABBCCDD-1111-2222-3333-AABBCCDDEEFF', $log[0] );
71 $this->assertNotContains( '11111111-1111-1111-1111-111111111111', $log[0] );
72 }
73
74 public function test_returns_wp_error_on_invalid_uuid() {
75 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
76 $result = call_user_func( $args['execute_callback'], array( 'cbid' => 'not-a-uuid' ) );
77 $this->assertInstanceOf( 'WP_Error', $result );
78 $this->assertSame( 'cookiebot_invalid_cbid', $result->get_error_code() );
79 }
80
81 public function test_returns_wp_error_on_empty_cbid() {
82 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
83 $result = call_user_func( $args['execute_callback'], array( 'cbid' => '' ) );
84 $this->assertInstanceOf( 'WP_Error', $result );
85 $this->assertSame( 'cookiebot_invalid_cbid', $result->get_error_code() );
86 }
87
88 public function test_no_log_written_on_error() {
89 $args = ( new Set_Cbid_Ability( $this->logger ) )->get_args();
90 call_user_func( $args['execute_callback'], array( 'cbid' => 'bad' ) );
91 $this->assertEmpty( get_option( 'cookiebot-ai-action-log', array() ) );
92 }
93 }
94