aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cron/ext/testext/cron/dummy_task.php2
-rw-r--r--tests/cron/includes/cron/task/core/dummy_task.php2
-rw-r--r--tests/cron/includes/cron/task/core/second_dummy_task.php2
-rw-r--r--tests/cron/task_provider_test.php50
-rw-r--r--tests/dbal/select_test.php4
-rw-r--r--tests/di/create_container_test.php72
-rw-r--r--tests/di/fixtures/config.php11
-rw-r--r--tests/event/dispatcher_test.php2
-rw-r--r--tests/functional/browse_test.php3
-rw-r--r--tests/functional/extension_controller_test.php2
-rw-r--r--tests/mock/container_builder.php160
-rw-r--r--tests/mock/request.php9
-rw-r--r--tests/privmsgs/delete_user_pms_test.php2
-rw-r--r--tests/request/request_test.php25
-rw-r--r--tests/search/fixtures/posts.xml43
-rw-r--r--tests/search/native_test.php186
-rw-r--r--tests/template/includephp_test.php12
-rw-r--r--tests/template/template_includejs_test.php7
-rw-r--r--tests/template/template_test.php7
-rw-r--r--tests/template/templates/include_variables.html1
-rw-r--r--tests/template/templates/includejs.html5
-rw-r--r--tests/template/templates/includephp_variables.html2
-rw-r--r--tests/template/templates/subdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/subsubdir/parent_only.js0
-rw-r--r--tests/template/templates/subdir/variable.html1
-rw-r--r--tests/test_framework/phpbb_database_test_case.php2
-rw-r--r--tests/test_framework/phpbb_database_test_connection_manager.php6
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php42
-rw-r--r--tests/upload/fileupload_test.php6
29 files changed, 584 insertions, 82 deletions
diff --git a/tests/cron/ext/testext/cron/dummy_task.php b/tests/cron/ext/testext/cron/dummy_task.php
index a31806c1b1..3e81db1895 100644
--- a/tests/cron/ext/testext/cron/dummy_task.php
+++ b/tests/cron/ext/testext/cron/dummy_task.php
@@ -9,7 +9,7 @@
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()
{
diff --git a/tests/cron/includes/cron/task/core/dummy_task.php b/tests/cron/includes/cron/task/core/dummy_task.php
index ce3e91a9ba..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,7 @@
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()
{
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 76a55588f9..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,7 @@
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()
{
diff --git a/tests/cron/task_provider_test.php b/tests/cron/task_provider_test.php
deleted file mode 100644
index ec853bb3ba..0000000000
--- a/tests/cron/task_provider_test.php
+++ /dev/null
@@ -1,50 +0,0 @@
-<?php
-/**
-*
-* @package testing
-* @copyright (c) 2010 phpBB Group
-* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
-*
-*/
-
-class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
-{
- public function setUp()
- {
- $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()
- {
- $task_names = array();
- foreach ($this->provider as $task)
- {
- $task_names[] = $task->get_name();
- }
- 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',
- ), $task_names);
- }
-}
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/di/create_container_test.php b/tests/di/create_container_test.php
new file mode 100644
index 0000000000..c2b8a0fc0b
--- /dev/null
+++ b/tests/di/create_container_test.php
@@ -0,0 +1,72 @@
+<?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_container.php';
+require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
+
+class phpbb_di_container_test extends phpbb_test_case
+{
+ public function test_phpbb_create_container()
+ {
+ $phpbb_root_path = __DIR__ . '/../../phpBB/';
+ $extensions = array(
+ new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
+ new phpbb_di_extension_core($phpbb_root_path),
+ );
+ $container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
+
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ }
+
+ public function test_phpbb_create_install_container()
+ {
+ $phpbb_root_path = __DIR__ . '/../../phpBB/';
+ $extensions = array(
+ new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
+ new phpbb_di_extension_core($phpbb_root_path),
+ );
+ $container = phpbb_create_install_container($phpbb_root_path, 'php');
+
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ $this->assertTrue($container->isFrozen());
+ }
+
+ public function test_phpbb_create_compiled_container()
+ {
+ $phpbb_root_path = __DIR__ . '/../../phpBB/';
+ $extensions = array(
+ new phpbb_di_extension_config(__DIR__ . '/fixtures/config.php'),
+ new phpbb_di_extension_core($phpbb_root_path),
+ );
+ $container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php');
+
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ $this->assertTrue($container->isFrozen());
+ }
+}
+
+class dbal_container_mock extends dbal
+{
+ public function sql_connect()
+ {
+ }
+
+ public function sql_query()
+ {
+ }
+
+ public function sql_fetchrow()
+ {
+ }
+
+ public function sql_freeresult()
+ {
+ }
+}
diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php
new file mode 100644
index 0000000000..5033d2dc9f
--- /dev/null
+++ b/tests/di/fixtures/config.php
@@ -0,0 +1,11 @@
+<?php
+// phpBB 3.1.x auto-generated configuration file
+// Do not change anything in this file!
+$dbms = 'container_mock';
+$dbhost = '127.0.0.1';
+$dbport = '';
+$dbname = 'phpbb';
+$dbuser = 'root';
+$dbpasswd = '';
+$table_prefix = 'phpbb_';
+$acm_type = 'phpbb_cache_driver_null';
diff --git a/tests/event/dispatcher_test.php b/tests/event/dispatcher_test.php
index f8fe060d99..9b9203e06a 100644
--- a/tests/event/dispatcher_test.php
+++ b/tests/event/dispatcher_test.php
@@ -11,7 +11,7 @@ class phpbb_event_dispatcher_test extends phpbb_test_case
{
public function test_trigger_event()
{
- $dispatcher = new phpbb_event_dispatcher();
+ $dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder());
$dispatcher->addListener('core.test_event', function (phpbb_event_data $event) {
$event['foo'] = $event['foo'] . '2';
diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php
index 26c18c4c1f..b5748059c6 100644
--- a/tests/functional/browse_test.php
+++ b/tests/functional/browse_test.php
@@ -15,18 +15,21 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
public function test_index()
{
$crawler = $this->request('GET', 'index.php');
+ $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
}
public function test_viewforum()
{
$crawler = $this->request('GET', 'viewforum.php?f=2');
+ $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
}
public function test_viewtopic()
{
$crawler = $this->request('GET', 'viewtopic.php?t=1');
+ $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
}
}
diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php
index e9409d9d3f..d92a830365 100644
--- a/tests/functional/extension_controller_test.php
+++ b/tests/functional/extension_controller_test.php
@@ -82,6 +82,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
{
$this->phpbb_extension_manager->enable('foobar');
$crawler = $this->request('GET', 'index.php?ext=foobar');
+ $this->assert_response_success();
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
$this->phpbb_extension_manager->purge('foobar');
}
@@ -94,6 +95,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
{
$this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'index.php?ext=foo/bar');
+ $this->assert_response_success();
$this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
$this->phpbb_extension_manager->purge('foo/bar');
}
diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php
new file mode 100644
index 0000000000..8a81dd72d1
--- /dev/null
+++ b/tests/mock/container_builder.php
@@ -0,0 +1,160 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\DependencyInjection\ScopeInterface;
+
+class phpbb_mock_container_builder implements ContainerInterface
+{
+ /**
+ * Sets a service.
+ *
+ * @param string $id The service identifier
+ * @param object $service The service instance
+ * @param string $scope The scope of the service
+ *
+ * @api
+ */
+ public function set($id, $service, $scope = self::SCOPE_CONTAINER)
+ {
+ }
+
+ /**
+ * Gets a service.
+ *
+ * @param string $id The service identifier
+ * @param int $invalidBehavior The behavior when the service does not exist
+ *
+ * @return object The associated service
+ *
+ * @throws InvalidArgumentException if the service is not defined
+ * @throws ServiceCircularReferenceException When a circular reference is detected
+ * @throws ServiceNotFoundException When the service is not defined
+ *
+ * @see Reference
+ *
+ * @api
+ */
+ public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
+ {
+ }
+
+ /**
+ * Returns true if the given service is defined.
+ *
+ * @param string $id The service identifier
+ *
+ * @return Boolean true if the service is defined, false otherwise
+ *
+ * @api
+ */
+ public function has($id)
+ {
+ }
+
+ /**
+ * Gets a parameter.
+ *
+ * @param string $name The parameter name
+ *
+ * @return mixed The parameter value
+ *
+ * @throws InvalidArgumentException if the parameter is not defined
+ *
+ * @api
+ */
+ public function getParameter($name)
+ {
+ }
+
+ /**
+ * Checks if a parameter exists.
+ *
+ * @param string $name The parameter name
+ *
+ * @return Boolean The presence of parameter in container
+ *
+ * @api
+ */
+ public function hasParameter($name)
+ {
+ }
+
+ /**
+ * Sets a parameter.
+ *
+ * @param string $name The parameter name
+ * @param mixed $value The parameter value
+ *
+ * @api
+ */
+ public function setParameter($name, $value)
+ {
+ }
+
+ /**
+ * Enters the given scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function enterScope($name)
+ {
+ }
+
+ /**
+ * Leaves the current scope, and re-enters the parent scope
+ *
+ * @param string $name
+ *
+ * @api
+ */
+ public function leaveScope($name)
+ {
+ }
+
+ /**
+ * Adds a scope to the container
+ *
+ * @param ScopeInterface $scope
+ *
+ * @api
+ */
+ public function addScope(ScopeInterface $scope)
+ {
+ }
+
+ /**
+ * Whether this container has the given scope
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function hasScope($name)
+ {
+ }
+
+ /**
+ * Determines whether the given scope is currently active.
+ *
+ * It does however not check if the scope actually exists.
+ *
+ * @param string $name
+ *
+ * @return Boolean
+ *
+ * @api
+ */
+ public function isScopeActive($name)
+ {
+ }
+}
diff --git a/tests/mock/request.php b/tests/mock/request.php
index 946dfdada9..2a272fc03b 100644
--- a/tests/mock/request.php
+++ b/tests/mock/request.php
@@ -11,13 +11,14 @@ class phpbb_mock_request implements phpbb_request_interface
{
protected $data;
- public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false)
+ public function __construct($get = array(), $post = array(), $cookie = array(), $server = array(), $request = false, $files = array())
{
$this->data[phpbb_request_interface::GET] = $get;
$this->data[phpbb_request_interface::POST] = $post;
$this->data[phpbb_request_interface::COOKIE] = $cookie;
$this->data[phpbb_request_interface::REQUEST] = ($request === false) ? $post + $get : $request;
$this->data[phpbb_request_interface::SERVER] = $server;
+ $this->data[phpbb_request_interface::FILES] = $files;
}
public function overwrite($var_name, $value, $super_global = phpbb_request_interface::REQUEST)
@@ -42,6 +43,12 @@ class phpbb_mock_request implements phpbb_request_interface
return $this->server($var_name, $default);
}
+ public function file($form_name)
+ {
+ $super_global = phpbb_request_interface::FILES;
+ return isset($this->data[$super_global][$form_name]) ? $this->data[$super_global][$form_name] : array();
+ }
+
public function is_set_post($name)
{
return $this->is_set($name, phpbb_request_interface::POST);
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/request_test.php b/tests/request/request_test.php
index bca5125b7a..52c21abd2a 100644
--- a/tests/request/request_test.php
+++ b/tests/request/request_test.php
@@ -21,6 +21,13 @@ class phpbb_request_test extends phpbb_test_case
$_COOKIE['test'] = 3;
$_REQUEST['test'] = 3;
$_GET['unset'] = '';
+ $_FILES['test'] = array(
+ 'name' => 'file',
+ 'tmp_name' => 'tmp',
+ 'size' => 256,
+ 'type' => 'application/octet-stream',
+ 'error' => UPLOAD_ERR_OK,
+ );
$_SERVER['HTTP_HOST'] = 'example.com';
$_SERVER['HTTP_ACCEPT'] = 'application/json';
@@ -42,6 +49,7 @@ class phpbb_request_test extends phpbb_test_case
$this->assertEquals(2, $_GET['test'], 'Checking $_GET after enable_super_globals');
$this->assertEquals(3, $_COOKIE['test'], 'Checking $_COOKIE after enable_super_globals');
$this->assertEquals(3, $_REQUEST['test'], 'Checking $_REQUEST after enable_super_globals');
+ $this->assertEquals(256, $_FILES['test']['size']);
$_POST['x'] = 2;
$this->assertEquals($_POST, $GLOBALS['_POST'], 'Checking whether $_POST can still be accessed via $GLOBALS[\'_POST\']');
@@ -85,6 +93,23 @@ class phpbb_request_test extends phpbb_test_case
$this->request->header('SOMEVAR');
}
+ public function test_file()
+ {
+ $file = $this->request->file('test');
+ $this->assertEquals('file', $file['name']);
+ $this->assertEquals('tmp', $file['tmp_name']);
+ $this->assertEquals(256, $file['size']);
+ $this->assertEquals('application/octet-stream', $file['type']);
+ $this->assertEquals(UPLOAD_ERR_OK, $file['error']);
+ }
+
+ public function test_file_not_exists()
+ {
+ $file = $this->request->file('404');
+ $this->assertTrue(is_array($file));
+ $this->assertTrue(empty($file));
+ }
+
/**
* Checks that directly accessing $_POST will trigger
* an error.
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/template/includephp_test.php b/tests/template/includephp_test.php
index f008a734eb..c93a53e2ad 100644
--- a/tests/template/includephp_test.php
+++ b/tests/template/includephp_test.php
@@ -23,6 +23,18 @@ class phpbb_template_includephp_test extends phpbb_template_template_test_case
$this->assertEquals("Path is relative to board root.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
}
+ public function test_includephp_variables()
+ {
+ $this->setup_engine(array('tpl_allow_php' => true));
+
+ $cache_file = $this->template->cachepath . 'includephp_variables.html.php';
+
+ $this->run_template('includephp_variables.html', array('TEMPLATES' => 'templates'), array(), array(), "Path includes variables.\ntesting included php", $cache_file);
+
+ $this->template->set_filenames(array('test' => 'includephp_variables.html'));
+ $this->assertEquals("Path includes variables.\ntesting included php", $this->display('test'), "Testing INCLUDEPHP");
+ }
+
public function test_includephp_absolute()
{
$path_to_php = dirname(__FILE__) . '/templates/_dummy_include.php.inc';
diff --git a/tests/template/template_includejs_test.php b/tests/template/template_includejs_test.php
index a8f9a9037f..22b020208b 100644
--- a/tests/template/template_includejs_test.php
+++ b/tests/template/template_includejs_test.php
@@ -20,11 +20,14 @@ class phpbb_template_template_includejs_test extends phpbb_template_template_tes
$scripts = array(
'<script src="' . $this->test_path . '/templates/parent_and_child.js?assets_version=1"></script>',
'<script src="' . $this->test_path . '/parent_templates/parent_only.js?assets_version=1"></script>',
- '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>'
+ '<script src="' . $this->test_path . '/templates/child_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/subsubdir/parent_only.js?assets_version=1"></script>',
+ '<script src="' . $this->test_path . '/templates/subdir/parent_only.js?assets_version=1"></script>',
);
// Run test
$cache_file = $this->template->cachepath . 'includejs.html.php';
- $this->run_template('includejs.html', array('PARENT' => 'parent_only.js'), array(), array(), implode('', $scripts), $cache_file);
+ $this->run_template('includejs.html', array('PARENT' => 'parent_only.js', 'SUBDIR' => 'subdir', 'EXT' => 'js'), array(), array(), implode('', $scripts), $cache_file);
}
}
diff --git a/tests/template/template_test.php b/tests/template/template_test.php
index f8677ed913..83995cb4ac 100644
--- a/tests/template/template_test.php
+++ b/tests/template/template_test.php
@@ -184,6 +184,13 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
'value',
),
array(
+ 'include_variables.html',
+ array('SUBDIR' => 'subdir', 'VARIABLE' => 'value'),
+ array(),
+ array(),
+ 'value',
+ ),
+ array(
'loop_vars.html',
array(),
array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())),
diff --git a/tests/template/templates/include_variables.html b/tests/template/templates/include_variables.html
new file mode 100644
index 0000000000..8371a061b5
--- /dev/null
+++ b/tests/template/templates/include_variables.html
@@ -0,0 +1 @@
+<!-- INCLUDE {SUBDIR}/variable.html -->
diff --git a/tests/template/templates/includejs.html b/tests/template/templates/includejs.html
index 8a2587d76b..ef73700eeb 100644
--- a/tests/template/templates/includejs.html
+++ b/tests/template/templates/includejs.html
@@ -2,4 +2,7 @@
<!-- INCLUDEJS {PARENT} -->
<!-- DEFINE $TEST = 'child_only.js' -->
<!-- INCLUDEJS {$TEST} -->
-{SCRIPTS} \ No newline at end of file
+<!-- INCLUDEJS subdir/{PARENT} -->
+<!-- INCLUDEJS {SUBDIR}/subsubdir/{PARENT} -->
+<!-- INCLUDEJS {SUBDIR}/parent_only.{EXT} -->
+{SCRIPTS}
diff --git a/tests/template/templates/includephp_variables.html b/tests/template/templates/includephp_variables.html
new file mode 100644
index 0000000000..6106efc86a
--- /dev/null
+++ b/tests/template/templates/includephp_variables.html
@@ -0,0 +1,2 @@
+Path includes variables.
+<!-- INCLUDEPHP ../tests/template/{TEMPLATES}/_dummy_include.php.inc -->
diff --git a/tests/template/templates/subdir/parent_only.js b/tests/template/templates/subdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/parent_only.js
diff --git a/tests/template/templates/subdir/subsubdir/parent_only.js b/tests/template/templates/subdir/subsubdir/parent_only.js
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/template/templates/subdir/subsubdir/parent_only.js
diff --git a/tests/template/templates/subdir/variable.html b/tests/template/templates/subdir/variable.html
new file mode 100644
index 0000000000..f68f91597c
--- /dev/null
+++ b/tests/template/templates/subdir/variable.html
@@ -0,0 +1 @@
+{VARIABLE}
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_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php
index 25e0972f42..a43215bcf2 100644
--- a/tests/test_framework/phpbb_database_test_connection_manager.php
+++ b/tests/test_framework/phpbb_database_test_connection_manager.php
@@ -166,12 +166,6 @@ class phpbb_database_test_connection_manager
switch ($this->config['dbms'])
{
case 'sqlite':
- if (file_exists($this->config['dbhost']))
- {
- unlink($this->config['dbhost']);
- }
- break;
-
case 'firebird':
$this->connect();
// Drop all of the tables
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index d002615e8c..16e1ccaff9 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -51,6 +51,7 @@ class phpbb_functional_test_case extends phpbb_test_case
// that were added in other tests are gone
$this->lang = array();
$this->add_lang('common');
+ $this->purge_cache();
}
public function request($method, $path)
@@ -125,7 +126,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->extension_manager = new phpbb_extension_manager(
$this->get_db(),
- new phpbb_config(),
+ new phpbb_config(array()),
self::$config['table_prefix'] . 'ext',
$phpbb_root_path,
".$phpEx",
@@ -199,7 +200,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, true));
+ file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true));
$this->do_request('final', $data);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
@@ -331,15 +332,30 @@ 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);
- }
+ /**
+ * 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);
+ }
+
+ /**
+ * Heuristic function to check that the response is success.
+ *
+ * When php decides to die with a fatal error, it still sends 200 OK
+ * status code. This assertion tries to catch that.
+ *
+ * @return null
+ */
+ public function assert_response_success()
+ {
+ $this->assertEquals(200, $this->client->getResponse()->getStatus());
+ $content = $this->client->getResponse()->getContent();
+ $this->assertNotContains('Fatal error:', $content);
+ }
}
diff --git a/tests/upload/fileupload_test.php b/tests/upload/fileupload_test.php
index 076855ab56..1665c493be 100644
--- a/tests/upload/fileupload_test.php
+++ b/tests/upload/fileupload_test.php
@@ -19,7 +19,8 @@ class phpbb_fileupload_test extends phpbb_test_case
{
// Global $config required by unique_id
// Global $user required by several functions dealing with translations
- global $config, $user;
+ // Global $request required by form_upload, local_upload and is_valid
+ global $config, $user, $request;
if (!is_array($config))
{
@@ -31,6 +32,9 @@ class phpbb_fileupload_test extends phpbb_test_case
$user = new phpbb_mock_user();
$user->lang = new phpbb_mock_lang();
+
+ $request = new phpbb_mock_request();
+
$this->path = __DIR__ . '/fixture/';
}