diff options
Diffstat (limited to 'tests/version/version_test.php')
| -rw-r--r-- | tests/version/version_test.php | 519 | 
1 files changed, 515 insertions, 4 deletions
diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 528f1602d6..2a0240f847 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -30,8 +30,7 @@ class phpbb_version_helper_test extends phpbb_test_case  			new \phpbb\config\config(array(  				'version'	=> '3.1.0',  			)), -			new \phpbb\file_downloader(), -			new \phpbb\user('\phpbb\datetime') +			new \phpbb\file_downloader()  		);  	} @@ -199,6 +198,11 @@ class phpbb_version_helper_test extends phpbb_test_case  	*/  	public function test_get_suggested_updates($current_version, $versions, $expected)  	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +  		$version_helper = $this  			->getMockBuilder('\phpbb\version_helper')  			->setMethods(array( @@ -210,7 +214,7 @@ class phpbb_version_helper_test extends phpbb_test_case  					'version'	=> $current_version,  				)),  				new \phpbb\file_downloader(), -				new \phpbb\user('\phpbb\datetime'), +				new \phpbb\user($lang, '\phpbb\datetime'),  			))  			->getMock()  		; @@ -310,6 +314,11 @@ class phpbb_version_helper_test extends phpbb_test_case  	*/  	public function test_get_latest_on_current_branch($current_version, $versions, $expected)  	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); +  		$version_helper = $this  			->getMockBuilder('\phpbb\version_helper')  			->setMethods(array( @@ -321,7 +330,7 @@ class phpbb_version_helper_test extends phpbb_test_case  					'version'	=> $current_version,  				)),  				new \phpbb\file_downloader(), -				new \phpbb\user('\phpbb\datetime'), +				new \phpbb\user($lang, '\phpbb\datetime'),  			))  			->getMock()  		; @@ -332,4 +341,506 @@ class phpbb_version_helper_test extends phpbb_test_case  		$this->assertSame($expected, $version_helper->get_latest_on_current_branch());  	} + +	public function get_update_on_branch_data() +	{ +		return array( +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.0.1', +				), +			), +			array( +				'1.0.1', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			array( +				'1.0.1-a1', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1-a2', +					), +					'1.1'	=> array( +						'current'		=> '1.1.0', +					), +				), +				array( +					'current'		=> '1.0.1-a2', +				), +			), +			array( +				'1.1.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'1.1.1', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			array( +				'1.1.0-a1', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.0-a2', +					), +				), +				array( +					'current'		=> '1.1.0-a2', +				), +			), +			array( +				'1.1.0', +				array(), +				array(), +			), +			// Latest safe release is 1.0.1 +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +						'security'		=> '1.0.1', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.0.1', +					'security'		=> '1.0.1', +				), +			), +			// Latest safe release is 1.0.0 +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +						'security'		=> '1.0.0', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.0.1', +					'security'		=> '1.0.0', +				), +			), +			// Latest safe release is 1.1.0 +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +						'security'		=> '1.1.0', +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			// Latest 1.0 release is EOL +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +						'eol'			=> true, +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			// All are EOL -- somewhat undefined behavior +			array( +				'1.0.0', +				array( +					'1.0'	=> array( +						'current'		=> '1.0.1', +						'eol'			=> true, +					), +					'1.1'	=> array( +						'current'		=> '1.1.1', +						'eol'			=> true, +					), +				), +				array(), +			), +		); +	} + +	/** +	 * @dataProvider get_update_on_branch_data +	 */ +	public function test_get_update_on_branch($current_version, $versions, $expected) +	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); + +		$version_helper = $this +			->getMockBuilder('\phpbb\version_helper') +			->setMethods(array( +				'get_versions_matching_stability', +			)) +			->setConstructorArgs(array( +				$this->cache, +				new \phpbb\config\config(array( +					'version'	=> $current_version, +				)), +				new \phpbb\file_downloader(), +				new \phpbb\user($lang, '\phpbb\datetime'), +			)) +			->getMock() +		; + +		$version_helper->expects($this->any()) +			->method('get_versions_matching_stability') +			->will($this->returnValue($versions)); + +		$this->assertSame($expected, $version_helper->get_update_on_branch()); +	} + +	public function get_ext_update_on_branch_data() +	{ +		return array( +			// Single branch, check version for current branch +			array( +				'3.1.0', +				'1.0.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +				), +				array( +					'current'		=> '1.0.1', +				), +			), +			array( +				'3.1.0', +				'1.0.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +				), +				array(), +			), +			array( +				'3.2.0', +				'1.0.0', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.2.0', +				'1.1.1', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			// Single branch, check for newest version when branches don't match up +			array( +				'3.1.0', +				'1.0.0', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.1.0', +				'1.1.1', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			array( +				'3.2.0', +				'1.0.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +				), +				array( +					'current'		=> '1.0.1', +				), +			), +			array( +				'3.2.0', +				'1.0.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +				), +				array(), +			), +			array( +				'3.3.0', +				'1.0.0', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.3.0', +				'1.1.1', +				array( +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			// Multiple branches, check version for current branch +			array( +				'3.1.0', +				'1.0.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.0.1', +				), +			), +			array( +				'3.1.0', +				'1.0.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			array( +				'3.1.0', +				'1.1.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			array( +				'3.2.0', +				'1.0.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.2.0', +				'1.0.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.2.0', +				'1.1.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +			// Multiple branches, check for newest version when branches don't match up +			array( +				'3.3.0', +				'1.0.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.3.0', +				'1.0.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.3.0', +				'1.1.0', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array( +					'current'		=> '1.1.1', +				), +			), +			array( +				'3.3.0', +				'1.1.1', +				array( +					'3.1'	=> array( +						'current'		=> '1.0.1', +					), +					'3.2'	=> array( +						'current'		=> '1.1.1', +					), +				), +				array(), +			), +		); +	} + +	/** +	 * @dataProvider get_ext_update_on_branch_data +	 */ +	public function test_get_ext_update_on_branch($phpbb_version, $ext_version, $versions, $expected) +	{ +		global $phpbb_root_path, $phpEx; + +		$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); +		$lang = new \phpbb\language\language($lang_loader); + +		$version_helper = $this +			->getMockBuilder('\phpbb\version_helper') +			->setMethods(array( +				'get_versions_matching_stability', +			)) +			->setConstructorArgs(array( +				$this->cache, +				new \phpbb\config\config(array( +					'version'	=> $phpbb_version, +				)), +				new \phpbb\file_downloader(), +				new \phpbb\user($lang, '\phpbb\datetime'), +			)) +			->getMock() +		; + +		$version_helper->expects($this->any()) +			->method('get_versions_matching_stability') +			->will($this->returnValue($versions)); + +		$version_helper->set_current_version($ext_version); + +		$this->assertSame($expected, $version_helper->get_ext_update_on_branch()); +	}  }  | 
