From 9bf9538dc642aeb2ae076bdbe8aad125bc566458 Mon Sep 17 00:00:00 2001 From: Ruben Calvo Date: Thu, 28 Nov 2024 22:30:37 +0100 Subject: [PATCH] [ticket/17361] Update thumbnail_test test PHPBB-17361 --- .../console/command/thumbnail/generate.php | 3 ++- tests/console/thumbnail_test.php | 27 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/phpBB/phpbb/console/command/thumbnail/generate.php b/phpBB/phpbb/console/command/thumbnail/generate.php index dfc6480510..52ae19a9de 100644 --- a/phpBB/phpbb/console/command/thumbnail/generate.php +++ b/phpBB/phpbb/console/command/thumbnail/generate.php @@ -151,11 +151,12 @@ class generate extends \phpbb\console\command\command $destination = tempnam(sys_get_temp_dir(), 'thumbnail_destination'); file_put_contents($source, $this->storage->read($row['physical_filename'])); - @unlink($source); if (create_thumbnail($source, $destination, $row['mimetype'])) { $this->storage->write('thumb_' . $row['physical_filename'], fopen($destination, 'rb')); + + @unlink($source); @unlink($destination); $thumbnail_created[] = (int) $row['attach_id']; diff --git a/tests/console/thumbnail_test.php b/tests/console/thumbnail_test.php index 3a08e4b1ac..ebe0dff62e 100644 --- a/tests/console/thumbnail_test.php +++ b/tests/console/thumbnail_test.php @@ -24,6 +24,7 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case protected $config; protected $cache; protected $user; + protected $storage; protected $phpEx; protected $phpbb_root_path; protected $application; @@ -46,11 +47,10 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case $config = $this->config = new \phpbb\config\config(array( 'img_min_thumb_filesize' => 2, - 'img_max_thumb_width' => 2, - 'upload_path' => 'files', + 'img_max_thumb_width' => 2 )); - $this->db = $this->db = $this->new_dbal(); + $this->db = $this->new_dbal(); $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); $this->phpbb_root_path = $phpbb_root_path; @@ -62,13 +62,24 @@ class phpbb_console_command_thumbnail_test extends phpbb_database_test_case 'txt' => array('display_cat' => attachment_category::NONE), ))); - $this->application = new Application(); - $this->application->add(new generate($config, $this->user, $this->db, $this->cache, $this->phpbb_root_path, $this->phpEx)); - $this->application->add(new delete($config, $this->user, $this->db, $this->phpbb_root_path)); - $this->application->add(new recreate($this->user)); - $phpbb_filesystem = new \phpbb\filesystem\filesystem(); + $this->storage = $this->createMock('\phpbb\storage\storage'); + $this->storage->method('write')->willReturnCallback(function ($path, $data) use ($phpbb_root_path) { + file_put_contents($phpbb_root_path . 'files/' . $path, $data); + }); + $this->storage->method('read')->willReturnCallback(function ($path) use ($phpbb_root_path) { + return fopen($phpbb_root_path . 'files/' . $path, 'rb'); + }); + $this->storage->method('delete')->willReturnCallback(function ($path) use ($phpbb_root_path) { + unlink($phpbb_root_path . 'files/' . $path); + }); + + $this->application = new Application(); + $this->application->add(new generate($this->user, $this->db, $this->cache, $this->language, $this->storage, $this->phpbb_root_path, $this->phpEx)); + $this->application->add(new delete($this->user, $this->db, $this->language, $this->storage)); + $this->application->add(new recreate($this->user, $this->language)); + copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1'); copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2'); copy(__DIR__ . '/fixtures/png.png', $this->phpbb_root_path . 'files/thumb_test_png_2');