mirror of
https://gh.wpcy.net/https://github.com/discourse/wp-discourse.git
synced 2026-05-23 03:20:46 +08:00
* Don't try to add url to <head> if it's not present * Update js config and formatting for comment block and sidebar * PHP Linting * FIX: Don't auto-publish updates to existing posts. See: https://meta.discourse.org/t/disable-posting-wordpress-articles-to-discourse-when-theyre-updated/204488 * Bump version and release notes. * Fix remote-post.php linting * Update tests.yml to install svn * Re-generate comments js build
91 lines
2.3 KiB
PHP
Vendored
91 lines
2.3 KiB
PHP
Vendored
<?php
|
|
/**
|
|
* Class LoggerTest
|
|
*
|
|
* @package WPDiscourse
|
|
*/
|
|
|
|
namespace WPDiscourse\Test;
|
|
|
|
use WPDiscourse\Logs\Logger;
|
|
use WPDiscourse\Logs\NullHandler;
|
|
use WPDiscourse\Logs\FileHandler;
|
|
use WPDiscourse\Logs\LineFormatter;
|
|
use WPDiscourse\Test\UnitTest;
|
|
|
|
/**
|
|
* Logger test case.
|
|
*/
|
|
class LoggerTest extends UnitTest {
|
|
|
|
/**
|
|
* Teardown each test.
|
|
*/
|
|
public function tearDown(): void {
|
|
parent::tearDown();
|
|
|
|
self::$plugin_options['logs-enabled'] = 1;
|
|
}
|
|
|
|
/**
|
|
* It creates an instance of Logger
|
|
*/
|
|
public function test_create() {
|
|
$logger = Logger::create( 'test', self::$plugin_options );
|
|
$this->assertInstanceOf( Logger::class, $logger );
|
|
|
|
return $logger;
|
|
}
|
|
|
|
/**
|
|
* It attaches FileHandler as the default handler
|
|
*
|
|
* @param object $logger Instance of \WPDiscourse\Logs\Logger.
|
|
* @depends test_create
|
|
*/
|
|
public function test_create_handler( $logger ) {
|
|
$handlers = $logger->getHandlers();
|
|
$this->assertCount( 1, $handlers );
|
|
|
|
$file_handler = reset( $handlers );
|
|
$this->assertInstanceOf( FileHandler::class, $file_handler );
|
|
|
|
return $file_handler;
|
|
}
|
|
|
|
/**
|
|
* It attaches LineFormatter as the default formatter
|
|
*
|
|
* @param object $file_handler Instance of \WPDiscourse\Logs\FileHandler.
|
|
* @depends test_create_handler
|
|
*/
|
|
public function test_create_handler_formatter( $file_handler ) {
|
|
$this->assertInstanceOf( LineFormatter::class, $file_handler->getFormatter() );
|
|
}
|
|
|
|
/**
|
|
* It attaches NullHandler if FileHandler is not enabled
|
|
*/
|
|
public function test_create_file_handler_not_enabled() {
|
|
$file_handler_double = \Mockery::mock( FileHandler::class )->makePartial();
|
|
$file_handler_double->shouldReceive( 'enabled' )->andReturn( false );
|
|
|
|
$logger = Logger::create( 'test', self::$plugin_options, $file_handler_double );
|
|
$handlers = $logger->getHandlers();
|
|
|
|
$this->assertCount( 1, $handlers );
|
|
$this->assertContainsOnlyInstancesOf( NullHandler::class, $handlers );
|
|
}
|
|
|
|
/**
|
|
* It attaches NullHandler if logs are not enabled
|
|
*/
|
|
public function test_create_logs_not_enabled() {
|
|
self::$plugin_options['logs-enabled'] = 0;
|
|
$logger = Logger::create( 'test', self::$plugin_options );
|
|
$handlers = $logger->getHandlers();
|
|
|
|
$this->assertCount( 1, $handlers );
|
|
$this->assertContainsOnlyInstancesOf( NullHandler::class, $handlers );
|
|
}
|
|
}
|