aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-03-14 14:04:30 +0100
committerJoas Schilling <nickvergessen@gmx.de>2014-03-14 14:04:30 +0100
commit0aa23d203ef8760bd4f536b4eeaa6e9022c68eee (patch)
tree725cca559d663efe32e9864514ff75b787d1cd57 /tests
parentc743e28b94e2764b23c6e7da0e8e8d3452aec71e (diff)
parent60d2c1f4006894f2bb4fa310372734d02565e9ca (diff)
downloadforums-0aa23d203ef8760bd4f536b4eeaa6e9022c68eee.tar
forums-0aa23d203ef8760bd4f536b4eeaa6e9022c68eee.tar.gz
forums-0aa23d203ef8760bd4f536b4eeaa6e9022c68eee.tar.bz2
forums-0aa23d203ef8760bd4f536b4eeaa6e9022c68eee.tar.xz
forums-0aa23d203ef8760bd4f536b4eeaa6e9022c68eee.zip
Merge remote-tracking branch 'EXreaction/ticket/9871-2' into develop
* EXreaction/ticket/9871-2: [ticket/9871] Can set current version to use instead of the phpBB version [ticket/9871] Fix indentation on comment [ticket/9871] Fix test name [ticket/9871] Split fast and slow version tests [ticket/9871] Option to force the stability when checking for updates [ticket/9871] Allow setting the host/file to load for the version class [ticket/9871] Restore get_remote_file_test [ticket/9871] Fix tests [ticket/9871] Typehint and comment on var types [ticket/9871] Mark test as slow [ticket/9871] Restore phpbb_version_compare [ticket/9871] Restore get_remote_file [ticket/9871] Use $request->variable instead of request_var [ticket/9871] Update version check file to use json format
Diffstat (limited to 'tests')
-rw-r--r--tests/version/version_fetch_test.php58
-rw-r--r--tests/version/version_test.php318
2 files changed, 376 insertions, 0 deletions
diff --git a/tests/version/version_fetch_test.php b/tests/version/version_fetch_test.php
new file mode 100644
index 0000000000..7b3ba5e717
--- /dev/null
+++ b/tests/version/version_fetch_test.php
@@ -0,0 +1,58 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/*
+* @group slow
+*/
+class phpbb_version_helper_fetch_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ 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(
+ $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
new file mode 100644
index 0000000000..2e2398bd45
--- /dev/null
+++ b/tests/version/version_test.php
@@ -0,0 +1,318 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2014 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class phpbb_version_helper_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ 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(
+ $this->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(
+ $this->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(
+ $this->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());
+ }
+}