X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=tests%2FUtilsTest.php;h=8225d95ae067d3c5db9fb4a352860bb341c8b961;hb=HEAD;hp=d0abd9968cfdc4afa152db87682b00ae4d5d73e5;hpb=067c2dd8f5f6eb6cc808ddc4bd30aec104caf73d;p=github%2Fshaarli%2FShaarli.git diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index d0abd996..59dca75f 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -10,7 +10,7 @@ require_once 'application/Languages.php'; /** * Unitary tests for Shaarli utilities */ -class UtilsTest extends PHPUnit_Framework_TestCase +class UtilsTest extends \Shaarli\TestCase { // Log file protected static $testLogFile = 'tests.log'; @@ -26,7 +26,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase /** * Assign reference data */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$defaultTimeZone = date_default_timezone_get(); // Timezone without DST for test consistency @@ -36,7 +36,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase /** * Reset the timezone */ - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { date_default_timezone_set(self::$defaultTimeZone); } @@ -44,7 +44,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase /** * Resets test data before each test */ - protected function setUp() + protected function setUp(): void { if (file_exists(self::$testLogFile)) { unlink(self::$testLogFile); @@ -63,41 +63,25 @@ class UtilsTest extends PHPUnit_Framework_TestCase } /** - * 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); } /** @@ -203,7 +187,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase public function testGenerateLocationLoop() { $ref = 'http://localhost/?test'; - $this->assertEquals('?', generateLocation($ref, 'localhost', array('test'))); + $this->assertEquals('./?', generateLocation($ref, 'localhost', array('test'))); } /** @@ -212,7 +196,7 @@ class UtilsTest extends PHPUnit_Framework_TestCase public function testGenerateLocationOut() { $ref = 'http://somewebsite.com/?test'; - $this->assertEquals('?', generateLocation($ref, 'localhost')); + $this->assertEquals('./?', generateLocation($ref, 'localhost')); }