From d517ed846be665ec04d9ca000d5f26f8a9571206 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 12 Jun 2014 23:16:51 +0200 Subject: [PATCH] [ticket/12692] Add unit test PHPBB3-12692 --- tests/console/fixtures/png | Bin 0 -> 129 bytes tests/console/fixtures/thumbnail.xml | 40 ++++++++++ tests/console/fixtures/txt | 2 + tests/console/thumbnail_test.php | 107 +++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 tests/console/fixtures/png create mode 100644 tests/console/fixtures/thumbnail.xml create mode 100644 tests/console/fixtures/txt create mode 100644 tests/console/thumbnail_test.php diff --git a/tests/console/fixtures/png b/tests/console/fixtures/png new file mode 100644 index 0000000000000000000000000000000000000000..c143a26a06cad7fc560ea51b8d716883c664a64a GIT binary patch literal 129 zcmeAS@N?(olHy`uVBq!ia0vp^EFjFm1|(O0oL2{=7>k44ofy`glX(e}Nq6*hWMJ6X z&;2Kn70Bl-@Q5sCVBk9f!i-b3`J{n@VxBIJArj%qfB0E=JQ_H?4l^n;vavC+#j>!> TyE$hqPz8ghtDnm{r-UW|uGbvP literal 0 HcmV?d00001 diff --git a/tests/console/fixtures/thumbnail.xml b/tests/console/fixtures/thumbnail.xml new file mode 100644 index 0000000000..8037523633 --- /dev/null +++ b/tests/console/fixtures/thumbnail.xml @@ -0,0 +1,40 @@ + + + + attach_id + physical_filename + real_filename + thumbnail + extension + mimetype + attach_comment + + + 1 + test_png_1 + real_test.png + 0 + png + image/png + + + + 2 + test_png_2 + real_test.png + 1 + png + image/png + + + + 10 + test_txt + real_test.txt + 0 + txt + text/plain + + +
+
diff --git a/tests/console/fixtures/txt b/tests/console/fixtures/txt new file mode 100644 index 0000000000..a78c858f5c --- /dev/null +++ b/tests/console/fixtures/txt @@ -0,0 +1,2 @@ +mime trigger +The HTML tags should remain uppercase so that case-insensitivity can be checked. diff --git a/tests/console/thumbnail_test.php b/tests/console/thumbnail_test.php new file mode 100644 index 0000000000..7ac18d931a --- /dev/null +++ b/tests/console/thumbnail_test.php @@ -0,0 +1,107 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\thumbnail\generate; +use phpbb\console\command\thumbnail\delete; +use phpbb\console\command\thumbnail\recreate; + +class phpbb_console_command_thumbnail_test extends phpbb_database_test_case +{ + protected $db; + protected $config; + protected $cache; + protected $user; + protected $phpEx; + protected $phpbb_root_path; + protected $application; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/thumbnail.xml'); + } + + public function setUp() + { + global $config, $phpbb_root_path, $phpEx; + + parent::setUp(); + + $config = $this->config = new \phpbb\config\config(array( + 'img_min_thumb_filesize' => 2, + 'img_max_thumb_width' => 2, + 'img_imagick' => '', + )); + + $this->db = $this->db = $this->new_dbal(); + $this->user = $this->getMock('\phpbb\user'); + $this->phpbb_root_path = $phpbb_root_path; + $this->phpEx = $phpEx; + + $this->cache = $this->getMock('\phpbb\cache\service', array(), array(new phpbb_mock_cache(), $this->config, $this->db, $this->phpbb_root_path, $this->phpEx)); + $this->cache->expects($this->any())->method('obtain_attach_extensions')->will($this->returnValue(array( + 'png' => array('display_cat' => ATTACHMENT_CATEGORY_IMAGE), + 'txt' => array('display_cat' => ATTACHMENT_CATEGORY_NONE), + ))); + + $this->application = new Application(); + $this->application->add(new generate($this->db, $this->user, $this->cache, $this->phpbb_root_path, $this->phpEx)); + $this->application->add(new delete($this->db, $this->user, $this->phpbb_root_path)); + $this->application->add(new recreate($this->user)); + } + + public function test_thumbnails() + { + copy(dirname(__FILE__) . '/fixtures/png', $this->phpbb_root_path . 'files/test_png_1'); + copy(dirname(__FILE__) . '/fixtures/png', $this->phpbb_root_path . 'files/test_png_2'); + copy(dirname(__FILE__) . '/fixtures/png', $this->phpbb_root_path . 'files/thumb_test_png_2'); + copy(dirname(__FILE__) . '/fixtures/txt', $this->phpbb_root_path . 'files/test_txt'); + + $command_tester = $this->get_command_tester('thumbnail:generate'); + $exit_status = $command_tester->execute(array('command' => 'thumbnail:generate')); + + $this->assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); + $this->assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); + $this->assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); + $this->assertSame(0, $exit_status); + + $command_tester = $this->get_command_tester('thumbnail:delete'); + $exit_status = $command_tester->execute(array('command' => 'thumbnail:delete')); + + $this->assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); + $this->assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); + $this->assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); + $this->assertSame(0, $exit_status); + + $command_tester = $this->get_command_tester('thumbnail:recreate'); + $exit_status = $command_tester->execute(array('command' => 'thumbnail:recreate')); + + $this->assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1')); + $this->assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2')); + $this->assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt')); + $this->assertSame(0, $exit_status); + + unlink($this->phpbb_root_path . 'files/test_png_1'); + unlink($this->phpbb_root_path . 'files/test_png_2'); + unlink($this->phpbb_root_path . 'files/test_txt'); + unlink($this->phpbb_root_path . 'files/thumb_test_png_1'); + unlink($this->phpbb_root_path . 'files/thumb_test_png_2'); + } + + public function get_command_tester($command_name) + { + $command = $this->application->find($command_name); + return new CommandTester($command); + } +}