diff options
Diffstat (limited to 'tests/wrapper')
| -rw-r--r-- | tests/wrapper/gmgetdate_test.php | 49 | ||||
| -rw-r--r-- | tests/wrapper/mt_rand_test.php | 46 | ||||
| -rw-r--r-- | tests/wrapper/version_compare_test.php | 130 | 
3 files changed, 225 insertions, 0 deletions
diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php new file mode 100644 index 0000000000..0b4c3378a9 --- /dev/null +++ b/tests/wrapper/gmgetdate_test.php @@ -0,0 +1,49 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_wrapper_gmgetdate_test extends phpbb_test_case +{ +	public function test_gmgetdate() +	{ +		$this->run_gmgetdate_assertion(); +		$this->run_test_with_timezone('UTC'); +		$this->run_test_with_timezone('Europe/Berlin'); +		$this->run_test_with_timezone('America/Los_Angeles'); +		$this->run_test_with_timezone('Antarctica/South_Pole'); +	} + +	protected function run_test_with_timezone($timezone_identifier) +	{ +		$current_timezone = date_default_timezone_get(); + +		date_default_timezone_set($timezone_identifier); +		$this->run_gmgetdate_assertion(); +		date_default_timezone_set($current_timezone); +	} + +	protected function run_gmgetdate_assertion() +	{ +		$expected = time(); + +		$date_array = phpbb_gmgetdate($expected); + +		$actual = gmmktime( +			$date_array['hours'], +			$date_array['minutes'], +			$date_array['seconds'], +			$date_array['mon'], +			$date_array['mday'], +			$date_array['year'] +		); + +		$this->assertEquals($expected, $actual); +	} +} diff --git a/tests/wrapper/mt_rand_test.php b/tests/wrapper/mt_rand_test.php new file mode 100644 index 0000000000..c8bcb3d14c --- /dev/null +++ b/tests/wrapper/mt_rand_test.php @@ -0,0 +1,46 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_wrapper_mt_rand_test extends phpbb_test_case +{ +	public function test_max_equals_min() +	{ +		$result = phpbb_mt_rand(42, 42); +		$this->assertEquals(42, $result); +	} + +	public function test_max_equals_min_negative() +	{ +		$result = phpbb_mt_rand(-42, -42); +		$this->assertEquals(-42, $result); +	} + +	public function test_max_greater_min() +	{ +		$result = phpbb_mt_rand(3, 4); +		$this->assertGreaterThanOrEqual(3, $result); +		$this->assertLessThanOrEqual(4, $result); +	} + +	public function test_min_greater_max() +	{ +		$result = phpbb_mt_rand(4, 3); +		$this->assertGreaterThanOrEqual(3, $result); +		$this->assertLessThanOrEqual(4, $result); +	} + +	public function test_min_greater_max_negative() +	{ +		$result = phpbb_mt_rand(-3, -4); +		$this->assertGreaterThanOrEqual(-4, $result); +		$this->assertLessThanOrEqual(-3, $result); +	} +} diff --git a/tests/wrapper/version_compare_test.php b/tests/wrapper/version_compare_test.php new file mode 100644 index 0000000000..f718cfd16b --- /dev/null +++ b/tests/wrapper/version_compare_test.php @@ -0,0 +1,130 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2011 phpBB Group +* @license http://opensource.org/licenses/gpl-license.php GNU Public License +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_wrapper_version_compare_test extends phpbb_test_case +{ +	public function test_two_parameters() +	{ +		$this->assertEquals(-1, phpbb_version_compare('1.0.0', '1.0.1')); +		$this->assertEquals(0, phpbb_version_compare('1.0.0', '1.0.0')); +		$this->assertEquals(1, phpbb_version_compare('1.0.1', '1.0.0')); +	} +	 +	public function test_three_parameters() +	{ +		$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.1', '<')); +		$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '<=')); +		$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '=')); +		$this->assertEquals(true, phpbb_version_compare('1.0.0', '1.0.0', '>=')); +		$this->assertEquals(true, phpbb_version_compare('1.0.1', '1.0.0', '>')); +	} + +	public function test_strict_order() +	{ +		$releases = array( +			'2.0.0', +			'2.0.1', +			// Those are not version_compare() compatible +			//'2.0.6a', +			//'2.0.6b', +			//'2.0.6c', +			//'2.0.6d', +			'2.0.7', +			'2.0.23', +			'3.0.A1', +			'3.0.A2', +			'3.0.A3', +			'3.0.B1', +			'3.0.B2', +			'3.0.B4', +			'3.0.B5', +			'3.0.RC1', +			'3.0.RC5', +			'3.0.0', +			'3.0.1', +			'3.0.2', +			'3.0.7', +			'3.0.7-PL1', +			'3.0.8-RC1', +			'3.0.8', +			'3.0.9-dev', +			'3.0.9-RC1', +			'3.0.9-RC2', +			'3.0.9-RC4', +			'3.0.10-RC1', +			'3.1-dev', +			'3.2-A1', +		); + +		for ($i = 0, $size = sizeof($releases); $i < $size - 1; ++$i) +		{ +			$version1 = $releases[$i]; +			$version2 = $releases[$i + 1]; + +			$this->assertEquals( +				true, +				phpbb_version_compare($version1, $version2, '<'), +				"Result of version comparison $version1 < $version2 is incorrect." +			); +		} +	} + +	/** +	* @dataProvider equality_test_data +	*/ +	public function test_equality($version1, $version2) +	{ +		$this->assertEquals( +			0, +			phpbb_version_compare($version1, $version2), +			"Result of version comparison $version1 = $version2 is incorrect." +		); + +		$this->assertEquals( +			true, +			phpbb_version_compare($version1, $version2, '='), +			"Result of version comparison $version1 = $version2 is incorrect." +		); +	} + +	public function equality_test_data() +	{ +		return array( +			array('1.1.0-A2', '1.1.0-a2'), +			array('1.1.0-B1', '1.1.0-b1'), +		); +	} + +	/** +	* @dataProvider alpha_beta_test_data +	*/ +	public function test_alpha_beta($expected, $version1, $version2) +	{ +		$this->assertEquals( +			$expected, +			phpbb_version_compare($version1, $version2), +			"Result of version comparison ($version1, $version2) = $expected is incorrect." +		); +		 +	} + +	public function alpha_beta_test_data() +	{ +		return array( +			array(-1, '1.1.0-A2', '1.1.0-B1'), +			array(-1, '1.1.0-a2', '1.1.0-b1'), + +			array(-1, '1.1.0-a2', '1.1.0-B1'), +			array(-1, '1.1.0-A2', '1.1.0-b1'), +		); +	} + +}  | 
