PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.7.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.7.2
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 / cli / Test_Cookiebot_CLI_Command.php
cookiebot / tests / integration / cli Last commit date
Test_Cookiebot_CLI_Command.php 1 month ago
Test_Cookiebot_CLI_Command.php
110 lines
1 <?php
2 /**
3 * Tests for Cookiebot_CLI_Command.
4 *
5 * @package cookiebot
6 * @subpackage tests
7 */
8
9 namespace cybot\cookiebot\tests\integration\cli;
10
11 use cybot\cookiebot\cli\Cookiebot_CLI_Command;
12 use cybot\cookiebot\cli\Output_Adapter;
13 use WP_UnitTestCase;
14
15 /**
16 * Fake output adapter that records all output calls for assertions.
17 */
18 class Fake_Output implements Output_Adapter {
19 public $successes = array();
20 public $errors = array();
21 public $items = array();
22
23 public function success( $message ) {
24 $this->successes[] = $message;
25 }
26
27 public function error( $message ) {
28 $this->errors[] = $message;
29 }
30
31 public function format_items( $items, $fields, $format ) {
32 $this->items[] = array(
33 'items' => $items,
34 'fields' => $fields,
35 'format' => $format,
36 );
37 }
38 }
39
40 /**
41 * Integration tests for Cookiebot_CLI_Command.
42 *
43 * @since 4.8.0
44 */
45 class Test_Cookiebot_CLI_Command extends WP_UnitTestCase {
46
47 /**
48 * Set up test fixtures.
49 *
50 * @return void
51 */
52 public function set_up() {
53 parent::set_up();
54 // Run as an administrator so that manage_options passes in execute().
55 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) );
56 wp_set_current_user( $user_id );
57 update_option( 'cookiebot-cbid', 'aabbccdd-1111-2222-3333-aabbccddeeff' );
58 update_option( 'cookiebot-gcm', '1' );
59 update_option( 'cookiebot-cookie-blocking-mode', 'auto' );
60 update_option( 'cookiebot-banner-enabled', '1' );
61 }
62
63 public function test_status_calls_get_status_ability_and_outputs_one_row() {
64 $output = new Fake_Output();
65 $command = new Cookiebot_CLI_Command( $output );
66
67 $command->status( array(), array( 'format' => 'json' ) );
68
69 $this->assertCount( 1, $output->items );
70 $this->assertCount( 1, $output->items[0]['items'] );
71 $row = $output->items[0]['items'][0];
72 $this->assertArrayHasKey( 'cbid_set', $row );
73 $this->assertArrayHasKey( 'gcm_enabled', $row );
74 $this->assertArrayHasKey( 'plugin_version', $row );
75 $this->assertEmpty( $output->errors );
76 }
77
78 public function test_set_cbid_with_invalid_uuid_routes_to_error() {
79 $output = new Fake_Output();
80 $command = new Cookiebot_CLI_Command( $output );
81
82 $command->set_cbid( array( 'not-a-uuid' ), array() );
83
84 $this->assertCount( 1, $output->errors );
85 $this->assertEmpty( $output->successes );
86 }
87
88 public function test_set_cbid_with_valid_uuid_calls_success() {
89 $output = new Fake_Output();
90 $command = new Cookiebot_CLI_Command( $output );
91
92 $command->set_cbid( array( '12345678-1234-1234-1234-123456789abc' ), array() );
93
94 $this->assertCount( 1, $output->successes );
95 // The success message must NOT contain the CBID value (security: CBID is sensitive).
96 $this->assertStringNotContainsString( '12345678', $output->successes[0] );
97 $this->assertStringContainsString( 'CBID updated', $output->successes[0] );
98 $this->assertEmpty( $output->errors );
99 }
100
101 public function test_toggle_gcm_without_flag_routes_to_error() {
102 $output = new Fake_Output();
103 $command = new Cookiebot_CLI_Command( $output );
104
105 $command->toggle_gcm( array(), array() );
106
107 $this->assertCount( 1, $output->errors );
108 }
109 }
110