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
115 lines
3.1 KiB
PHP
Vendored
115 lines
3.1 KiB
PHP
Vendored
<?php
|
|
/**
|
|
* Class LogViewerTest
|
|
*
|
|
* @package WPDiscourse
|
|
*/
|
|
|
|
namespace WPDiscourse\Test;
|
|
|
|
use DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;
|
|
use WPDiscourse\Logs\FileManager;
|
|
use WPDiscourse\Logs\FileHandler;
|
|
use WPDiscourse\Logs\Logger;
|
|
use WPDiscourse\Admin\LogViewer;
|
|
use WPDiscourse\Admin\FormHelper;
|
|
use WPDiscourse\Test\UnitTest;
|
|
|
|
/**
|
|
* Logger test case.
|
|
*/
|
|
class LogViewerTest extends UnitTest {
|
|
use ArraySubsetAsserts;
|
|
|
|
/**
|
|
* Instance of LogViewer.
|
|
*
|
|
* @access protected
|
|
* @var \WPDiscourse\LogViewer\LogViewer
|
|
*/
|
|
protected $viewer;
|
|
|
|
/**
|
|
* Setup each test.
|
|
*/
|
|
public function setUp(): void {
|
|
parent::setUp();
|
|
|
|
$this->viewer = new LogViewer( FormHelper::get_instance() );
|
|
$this->viewer->setup_options( self::$plugin_options );
|
|
}
|
|
|
|
/**
|
|
* Teardown each test.
|
|
*/
|
|
public function tearDown(): void {
|
|
parent::tearDown();
|
|
|
|
self::$plugin_options['logs-enabled'] = 1;
|
|
$this->viewer->setup_options( self::$plugin_options );
|
|
}
|
|
|
|
/**
|
|
* It should be disabled if file handler is disabled
|
|
*/
|
|
public function test_file_handler_not_enabled() {
|
|
$handler = new FileHandler( new FileManager() );
|
|
$handler_double = \Mockery::mock( $handler )->makePartial();
|
|
$handler_double->shouldReceive( 'enabled' )->andReturn( false );
|
|
|
|
$this->viewer->setup_log_viewer( $handler_double );
|
|
|
|
$this->assertFalse( $this->viewer->is_enabled() );
|
|
|
|
ob_start();
|
|
$this->viewer->log_viewer_markup();
|
|
$markup = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
$this->assertXmlStringEqualsXmlString( $markup, '<div class="inline"><p>Logs are disabled.</p></div>' );
|
|
}
|
|
|
|
/**
|
|
* It should be disabled if logs are not enabled
|
|
*/
|
|
public function test_logs_not_enabled() {
|
|
self::$plugin_options['logs-enabled'] = 0;
|
|
$this->viewer->setup_options( self::$plugin_options );
|
|
$this->viewer->setup_log_viewer();
|
|
|
|
$this->assertFalse( $this->viewer->is_enabled() );
|
|
|
|
ob_start();
|
|
$this->viewer->log_viewer_markup();
|
|
$markup = ob_get_contents();
|
|
ob_end_clean();
|
|
|
|
$this->assertXmlStringEqualsXmlString( $markup, '<div class="inline"><p>Logs are disabled.</p></div>' );
|
|
}
|
|
|
|
/**
|
|
* It should retrieve logs and map them to date, number and file
|
|
*/
|
|
public function test_log_retrieval() {
|
|
$handler = new FileHandler( new FileManager() );
|
|
$logger = Logger::create( 'test', self::$plugin_options, $handler );
|
|
$logger->info( 'New Log' );
|
|
|
|
$this->viewer->setup_log_viewer();
|
|
|
|
$date = $handler->get_date();
|
|
$number = $handler->current_file_number();
|
|
$file = $handler->current_file_url();
|
|
|
|
$this->assertArraySubset(
|
|
array(
|
|
"$date-$number" => array(
|
|
'date' => $date,
|
|
'number' => $number,
|
|
'file' => $file,
|
|
),
|
|
),
|
|
$this->viewer->get_logs()
|
|
);
|
|
}
|
|
}
|