aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/compress/archive/.gitkeep0
-rw-r--r--tests/compress/compress_test.php173
-rw-r--r--tests/compress/extract/.gitkeep0
-rw-r--r--tests/compress/fixtures/1.txt1
-rw-r--r--tests/compress/fixtures/archive.tarbin0 -> 10240 bytes
-rw-r--r--tests/compress/fixtures/archive.tar.bz2bin0 -> 224 bytes
-rw-r--r--tests/compress/fixtures/archive.tar.gzbin0 -> 239 bytes
-rw-r--r--tests/compress/fixtures/archive.zipbin0 -> 412 bytes
-rw-r--r--tests/compress/fixtures/dir/2.txt1
-rw-r--r--tests/compress/fixtures/dir/3.txt1
-rw-r--r--tests/compress/fixtures/dir/subdir/4.txt1
-rw-r--r--tests/cron/ext/testext/cron/dummy_task.php7
-rw-r--r--tests/cron/includes/cron/task/core/dummy_task.php7
-rw-r--r--tests/cron/includes/cron/task/core/second_dummy_task.php7
-rw-r--r--tests/cron/manager_test.php32
-rw-r--r--tests/cron/task_provider_test.php37
-rw-r--r--tests/cron/tasks/simple_not_runnable.php5
-rw-r--r--tests/cron/tasks/simple_ready.php5
-rw-r--r--tests/cron/tasks/simple_should_not_run.php5
-rw-r--r--tests/dbal/select_test.php4
-rw-r--r--tests/extension/acp.php205
-rw-r--r--tests/extension/ext/foo/composer.json22
-rw-r--r--tests/extension/ext/vendor/moo/composer.json22
-rw-r--r--tests/extension/manager_test.php2
-rw-r--r--tests/extension/metadata_manager_test.php431
-rw-r--r--tests/functional/posting_test.php102
-rw-r--r--tests/functions/clean_path_test.php44
-rw-r--r--tests/privmsgs/delete_user_pms_test.php2
-rw-r--r--tests/request/type_cast_helper_test.php20
-rw-r--r--tests/search/fixtures/posts.xml43
-rw-r--r--tests/search/native_test.php186
-rw-r--r--tests/session/append_sid_test.php3
-rw-r--r--tests/template/includephp_test.php2
-rw-r--r--tests/template/template_test_case.php2
-rw-r--r--tests/template/template_test_case_with_tree.php2
-rw-r--r--tests/test_framework/phpbb_database_test_case.php2
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php57
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php108
38 files changed, 1500 insertions, 41 deletions
diff --git a/tests/compress/archive/.gitkeep b/tests/compress/archive/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/compress/archive/.gitkeep
diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php
new file mode 100644
index 0000000000..ac8dd358d3
--- /dev/null
+++ b/tests/compress/compress_test.php
@@ -0,0 +1,173 @@
+<?php
+/**
+ *
+ * @package testing
+ * @copyright (c) 2012 phpBB Group
+ * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+ *
+ */
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_admin.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions_compress.php';
+
+class phpbb_compress_test extends phpbb_test_case
+{
+ const EXTRACT_DIR = '/extract/';
+ const ARCHIVE_DIR = '/archive/';
+
+ private $path;
+
+ protected $filelist = array(
+ '1.txt',
+ 'dir/2.txt',
+ 'dir/3.txt',
+ 'dir/subdir/4.txt',
+ );
+
+ protected $conflicts = array(
+ '1_1.txt',
+ '1_2.txt',
+ 'dir/2_1.txt',
+ );
+
+ protected function setUp()
+ {
+ // Required for compress::add_file
+ global $phpbb_root_path;
+ $phpbb_root_path = '';
+
+ $this->path = dirname(__FILE__) . '/fixtures/';
+
+ if (!@extension_loaded('zlib') || !@extension_loaded('bz2'))
+ {
+ $this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests');
+ }
+ }
+
+ protected function tearDown()
+ {
+ foreach (array(dirname(__FILE__) . self::EXTRACT_DIR, dirname(__FILE__) . self::ARCHIVE_DIR) as $dir)
+ {
+ $this->clear_dir($dir);
+ }
+ }
+
+ protected function clear_dir($dir)
+ {
+ $iterator = new DirectoryIterator($dir);
+ foreach ($iterator as $fileinfo)
+ {
+ $name = $fileinfo->getFilename();
+ $path = $fileinfo->getPathname();
+
+ if ($name[0] !== '.')
+ {
+ if ($fileinfo->isDir())
+ {
+ $this->clear_dir($path);
+ rmdir($path);
+ }
+ else
+ {
+ unlink($path);
+ }
+ }
+ }
+ }
+
+ protected function archive_files($compress)
+ {
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file(
+ 'tests/compress/fixtures/dir/',
+ 'tests/compress/fixtures/',
+ '',
+ // The comma here is not an error, this is a comma-separated list
+ 'subdir/4.txt,3.txt'
+ );
+ $compress->add_custom_file($this->path . 'dir/3.txt', 'dir/3.txt');
+ $compress->add_data(file_get_contents($this->path . 'dir/subdir/4.txt'), 'dir/subdir/4.txt');
+
+ // Add multiples of the same file to check conflicts are handled
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file($this->path . '1.txt', $this->path);
+ $compress->add_file($this->path . 'dir/2.txt', $this->path);
+ }
+
+ protected function valid_extraction($extra = array())
+ {
+ $filelist = array_merge($this->filelist, $extra);
+
+ foreach ($filelist as $filename)
+ {
+ $path = dirname(__FILE__) . self::EXTRACT_DIR . $filename;
+ $this->assertTrue(file_exists($path));
+
+ // Check the file's contents is correct
+ $contents = explode('_', basename($filename, '.txt'));
+ $contents = $contents[0];
+ $this->assertEquals($contents . "\n", file_get_contents($path));
+ }
+ }
+
+ public function tar_archive_list()
+ {
+ return array(
+ array('archive.tar', '.tar'),
+ array('archive.tar.gz', '.tar.gz'),
+ array('archive.tar.bz2', '.tar.bz2'),
+ );
+ }
+
+ /**
+ * @dataProvider tar_archive_list
+ */
+ public function test_extract_tar($filename, $type)
+ {
+ $compress = new compress_tar('r', $this->path . $filename);
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+
+ public function test_extract_zip()
+ {
+ $compress = new compress_zip('r', $this->path . 'archive.zip');
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction();
+ }
+
+ /**
+ * @depends test_extract_tar
+ * @dataProvider tar_archive_list
+ */
+ public function test_compress_tar($filename, $type)
+ {
+ $tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename;
+ $compress = new compress_tar('w', $tar);
+ $this->archive_files($compress);
+ $compress->close();
+ $this->assertTrue(file_exists($tar));
+
+ $compress->mode = 'r';
+ $compress->open();
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction($this->conflicts);
+ }
+
+ /**
+ * @depends test_extract_zip
+ */
+ public function test_compress_zip()
+ {
+ $zip = dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip';
+ $compress = new compress_zip('w', $zip);
+ $this->archive_files($compress);
+ $compress->close();
+ $this->assertTrue(file_exists($zip));
+
+ $compress = new compress_zip('r', $zip);
+ $compress->extract('tests/compress/' . self::EXTRACT_DIR);
+ $this->valid_extraction($this->conflicts);
+ }
+}
diff --git a/tests/compress/extract/.gitkeep b/tests/compress/extract/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/compress/extract/.gitkeep
diff --git a/tests/compress/fixtures/1.txt b/tests/compress/fixtures/1.txt
new file mode 100644
index 0000000000..d00491fd7e
--- /dev/null
+++ b/tests/compress/fixtures/1.txt
@@ -0,0 +1 @@
+1
diff --git a/tests/compress/fixtures/archive.tar b/tests/compress/fixtures/archive.tar
new file mode 100644
index 0000000000..54ed56084e
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar
Binary files differ
diff --git a/tests/compress/fixtures/archive.tar.bz2 b/tests/compress/fixtures/archive.tar.bz2
new file mode 100644
index 0000000000..04c0eccd74
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar.bz2
Binary files differ
diff --git a/tests/compress/fixtures/archive.tar.gz b/tests/compress/fixtures/archive.tar.gz
new file mode 100644
index 0000000000..195e7a060a
--- /dev/null
+++ b/tests/compress/fixtures/archive.tar.gz
Binary files differ
diff --git a/tests/compress/fixtures/archive.zip b/tests/compress/fixtures/archive.zip
new file mode 100644
index 0000000000..bdb618fc26
--- /dev/null
+++ b/tests/compress/fixtures/archive.zip
Binary files differ
diff --git a/tests/compress/fixtures/dir/2.txt b/tests/compress/fixtures/dir/2.txt
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/tests/compress/fixtures/dir/2.txt
@@ -0,0 +1 @@
+2
diff --git a/tests/compress/fixtures/dir/3.txt b/tests/compress/fixtures/dir/3.txt
new file mode 100644
index 0000000000..00750edc07
--- /dev/null
+++ b/tests/compress/fixtures/dir/3.txt
@@ -0,0 +1 @@
+3
diff --git a/tests/compress/fixtures/dir/subdir/4.txt b/tests/compress/fixtures/dir/subdir/4.txt
new file mode 100644
index 0000000000..b8626c4cff
--- /dev/null
+++ b/tests/compress/fixtures/dir/subdir/4.txt
@@ -0,0 +1 @@
+4
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php
index 996f5b39cf..3e81db1895 100644
--- a/tests/cron/ext/testext/cron/dummy_task.php
+++ b/tests/cron/ext/testext/cron/dummy_task.php
@@ -9,7 +9,12 @@
class phpbb_ext_testext_cron_dummy_task extends phpbb_cron_task_base
{
- public static $was_run = 0;
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
public function run()
{
diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php
index 6e2e2db636..c94455603f 100644
--- a/tests/cron/includes/cron/task/core/dummy_task.php
+++ b/tests/cron/includes/cron/task/core/dummy_task.php
@@ -9,7 +9,12 @@
class phpbb_cron_task_core_dummy_task extends phpbb_cron_task_base
{
- public static $was_run = 0;
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
public function run()
{
diff --git a/tests/cron/includes/cron/task/core/second_dummy_task.php b/tests/cron/includes/cron/task/core/second_dummy_task.php
index 8cd0bddfc0..77ef6f70ed 100644
--- a/tests/cron/includes/cron/task/core/second_dummy_task.php
+++ b/tests/cron/includes/cron/task/core/second_dummy_task.php
@@ -9,7 +9,12 @@
class phpbb_cron_task_core_second_dummy_task extends phpbb_cron_task_base
{
- public static $was_run = 0;
+ static public $was_run = 0;
+
+ public function get_name()
+ {
+ return get_class($this);
+ }
public function run()
{
diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php
index 3e40a6d338..3c541be2a6 100644
--- a/tests/cron/manager_test.php
+++ b/tests/cron/manager_test.php
@@ -18,10 +18,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->manager = new phpbb_cron_manager(array(
- 'phpbb_cron_task_core_dummy_task',
- 'phpbb_cron_task_core_second_dummy_task',
- 'phpbb_ext_testext_cron_dummy_task',
+ $this->manager = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_dummy_task(),
+ new phpbb_cron_task_core_second_dummy_task(),
+ new phpbb_ext_testext_cron_dummy_task(),
));
$this->task_name = 'phpbb_cron_task_core_dummy_task';
}
@@ -33,13 +33,6 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
$this->assertEquals($this->task_name, $task->get_name());
}
- public function test_manager_instantiates_task_by_name()
- {
- $task = $this->manager->instantiate_task($this->task_name, array());
- $this->assertInstanceOf('phpbb_cron_task_wrapper', $task);
- $this->assertEquals($this->task_name, $task->get_name());
- }
-
public function test_manager_finds_all_ready_tasks()
{
$tasks = $this->manager->find_all_ready_tasks();
@@ -54,10 +47,10 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
public function test_manager_finds_only_ready_tasks()
{
- $manager = new phpbb_cron_manager(array(
- 'phpbb_cron_task_core_simple_ready',
- 'phpbb_cron_task_core_simple_not_runnable',
- 'phpbb_cron_task_core_simple_should_not_run',
+ $manager = $this->create_cron_manager(array(
+ new phpbb_cron_task_core_simple_ready(),
+ new phpbb_cron_task_core_simple_not_runnable(),
+ new phpbb_cron_task_core_simple_should_not_run(),
));
$tasks = $manager->find_all_ready_tasks();
$task_names = $this->tasks_to_names($tasks);
@@ -69,8 +62,15 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
$names = array();
foreach ($tasks as $task)
{
- $names[] = get_class($task->task);
+ $names[] = $task->get_name();
}
return $names;
}
+
+ private function create_cron_manager($tasks)
+ {
+ global $phpbb_root_path, $phpEx;
+
+ return new phpbb_cron_manager($tasks, $phpbb_root_path, $phpEx);
+ }
}
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php
index b42f40bb4a..ec853bb3ba 100644
--- a/tests/cron/task_provider_test.php
+++ b/tests/cron/task_provider_test.php
@@ -11,31 +11,40 @@ class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
- $this->extension_manager = new phpbb_mock_extension_manager(
- dirname(__FILE__) . '/',
- array(
- 'testext' => array(
- 'ext_name' => 'testext',
- 'ext_active' => true,
- 'ext_path' => 'ext/testext/'
- ),
- ));
- $this->provider = new phpbb_cron_task_provider($this->extension_manager);
+ $this->tasks = array(
+ 'phpbb_cron_task_core_dummy_task',
+ 'phpbb_cron_task_core_second_dummy_task',
+ 'phpbb_ext_testext_cron_dummy_task',
+ );
+
+ $container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface');
+ $container
+ ->expects($this->once())
+ ->method('findTaggedServiceIds')
+ ->will($this->returnValue(array_flip($this->tasks)));
+ $container
+ ->expects($this->any())
+ ->method('get')
+ ->will($this->returnCallback(function ($name) {
+ return new $name;
+ }));
+
+ $this->provider = new phpbb_cron_task_provider($container);
}
public function test_manager_finds_shipped_tasks()
{
- $tasks = array();
+ $task_names = array();
foreach ($this->provider as $task)
{
- $tasks[] = $task;
+ $task_names[] = $task->get_name();
}
- sort($tasks);
+ sort($task_names);
$this->assertEquals(array(
'phpbb_cron_task_core_dummy_task',
'phpbb_cron_task_core_second_dummy_task',
'phpbb_ext_testext_cron_dummy_task',
- ), $tasks);
+ ), $task_names);
}
}
diff --git a/tests/cron/tasks/simple_not_runnable.php b/tests/cron/tasks/simple_not_runnable.php
index 837f28f1c0..56d484eacd 100644
--- a/tests/cron/tasks/simple_not_runnable.php
+++ b/tests/cron/tasks/simple_not_runnable.php
@@ -2,6 +2,11 @@
class phpbb_cron_task_core_simple_not_runnable extends phpbb_cron_task_base
{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
public function run()
{
}
diff --git a/tests/cron/tasks/simple_ready.php b/tests/cron/tasks/simple_ready.php
index de5f10e491..8aa0507406 100644
--- a/tests/cron/tasks/simple_ready.php
+++ b/tests/cron/tasks/simple_ready.php
@@ -2,6 +2,11 @@
class phpbb_cron_task_core_simple_ready extends phpbb_cron_task_base
{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
public function run()
{
}
diff --git a/tests/cron/tasks/simple_should_not_run.php b/tests/cron/tasks/simple_should_not_run.php
index c2a41616f6..58f6df2616 100644
--- a/tests/cron/tasks/simple_should_not_run.php
+++ b/tests/cron/tasks/simple_should_not_run.php
@@ -2,6 +2,11 @@
class phpbb_cron_task_core_simple_should_not_run extends phpbb_cron_task_base
{
+ public function get_name()
+ {
+ return get_class($this);
+ }
+
public function run()
{
}
diff --git a/tests/dbal/select_test.php b/tests/dbal/select_test.php
index bd524100a2..c8cfad04e0 100644
--- a/tests/dbal/select_test.php
+++ b/tests/dbal/select_test.php
@@ -125,7 +125,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $ary);
}
- public static function fetchfield_seek_data()
+ static public function fetchfield_seek_data()
{
return array(
array(1, 'foobar'),
@@ -151,7 +151,7 @@ class phpbb_dbal_select_test extends phpbb_database_test_case
$this->assertEquals($expected, $field);
}
- public static function query_limit_data()
+ static public function query_limit_data()
{
return array(
array(0, 0, array(array('username_clean' => 'barfoo'),
diff --git a/tests/extension/acp.php b/tests/extension/acp.php
new file mode 100644
index 0000000000..790df77c0d
--- /dev/null
+++ b/tests/extension/acp.php
@@ -0,0 +1,205 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class acp_test extends phpbb_functional_test_case
+{
+ static private $copied_files = array();
+ static private $helper;
+
+ /**
+ * This should only be called once before the tests are run.
+ * This is used to copy the extensions to the phpBB install
+ */
+ static public function setUpBeforeClass()
+ {
+ global $phpbb_root_path;
+
+ parent::setUpBeforeClass();
+
+ self::$helper = new phpbb_test_case_helpers(self);
+
+ // First, move any extensions setup on the board to a temp directory
+ self::$copied_files = self::$helper->copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/');
+
+ // Then empty the ext/ directory on the board (for accurate test cases)
+ self::$helper->empty_dir($phpbb_root_path . 'ext/');
+
+ // Copy our ext/ files from the test case to the board
+ self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/'));
+ }
+
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->get_db();
+
+ // Clear the phpbb_ext table
+ $this->db->sql_query('DELETE FROM phpbb_ext');
+
+ // Insert our base data
+ $insert_rows = array(
+ array(
+ 'ext_name' => 'foo',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'vendor/moo',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+
+ // do not exist
+ array(
+ 'ext_name' => 'test2',
+ 'ext_active' => true,
+ 'ext_state' => 'b:0;',
+ ),
+ array(
+ 'ext_name' => 'test3',
+ 'ext_active' => false,
+ 'ext_state' => 'b:0;',
+ ),
+ );
+ $this->db->sql_multi_insert('phpbb_ext', $insert_rows);
+
+ $this->login();
+ $this->admin_login();
+
+ $this->add_lang('acp/extensions');
+ }
+
+ /**
+ * This should only be called once after the tests are run.
+ * This is used to remove the files copied to the phpBB install
+ */
+ static public function tearDownAfterClass()
+ {
+ global $phpbb_root_path;
+
+ // Copy back the board installed extensions from the temp directory
+ self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/');
+
+ self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/';
+
+ // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext)
+ self::$helper->remove_files(self::$copied_files);
+ }
+
+ public function test_list()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
+
+ $this->assertCount(1, $crawler->filter('.ext_enabled'));
+ $this->assertCount(4, $crawler->filter('.ext_disabled'));
+
+ $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text());
+ $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text());
+
+ $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text());
+
+ $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text());
+
+ $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text());
+ $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text());
+
+ $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text());
+ }
+
+ public function test_details()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid);
+
+ $validation = array(
+ 'DISPLAY_NAME' => 'phpBB Foo Extension',
+ 'CLEAN_NAME' => 'foo/example',
+ 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.',
+ 'VERSION' => '1.0.0',
+ 'TIME' => '2012-02-15 01:01:01',
+ 'LICENCE' => 'GPL-2.0',
+ 'PHPBB_VERSION' => '3.1.0-dev',
+ 'PHP_VERSION' => '>=5.3',
+ 'AUTHOR_NAME' => 'Nathan Guse',
+ 'AUTHOR_EMAIL' => 'email@phpbb.com',
+ 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org',
+ 'AUTHOR_ROLE' => 'N/A',
+ );
+
+ for ($i = 0; $i < $crawler->filter('dl')->count(); $i++)
+ {
+ $text = $crawler->filter('dl')->eq($i)->text();
+
+ $match = false;
+
+ foreach ($validation as $language_key => $expected)
+ {
+ if (strpos($text, $this->lang($language_key)) === 0)
+ {
+ $match = true;
+
+ $this->assertContains($expected, $text);
+ }
+ }
+
+ if (!$match)
+ {
+ $this->fail('Unexpected field: "' . $text . '"');
+ }
+ }
+ }
+
+ public function test_enable_pre()
+ {
+ // Foo is already enabled (redirect to list)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_disable_pre()
+ {
+ // Moo is not enabled (redirect to list)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
+ $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_purge_pre()
+ {
+ // test2 is not available (error)
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid);
+ $this->assertContains('The required file does not exist', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid);
+ $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text());
+ }
+
+ public function test_actions()
+ {
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid);
+ $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text());
+ }
+} \ No newline at end of file
diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json
new file mode 100644
index 0000000000..744f7be625
--- /dev/null
+++ b/tests/extension/ext/foo/composer.json
@@ -0,0 +1,22 @@
+{
+ "name": "foo/example",
+ "type": "phpbb3-extension",
+ "description": "An example/sample extension to be used for testing purposes in phpBB Development.",
+ "version": "1.0.0",
+ "time": "2012-02-15 01:01:01",
+ "licence": "GPL-2.0",
+ "authors": [{
+ "name": "Nathan Guse",
+ "username": "EXreaction",
+ "email": "email@phpbb.com",
+ "homepage": "http://lithiumstudios.org",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.3",
+ "phpbb": "3.1.0-dev"
+ },
+ "extra": {
+ "display-name": "phpBB Foo Extension"
+ }
+}
diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json
new file mode 100644
index 0000000000..c91a5e027b
--- /dev/null
+++ b/tests/extension/ext/vendor/moo/composer.json
@@ -0,0 +1,22 @@
+{
+ "name": "moo/example",
+ "type": "phpbb3-extension",
+ "description": "An example/sample extension to be used for testing purposes in phpBB Development.",
+ "version": "1.0.0",
+ "time": "2012-02-15 01:01:01",
+ "licence": "GNU GPL v2",
+ "authors": [{
+ "name": "Nathan Guse",
+ "username": "EXreaction",
+ "email": "email@phpbb.com",
+ "homepage": "http://lithiumstudios.org",
+ "role": "N/A"
+ }],
+ "require": {
+ "php": ">=5.3",
+ "phpbb": "3.1.0-dev"
+ },
+ "extra": {
+ "display-name": "phpBB Moo Extension"
+ }
+}
diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php
index 45bed247ae..5cde5bccdb 100644
--- a/tests/extension/manager_test.php
+++ b/tests/extension/manager_test.php
@@ -27,6 +27,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$this->extension_manager = new phpbb_extension_manager(
$this->new_dbal(),
+ new phpbb_config(array()),
'phpbb_ext',
dirname(__FILE__) . '/',
'.php',
@@ -90,6 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
{
$extension_manager = new phpbb_extension_manager(
$this->new_dbal(),
+ new phpbb_config(array()),
'phpbb_ext',
dirname(__FILE__) . '/',
'.php'
diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php
new file mode 100644
index 0000000000..ce7be0dea5
--- /dev/null
+++ b/tests/extension/metadata_manager_test.php
@@ -0,0 +1,431 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+class metadata_manager_test extends phpbb_database_test_case
+{
+ protected $class_loader;
+ protected $extension_manager;
+
+ protected $cache;
+ protected $config;
+ protected $db;
+ protected $phpbb_root_path;
+ protected $phpEx;
+ protected $template;
+ protected $user;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml');
+ }
+
+ protected function setUp()
+ {
+ parent::setUp();
+
+ $this->cache = new phpbb_mock_cache();
+ $this->config = new phpbb_config(array(
+ 'version' => '3.1.0',
+ ));
+ $this->db = $this->new_dbal();
+ $this->phpbb_root_path = dirname(__FILE__) . '/';
+ $this->phpEx = '.php';
+ $this->user = new phpbb_user();
+
+ $this->template = new phpbb_template(
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->config,
+ $this->user,
+ new phpbb_style_resource_locator(),
+ new phpbb_template_context()
+ );
+
+ $this->extension_manager = new phpbb_extension_manager(
+ $this->db,
+ $this->config,
+ 'phpbb_ext',
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->cache
+ );
+ }
+
+ // Should fail from missing composer.json
+ public function test_bar()
+ {
+ $ext_name = 'bar';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ try
+ {
+ $manager->get_metadata();
+ }
+ catch(phpbb_extension_exception $e){}
+
+ $this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json');
+ }
+
+ // Should be the same as a direct json_decode of the composer.json file
+ public function test_foo()
+ {
+ $ext_name = 'foo';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ try
+ {
+ $metadata = $manager->get_metadata();
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+ $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/foo/composer.json'), true);
+
+ $this->assertEquals($metadata, $json);
+ }
+
+ public function test_validator_non_existant()
+ {
+ $ext_name = 'validator';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ // Non-existant data
+ try
+ {
+ $manager->validate('name');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.');
+ }
+
+ try
+ {
+ $manager->validate('type');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.');
+ }
+
+ try
+ {
+ $manager->validate('licence');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.');
+ }
+
+ try
+ {
+ $manager->validate('version');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.');
+ }
+
+ try
+ {
+ $manager->validate_authors();
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.');
+ }
+
+ $manager->merge_metadata(array(
+ 'authors' => array(
+ array(),
+ ),
+ ));
+
+ try
+ {
+ $manager->validate_authors();
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.');
+ }
+ }
+
+
+ public function test_validator_invalid()
+ {
+ $ext_name = 'validator';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ // Invalid data
+ $manager->set_metadata(array(
+ 'name' => 'asdf',
+ 'type' => 'asdf',
+ 'licence' => '',
+ 'version' => '',
+ ));
+
+ try
+ {
+ $manager->validate('name');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.');
+ }
+
+ try
+ {
+ $manager->validate('type');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.');
+ }
+
+ try
+ {
+ $manager->validate('licence');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.');
+ }
+
+ try
+ {
+ $manager->validate('version');
+
+ $this->fail('Exception not triggered');
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.');
+ }
+ }
+
+ public function test_validator_valid()
+ {
+ $ext_name = 'validator';
+
+ $manager = $this->get_metadata_manager($ext_name);
+
+ // Valid data
+ $manager->set_metadata(array(
+ 'name' => 'test/foo',
+ 'type' => 'phpbb3-extension',
+ 'licence' => 'GPL v2',
+ 'version' => '1.0.0',
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate('enable'));
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+ }
+
+
+ public function test_validator_requirements()
+ {
+ $ext_name = 'validator';
+
+ $manager = $this->get_metadata_manager($ext_name);
+ // Too high of requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '10.0.0',
+ 'phpbb' => '3.2.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(false, $manager->validate_require_php());
+ $this->assertEquals(false, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Too high of requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '5.3.0',
+ 'phpbb' => '3.1.0-beta', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate_require_php());
+ $this->assertEquals(true, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Too high of requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '>' . phpversion(),
+ 'phpbb' => '>3.1.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(false, $manager->validate_require_php());
+ $this->assertEquals(false, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Too high of current install
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '<' . phpversion(),
+ 'phpbb' => '<3.1.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(false, $manager->validate_require_php());
+ $this->assertEquals(false, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Matching requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => phpversion(),
+ 'phpbb' => '3.1.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate_require_php());
+ $this->assertEquals(true, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Matching requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '>=' . phpversion(),
+ 'phpbb' => '>=3.1.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate_require_php());
+ $this->assertEquals(true, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+
+
+ // Matching requirements
+ $manager->merge_metadata(array(
+ 'require' => array(
+ 'php' => '<=' . phpversion(),
+ 'phpbb' => '<=3.1.0', // config is set to 3.1.0
+ ),
+ ));
+
+ try
+ {
+ $this->assertEquals(true, $manager->validate_require_php());
+ $this->assertEquals(true, $manager->validate_require_phpbb());
+ }
+ catch(phpbb_extension_exception $e)
+ {
+ $this->fail($e);
+ }
+ }
+
+ /**
+ * Get an instance of the metadata manager
+ *
+ * @param string $ext_name
+ * @return phpbb_extension_metadata_manager_test
+ */
+ private function get_metadata_manager($ext_name)
+ {
+ return new phpbb_extension_metadata_manager_test(
+ $ext_name,
+ $this->db,
+ $this->extension_manager,
+ $this->phpbb_root_path,
+ $this->phpEx,
+ $this->template,
+ $this->config
+ );
+ }
+}
+
+class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager
+{
+ public function set_metadata($metadata)
+ {
+ $this->metadata = $metadata;
+ }
+
+ public function merge_metadata($metadata)
+ {
+ $this->metadata = array_merge($this->metadata, $metadata);
+ }
+} \ No newline at end of file
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
new file mode 100644
index 0000000000..f54a3591b2
--- /dev/null
+++ b/tests/functional/posting_test.php
@@ -0,0 +1,102 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+class phpbb_functional_posting_test extends phpbb_functional_test_case
+{
+ public function test_post_new_topic()
+ {
+ $this->login();
+ $this->add_lang('posting');
+
+ $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid);
+ $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text());
+
+ $hidden_fields = array();
+ $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
+ return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ });
+
+ $test_message = 'This is a test topic posted by the testing framework.';
+ $form_data = array(
+ 'subject' => 'Test Topic 1',
+ 'message' => $test_message,
+ 'post' => true,
+ 'f' => 2,
+ 'mode' => 'post',
+ 'sid' => $this->sid,
+ );
+
+ foreach ($hidden_fields as $fields)
+ {
+ foreach($fields as $field)
+ {
+ $form_data[$field['name']] = $field['value'];
+ }
+ }
+
+ // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
+ // is not at least 2 seconds before submission, cancel the form
+ $form_data['lastclick'] = 0;
+
+ // I use a request because the form submission method does not allow you to send data that is not
+ // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs)
+ // Instead, I send it as a request with the submit button "post" set to true.
+ $crawler = $this->client->request('POST', 'posting.php', $form_data);
+ $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
+ $this->assertContains($test_message, $crawler->filter('html')->text());
+ }
+
+ public function test_post_reply()
+ {
+ $this->login();
+ $this->add_lang('posting');
+
+ $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid);
+ $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text());
+
+ $hidden_fields = array();
+ $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) {
+ return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value'));
+ });
+
+ $test_message = 'This is a test post posted by the testing framework.';
+ $form_data = array(
+ 'subject' => 'Re: Test Topic 1',
+ 'message' => $test_message,
+ 'post' => true,
+ 't' => 2,
+ 'f' => 2,
+ 'mode' => 'reply',
+ 'sid' => $this->sid,
+ );
+
+ foreach ($hidden_fields as $fields)
+ {
+ foreach($fields as $field)
+ {
+ $form_data[$field['name']] = $field['value'];
+ }
+ }
+
+ // For reasoning behind the following command, see the test_post_new_topic() test
+ $form_data['lastclick'] = 0;
+
+ // Submit the post
+ $crawler = $this->client->request('POST', 'posting.php', $form_data);
+ $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
+
+ $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid);
+ $this->assertContains($test_message, $crawler->filter('html')->text());
+ }
+}
diff --git a/tests/functions/clean_path_test.php b/tests/functions/clean_path_test.php
new file mode 100644
index 0000000000..bcbe9838d9
--- /dev/null
+++ b/tests/functions/clean_path_test.php
@@ -0,0 +1,44 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+
+class phpbb_clean_path_test extends phpbb_test_case
+{
+ public function clean_path_test_data()
+ {
+ return array(
+ array('foo', 'foo'),
+ array('foo/bar', 'foo/bar'),
+ array('foo/bar/', 'foo/bar/'),
+ array('foo/./bar', 'foo/bar'),
+ array('foo/./././bar', 'foo/bar'),
+ array('foo/bar/.', 'foo/bar'),
+ array('./foo/bar', './foo/bar'),
+ array('../foo/bar', '../foo/bar'),
+ array('one/two/three', 'one/two/three'),
+ array('one/two/../three', 'one/three'),
+ array('one/../two/three', 'two/three'),
+ array('one/two/..', 'one'),
+ array('one/two/../', 'one/'),
+ array('one/two/../three/../four', 'one/four'),
+ array('one/two/three/../../four', 'one/four'),
+ );
+ }
+
+ /**
+ * @dataProvider clean_path_test_data
+ */
+ public function test_clean_path($input, $expected)
+ {
+ $output = phpbb_clean_path($input);
+
+ $this->assertEquals($expected, $output);
+ }
+}
diff --git a/tests/privmsgs/delete_user_pms_test.php b/tests/privmsgs/delete_user_pms_test.php
index 265df1596a..f705825262 100644
--- a/tests/privmsgs/delete_user_pms_test.php
+++ b/tests/privmsgs/delete_user_pms_test.php
@@ -16,7 +16,7 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/delete_user_pms.xml');
}
- public static function delete_user_pms_data()
+ static public function delete_user_pms_data()
{
return array(
// array(
diff --git a/tests/request/type_cast_helper_test.php b/tests/request/type_cast_helper_test.php
index d553d5b8cd..f41db005af 100644
--- a/tests/request/type_cast_helper_test.php
+++ b/tests/request/type_cast_helper_test.php
@@ -48,4 +48,24 @@ class phpbb_type_cast_helper_test extends phpbb_test_case
$this->assertEquals($expected, $data);
}
+
+ public function test_simple_untrimmed_recursive_set_var()
+ {
+ $data = " eviL<3\t\t";
+ $expected = " eviL&lt;3\t\t";
+
+ $this->type_cast_helper->recursive_set_var($data, '', true, false);
+
+ $this->assertEquals($expected, $data);
+ }
+
+ public function test_nested_untrimmed_recursive_set_var()
+ {
+ $data = array(" eviL<3\t\t");
+ $expected = array(" eviL&lt;3\t\t");
+
+ $this->type_cast_helper->recursive_set_var($data, array(0 => ''), true, false);
+
+ $this->assertEquals($expected, $data);
+ }
}
diff --git a/tests/search/fixtures/posts.xml b/tests/search/fixtures/posts.xml
new file mode 100644
index 0000000000..7b249ee303
--- /dev/null
+++ b/tests/search/fixtures/posts.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_posts">
+ <column>post_username</column>
+ <column>post_subject</column>
+ <column>post_text</column>
+ <row>
+ <value>foo</value>
+ <value>foo</value>
+ <value>foo</value>
+ </row>
+ <row>
+ <value>bar</value>
+ <value>bar</value>
+ <value>bar</value>
+ </row>
+ <row>
+ <value>commonword</value>
+ <value>commonword</value>
+ <value>commonword</value>
+ </row>
+ </table>
+ <table name="phpbb_search_wordlist">
+ <column>word_id</column>
+ <column>word_text</column>
+ <column>word_common</column>
+ <row>
+ <value>1</value>
+ <value>foo</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>2</value>
+ <value>bar</value>
+ <value>0</value>
+ </row>
+ <row>
+ <value>3</value>
+ <value>commonword</value>
+ <value>1</value>
+ </row>
+ </table>
+</dataset>
diff --git a/tests/search/native_test.php b/tests/search/native_test.php
new file mode 100644
index 0000000000..66972079cf
--- /dev/null
+++ b/tests/search/native_test.php
@@ -0,0 +1,186 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+function phpbb_search_wrapper($class)
+{
+ $wrapped = $class . '_wrapper';
+ if (!class_exists($wrapped))
+ {
+ $code = "
+class $wrapped extends $class
+{
+ public function get_must_contain_ids() { return \$this->must_contain_ids; }
+ public function get_must_not_contain_ids() { return \$this->must_not_contain_ids; }
+}
+ ";
+ eval($code);
+ }
+ return $wrapped;
+}
+
+class phpbb_search_native_test extends phpbb_database_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/posts.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_cache_driver_null;
+
+ $this->db = $this->new_dbal();
+ $error = null;
+ $class = phpbb_search_wrapper('phpbb_search_fulltext_native');
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
+ }
+
+ protected function tearDown()
+ {
+ parent::tearDown();
+ }
+
+ public function keywords()
+ {
+ return array(
+ // keywords
+ // terms
+ // ok
+ // must contain ids
+ // must not contain ids
+ // common words
+ array(
+ 'foo',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array(),
+ ),
+ array(
+ 'foo bar',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ // leading, trailing and multiple spaces
+ array(
+ ' foo bar ',
+ 'all',
+ true,
+ array(1, 2),
+ array(),
+ array(),
+ ),
+ // words too short
+ array(
+ 'f',
+ 'all',
+ false,
+ null,
+ null,
+ // short words count as "common" words
+ array('f'),
+ ),
+ array(
+ 'f o o',
+ 'all',
+ false,
+ null,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
+ 'foo -bar',
+ 'all',
+ true,
+ array(1),
+ array(2),
+ array(),
+ ),
+ // all negative
+ array(
+ '-foo',
+ 'all',
+ false,
+ null,
+ null,
+ array(),
+ ),
+ array(
+ '-foo -bar',
+ 'all',
+ false,
+ null,
+ null,
+ array(),
+ ),
+ // all common
+ array(
+ 'commonword',
+ 'all',
+ false,
+ null,
+ null,
+ array('commonword'),
+ ),
+ // some common
+ array(
+ 'commonword foo',
+ 'all',
+ true,
+ array(1),
+ array(),
+ array('commonword'),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider keywords
+ */
+ public function test_split_keywords($keywords, $terms, $ok, $must_contain, $must_not_contain, $common)
+ {
+ $rv = $this->search->split_keywords($keywords, $terms);
+ $this->assertEquals($ok, $rv);
+ if ($ok)
+ {
+ // only check criteria if the search is going to be performed
+ $this->assert_array_content_equals($must_contain, $this->search->get_must_contain_ids());
+ $this->assert_array_content_equals($must_not_contain, $this->search->get_must_not_contain_ids());
+ }
+ $this->assert_array_content_equals($common, $this->search->get_common_words());
+ }
+
+ public function assert_array_content_equals($one, $two)
+ {
+ // http://stackoverflow.com/questions/3838288/phpunit-assert-two-arrays-are-equal-but-order-of-elements-not-important
+ // but one array_diff is not enough!
+ if (sizeof(array_diff($one, $two)) || sizeof(array_diff($two, $one)))
+ {
+ // get a nice error message
+ $this->assertEquals($one, $two);
+ }
+ else
+ {
+ // increase assertion count
+ $this->assertTrue(true);
+ }
+ }
+}
diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php
index 88f6f0718e..34f6dea8ca 100644
--- a/tests/session/append_sid_test.php
+++ b/tests/session/append_sid_test.php
@@ -45,6 +45,9 @@ class phpbb_session_append_sid_test extends phpbb_test_case
*/
public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description)
{
+ global $phpbb_dispatcher;
+
+ $phpbb_dispatcher = new phpbb_mock_event_dispatcher;
$this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id));
}
}
diff --git a/tests/template/includephp_test.php b/tests/template/includephp_test.php
index 626735f15f..f008a734eb 100644
--- a/tests/template/includephp_test.php
+++ b/tests/template/includephp_test.php
@@ -36,7 +36,7 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$this->setup_engine(array('tpl_allow_php' => true));
- $this->style->set_custom_style('tests', $cache_dir);
+ $this->style->set_custom_style('tests', $cache_dir, '');
$cache_file = $this->template->cachepath . 'includephp_absolute.html.php';
$this->run_template('includephp_absolute.html', array(), array(), array(), "Path is absolute.\ntesting included php", $cache_file);
diff --git a/tests/template/template_test_case.php b/tests/template/template_test_case.php
index 6f76cb049d..2e6f703eb1 100644
--- a/tests/template/template_test_case.php
+++ b/tests/template/template_test_case.php
@@ -67,7 +67,7 @@ class phpbb_template_template_test_case extends phpbb_test_case
$this->template_path = $this->test_path . '/templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', $this->template_path, '');
}
diff --git a/tests/template/template_test_case_with_tree.php b/tests/template/template_test_case_with_tree.php
index 05ccb7ee55..6a226f317a 100644
--- a/tests/template/template_test_case_with_tree.php
+++ b/tests/template/template_test_case_with_tree.php
@@ -22,7 +22,7 @@ class phpbb_template_template_test_case_with_tree extends phpbb_template_templat
$this->parent_template_path = $this->test_path . '/parent_templates';
$this->style_resource_locator = new phpbb_style_resource_locator();
$this->style_provider = new phpbb_style_path_provider();
- $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator);
+ $this->template = new phpbb_template($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, new phpbb_template_context());
$this->style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $this->style_resource_locator, $this->style_provider, $this->template);
$this->style->set_custom_style('tests', array($this->template_path, $this->parent_template_path), '');
}
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index bb86df0ef0..75a3c0944b 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -137,7 +137,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
*
* @return string The string with the specified match converted to uppercase
*/
- public static function to_upper($matches)
+ static public function to_upper($matches)
{
return $matches[1] . strtoupper($matches[2]) . $matches[3];
}
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index b953017d0a..d002615e8c 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -125,6 +125,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->extension_manager = new phpbb_extension_manager(
$this->get_db(),
+ new phpbb_config(),
self::$config['table_prefix'] . 'ext',
$phpbb_root_path,
".$phpEx",
@@ -198,7 +199,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->do_request('create_table', $data);
$this->do_request('config_file', $data);
- file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true));
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], array(), true, true));
$this->do_request('final', $data);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
@@ -251,6 +252,48 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
+ /**
+ * Login to the ACP
+ * You must run login() before calling this.
+ */
+ protected function admin_login()
+ {
+ $this->add_lang('acp/common');
+
+ // Requires login first!
+ if (empty($this->sid))
+ {
+ $this->fail('$this->sid is empty. Make sure you call login() before admin_login()');
+ return;
+ }
+
+ $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid);
+ $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text());
+
+ $form = $crawler->selectButton($this->lang('LOGIN'))->form();
+
+ foreach ($form->getValues() as $field => $value)
+ {
+ if (strpos($field, 'password_') === 0)
+ {
+ $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin'));
+
+ $cookies = $this->cookieJar->all();
+
+ // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
+ foreach ($cookies as $cookie);
+ {
+ if (substr($cookie->getName(), -4) == '_sid')
+ {
+ $this->sid = $cookie->getValue();
+ }
+ }
+
+ break;
+ }
+ }
+ }
+
protected function add_lang($lang_file)
{
if (is_array($lang_file))
@@ -287,4 +330,16 @@ class phpbb_functional_test_case extends phpbb_test_case
return call_user_func_array('sprintf', $args);
}
+
+ /**
+ * assertContains for language strings
+ *
+ * @param string $needle Search string
+ * @param string $haystack Search this
+ * @param string $message Optional failure message
+ */
+ public function assertContainsLang($needle, $haystack, $message = null)
+ {
+ $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
+ }
}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index 46feef550a..d10645a732 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -115,4 +115,112 @@ class phpbb_test_case_helpers
return $config;
}
+
+ /**
+ * Recursive directory copying function
+ *
+ * @param string $source
+ * @param string $dest
+ * @return array list of files copied
+ */
+ public function copy_dir($source, $dest)
+ {
+ $source = (substr($source, -1) == '/') ? $source : $source . '/';
+ $dest = (substr($dest, -1) == '/') ? $dest : $dest . '/';
+
+ $copied_files = array();
+
+ if (!is_dir($dest))
+ {
+ $this->makedirs($dest);
+ }
+
+ $files = scandir($source);
+ foreach ($files as $file)
+ {
+ if ($file == '.' || $file == '..')
+ {
+ continue;
+ }
+
+ if (is_dir($source . $file))
+ {
+ $created_dir = false;
+ if (!is_dir($dest . $file))
+ {
+ $created_dir = true;
+ $this->makedirs($dest . $file);
+ }
+
+ $copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file));
+
+ if ($created_dir)
+ {
+ $copied_files[] = $dest . $file;
+ }
+ }
+ else
+ {
+ if (!file_exists($dest . $file))
+ {
+ copy($source . $file, $dest . $file);
+
+ $copied_files[] = $dest . $file;
+ }
+ }
+ }
+
+ return $copied_files;
+ }
+
+ /**
+ * Remove files/directories that are listed in an array
+ * Designed for use with $this->copy_dir()
+ *
+ * @param array $file_list
+ */
+ public function remove_files($file_list)
+ {
+ foreach ($file_list as $file)
+ {
+ if (is_dir($file))
+ {
+ rmdir($file);
+ }
+ else
+ {
+ unlink($file);
+ }
+ }
+ }
+
+ /**
+ * Empty directory (remove any subdirectories/files below)
+ *
+ * @param array $file_list
+ */
+ public function empty_dir($path)
+ {
+ $path = (substr($path, -1) == '/') ? $path : $path . '/';
+
+ $files = scandir($path);
+ foreach ($files as $file)
+ {
+ if ($file == '.' || $file == '..')
+ {
+ continue;
+ }
+
+ if (is_dir($path . $file))
+ {
+ $this->empty_dir($path . $file);
+
+ rmdir($path . $file);
+ }
+ else
+ {
+ unlink($path . $file);
+ }
+ }
+ }
}