mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-10 10:44:20 +02:00
Merge pull request #6687 from marc1706/ticket/12479
[ticket/12479] Remove deprecated functions
This commit is contained in:
@@ -33,7 +33,7 @@ class phpbb_auth_provider_apache_test extends phpbb_database_test_case
|
||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||
$lang = new \phpbb\language\language($lang_loader);
|
||||
$this->request = $this->createMock('\phpbb\request\request');
|
||||
$this->user = new \phpbb\user($lang, '\phpbb\datetime');;
|
||||
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
|
||||
$this->provider = new \phpbb\auth\provider\apache($config, $db, $lang, $this->request, $this->user, $phpbb_root_path, $phpEx);
|
||||
}
|
||||
|
@@ -136,7 +136,7 @@ class phpbb_config_db_test extends phpbb_database_test_case
|
||||
public function test_increment_new()
|
||||
{
|
||||
$this->config->increment('foobar', 3);
|
||||
$this->assertEquals(3, $this->config['foobar']);;
|
||||
$this->assertEquals(3, $this->config['foobar']);
|
||||
}
|
||||
|
||||
public function test_delete()
|
||||
|
@@ -111,7 +111,7 @@ abstract class phpbb_controller_common_helper_route extends phpbb_database_test_
|
||||
$this->config = new \phpbb\config\config(array('enable_mod_rewrite' => '0'));
|
||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||
$lang = new \phpbb\language\language($lang_loader);
|
||||
$this->user = new \phpbb\user($lang, '\phpbb\datetime');;
|
||||
$this->user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
|
||||
$container = new phpbb_mock_container_builder();
|
||||
$container->setParameter('core.environment', PHPBB_ENVIRONMENT);
|
||||
|
@@ -1,73 +0,0 @@
|
||||
<?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_build_hidden_fields_for_query_params_test extends phpbb_test_case
|
||||
{
|
||||
public function build_hidden_fields_for_query_params_test_data()
|
||||
{
|
||||
return array(
|
||||
// get
|
||||
// post
|
||||
// exclude
|
||||
// expected
|
||||
array(
|
||||
array('foo' => 'bar'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => 'b'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" /><input type='hidden' name=\"a\" value=\"b\" />",
|
||||
),
|
||||
array(
|
||||
array('a' => 'quote"', 'b' => '<less>'),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"a\" value='quote\"' /><input type='hidden' name=\"b\" value=\"<less>\" />",
|
||||
),
|
||||
array(
|
||||
array('a' => "quotes'\""),
|
||||
array(),
|
||||
array(),
|
||||
"<input type='hidden' name=\"a\" value=\"quotes'"\" />",
|
||||
),
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => 'b'),
|
||||
array('a' => 'c'),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
// strict equality check
|
||||
array(
|
||||
array('foo' => 'bar', 'a' => '0'),
|
||||
array('a' => ''),
|
||||
array(),
|
||||
"<input type='hidden' name=\"foo\" value=\"bar\" />",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider build_hidden_fields_for_query_params_test_data
|
||||
*/
|
||||
public function test_build_hidden_fields_for_query_params($get, $post, $exclude, $expected)
|
||||
{
|
||||
$request = new phpbb_mock_request($get, $post);
|
||||
$result = phpbb_build_hidden_fields_for_query_params($request, $exclude);
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
@@ -1,80 +0,0 @@
|
||||
<?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.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group slow
|
||||
*/
|
||||
class phpbb_functions_get_remote_file extends phpbb_test_case
|
||||
{
|
||||
public function test_version_phpbb_com()
|
||||
{
|
||||
global $phpbb_container;
|
||||
$phpbb_container = new phpbb_mock_container_builder();
|
||||
$phpbb_container->set('file_downloader', new \phpbb\file_downloader());
|
||||
|
||||
$hostname = 'version.phpbb.com';
|
||||
|
||||
if (!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,
|
||||
count($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->assertStringContainsString('http', $lines[1]);
|
||||
$this->assertStringContainsString('phpbb.com', $lines[1], '', true);
|
||||
}
|
||||
}
|
@@ -172,19 +172,63 @@ class phpbb_log_function_add_log_test extends phpbb_database_test_case
|
||||
|
||||
if ($additional3 != null)
|
||||
{
|
||||
add_log($mode, $required1, $additional1, $additional2, $additional3);
|
||||
$additional_data = [
|
||||
'forum_id' => $required1,
|
||||
'topic_id' => $additional1,
|
||||
$additional3,
|
||||
];
|
||||
$phpbb_log->add($mode, $user_id, '', $additional2, false, $additional_data);
|
||||
}
|
||||
else if ($additional2 != null)
|
||||
{
|
||||
add_log($mode, $required1, $additional1, $additional2);
|
||||
if ($mode == 'user')
|
||||
{
|
||||
$additional_data = [
|
||||
'reportee_id' => $required1,
|
||||
$additional2,
|
||||
];
|
||||
$log_operation = $additional1;
|
||||
}
|
||||
else if ($mode == 'mod')
|
||||
{
|
||||
$additional_data = [
|
||||
'forum_id' => $required1,
|
||||
'topic_id' => $additional1,
|
||||
];
|
||||
$log_operation = $additional2;
|
||||
}
|
||||
else
|
||||
{
|
||||
$log_operation = $required1;
|
||||
$additional_data = [
|
||||
$additional1,
|
||||
$additional2,
|
||||
];
|
||||
}
|
||||
$phpbb_log->add($mode, $user_id, '', $log_operation, false, $additional_data);
|
||||
}
|
||||
else if ($additional1 != null)
|
||||
{
|
||||
add_log($mode, $required1, $additional1);
|
||||
if ($mode == 'user')
|
||||
{
|
||||
$additional_data = [
|
||||
'reportee_id' => $required1,
|
||||
];
|
||||
$log_operation = $additional1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$log_operation = $required1;
|
||||
$additional_data = [
|
||||
$additional1,
|
||||
];
|
||||
}
|
||||
|
||||
$phpbb_log->add($mode, $user_id, '', $log_operation, false, $additional_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
add_log($mode, $required1);
|
||||
$phpbb_log->add($mode, $user_id, '', $required1);
|
||||
}
|
||||
|
||||
$result = $db->sql_query('SELECT user_id, log_type, log_operation, log_data, reportee_id, forum_id, topic_id
|
||||
|
@@ -97,7 +97,7 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
|
||||
// Works as a workaround for tests
|
||||
$phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage));
|
||||
|
||||
phpbb_delete_user_pms($delete_user);
|
||||
phpbb_delete_users_pms([$delete_user]);
|
||||
|
||||
$sql = 'SELECT msg_id
|
||||
FROM ' . PRIVMSGS_TABLE;
|
||||
|
@@ -13,15 +13,6 @@
|
||||
|
||||
class phpbb_request_var_test extends phpbb_test_case
|
||||
{
|
||||
/**
|
||||
* Makes sure request_var has its standard behaviour.
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
request_var(false, false, false, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider request_variables
|
||||
*/
|
||||
@@ -33,7 +24,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||
$_POST[$variable_name] = $variable_value;
|
||||
$_REQUEST[$variable_name] = $variable_value;
|
||||
|
||||
$result = request_var($variable_name, $default, $multibyte);
|
||||
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||
$result = $request->variable($variable_name, $default, $multibyte);
|
||||
|
||||
$label = 'Requesting POST variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
@@ -50,7 +42,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||
$_GET[$variable_name] = $variable_value;
|
||||
$_REQUEST[$variable_name] = $variable_value;
|
||||
|
||||
$result = request_var($variable_name, $default, $multibyte);
|
||||
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||
$result = $request->variable($variable_name, $default, $multibyte);
|
||||
|
||||
$label = 'Requesting GET variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
@@ -69,7 +62,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||
$_REQUEST[$variable_name] = false;
|
||||
$_COOKIE[$variable_name] = $variable_value;
|
||||
|
||||
$result = request_var($variable_name, $default, $multibyte, true);
|
||||
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||
$result = $request->variable($variable_name, $default, $multibyte, \phpbb\request\request_interface::COOKIE);
|
||||
|
||||
$label = 'Requesting COOKIE variable, converting from ' . gettype($variable_value) . ' to ' . gettype($default) . (($multibyte) ? ' multibyte' : '');
|
||||
$this->assertEquals($expected, $result, $label);
|
||||
@@ -109,7 +103,8 @@ class phpbb_request_var_test extends phpbb_test_case
|
||||
),
|
||||
);
|
||||
|
||||
$result = request_var($path, $default);
|
||||
$request = new \phpbb\request\request(new \phpbb\request\type_cast_helper(), false);
|
||||
$result = $request->variable($path, $default);
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ class phpbb_search_native_test extends phpbb_search_test_case
|
||||
|
||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||
$lang = new \phpbb\language\language($lang_loader);
|
||||
$user = new \phpbb\user($lang, '\phpbb\datetime');;
|
||||
$user = new \phpbb\user($lang, '\phpbb\datetime');
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$tools_factory = new \phpbb\db\tools\factory();
|
||||
|
@@ -40,16 +40,26 @@ class phpbb_security_hash_test extends phpbb_test_case
|
||||
|
||||
public function test_check_hash_with_phpass()
|
||||
{
|
||||
$this->assertTrue(phpbb_check_hash('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertTrue(phpbb_check_hash('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertFalse(phpbb_check_hash('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
global $phpbb_container;
|
||||
|
||||
/** @var \phpbb\passwords\manager $passwords_manager */
|
||||
$passwords_manager = $phpbb_container->get('passwords.manager');
|
||||
|
||||
$this->assertTrue($passwords_manager->check('test', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertTrue($passwords_manager->check('test', '$P$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertFalse($passwords_manager->check('foo', '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
}
|
||||
|
||||
public function test_check_hash_with_large_input()
|
||||
{
|
||||
global $phpbb_container;
|
||||
|
||||
/** @var \phpbb\passwords\manager $passwords_manager */
|
||||
$passwords_manager = $phpbb_container->get('passwords.manager');
|
||||
|
||||
// 16 MB password, should be rejected quite fast
|
||||
$start_time = time();
|
||||
$this->assertFalse(phpbb_check_hash(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertFalse($passwords_manager->check(str_repeat('a', 1024 * 1024 * 16), '$H$9isfrtKXWqrz8PvztXlL3.daw4U0zI1'));
|
||||
$this->assertLessThanOrEqual(5, time() - $start_time);
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,6 @@ class phpbb_text_processing_generate_text_for_display_test extends phpbb_test_ca
|
||||
|
||||
$phpbb_dispatcher = new phpbb_mock_event_dispatcher;
|
||||
$config = new \phpbb\config\config(array());
|
||||
set_config(null, null, null, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -20,7 +20,6 @@ class phpbb_text_processing_generate_text_for_storage_test extends phpbb_test_ca
|
||||
parent::setUp();
|
||||
|
||||
$config = new \phpbb\config\config(array());
|
||||
set_config(null, null, null, $config);
|
||||
|
||||
$phpbb_container = new phpbb_mock_container_builder;
|
||||
$phpbb_container->set('config', $config);
|
||||
|
4
tests/version/fixture/30x.txt
Normal file
4
tests/version/fixture/30x.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
3.0.14
|
||||
https://www.phpbb.com/community/viewtopic.php?f=14&t=2313941
|
||||
3.3.12
|
||||
https://www.phpbb.com/community/viewtopic.php?t=2653732
|
@@ -1,4 +1,7 @@
|
||||
<?php
|
||||
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
*
|
||||
* This file is part of the phpBB Forum Software package.
|
||||
@@ -18,6 +21,11 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||
protected $version_helper;
|
||||
protected $user;
|
||||
|
||||
// Guzzle mock data
|
||||
protected $guzzle_status = 200; // Default to 200 status
|
||||
protected $guzzle_data;
|
||||
protected $guzzle_mock;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
@@ -41,7 +49,29 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
$this->file_downloader = new phpbb_mock_file_downloader();
|
||||
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->addMethods(['set_data'])
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
$this->guzzle_mock->method('set_data')
|
||||
->will($this->returnCallback(function($data)
|
||||
{
|
||||
$this->guzzle_data = $data;
|
||||
}
|
||||
));
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function()
|
||||
{
|
||||
return new \GuzzleHttp\Psr7\Response($this->guzzle_status, [], $this->guzzle_data);
|
||||
}
|
||||
));
|
||||
|
||||
$this->file_downloader = $this->getMockBuilder('\phpbb\file_downloader')
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
$this->file_downloader->method('create_client')
|
||||
->will($this->returnValue($this->guzzle_mock));
|
||||
|
||||
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
|
||||
|
||||
@@ -203,7 +233,7 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||
*/
|
||||
public function test_get_versions($input, $valid_data, $expected_return = '', $expected_exception = '')
|
||||
{
|
||||
$this->file_downloader->set($input);
|
||||
$this->guzzle_mock->set_data($input);
|
||||
|
||||
// version_helper->get_versions() doesn't return a value on VERSIONCHECK_FAIL but only throws exception
|
||||
// so the $return is undefined. Define it here
|
||||
@@ -214,7 +244,7 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||
try {
|
||||
$return = $this->version_helper->get_versions();
|
||||
} catch (\phpbb\exception\runtime_exception $e) {
|
||||
$this->assertEquals((string)$e->getMessage(), $expected_exception);
|
||||
$this->assertEquals($expected_exception, $e->getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -224,4 +254,206 @@ class version_helper_remote_test extends \phpbb_test_case
|
||||
|
||||
$this->assertEquals($expected_return, $return);
|
||||
}
|
||||
|
||||
public function test_version_phpbb_com()
|
||||
{
|
||||
$guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function()
|
||||
{
|
||||
return new \GuzzleHttp\Psr7\Response(200, [], file_get_contents(__DIR__ . '/fixture/30x.txt'));
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($guzzle_mock);
|
||||
|
||||
$hostname = 'version.phpbb.com';
|
||||
|
||||
$file = $file_downloader->get($hostname, '/phpbb', '30x.txt');
|
||||
$errstr = $file_downloader->get_error_string();
|
||||
$errno = $file_downloader->get_error_number();
|
||||
|
||||
$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,
|
||||
count($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->assertStringContainsString('http', $lines[1]);
|
||||
$this->assertStringContainsString('phpbb.com', $lines[1], '', true);
|
||||
}
|
||||
|
||||
public function test_file_downloader_file_not_found()
|
||||
{
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function()
|
||||
{
|
||||
return new \GuzzleHttp\Psr7\Response(404, [], '');
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($this->guzzle_mock);
|
||||
|
||||
$this->expectException(\phpbb\exception\runtime_exception::class);
|
||||
$this->expectExceptionMessage('FILE_NOT_FOUND');
|
||||
|
||||
$file_downloader->get('foo.com', 'bar', 'foo.txt');
|
||||
}
|
||||
|
||||
public function test_file_downloader_exception_not_found()
|
||||
{
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function($method, $uri)
|
||||
{
|
||||
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
|
||||
$response = new \GuzzleHttp\Psr7\Response(404, [], '');
|
||||
throw new RequestException('FILE_NOT_FOUND', $request, $response);
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($this->guzzle_mock);
|
||||
|
||||
$this->expectException(\phpbb\exception\runtime_exception::class);
|
||||
$this->expectExceptionMessage('FILE_NOT_FOUND');
|
||||
|
||||
$file_downloader->get('foo.com', 'bar', 'foo.txt');
|
||||
}
|
||||
|
||||
public function test_file_downloader_exception_moved()
|
||||
{
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function($method, $uri)
|
||||
{
|
||||
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
|
||||
$response = new \GuzzleHttp\Psr7\Response(302, [], '');
|
||||
throw new RequestException('FILE_MOVED', $request, $response);
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($this->guzzle_mock);
|
||||
|
||||
$this->assertFalse($file_downloader->get('foo.com', 'bar', 'foo.txt'));
|
||||
$this->assertEquals(302, $file_downloader->get_error_number());
|
||||
$this->assertEquals('FILE_MOVED', $file_downloader->get_error_string());
|
||||
}
|
||||
|
||||
public function test_file_downloader_exception_timeout()
|
||||
{
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function($method, $uri)
|
||||
{
|
||||
$request = new \GuzzleHttp\Psr7\Request('GET', $uri);
|
||||
throw new RequestException('FILE_NOT_FOUND', $request);
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($this->guzzle_mock);
|
||||
|
||||
$this->expectException(\phpbb\exception\runtime_exception::class);
|
||||
$this->expectExceptionMessage('FSOCK_TIMEOUT');
|
||||
|
||||
$file_downloader->get('foo.com', 'bar', 'foo.txt');
|
||||
}
|
||||
|
||||
public function test_file_downloader_exception_other()
|
||||
{
|
||||
$this->guzzle_mock = $this->getMockBuilder('\GuzzleHttp\Client')
|
||||
->onlyMethods(['request'])
|
||||
->getMock();
|
||||
|
||||
$this->guzzle_mock->method('request')
|
||||
->will($this->returnCallback(function($method, $uri)
|
||||
{
|
||||
throw new \RuntimeException('FSOCK_NOT_SUPPORTED');
|
||||
}
|
||||
));
|
||||
|
||||
$file_downloader = $this->getMockBuilder(\phpbb\file_downloader::class)
|
||||
->onlyMethods(['create_client'])
|
||||
->getMock();
|
||||
|
||||
$file_downloader->method('create_client')
|
||||
->willReturn($this->guzzle_mock);
|
||||
|
||||
$this->expectException(\phpbb\exception\runtime_exception::class);
|
||||
$this->expectExceptionMessage('FSOCK_DISABLED');
|
||||
|
||||
$file_downloader->get('foo.com', 'bar', 'foo.txt');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user