diff --git a/.gitignore b/.gitignore index 0aa35273..2a9aa49c 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ plugins/additional_plugins* .DS_Store .editorconfig *.git +tests/phpunit.xml diff --git a/include/functions.inc.php b/include/functions.inc.php index 2dc4d148..c8e305a9 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -62,7 +62,7 @@ function serendipity_gzCompression() { function serendipity_serverOffsetHour($timestamp = null, $negative = false) { global $serendipity; - if ($timestamp == null) { + if ($timestamp === null) { $timestamp = time(); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 00000000..e2c68f86 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,2 @@ +assertEquals($expected, $result); + } + + /** + * @return array + */ + public function serverOffsetHourDataProvider() + { + return array( + array(0, 0, false, 0), + array(0, 0, true, 0), + array(0, 960793800, false, 960793800), + array(0, 960793800, true, 960793800), + array(10, 0, false, 36000), + array(10, 0, true, -36000), + array(10, 960793800, false, 960829800), + array(10, 960793800, true, 960757800), + ); + } + + /** + * @test + * @dataProvider serverOffsetHourWithTimestampNullDataProvider + */ + public function test_serendipity_serverOffsetHourWithTimestampNull($serverOffsetHours, $negative) + { + global $serendipity; + $now = time(); + $serendipity['serverOffsetHours'] = $serverOffsetHours; + $result = serendipity_serverOffsetHour(null, $negative); + if ($serverOffsetHours > 0) { + if ($negative) { + $this->assertGreaterThanOrEqual($now - ($serverOffsetHours * 3600), $result); + } else { + $this->assertGreaterThan($now - ($serverOffsetHours * 3600), $result); + } + } else { + $this->assertGreaterThanOrEqual($now, $result); + } + } + + /** + * @return array + */ + public function serverOffsetHourWithTimestampNullDataProvider() + { + return array( + array(null, false), + array(null, true), + array(10, false), + array(10, true), + ); + } +} diff --git a/tests/phpunit.xml.dist b/tests/phpunit.xml.dist new file mode 100644 index 00000000..ad28e69d --- /dev/null +++ b/tests/phpunit.xml.dist @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + ../tests/include + + +