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_Toggle_Gcm_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_Toggle_Gcm_Ability.php
78 lines
1 <?php
2 /**
3 * Test_Toggle_Gcm_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\Toggle_Gcm_Ability;
13 use WP_UnitTestCase;
14
15 /**
16 * Tests for Toggle_Gcm_Ability.
17 *
18 * @since 4.8.0
19 */
20 class Test_Toggle_Gcm_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 }
32
33 public function test_get_name() {
34 $this->assertSame( 'cookiebot/toggle-gcm', ( new Toggle_Gcm_Ability( $this->logger ) )->get_name() );
35 }
36
37 public function test_enable_sets_option_to_1() {
38 update_option( 'cookiebot-gcm', '0' );
39 $args = ( new Toggle_Gcm_Ability( $this->logger ) )->get_args();
40 $result = call_user_func( $args['execute_callback'], array( 'enabled' => true ) );
41 $this->assertTrue( $result['success'] );
42 $this->assertSame( '1', get_option( 'cookiebot-gcm' ) );
43 }
44
45 public function test_disable_sets_option_to_0() {
46 update_option( 'cookiebot-gcm', '1' );
47 $args = ( new Toggle_Gcm_Ability( $this->logger ) )->get_args();
48 $result = call_user_func( $args['execute_callback'], array( 'enabled' => false ) );
49 $this->assertTrue( $result['success'] );
50 $this->assertSame( '0', get_option( 'cookiebot-gcm' ) );
51 }
52
53 public function test_old_and_new_values_are_booleans() {
54 update_option( 'cookiebot-gcm', '1' );
55 $args = ( new Toggle_Gcm_Ability( $this->logger ) )->get_args();
56 $result = call_user_func( $args['execute_callback'], array( 'enabled' => false ) );
57 $this->assertSame( true, $result['old_value'] );
58 $this->assertSame( false, $result['new_value'] );
59 }
60
61 public function test_writes_audit_log() {
62 update_option( 'cookiebot-gcm', '1' );
63 $args = ( new Toggle_Gcm_Ability( $this->logger ) )->get_args();
64 call_user_func( $args['execute_callback'], array( 'enabled' => false ) );
65 $log = get_option( 'cookiebot-ai-action-log', array() );
66 $this->assertCount( 1, $log );
67 $this->assertSame( 'cookiebot/toggle-gcm', $log[0]['ability'] );
68 }
69
70 public function test_idempotent_same_value_succeeds() {
71 update_option( 'cookiebot-gcm', '1' );
72 $args = ( new Toggle_Gcm_Ability( $this->logger ) )->get_args();
73 $result = call_user_func( $args['execute_callback'], array( 'enabled' => true ) );
74 $this->assertTrue( $result['success'] );
75 $this->assertSame( '1', get_option( 'cookiebot-gcm' ) );
76 }
77 }
78