diff options
Diffstat (limited to 'tests/wrapper')
| -rw-r--r-- | tests/wrapper/gmgetdate_test.php | 60 | ||||
| -rw-r--r-- | tests/wrapper/mt_rand_test.php | 10 | ||||
| -rw-r--r-- | tests/wrapper/phpbb_php_ini_fake.php | 20 | ||||
| -rw-r--r-- | tests/wrapper/phpbb_php_ini_test.php | 90 | ||||
| -rw-r--r-- | tests/wrapper/version_compare_test.php | 10 | 
5 files changed, 165 insertions, 25 deletions
diff --git a/tests/wrapper/gmgetdate_test.php b/tests/wrapper/gmgetdate_test.php index a838cfdba9..2e55a78d21 100644 --- a/tests/wrapper/gmgetdate_test.php +++ b/tests/wrapper/gmgetdate_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ @@ -11,26 +15,28 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';  class phpbb_wrapper_gmgetdate_test extends phpbb_test_case  { -	public function test_gmgetdate() +	public static function phpbb_gmgetdate_data()  	{ -		$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'); +		return array( +			array(''), +			array('UTC'), +			array('Europe/Berlin'), +			array('America/Los_Angeles'), +			array('Antarctica/South_Pole'), +		);  	} -	protected function run_test_with_timezone($timezone_identifier) +	/** +	 * @dataProvider phpbb_gmgetdate_data +	 */ +	public function test_phpbb_gmgetdate($timezone_identifier)  	{ -		$current_timezone = date_default_timezone_get(); - -		date_default_timezone_set($timezone_identifier); -		$this->run_gmgetdate_assertion(); -		date_default_timezone_set($current_timezone); -	} +		if ($timezone_identifier) +		{ +			$current_timezone = date_default_timezone_get(); +			date_default_timezone_set($timezone_identifier); +		} -	protected function run_gmgetdate_assertion() -	{  		$expected = time();  		$date_array = phpbb_gmgetdate($expected); @@ -44,6 +50,22 @@ class phpbb_wrapper_gmgetdate_test extends phpbb_test_case  			$date_array['year']  		); -		$this->assertEquals($expected, $actual); +		// Calling second-granularity time functions twice isn't guaranteed to +		// give the same results. As long as they're in the right order, allow +		// a 1 second difference. +		$this->assertGreaterThanOrEqual( +			$expected, $actual, +			'Expected second time to be after (or equal to) the previous one' +		); +		$this->assertLessThanOrEqual( +			1, +			abs($actual - $expected), +			"Expected $actual to be within 1 second of $expected." +		); + +		if (isset($current_timezone)) +		{ +			date_default_timezone_set($current_timezone); +		}  	}  } diff --git a/tests/wrapper/mt_rand_test.php b/tests/wrapper/mt_rand_test.php index eba0bf2faa..d190182286 100644 --- a/tests/wrapper/mt_rand_test.php +++ b/tests/wrapper/mt_rand_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */ diff --git a/tests/wrapper/phpbb_php_ini_fake.php b/tests/wrapper/phpbb_php_ini_fake.php new file mode 100644 index 0000000000..f218ff6d03 --- /dev/null +++ b/tests/wrapper/phpbb_php_ini_fake.php @@ -0,0 +1,20 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +class phpbb_php_ini_fake extends \phpbb\php\ini +{ +	function get($varname) +	{ +		return $varname; +	} +} diff --git a/tests/wrapper/phpbb_php_ini_test.php b/tests/wrapper/phpbb_php_ini_test.php new file mode 100644 index 0000000000..27c2487f0a --- /dev/null +++ b/tests/wrapper/phpbb_php_ini_test.php @@ -0,0 +1,90 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +require_once dirname(__FILE__) . '/phpbb_php_ini_fake.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + +class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case +{ +	protected $php_ini; + +	public function setUp() +	{ +		$this->php_ini = new phpbb_php_ini_fake; +	} + +	public function test_get_string() +	{ +		$this->assertSame(false, $this->php_ini->get_string(false)); +		$this->assertSame('phpbb', $this->php_ini->get_string(' phpbb ')); +	} + +	public function test_get_bool() +	{ +		$this->assertSame(true, $this->php_ini->get_bool('ON')); +		$this->assertSame(true, $this->php_ini->get_bool('on')); +		$this->assertSame(true, $this->php_ini->get_bool('1')); + +		$this->assertSame(false, $this->php_ini->get_bool('OFF')); +		$this->assertSame(false, $this->php_ini->get_bool('off')); +		$this->assertSame(false, $this->php_ini->get_bool('0')); +		$this->assertSame(false, $this->php_ini->get_bool('')); +	} + +	public function test_get_int() +	{ +		$this->assertSame(1234, $this->php_ini->get_int('1234')); +		$this->assertSame(-12345, $this->php_ini->get_int('-12345')); +		$this->assertSame(false, $this->php_ini->get_int('phpBB')); +	} + +	public function test_get_float() +	{ +		$this->assertSame(1234.0, $this->php_ini->get_float('1234')); +		$this->assertSame(-12345.0, $this->php_ini->get_float('-12345')); +		$this->assertSame(false, $this->php_ini->get_float('phpBB')); +	} + +	public function test_get_bytes_invalid() +	{ +		$this->assertSame(false, $this->php_ini->get_bytes(false)); +		$this->assertSame(false, $this->php_ini->get_bytes('phpBB')); +		$this->assertSame(false, $this->php_ini->get_bytes('k')); +		$this->assertSame(false, $this->php_ini->get_bytes('-k')); +		$this->assertSame(false, $this->php_ini->get_bytes('M')); +		$this->assertSame(false, $this->php_ini->get_bytes('-M')); +	} + +	/** +	* @dataProvider get_bytes_data +	*/ +	public function test_get_bytes($expected, $value) +	{ +		$actual = $this->php_ini->get_bytes($value); + +		$this->assertTrue(is_float($actual) || is_int($actual)); +		$this->assertEquals($expected, $actual); +	} + +	static public function get_bytes_data() +	{ +		return array( +			array(32 * pow(2, 20),		'32m'), +			array(- 32 * pow(2, 20),	'-32m'), +			array(8 * pow(2, 30),		'8G'), +			array(- 8 * pow(2, 30),		'-8G'), +			array(1234,					'1234'), +			array(-12345,				'-12345'), +		); +	} +} diff --git a/tests/wrapper/version_compare_test.php b/tests/wrapper/version_compare_test.php index 8b42eb4bee..93d9e0117d 100644 --- a/tests/wrapper/version_compare_test.php +++ b/tests/wrapper/version_compare_test.php @@ -1,9 +1,13 @@  <?php  /**  * -* @package testing -* @copyright (c) 2011 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file.  *  */  | 
