/**
* Unitary tests for Shaarli utilities
*/
-class UtilsTest extends PHPUnit\Framework\TestCase
+class UtilsTest extends \Shaarli\TestCase
{
// Log file
protected static $testLogFile = 'tests.log';
/**
* Assign reference data
*/
- public static function setUpBeforeClass()
+ public static function setUpBeforeClass(): void
{
self::$defaultTimeZone = date_default_timezone_get();
// Timezone without DST for test consistency
/**
* Reset the timezone
*/
- public static function tearDownAfterClass()
+ public static function tearDownAfterClass(): void
{
date_default_timezone_set(self::$defaultTimeZone);
}
/**
* Resets test data before each test
*/
- protected function setUp()
+ protected function setUp(): void
{
if (file_exists(self::$testLogFile)) {
unlink(self::$testLogFile);
}
/**
- * Log a message to a file - IPv4 client address
+ * Format a log a message - IPv4 client address
*/
- public function testLogmIp4()
+ public function testFormatLogIp4()
{
- $logMessage = 'IPv4 client connected';
- logm(self::$testLogFile, '127.0.0.1', $logMessage);
- list($date, $ip, $message) = $this->getLastLogEntry();
+ $message = 'IPv4 client connected';
+ $log = format_log($message, '127.0.0.1');
- $this->assertInstanceOf(
- 'DateTime',
- DateTime::createFromFormat(self::$dateFormat, $date)
- );
- $this->assertTrue(
- filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false
- );
- $this->assertEquals($logMessage, $message);
+ static::assertSame('- 127.0.0.1 - IPv4 client connected', $log);
}
/**
- * Log a message to a file - IPv6 client address
+ * Format a log a message - IPv6 client address
*/
- public function testLogmIp6()
+ public function testFormatLogIp6()
{
- $logMessage = 'IPv6 client connected';
- logm(self::$testLogFile, '2001:db8::ff00:42:8329', $logMessage);
- list($date, $ip, $message) = $this->getLastLogEntry();
+ $message = 'IPv6 client connected';
+ $log = format_log($message, '2001:db8::ff00:42:8329');
- $this->assertInstanceOf(
- 'DateTime',
- DateTime::createFromFormat(self::$dateFormat, $date)
- );
- $this->assertTrue(
- filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false
- );
- $this->assertEquals($logMessage, $message);
+ static::assertSame('- 2001:db8::ff00:42:8329 - IPv6 client connected', $log);
}
/**
public function testGenerateLocationLoop()
{
$ref = 'http://localhost/?test';
- $this->assertEquals('?', generateLocation($ref, 'localhost', array('test')));
+ $this->assertEquals('./?', generateLocation($ref, 'localhost', array('test')));
}
/**
public function testGenerateLocationOut()
{
$ref = 'http://somewebsite.com/?test';
- $this->assertEquals('?', generateLocation($ref, 'localhost'));
+ $this->assertEquals('./?', generateLocation($ref, 'localhost'));
}