diff --git a/includes/openid-connect-generic-option-logger.php b/includes/openid-connect-generic-option-logger.php index 75dde9b..fc70616 100644 --- a/includes/openid-connect-generic-option-logger.php +++ b/includes/openid-connect-generic-option-logger.php @@ -73,54 +73,6 @@ public function __construct( $default_message_type = null, $logging_enabled = nu } } - /** - * Subscribe logger to a set of filters. - * - * @param array|string $filter_names The array, or string, of the name(s) of an filter(s) to hook the logger into. - * @param int $priority The WordPress filter priority level. - * - * @return void - */ - public function log_filters( $filter_names, $priority = 10 ) { - if ( ! is_array( $filter_names ) ) { - $filter_names = array( $filter_names ); - } - - foreach ( $filter_names as $filter ) { - add_filter( $filter, array( $this, 'log_hook' ), $priority ); - } - } - - /** - * Subscribe logger to a set of actions. - * - * @param array|string $action_names The array, or string, of the name(s) of an action(s) to hook the logger into. - * @param int $priority The WordPress action priority level. - * - * @return void - */ - public function log_actions( $action_names, $priority ) { - if ( ! is_array( $action_names ) ) { - $action_names = array( $action_names ); - } - - foreach ( $action_names as $action ) { - add_filter( $action, array( $this, 'log_hook' ), $priority ); - } - } - - /** - * Log the data. - * - * @param mixed $arg The hook argument. - * - * @return mixed - */ - public function log_hook( $arg = null ) { - $this->log( func_get_args(), current_filter() ); - return $arg; - } - /** * Save an array of data to the logs. * @@ -181,6 +133,7 @@ private function make_message( $data, $type, $processing_time ) { if ( is_array( $data ) && isset( $data['type'] ) ) { $type = $data['type']; + unset( $data['type'] ); } else if ( is_wp_error( $data ) ) { $type = $data->get_error_code(); } diff --git a/tests/phpunit/includes/openid-connect-generic-option-logger_test.php b/tests/phpunit/includes/openid-connect-generic-option-logger_test.php index a82ab7e..3e046e9 100644 --- a/tests/phpunit/includes/openid-connect-generic-option-logger_test.php +++ b/tests/phpunit/includes/openid-connect-generic-option-logger_test.php @@ -23,7 +23,9 @@ class OpenID_Connect_Generic_Option_Logger_Test extends WP_UnitTestCase { public function setUp(): void { parent::setUp(); - $this->logger = new OpenID_Connect_Generic_Option_Logger(); + + // Initialize a logger instance with some testable defaults. + $this->logger = new OpenID_Connect_Generic_Option_Logger( null, true, 2 ); } @@ -34,7 +36,12 @@ public function setUp(): void { */ public function tearDown(): void { + // Make sure we cleanup any test log entries. + $this->logger->clear_logs(); + + // Clean-up the logger instance. unset( $this->logger ); + parent::tearDown(); } @@ -90,7 +97,17 @@ public function test_logger_has_logs_propery() { */ public function test_plugin_logger_get_option_name() { - $this->assertEquals( 'openid-connect-generic-logs', $this->logger->get_option_name(), 'OpenID_Connect_Generic_Option_Logger has a correct OPTION_NAME.' ); + $expected_option_name = 'openid-connect-generic-logs'; + $this->assertEquals( $expected_option_name, $this->logger->get_option_name(), 'OpenID_Connect_Generic_Option_Logger has a correct OPTION_NAME.' ); + + } + + /** + * Test plugin logger upkeep_logs() method. + */ + public function test_plugin_logger_upkeep_logs() { + + $this->logger->log( 'test', 'test', 100 ); }