From 74054317d2caa08aef05997ad27a52d5ba20f369 Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Fri, 24 Mar 2017 11:45:50 -0700 Subject: [PATCH] [ticket/15142] Add ext branch update tests PHPBB3-15142 --- tests/version/version_test.php | 292 +++++++++++++++++++++++++++++++++ 1 file changed, 292 insertions(+) diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 54237f2059..0ed0fcb589 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -532,4 +532,296 @@ class phpbb_version_helper_test extends phpbb_test_case $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) + { + $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('\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()); + } }