aboutsummaryrefslogtreecommitdiffstats
path: root/tests/console
diff options
context:
space:
mode:
Diffstat (limited to 'tests/console')
-rw-r--r--tests/console/cache/purge_test.php9
-rw-r--r--tests/console/config/config_test.php7
-rw-r--r--tests/console/cron/cron_list_test.php7
-rw-r--r--tests/console/cron/run_test.php14
-rw-r--r--tests/console/fixtures/png.pngbin0 -> 129 bytes
-rw-r--r--tests/console/fixtures/thumbnail.xml40
-rw-r--r--tests/console/fixtures/txt.txt2
-rw-r--r--tests/console/thumbnail_test.php125
8 files changed, 198 insertions, 6 deletions
diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php
index 96988c1028..6c92660580 100644
--- a/tests/console/cache/purge_test.php
+++ b/tests/console/cache/purge_test.php
@@ -32,6 +32,8 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
protected function setUp()
{
+ global $phpbb_root_path, $phpEx;
+
if (file_exists($this->cache_dir))
{
// cache directory possibly left after aborted
@@ -45,7 +47,10 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
$this->db = $this->getMock('\phpbb\db\driver\driver_interface');
$this->config = new \phpbb\config\config(array('assets_version' => 1));
- $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user = $this->getMock('\phpbb\user', array(), array(
+ new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime')
+ );
}
public function test_purge()
@@ -86,7 +91,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case
public function get_command_tester()
{
$application = new Application();
- $application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config));
+ $application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\dummy(), $this->config));
$command = $application->find('cache:purge');
$this->command_name = $command->getName();
diff --git a/tests/console/config/config_test.php b/tests/console/config/config_test.php
index 7c098af004..076316217d 100644
--- a/tests/console/config/config_test.php
+++ b/tests/console/config/config_test.php
@@ -22,9 +22,14 @@ class phpbb_console_command_config_test extends phpbb_test_case
public function setUp()
{
+ global $phpbb_root_path, $phpEx;
+
$this->config = new \phpbb\config\config(array());
- $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user = $this->getMock('\phpbb\user', array(), array(
+ new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime')
+ );
$this->user->method('lang')->will($this->returnArgument(0));
}
diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php
index 22423304be..3bbe2078ba 100644
--- a/tests/console/cron/cron_list_test.php
+++ b/tests/console/cron/cron_list_test.php
@@ -32,7 +32,12 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case
protected function setUp()
{
- $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ global $phpbb_root_path, $phpEx;
+
+ $this->user = $this->getMock('\phpbb\user', array(), array(
+ new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime'
+ ));
$this->user->method('lang')->will($this->returnArgument(0));
}
diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php
index f76e967484..d6c7b21781 100644
--- a/tests/console/cron/run_test.php
+++ b/tests/console/cron/run_test.php
@@ -39,10 +39,12 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
$db = $this->db = $this->new_dbal();
$config = $this->config = new \phpbb\config\config(array('cron_lock' => '0'));
- set_config(null, null, null, $this->config);
$this->lock = new \phpbb\lock\db('cron_lock', $this->config, $this->db);
- $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime'));
+ $this->user = $this->getMock('\phpbb\user', array(), array(
+ new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime'
+ ));
$this->user->method('lang')->will($this->returnArgument(0));
$this->task = new phpbb_cron_task_simple();
@@ -76,6 +78,10 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
$this->assertSame(false, $this->lock->owns_lock());
}
+ /**
+ * @expectedException \phpbb\exception\runtime_exception
+ * @expectedExceptionMessage CRON_LOCK_ERROR
+ */
public function test_error_lock()
{
$this->lock->acquire();
@@ -124,6 +130,10 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case
$this->assertSame(false, $this->lock->owns_lock());
}
+ /**
+ * @expectedException \phpbb\exception\runtime_exception
+ * @expectedExceptionMessage CRON_NO_SUCH_TASK
+ */
public function test_arg_invalid()
{
$command_tester = $this->get_command_tester();
diff --git a/tests/console/fixtures/png.png b/tests/console/fixtures/png.png
new file mode 100644
index 0000000000..c143a26a06
--- /dev/null
+++ b/tests/console/fixtures/png.png
Binary files differ
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.txt b/tests/console/fixtures/txt.txt
new file mode 100644
index 0000000000..a78c858f5c
--- /dev/null
+++ b/tests/console/fixtures/txt.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..45d7adacb9
--- /dev/null
+++ b/tests/console/thumbnail_test.php
@@ -0,0 +1,125 @@
+<?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.
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compatibility.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+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, $phpbb_filesystem;
+
+ if (!@extension_loaded('gd'))
+ {
+ $this->markTestSkipped('Thumbnail tests require gd extension.');
+ }
+
+ 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', array(), array(
+ new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)),
+ '\phpbb\datetime')
+ );
+ $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(self::any())->method('obtain_attach_extensions')->will(self::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->user, $this->db, $this->cache, $this->phpbb_root_path, $this->phpEx));
+ $this->application->add(new delete($this->user, $this->db, $this->phpbb_root_path));
+ $this->application->add(new recreate($this->user));
+
+ $phpbb_filesystem = new \phpbb\filesystem\filesystem();
+
+ copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_1');
+ copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/test_png_2');
+ copy(dirname(__FILE__) . '/fixtures/png.png', $this->phpbb_root_path . 'files/thumb_test_png_2');
+ copy(dirname(__FILE__) . '/fixtures/txt.txt', $this->phpbb_root_path . 'files/test_txt');
+ }
+
+ protected function tearDown()
+ {
+ parent::tearDown();
+
+ 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 test_thumbnails()
+ {
+ $command_tester = $this->get_command_tester('thumbnail:generate');
+ $exit_status = $command_tester->execute(array('command' => 'thumbnail:generate'));
+
+ self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
+ self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
+ self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
+ self::assertSame(0, $exit_status);
+
+ $command_tester = $this->get_command_tester('thumbnail:delete');
+ $exit_status = $command_tester->execute(array('command' => 'thumbnail:delete'));
+
+ self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
+ self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
+ self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
+ self::assertSame(0, $exit_status);
+
+ $command_tester = $this->get_command_tester('thumbnail:recreate');
+ $exit_status = $command_tester->execute(array('command' => 'thumbnail:recreate'));
+
+ self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_1'));
+ self::assertSame(true, file_exists($this->phpbb_root_path . 'files/thumb_test_png_2'));
+ self::assertSame(false, file_exists($this->phpbb_root_path . 'files/thumb_test_txt'));
+ self::assertSame(0, $exit_status);
+ }
+
+ public function get_command_tester($command_name)
+ {
+ $command = $this->application->find($command_name);
+ return new CommandTester($command);
+ }
+}