diff options
author | Tristan Darricau <github@nicofuma.fr> | 2014-06-12 23:16:51 +0200 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-07-09 09:21:50 +0200 |
commit | d517ed846be665ec04d9ca000d5f26f8a9571206 (patch) | |
tree | e0975e91e08de3e429b1f83e9bba06dca1777a98 /tests/console | |
parent | 98ab5478e6a74b4325f002c1a5daae9d6dbe80e1 (diff) | |
download | forums-d517ed846be665ec04d9ca000d5f26f8a9571206.tar forums-d517ed846be665ec04d9ca000d5f26f8a9571206.tar.gz forums-d517ed846be665ec04d9ca000d5f26f8a9571206.tar.bz2 forums-d517ed846be665ec04d9ca000d5f26f8a9571206.tar.xz forums-d517ed846be665ec04d9ca000d5f26f8a9571206.zip |
[ticket/12692] Add unit test
PHPBB3-12692
Diffstat (limited to 'tests/console')
-rw-r--r-- | tests/console/fixtures/png | bin | 0 -> 129 bytes | |||
-rw-r--r-- | tests/console/fixtures/thumbnail.xml | 40 | ||||
-rw-r--r-- | tests/console/fixtures/txt | 2 | ||||
-rw-r--r-- | tests/console/thumbnail_test.php | 107 |
4 files changed, 149 insertions, 0 deletions
diff --git a/tests/console/fixtures/png b/tests/console/fixtures/png Binary files differnew file mode 100644 index 0000000000..c143a26a06 --- /dev/null +++ b/tests/console/fixtures/png 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 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<dataset> + <table name="phpbb_attachments"> + <column>attach_id</column> + <column>physical_filename</column> + <column>real_filename</column> + <column>thumbnail</column> + <column>extension</column> + <column>mimetype</column> + <column>attach_comment</column> + + <row> + <value>1</value> + <value>test_png_1</value> + <value>real_test.png</value> + <value>0</value> + <value>png</value> + <value>image/png</value> + <value></value> + </row> + <row> + <value>2</value> + <value>test_png_2</value> + <value>real_test.png</value> + <value>1</value> + <value>png</value> + <value>image/png</value> + <value></value> + </row> + <row> + <value>10</value> + <value>test_txt</value> + <value>real_test.txt</value> + <value>0</value> + <value>txt</value> + <value>text/plain</value> + <value></value> + </row> + </table> +</dataset> 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 @@ +<HTML>mime trigger</HTML> +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 @@ +<?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. +* +*/ + +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); + } +} |