mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/security-171] Modify tests for new file_downloader class
SECURITY-171
This commit is contained in:
parent
9649d78fa4
commit
f648fe88d5
2 changed files with 31 additions and 12 deletions
27
tests/mock/file_downloader.php
Normal file
27
tests/mock/file_downloader.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* This file is part of the phpBB Forum Software package.
|
||||||
|
*
|
||||||
|
* @copyright (c) phpBB Limited <https://www.phpbb.com>
|
||||||
|
* @license GNU General Public License, version 2 (GPL-2.0)
|
||||||
|
*
|
||||||
|
* For full copyright and license information, please see
|
||||||
|
* the docs/CREDITS.txt file.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class phpbb_mock_file_downloader extends \phpbb\file_downloader
|
||||||
|
{
|
||||||
|
public $data;
|
||||||
|
|
||||||
|
public function set($data)
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get($host, $directory, $filename, $port = 80, $timeout = 6)
|
||||||
|
{
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,11 +11,9 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace phpbb;
|
|
||||||
|
|
||||||
class version_helper_remote_test extends \phpbb_test_case
|
class version_helper_remote_test extends \phpbb_test_case
|
||||||
{
|
{
|
||||||
static $remote_data = '';
|
protected $file_downloader;
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $version_helper;
|
protected $version_helper;
|
||||||
|
|
||||||
|
@ -37,10 +35,12 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||||
->method('get')
|
->method('get')
|
||||||
->with($this->anything())
|
->with($this->anything())
|
||||||
->will($this->returnValue(false));
|
->will($this->returnValue(false));
|
||||||
|
$this->file_downloader = new phpbb_mock_file_downloader();
|
||||||
|
|
||||||
$this->version_helper = new \phpbb\version_helper(
|
$this->version_helper = new \phpbb\version_helper(
|
||||||
$this->cache,
|
$this->cache,
|
||||||
$config,
|
$config,
|
||||||
|
$this->file_downloader,
|
||||||
new \phpbb\user('\phpbb\datetime')
|
new \phpbb\user('\phpbb\datetime')
|
||||||
);
|
);
|
||||||
$this->user = new \phpbb\user('\phpbb\datetime');
|
$this->user = new \phpbb\user('\phpbb\datetime');
|
||||||
|
@ -153,7 +153,7 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||||
*/
|
*/
|
||||||
public function test_get_versions($input, $valid_data, $expected_return = '')
|
public function test_get_versions($input, $valid_data, $expected_return = '')
|
||||||
{
|
{
|
||||||
self::$remote_data = $input;
|
$this->file_downloader->set($input);;
|
||||||
|
|
||||||
if (!$valid_data)
|
if (!$valid_data)
|
||||||
{
|
{
|
||||||
|
@ -171,11 +171,3 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||||
$this->assertEquals($expected_return, $return);
|
$this->assertEquals($expected_return, $return);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Mock function for get_remote_file()
|
|
||||||
*/
|
|
||||||
function get_remote_file($host, $path, $file, $errstr, $errno)
|
|
||||||
{
|
|
||||||
return \phpbb\version_helper_remote_test::$remote_data;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue