Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
timnolte committed Mar 11, 2024
1 parent 60893ea commit 4697954
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 50 deletions.
49 changes: 1 addition & 48 deletions includes/openid-connect-generic-option-logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

}

Expand All @@ -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();

}
Expand Down Expand Up @@ -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 );

}

Expand Down

0 comments on commit 4697954

Please sign in to comment.