1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-10-12 07:24:31 +02:00

[ticket/17555] Reduce callbacks to external URLs in unit tests

PHPBB-17555
This commit is contained in:
Marc Alexander
2025-10-05 20:53:21 +02:00
parent b104af78c3
commit 7e22d7ad24
2 changed files with 33 additions and 4 deletions

View File

@@ -57,7 +57,11 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
new \phpbb\mimetype\content_guesser, new \phpbb\mimetype\content_guesser,
); );
$guesser = new \phpbb\mimetype\guesser($guessers); $guesser = new \phpbb\mimetype\guesser($guessers);
$imagesize = new \FastImageSize\FastImageSize(); $imagesize = $this->getMockBuilder('\FastImageSize\FastImageSize')
->setMethods(['getImageSize'])
->getMock();
$imagesize->method('getImageSize')
->willReturn(['width' => 80, 'height' => 80, 'mime' => 'image/jpeg']);
$dispatcher = new phpbb_mock_event_dispatcher(); $dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_dispatcher = $dispatcher; $phpbb_dispatcher = $dispatcher;
@@ -405,9 +409,9 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
{ {
return array( return array(
array('127.0.0.1:91?foo.jpg', 80, 80, array('AVATAR_URL_INVALID')), array('127.0.0.1:91?foo.jpg', 80, 80, array('AVATAR_URL_INVALID')),
array(gethostbyname('secure.gravatar.com') . '/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), array('127.0.0.1/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
array('secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80), array('secure.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80),
array(gethostbyname('secure.gravatar.com') . ':120/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), array('127.0.0.1:120/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
array('secure.gravatar.com:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), array('secure.gravatar.com:80/avatar/55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
array('secure.gravatar.com:80?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), array('secure.gravatar.com:80?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')),
array('secure.gravatar.com?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), // should be a 404 array('secure.gravatar.com?55502f40dc8b7c769880b10874abc9d0.jpg', 80, 80, array('AVATAR_URL_INVALID')), // should be a 404

View File

@@ -94,7 +94,32 @@ class phpbb_console_command_check_test extends phpbb_test_case
->getMock(); ->getMock();
$config = new \phpbb\config\config(array('version' => $current_version)); $config = new \phpbb\config\config(array('version' => $current_version));
$this->version_helper = new \phpbb\version_helper($cache, $config, new \phpbb\file_downloader()); $this->version_helper = $this->getMockBuilder('\phpbb\version_helper')
->setConstructorArgs([$cache, $config, new \phpbb\file_downloader()])
->setMethods(['get_latest_version', 'get_suggested_updates'])
->getMock();
$this->version_helper->method('get_suggested_updates')
->willReturnCallback(function($force_update = false, $force_cache = false) use ($config)
{
if ($config['version'] === '100000')
{
return [];
}
else if ($config['version'] === '0')
{
return [
[
'version' => '100000',
'stability' => 'stable',
'download_url' => 'https://www.phpbb.com/downloads/',
],
];
}
else
{
throw new \phpbb\exception\runtime_exception('VERSIONCHECK_FAIL');
}
});
$container = new phpbb_mock_container_builder; $container = new phpbb_mock_container_builder;
$container->set('version_helper', $this->version_helper); $container->set('version_helper', $this->version_helper);