From 6c8589775b8df2b6fbeffbe594d9279ae90e85ba Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 19 Feb 2014 16:11:40 -0600 Subject: [ticket/9871] Update version check file to use json format PHPBB3-9871 --- tests/functions/get_remote_file_test.php | 75 ------- tests/version/version_test.php | 333 +++++++++++++++++++++++++++++++ 2 files changed, 333 insertions(+), 75 deletions(-) delete mode 100644 tests/functions/get_remote_file_test.php create mode 100644 tests/version/version_test.php (limited to 'tests') diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php deleted file mode 100644 index 4032ca5b58..0000000000 --- a/tests/functions/get_remote_file_test.php +++ /dev/null @@ -1,75 +0,0 @@ -markTestSkipped(sprintf( - 'Could not find a DNS record for hostname %s. ' . - 'Assuming network is down.', - $hostname - )); - } - - $errstr = $errno = null; - $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); - - $this->assertNotEquals( - 0, - strlen($file), - 'Failed asserting that the response is not empty.' - ); - - $this->assertSame( - '', - $errstr, - 'Failed asserting that the error string is empty.' - ); - - $this->assertSame( - 0, - $errno, - 'Failed asserting that the error number is 0 (i.e. no error occurred).' - ); - - $lines = explode("\n", $file); - - $this->assertGreaterThanOrEqual( - 2, - sizeof($lines), - 'Failed asserting that the version file has at least two lines.' - ); - - $this->assertStringStartsWith( - '3.', - $lines[0], - "Failed asserting that the first line of the version file starts with '3.'" - ); - - $this->assertNotSame( - false, - filter_var($lines[1], FILTER_VALIDATE_URL), - 'Failed asserting that the second line of the version file is a valid URL.' - ); - - $this->assertContains('http', $lines[1]); - $this->assertContains('phpbb.com', $lines[1], '', true); - } -} diff --git a/tests/version/version_test.php b/tests/version/version_test.php new file mode 100644 index 0000000000..e7df30634c --- /dev/null +++ b/tests/version/version_test.php @@ -0,0 +1,333 @@ +version_helper = new \phpbb\version_helper( + new phpbb_mock_null_cache(), + new \phpbb\config\config(array( + 'version' => '3.1.0', + )), + new \phpbb\user() + ); + } + + public function is_stable_data() + { + return array( + array( + '3.0.0-a1', + false, + ), + array( + '3.0.0-b1', + false, + ), + array( + '3.0.0-rc1', + false, + ), + array( + '3.0.0-RC1', + false, + ), + array( + '3.0.0', + true, + ), + array( + '3.0.0-pl1', + true, + ), + array( + '3.0.0.1-pl1', + true, + ), + array( + '3.1-dev', + false, + ), + array( + 'foobar', + false, + ), + ); + } + + /** + * @dataProvider is_stable_data + */ + public function test_is_stable($version, $expected) + { + $this->assertSame($expected, $this->version_helper->is_stable($version)); + } + + public function get_suggested_updates_data() + { + return array( + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + ), + array( + '1.0.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '1.1' => array( + 'current' => '1.1.1', + ), + ), + ), + array( + '1.0.1-a1', + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + ), + array( + '1.1.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + array( + '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( + '1.1' => array( + 'current' => '1.1.0-a2', + ), + ), + ), + ); + } + + /** + * @dataProvider get_suggested_updates_data + */ + public function test_get_suggested_updates($current_version, $versions, $expected) + { + $version_helper = $this + ->getMockBuilder('\phpbb\version_helper') + ->setMethods(array( + 'get_versions_matching_stability', + )) + ->setConstructorArgs(array( + new phpbb_mock_null_cache(), + new \phpbb\config\config(array( + 'version' => $current_version, + )), + new \phpbb\user(), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $this->assertSame($expected, $version_helper->get_suggested_updates()); + } + + public function get_latest_on_current_branch_data() + { + return array( + array( + '1.0.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.0.1', + ), + array( + '1.0.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.0.1', + ), + array( + '1.0.1-a1', + array( + '1.0' => array( + 'current' => '1.0.1-a2', + ), + '1.1' => array( + 'current' => '1.1.0', + ), + ), + '1.0.1-a2', + ), + array( + '1.1.0', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.1.1', + ), + array( + '1.1.1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.1', + ), + ), + '1.1.1', + ), + array( + '1.1.0-a1', + array( + '1.0' => array( + 'current' => '1.0.1', + ), + '1.1' => array( + 'current' => '1.1.0-a2', + ), + ), + '1.1.0-a2', + ), + ); + } + + /** + * @dataProvider get_latest_on_current_branch_data + */ + public function test_get_latest_on_current_branch($current_version, $versions, $expected) + { + $version_helper = $this + ->getMockBuilder('\phpbb\version_helper') + ->setMethods(array( + 'get_versions_matching_stability', + )) + ->setConstructorArgs(array( + new phpbb_mock_null_cache(), + new \phpbb\config\config(array( + 'version' => $current_version, + )), + new \phpbb\user(), + )) + ->getMock() + ; + + $version_helper->expects($this->any()) + ->method('get_versions_matching_stability') + ->will($this->returnValue($versions)); + + $this->assertSame($expected, $version_helper->get_latest_on_current_branch()); + } + + public function test_version_phpbb_com() + { + global $phpbb_root_path, $phpEx; + include_once($phpbb_root_path . 'includes/functions.' . $phpEx); + + if (!phpbb_checkdnsrr('version.phpbb.com', 'A')) + { + $this->markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + 'version.phpbb.com' + )); + } + + $this->version_helper->get_versions(); + + // get_versions checks to make sure we got a valid versions file or + // throws an exception if we did not. We don't need to test anything + // here, but adding an assertion so we do not get a warning about no + // assertions in this test + $this->assertSame(true, true); + } +} -- cgit v1.2.1 From dc5a34eb880974c47c2b3bcc8468c57cd6169612 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 5 Mar 2014 19:18:23 -0600 Subject: [ticket/9871] Mark test as slow PHPBB3-9871 --- tests/version/version_test.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/version/version_test.php b/tests/version/version_test.php index e7df30634c..3ac2b46b0d 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -7,6 +7,9 @@ * */ +/* +* @group slow +*/ class phpbb_version_helper_test extends phpbb_test_case { public function setUp() -- cgit v1.2.1 From c655757aa635ced42db1f00023aadf423d37bbff Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 8 Mar 2014 17:43:58 -0600 Subject: [ticket/9871] Fix tests PHPBB3-9871 --- tests/version/version_test.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 3ac2b46b0d..87922d50b4 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -16,8 +16,16 @@ class phpbb_version_helper_test extends phpbb_test_case { parent::setUp(); + global $phpbb_root_path, $phpEx; + + include_once($phpbb_root_path . 'includes/functions.' . $phpEx); + + $this->cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + $this->version_helper = new \phpbb\version_helper( - new phpbb_mock_null_cache(), + $this->cache, new \phpbb\config\config(array( 'version' => '3.1.0', )), @@ -190,7 +198,7 @@ class phpbb_version_helper_test extends phpbb_test_case 'get_versions_matching_stability', )) ->setConstructorArgs(array( - new phpbb_mock_null_cache(), + $this->cache, new \phpbb\config\config(array( 'version' => $current_version, )), @@ -295,7 +303,7 @@ class phpbb_version_helper_test extends phpbb_test_case 'get_versions_matching_stability', )) ->setConstructorArgs(array( - new phpbb_mock_null_cache(), + $this->cache, new \phpbb\config\config(array( 'version' => $current_version, )), -- cgit v1.2.1 From 1f7c891da2590cd2d70f4e7278cf4d6119a820a5 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 10 Mar 2014 20:57:20 -0500 Subject: [ticket/9871] Restore get_remote_file_test PHPBB3-9871 --- tests/functions/get_remote_file_test.php | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/functions/get_remote_file_test.php (limited to 'tests') diff --git a/tests/functions/get_remote_file_test.php b/tests/functions/get_remote_file_test.php new file mode 100644 index 0000000000..4032ca5b58 --- /dev/null +++ b/tests/functions/get_remote_file_test.php @@ -0,0 +1,75 @@ +markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + $hostname + )); + } + + $errstr = $errno = null; + $file = get_remote_file($hostname, '/phpbb', '30x.txt', $errstr, $errno); + + $this->assertNotEquals( + 0, + strlen($file), + 'Failed asserting that the response is not empty.' + ); + + $this->assertSame( + '', + $errstr, + 'Failed asserting that the error string is empty.' + ); + + $this->assertSame( + 0, + $errno, + 'Failed asserting that the error number is 0 (i.e. no error occurred).' + ); + + $lines = explode("\n", $file); + + $this->assertGreaterThanOrEqual( + 2, + sizeof($lines), + 'Failed asserting that the version file has at least two lines.' + ); + + $this->assertStringStartsWith( + '3.', + $lines[0], + "Failed asserting that the first line of the version file starts with '3.'" + ); + + $this->assertNotSame( + false, + filter_var($lines[1], FILTER_VALIDATE_URL), + 'Failed asserting that the second line of the version file is a valid URL.' + ); + + $this->assertContains('http', $lines[1]); + $this->assertContains('phpbb.com', $lines[1], '', true); + } +} -- cgit v1.2.1 From fb6b350c21f5f63991099ae2ef9f007c9786cb61 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Mar 2014 19:38:20 -0500 Subject: [ticket/9871] Split fast and slow version tests PHPBB3-9871 --- tests/version/version_fetch_test.php | 58 ++++++++++++++++++++++++++++++++++++ tests/version/version_test.php | 26 ---------------- 2 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 tests/version/version_fetch_test.php (limited to 'tests') diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php new file mode 100644 index 0000000000..b4912861f4 --- /dev/null +++ b/tests/version/version_fetch_test.php @@ -0,0 +1,58 @@ +cache = $this->getMockBuilder('\phpbb\cache\service') + ->disableOriginalConstructor() + ->getMock(); + + $this->version_helper = new \phpbb\version_helper( + $this->cache, + new \phpbb\config\config(array( + 'version' => '3.1.0', + )), + new \phpbb\user() + ); + } + + public function test_version_phpbb_com() + { + global $phpbb_root_path, $phpEx; + include_once($phpbb_root_path . 'includes/functions.' . $phpEx); + + if (!phpbb_checkdnsrr('version.phpbb.com', 'A')) + { + $this->markTestSkipped(sprintf( + 'Could not find a DNS record for hostname %s. ' . + 'Assuming network is down.', + 'version.phpbb.com' + )); + } + + $this->version_helper->get_versions(); + + // get_versions checks to make sure we got a valid versions file or + // throws an exception if we did not. We don't need to test anything + // here, but adding an assertion so we do not get a warning about no + // assertions in this test + $this->assertSame(true, true); + } +} diff --git a/tests/version/version_test.php b/tests/version/version_test.php index 87922d50b4..2e2398bd45 100644 --- a/tests/version/version_test.php +++ b/tests/version/version_test.php @@ -7,9 +7,6 @@ * */ -/* -* @group slow -*/ class phpbb_version_helper_test extends phpbb_test_case { public function setUp() @@ -318,27 +315,4 @@ class phpbb_version_helper_test extends phpbb_test_case $this->assertSame($expected, $version_helper->get_latest_on_current_branch()); } - - public function test_version_phpbb_com() - { - global $phpbb_root_path, $phpEx; - include_once($phpbb_root_path . 'includes/functions.' . $phpEx); - - if (!phpbb_checkdnsrr('version.phpbb.com', 'A')) - { - $this->markTestSkipped(sprintf( - 'Could not find a DNS record for hostname %s. ' . - 'Assuming network is down.', - 'version.phpbb.com' - )); - } - - $this->version_helper->get_versions(); - - // get_versions checks to make sure we got a valid versions file or - // throws an exception if we did not. We don't need to test anything - // here, but adding an assertion so we do not get a warning about no - // assertions in this test - $this->assertSame(true, true); - } } -- cgit v1.2.1 From 23289c89a19ef8c262c46d2761b75a2506354d4e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Fri, 14 Mar 2014 07:02:25 -0500 Subject: [ticket/9871] Fix test name PHPBB3-9871 --- tests/version/version_fetch_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php index b4912861f4..7b3ba5e717 100644 --- a/tests/version/version_fetch_test.php +++ b/tests/version/version_fetch_test.php @@ -10,7 +10,7 @@ /* * @group slow */ -class phpbb_version_helper_test extends phpbb_test_case +class phpbb_version_helper_fetch_test extends phpbb_test_case { public function setUp() { -- cgit v1.2.1