From badf31f3b09eb3207896f43c09ddceadbe96f5ce Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 13 Sep 2023 15:04:58 -0600 Subject: [PATCH] Cast "1" and "0" as booleans when they are expected as booleans. Rollbar/WordPress/UI creates checkboxes for booleans and stores the state as "1" and "0". The PHP8 version of https://github.com/rollbar/rollbar-php expects actual booleans. this updates the config builder to convert "1" and "0" into TRUE and FALSE. Fixes: https://github.com/rollbar/rollbar-php-wordpress/issues/119 --- src/Plugin.php | 7 +++++++ tests/PluginTest.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Plugin.php b/src/Plugin.php index 77a4b02b..3acaa7ac 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -350,6 +350,13 @@ public function buildPHPConfig() } else if (isset($config[$setting]) && $config[$setting] === 'true') { $config[$setting] = true; } + + // also handle 1 and 0 as booleans + else if (isset($config[$setting]) && $config[$setting] === '0') { + $config[$setting] = false; + } else if (isset($config[$setting]) && $config[$setting] === '1') { + $config[$setting] = true; + } } return $config; diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 4ec3a918..967d5c2d 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -61,6 +61,22 @@ public function testLoggingLevel( } } + + /** + * Tests to ensure bools are properly converted from "1" and "0" strings + * + * @ticket https://github.com/rollbar/rollbar-php-wordpress/issues/119 + */ + public function testSendMessageTraceBool(){ + $plugin = $this->subject; + + $plugin->setting( 'send_message_trace', '1' ); + $plugin->setting( 'report_suppressed', '0' ); + $data = $plugin->buildPHPConfig(); + + $this->assertTrue( $data['send_message_trace'] ); + $this->assertFalse( $data['report_suppressed'] ); + } public static function loggingLevelTestDataProvider() {