aboutsummaryrefslogtreecommitdiffstats
path: root/tests/console
diff options
context:
space:
mode:
authorLEZY Thomas <thomas.lezy@ensimag.grenoble-inp.fr>2014-06-04 16:24:33 +0200
committerTristan Darricau <github@nicofuma.fr>2014-09-19 11:09:29 +0200
commit4a76763a8a404a04f141825f572ff65620f400c4 (patch)
tree834e5b4bfbc1990860864791f68380855c1a04fc /tests/console
parent98f02ece97cd92de6f71632247a439a1ba25a408 (diff)
downloadforums-4a76763a8a404a04f141825f572ff65620f400c4.tar
forums-4a76763a8a404a04f141825f572ff65620f400c4.tar.gz
forums-4a76763a8a404a04f141825f572ff65620f400c4.tar.bz2
forums-4a76763a8a404a04f141825f572ff65620f400c4.tar.xz
forums-4a76763a8a404a04f141825f572ff65620f400c4.zip
[ticket/12657] Add a test file for base case
PHPBB3-12657
Diffstat (limited to 'tests/console')
-rw-r--r--tests/console/cache/fixtures/config.xml8
-rw-r--r--tests/console/cache/purge_test.php103
2 files changed, 111 insertions, 0 deletions
diff --git a/tests/console/cache/fixtures/config.xml b/tests/console/cache/fixtures/config.xml
new file mode 100644
index 0000000000..2cb683d409
--- /dev/null
+++ b/tests/console/cache/fixtures/config.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_config">
+ <column>config_name</column>
+ <column>config_value</column>
+ <column>is_dynamic</column>
+ </table>
+</dataset>
diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php
new file mode 100644
index 0000000000..7fc9c97ca9
--- /dev/null
+++ b/tests/console/cache/purge_test.php
@@ -0,0 +1,103 @@
+<?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\cache\purge;
+
+require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php';
+
+class phpbb_console_command_cache_purge_test extends phpbb_database_test_case
+{
+ protected $cache_dir;
+ protected $cache;
+ protected $command_name;
+ protected $db;
+ protected $config;
+
+ public function __construct()
+ {
+ $this->cache_dir = dirname(__FILE__) . 'tmp/cache/';
+ }
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ if (file_exists($this->cache_dir))
+ {
+ // cache directory possibly left after aborted
+ // or failed run earlier
+ $this->remove_cache_dir();
+ }
+ $this->create_cache_dir();
+
+ $this->cache = new \phpbb\cache\driver\file($this->cache_dir);
+
+ $this->db = $this->new_dbal();
+
+ $this->config = new \phpbb\config\config(array('assets_version' => 1));
+ }
+
+ public function test_purge()
+ {
+ $this->cache->put('test_key', 'test_value');
+
+ $this->assertEquals(
+ 'test_value',
+ $this->cache->get('test_key'),
+ 'File ACM put and get'
+ );
+
+ $command_tester = $this->get_command_tester();
+ $exit_status = $command_tester->execute(array('command' => $this->command_name));
+
+ $this->assertSame(false, $this->cache->get('test_key'));
+ $this->assertSame(2, $this->config['assets_version']);
+ }
+
+ private function create_cache_dir()
+ {
+ $this->get_test_case_helpers()->makedirs($this->cache_dir);
+ }
+
+ private function remove_cache_dir()
+ {
+ $iterator = new DirectoryIterator($this->cache_dir);
+ foreach ($iterator as $file)
+ {
+ if ($file != '.' && $file != '..')
+ {
+ unlink($this->cache_dir . '/' . $file);
+ }
+ }
+ rmdir($this->cache_dir);
+ }
+
+ public function get_command_tester()
+ {
+ global $phpbb_root_path, $phpEx;
+
+ $application = new Application();
+ $application->add(new purge($this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->getMock('\phpbb\user'), $this->config));
+
+ $command = $application->find('cache:purge');
+ $this->command_name = $command->getName();
+ return new CommandTester($command);
+ }
+}