1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-01 14:30:32 +02:00

[ticket/9871] Update version check file to use json format

PHPBB3-9871
This commit is contained in:
Nathan Guse
2014-02-19 16:11:40 -06:00
parent bd8951cfbe
commit 6c8589775b
13 changed files with 742 additions and 324 deletions

View File

@@ -1,75 +0,0 @@
<?php
/**
*
* @package testing
* @copyright (c) 2013 phpBB Group
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
*
*/
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';
/**
* @group slow
*/
class phpbb_functions_get_remote_file extends phpbb_test_case
{
public function test_version_phpbb_com()
{
$hostname = 'version.phpbb.com';
if (!phpbb_checkdnsrr($hostname, 'A'))
{
$this->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);
}
}

View File

@@ -0,0 +1,333 @@
<?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();
$this->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);
}
}