2015-04-08 15:55:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Class Log.
|
2015-04-08 15:55:19 +00:00
|
|
|
* @package WooCommerce\Tests\Util
|
|
|
|
* @since 2.3
|
|
|
|
*/
|
2016-03-23 12:14:13 +00:00
|
|
|
class WC_Tests_Log extends WC_Unit_Test_Case {
|
2015-04-08 15:55:19 +00:00
|
|
|
public function read_content( $handle ) {
|
|
|
|
return file_get_contents( wc_get_log_file_path( $handle ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test add().
|
2015-04-08 15:55:19 +00:00
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_add() {
|
2016-08-08 12:59:23 +00:00
|
|
|
$log = wc_get_logger();
|
2015-04-08 15:55:19 +00:00
|
|
|
|
|
|
|
$log->add( 'unit-tests', 'this is a message' );
|
|
|
|
|
2015-09-12 14:18:41 +00:00
|
|
|
$this->assertStringMatchesFormat( '%d-%d-%d @ %d:%d:%d - %s', $this->read_content( 'unit-tests' ) );
|
|
|
|
$this->assertStringEndsWith( ' - this is a message' . PHP_EOL, $this->read_content( 'unit-tests' ) );
|
2015-04-08 15:55:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-11-03 13:31:20 +00:00
|
|
|
* Test clear().
|
2015-04-08 15:55:19 +00:00
|
|
|
*
|
|
|
|
* @since 2.4
|
|
|
|
*/
|
|
|
|
public function test_clear() {
|
2016-08-08 12:59:23 +00:00
|
|
|
$log = wc_get_logger();
|
2015-04-08 15:55:19 +00:00
|
|
|
|
|
|
|
$log->add( 'unit-tests', 'this is a message' );
|
|
|
|
$log->clear( 'unit-tests' );
|
|
|
|
|
|
|
|
$this->assertEquals( '', $this->read_content( 'unit-tests' ) );
|
|
|
|
}
|
|
|
|
}
|