aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/controller/config/routing.yml3
-rw-r--r--tests/controller/config/services.yml3
-rw-r--r--tests/controller/controller_test.php76
-rw-r--r--tests/controller/ext/foo/config/routing.yml3
-rw-r--r--tests/controller/ext/foo/config/services.yml3
-rw-r--r--tests/controller/ext/foo/controller.php16
-rw-r--r--tests/controller/includes/controller/foo.php16
-rw-r--r--tests/fixtures/empty.xml5
-rw-r--r--tests/functional/extension_controller_test.php139
-rw-r--r--tests/functional/fixtures/ext/error/class/controller.php14
-rw-r--r--tests/functional/fixtures/ext/error/class/ext.php6
-rw-r--r--tests/functional/fixtures/ext/error/classtype/controller.php15
-rw-r--r--tests/functional/fixtures/ext/error/classtype/ext.php6
-rw-r--r--tests/functional/fixtures/ext/error/disabled/controller.php14
-rw-r--r--tests/functional/fixtures/ext/error/disabled/ext.php6
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/routing.yml15
-rw-r--r--tests/functional/fixtures/ext/foo/bar/config/services.yml6
-rw-r--r--tests/functional/fixtures/ext/foo/bar/controller.php14
-rw-r--r--tests/functional/fixtures/ext/foo/bar/controller/controller.php35
-rw-r--r--tests/functional/fixtures/ext/foo/bar/ext.php2
-rw-r--r--tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html (renamed from tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html)4
-rw-r--r--tests/functional/fixtures/ext/foobar/controller.php14
-rw-r--r--tests/functional/fixtures/ext/foobar/ext.php6
-rw-r--r--tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html5
-rw-r--r--tests/search/common_test_case.php106
-rw-r--r--tests/search/mysql_test.php40
-rw-r--r--tests/search/native_test.php52
-rw-r--r--tests/search/postgres_test.php40
-rw-r--r--tests/test_framework/phpbb_database_test_case.php16
-rw-r--r--tests/test_framework/phpbb_search_test_case.php29
30 files changed, 498 insertions, 211 deletions
diff --git a/tests/controller/config/routing.yml b/tests/controller/config/routing.yml
new file mode 100644
index 0000000000..175b11f130
--- /dev/null
+++ b/tests/controller/config/routing.yml
@@ -0,0 +1,3 @@
+core_controller:
+ pattern: /core_foo
+ defaults: { _controller: core_foo.controller:bar }
diff --git a/tests/controller/config/services.yml b/tests/controller/config/services.yml
new file mode 100644
index 0000000000..f1bd047489
--- /dev/null
+++ b/tests/controller/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ core_foo.controller:
+ class: phpbb_controller_foo
diff --git a/tests/controller/controller_test.php b/tests/controller/controller_test.php
new file mode 100644
index 0000000000..198fb3c6dd
--- /dev/null
+++ b/tests/controller/controller_test.php
@@ -0,0 +1,76 @@
+<?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\HttpFoundation\Request;
+use Symfony\Component\Routing\Route;
+use Symfony\Component\Routing\RouteCollection;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
+class phpbb_controller_test extends phpbb_test_case
+{
+ public function setUp()
+ {
+ $this->extension_manager = new phpbb_mock_extension_manager(
+ dirname(__FILE__) . '/',
+ array(
+ 'foo' => array(
+ 'ext_name' => 'foo',
+ 'ext_active' => '1',
+ 'ext_path' => 'ext/foo/',
+ ),
+ ));
+ }
+
+ public function test_provider()
+ {
+ $provider = new phpbb_controller_provider;
+ $routes = $provider
+ ->import_paths_from_finder($this->extension_manager->get_finder())
+ ->find('./tests/controller/');
+
+ // This will need to be updated if any new routes are defined
+ $this->assertEquals(2, sizeof($routes));
+ }
+
+ public function test_controller_resolver()
+ {
+ $container = new ContainerBuilder();
+ // YamlFileLoader only uses one path at a time, so we need to loop
+ // through all of the ones we are using.
+ foreach (array(__DIR__.'/config', __DIR__.'/ext/foo/config') as $path)
+ {
+ $loader = new YamlFileLoader($container, new FileLocator($path));
+ $loader->load('services.yml');
+ }
+
+ // Autoloading classes within the tests folder does not work
+ // so I'll include them manually.
+ if (!class_exists('phpbb_ext_foo_controller'))
+ {
+ include(__DIR__.'/ext/foo/controller.php');
+ }
+ if (!class_exists('phpbb_controller_foo'))
+ {
+ include(__DIR__.'/includes/controller/foo.php');
+ }
+
+ $resolver = new phpbb_controller_resolver(new phpbb_user, $container);
+ $symfony_request = new Request();
+ $symfony_request->attributes->set('_controller', 'foo.controller:handle');
+
+ $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_ext_foo_controller, 'handle'));
+
+ $symfony_request = new Request();
+ $symfony_request->attributes->set('_controller', 'core_foo.controller:bar');
+
+ $this->assertEquals($resolver->getController($symfony_request), array(new phpbb_controller_foo, 'bar'));
+ }
+}
diff --git a/tests/controller/ext/foo/config/routing.yml b/tests/controller/ext/foo/config/routing.yml
new file mode 100644
index 0000000000..4799fec37d
--- /dev/null
+++ b/tests/controller/ext/foo/config/routing.yml
@@ -0,0 +1,3 @@
+controller1:
+ pattern: /foo
+ defaults: { _controller: foo.controller:handle }
diff --git a/tests/controller/ext/foo/config/services.yml b/tests/controller/ext/foo/config/services.yml
new file mode 100644
index 0000000000..ce0e18c610
--- /dev/null
+++ b/tests/controller/ext/foo/config/services.yml
@@ -0,0 +1,3 @@
+services:
+ foo.controller:
+ class: phpbb_ext_foo_controller
diff --git a/tests/controller/ext/foo/controller.php b/tests/controller/ext/foo/controller.php
new file mode 100644
index 0000000000..cfc5c20622
--- /dev/null
+++ b/tests/controller/ext/foo/controller.php
@@ -0,0 +1,16 @@
+<?php
+
+use Symfony\Component\HttpFoundation\Response;
+
+class phpbb_ext_foo_controller
+{
+ /**
+ * Handle method
+ *
+ * @return null
+ */
+ public function handle()
+ {
+ return new Response('Test', 200);
+ }
+}
diff --git a/tests/controller/includes/controller/foo.php b/tests/controller/includes/controller/foo.php
new file mode 100644
index 0000000000..04576e16c4
--- /dev/null
+++ b/tests/controller/includes/controller/foo.php
@@ -0,0 +1,16 @@
+<?php
+
+use Symfony\Component\HttpFoundation\Response;
+
+class phpbb_controller_foo
+{
+ /**
+ * Bar method
+ *
+ * @return null
+ */
+ public function bar()
+ {
+ return new Response('bar()', 200);
+ }
+}
diff --git a/tests/fixtures/empty.xml b/tests/fixtures/empty.xml
new file mode 100644
index 0000000000..96eb1ab483
--- /dev/null
+++ b/tests/fixtures/empty.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<dataset>
+ <table name="phpbb_posts">
+ </table>
+</dataset>
diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php
index d92a830365..f28b321942 100644
--- a/tests/functional/extension_controller_test.php
+++ b/tests/functional/extension_controller_test.php
@@ -13,6 +13,14 @@
class phpbb_functional_extension_controller_test extends phpbb_functional_test_case
{
protected $phpbb_extension_manager;
+
+ static protected $fixtures = array(
+ 'foo/bar/config/routing.yml',
+ 'foo/bar/config/services.yml',
+ 'foo/bar/controller/controller.php',
+ 'foo/bar/styles/prosilver/template/foo_bar_body.html',
+ );
+
/**
* This should only be called once before the tests are run.
* This is used to copy the fixtures to the phpBB install
@@ -22,15 +30,11 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
global $phpbb_root_path;
parent::setUpBeforeClass();
- // these directories need to be created before the files can be copied
$directories = array(
- $phpbb_root_path . 'ext/error/class/',
- $phpbb_root_path . 'ext/error/classtype/',
- $phpbb_root_path . 'ext/error/disabled/',
$phpbb_root_path . 'ext/foo/bar/',
- $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template/',
- $phpbb_root_path . 'ext/foobar/',
- $phpbb_root_path . 'ext/foobar/styles/prosilver/template/',
+ $phpbb_root_path . 'ext/foo/bar/config/',
+ $phpbb_root_path . 'ext/foo/bar/controller/',
+ $phpbb_root_path . 'ext/foo/bar/styles/prosilver/template',
);
foreach ($directories as $dir)
@@ -41,28 +45,34 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
}
}
- $fixtures = array(
- 'error/class/controller.php',
- 'error/class/ext.php',
- 'error/classtype/controller.php',
- 'error/classtype/ext.php',
- 'error/disabled/controller.php',
- 'error/disabled/ext.php',
- 'foo/bar/controller.php',
- 'foo/bar/ext.php',
- 'foo/bar/styles/prosilver/template/foobar_body.html',
- 'foobar/controller.php',
- 'foobar/ext.php',
- 'foobar/styles/prosilver/template/foobar_body.html',
- );
+ foreach (self::$fixtures as $fixture)
+ {
+ copy(
+ "tests/functional/fixtures/ext/$fixture",
+ "{$phpbb_root_path}ext/$fixture");
+ }
+ }
+
+ /**
+ * This should only be called once after the tests are run.
+ * This is used to remove the fixtures from the phpBB install
+ */
+ static public function tearDownAfterClass()
+ {
+ global $phpbb_root_path;
- foreach ($fixtures as $fixture)
+ foreach (self::$fixtures as $fixture)
{
- if (!copy("tests/functional/fixtures/ext/$fixture", "{$phpbb_root_path}ext/$fixture"))
- {
- echo 'Could not copy file ' . $fixture;
- }
+ unlink("{$phpbb_root_path}ext/$fixture");
}
+
+ rmdir("{$phpbb_root_path}ext/foo/bar/config");
+ rmdir("{$phpbb_root_path}ext/foo/bar/controller");
+ rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver/template");
+ rmdir("{$phpbb_root_path}ext/foo/bar/styles/prosilver");
+ rmdir("{$phpbb_root_path}ext/foo/bar/styles");
+ rmdir("{$phpbb_root_path}ext/foo/bar");
+ rmdir("{$phpbb_root_path}ext/foo");
}
public function setUp()
@@ -75,72 +85,67 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
}
/**
- * Check an extension at ./ext/foobar/ which should have the class
- * phpbb_ext_foobar_controller
- */
- public function test_foobar()
- {
- $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');
- }
-
- /**
- * Check an extension at ./ext/foo/bar/ which should have the class
- * phpbb_ext_foo_bar_controller
+ * Check a controller for extension foo/bar.
*/
public function test_foo_bar()
{
$this->phpbb_extension_manager->enable('foo/bar');
- $crawler = $this->request('GET', 'index.php?ext=foo/bar');
+ $crawler = $this->request('GET', 'app.php?controller=foo/bar');
$this->assert_response_success();
- $this->assertContains("This is for testing purposes.", $crawler->filter('#page-body')->text());
+ $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
$this->phpbb_extension_manager->purge('foo/bar');
}
/**
- * Check the error produced by extension at ./ext/error/class which has class
- * phpbb_ext_foobar_controller
+ * Check the output of a controller using the template system
*/
- public function test_error_class_name()
+ public function test_controller_with_template()
{
- $this->phpbb_extension_manager->enable('error/class');
- $crawler = $this->request('GET', 'index.php?ext=error/class');
- $this->assertContains("The extension error/class is missing a controller class and cannot be accessed through the front-end.", $crawler->filter('#message')->text());
- $this->phpbb_extension_manager->purge('error/class');
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = $this->request('GET', 'app.php?controller=foo/template');
+ $this->assert_response_success();
+ $this->assertContains("I am a variable", $crawler->filter('#content')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
}
/**
- * Check the error produced by extension at ./ext/error/classtype which has class
- * phpbb_ext_error_classtype_controller but does not implement phpbb_extension_controller_interface
+ * Check the error produced by calling a controller without a required
+ * argument.
*/
- public function test_error_class_type()
+ public function test_missing_argument()
{
- $this->phpbb_extension_manager->enable('error/classtype');
- $crawler = $this->request('GET', 'index.php?ext=error/classtype');
- $this->assertContains("The extension controller class phpbb_ext_error_classtype_controller is not an instance of the phpbb_extension_controller_interface.", $crawler->filter('#message')->text());
- $this->phpbb_extension_manager->purge('error/classtype');
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = $this->request('GET', 'app.php?controller=foo/baz');
+ $this->assertEquals(500, $this->client->getResponse()->getStatus());
+ $this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
}
/**
- * Check the error produced by extension at ./ext/error/disabled that is (obviously)
- * a disabled extension
+ * Check the status code resulting from an exception thrown by a controller
*/
- public function test_error_ext_disabled()
+ public function test_exception_should_result_in_500_status_code()
{
- $crawler = $this->request('GET', 'index.php?ext=error/disabled');
- $this->assertContains("The extension error/disabled is not enabled", $crawler->filter('#message')->text());
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = $this->request('GET', 'app.php?controller=foo/exception');
+ $this->assertEquals(500, $this->client->getResponse()->getStatus());
+ $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
}
/**
- * Check the error produced by extension at ./ext/error/404 that is (obviously)
- * not existant
+ * Check the error produced by extension at ./ext/does/not/exist.
+ *
+ * If an extension is disabled, its routes are not loaded. Because we
+ * are not looking for a controller based on a specified extension,
+ * we don't know the difference between a route in a disabled
+ * extension and a route that is not defined anyway; it is the same
+ * error message.
*/
- public function test_error_ext_missing()
+ public function test_error_ext_disabled_or_404()
{
- $crawler = $this->request('GET', 'index.php?ext=error/404');
- $this->assertContains("The extension error/404 does not exist.", $crawler->filter('#message')->text());
+ $crawler = $this->request('GET', 'app.php?controller=does/not/exist');
+ $this->assertEquals(404, $this->client->getResponse()->getStatus());
+ $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
}
}
diff --git a/tests/functional/fixtures/ext/error/class/controller.php b/tests/functional/fixtures/ext/error/class/controller.php
deleted file mode 100644
index 74bbbee540..0000000000
--- a/tests/functional/fixtures/ext/error/class/controller.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-class phpbb_ext_foobar_controller extends phpbb_extension_controller
-{
- public function handle()
- {
- $this->template->set_filenames(array(
- 'body' => 'index_body.html'
- ));
-
- page_header('Test extension');
- page_footer();
- }
-}
diff --git a/tests/functional/fixtures/ext/error/class/ext.php b/tests/functional/fixtures/ext/error/class/ext.php
deleted file mode 100644
index f97ad2b838..0000000000
--- a/tests/functional/fixtures/ext/error/class/ext.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-class phpbb_ext_error_class_ext extends phpbb_extension_base
-{
-
-}
diff --git a/tests/functional/fixtures/ext/error/classtype/controller.php b/tests/functional/fixtures/ext/error/classtype/controller.php
deleted file mode 100644
index 55ac651bdf..0000000000
--- a/tests/functional/fixtures/ext/error/classtype/controller.php
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-
-class phpbb_ext_error_classtype_controller
-{
- public function handle()
- {
- global $template;
- $template->set_filenames(array(
- 'body' => 'index_body.html'
- ));
-
- page_header('Test extension');
- page_footer();
- }
-}
diff --git a/tests/functional/fixtures/ext/error/classtype/ext.php b/tests/functional/fixtures/ext/error/classtype/ext.php
deleted file mode 100644
index 35b1cd15a2..0000000000
--- a/tests/functional/fixtures/ext/error/classtype/ext.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-class phpbb_ext_error_classtype_ext extends phpbb_extension_base
-{
-
-}
diff --git a/tests/functional/fixtures/ext/error/disabled/controller.php b/tests/functional/fixtures/ext/error/disabled/controller.php
deleted file mode 100644
index 57b913f377..0000000000
--- a/tests/functional/fixtures/ext/error/disabled/controller.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-class phpbb_ext_error_disabled_controller extends phpbb_extension_controller
-{
- public function handle()
- {
- $this->template->set_filenames(array(
- 'body' => 'index_body.html'
- ));
-
- page_header('Test extension');
- page_footer();
- }
-}
diff --git a/tests/functional/fixtures/ext/error/disabled/ext.php b/tests/functional/fixtures/ext/error/disabled/ext.php
deleted file mode 100644
index aec8051848..0000000000
--- a/tests/functional/fixtures/ext/error/disabled/ext.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-class phpbb_ext_error_disabled_ext extends phpbb_extension_base
-{
-
-}
diff --git a/tests/functional/fixtures/ext/foo/bar/config/routing.yml b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
new file mode 100644
index 0000000000..09a30a8c67
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/config/routing.yml
@@ -0,0 +1,15 @@
+foo_bar_controller:
+ pattern: /foo/bar
+ defaults: { _controller: foo_bar.controller:handle }
+
+foo_baz_controller:
+ pattern: /foo/baz
+ defaults: { _controller: foo_bar.controller:baz }
+
+foo_template_controller:
+ pattern: /foo/template
+ defaults: { _controller: foo_bar.controller:template }
+
+foo_exception_controller:
+ pattern: /foo/exception
+ defaults: { _controller: foo_bar.controller:exception }
diff --git a/tests/functional/fixtures/ext/foo/bar/config/services.yml b/tests/functional/fixtures/ext/foo/bar/config/services.yml
new file mode 100644
index 0000000000..33ced55af9
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/config/services.yml
@@ -0,0 +1,6 @@
+services:
+ foo_bar.controller:
+ class: phpbb_ext_foo_bar_controller
+ arguments:
+ - @controller.helper
+ - @template
diff --git a/tests/functional/fixtures/ext/foo/bar/controller.php b/tests/functional/fixtures/ext/foo/bar/controller.php
deleted file mode 100644
index 3375e317b3..0000000000
--- a/tests/functional/fixtures/ext/foo/bar/controller.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-class phpbb_ext_foo_bar_controller extends phpbb_extension_controller
-{
- public function handle()
- {
- $this->template->set_filenames(array(
- 'body' => 'foobar_body.html'
- ));
-
- page_header('Test extension');
- page_footer();
- }
-}
diff --git a/tests/functional/fixtures/ext/foo/bar/controller/controller.php b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
new file mode 100644
index 0000000000..5a91b5f681
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/controller/controller.php
@@ -0,0 +1,35 @@
+<?php
+use Symfony\Component\HttpFoundation\Response;
+
+class phpbb_ext_foo_bar_controller
+{
+ protected $template;
+
+ public function __construct(phpbb_controller_helper $helper, phpbb_template $template)
+ {
+ $this->template = $template;
+ $this->helper = $helper;
+ }
+
+ public function handle()
+ {
+ return new Response('foo/bar controller handle() method', 200);
+ }
+
+ public function baz($test)
+ {
+ return new Response('Value of "test" URL argument is: ' . $test);
+ }
+
+ public function template()
+ {
+ $this->template->assign_var('A_VARIABLE', 'I am a variable');
+
+ return $this->helper->render('foo_bar_body.html');
+ }
+
+ public function exception()
+ {
+ throw new phpbb_controller_exception('Exception thrown from foo/exception route');
+ }
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/ext.php b/tests/functional/fixtures/ext/foo/bar/ext.php
index 3a2068631e..74359d51ab 100644
--- a/tests/functional/fixtures/ext/foo/bar/ext.php
+++ b/tests/functional/fixtures/ext/foo/bar/ext.php
@@ -2,5 +2,5 @@
class phpbb_ext_foo_bar_ext extends phpbb_extension_base
{
-
+
}
diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
index 4addf2666f..8fb6994d3d 100644
--- a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foobar_body.html
+++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
@@ -1,5 +1,3 @@
<!-- INCLUDE overall_header.html -->
-
-<div id="welcome">This is for testing purposes.</div>
-
+<div id="content">{A_VARIABLE}</div>
<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/ext/foobar/controller.php b/tests/functional/fixtures/ext/foobar/controller.php
deleted file mode 100644
index ff35f12ee0..0000000000
--- a/tests/functional/fixtures/ext/foobar/controller.php
+++ /dev/null
@@ -1,14 +0,0 @@
-<?php
-
-class phpbb_ext_foobar_controller extends phpbb_extension_controller
-{
- public function handle()
- {
- $this->template->set_filenames(array(
- 'body' => 'foobar_body.html'
- ));
-
- page_header('Test extension');
- page_footer();
- }
-}
diff --git a/tests/functional/fixtures/ext/foobar/ext.php b/tests/functional/fixtures/ext/foobar/ext.php
deleted file mode 100644
index 7cf443d369..0000000000
--- a/tests/functional/fixtures/ext/foobar/ext.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
-
-class phpbb_ext_foobar_ext extends phpbb_extension_base
-{
-
-}
diff --git a/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html b/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html
deleted file mode 100644
index 4addf2666f..0000000000
--- a/tests/functional/fixtures/ext/foobar/styles/prosilver/template/foobar_body.html
+++ /dev/null
@@ -1,5 +0,0 @@
-<!-- INCLUDE overall_header.html -->
-
-<div id="welcome">This is for testing purposes.</div>
-
-<!-- INCLUDE overall_footer.html -->
diff --git a/tests/search/common_test_case.php b/tests/search/common_test_case.php
new file mode 100644
index 0000000000..dd04f7048c
--- /dev/null
+++ b/tests/search/common_test_case.php
@@ -0,0 +1,106 @@
+<?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__) . '/../test_framework/phpbb_search_test_case.php';
+
+abstract class phpbb_search_common_test_case extends phpbb_search_test_case
+{
+ public function keywords()
+ {
+ return array(
+ // keywords
+ // terms
+ // ok
+ // split words
+ // common words
+ array(
+ 'fooo',
+ 'all',
+ true,
+ array('fooo'),
+ array(),
+ ),
+ array(
+ 'fooo baar',
+ 'all',
+ true,
+ array('fooo', 'baar'),
+ array(),
+ ),
+ // leading, trailing and multiple spaces
+ array(
+ ' fooo baar ',
+ 'all',
+ true,
+ array('fooo', 'baar'),
+ array(),
+ ),
+ // words too short
+ array(
+ 'f',
+ 'all',
+ false,
+ null,
+ // short words count as "common" words
+ array('f'),
+ ),
+ array(
+ 'f o o',
+ 'all',
+ false,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
+ 'f -o -o',
+ 'all',
+ false,
+ null,
+ array('f', '-o', '-o'),
+ ),
+ array(
+ 'fooo -baar',
+ 'all',
+ true,
+ array('-baar', 'fooo'),
+ array(),
+ ),
+ // all negative
+ array(
+ '-fooo',
+ 'all',
+ true,
+ array('-fooo'),
+ array(),
+ ),
+ array(
+ '-fooo -baar',
+ 'all',
+ true,
+ array('-fooo', '-baar'),
+ array(),
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider keywords
+ */
+ public function test_split_keywords($keywords, $terms, $ok, $split_words, $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($split_words, $this->search->get_split_words());
+ }
+ $this->assert_array_content_equals($common, $this->search->get_common_words());
+ }
+}
diff --git a/tests/search/mysql_test.php b/tests/search/mysql_test.php
new file mode 100644
index 0000000000..3ba3915714
--- /dev/null
+++ b/tests/search/mysql_test.php
@@ -0,0 +1,40 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_search_mysql_test extends phpbb_search_common_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_cache_service(new phpbb_cache_driver_null);
+
+ // set config values
+ $config['fulltext_mysql_min_word_len'] = 4;
+ $config['fulltext_mysql_max_word_len'] = 254;
+
+ $this->db = $this->new_dbal();
+ $error = null;
+ $class = self::get_search_wrapper('phpbb_search_fulltext_mysql');
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
+ }
+}
diff --git a/tests/search/native_test.php b/tests/search/native_test.php
index 66972079cf..eeee3a44f3 100644
--- a/tests/search/native_test.php
+++ b/tests/search/native_test.php
@@ -7,24 +7,9 @@
*
*/
-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;
-}
+require_once dirname(__FILE__) . '/../test_framework/phpbb_search_test_case.php';
-class phpbb_search_native_test extends phpbb_database_test_case
+class phpbb_search_native_test extends phpbb_search_test_case
{
protected $db;
protected $search;
@@ -41,19 +26,14 @@ class phpbb_search_native_test extends phpbb_database_test_case
parent::setUp();
// dbal uses cache
- $cache = new phpbb_cache_driver_null;
+ $cache = new phpbb_cache_service(new phpbb_cache_driver_null);
$this->db = $this->new_dbal();
$error = null;
- $class = phpbb_search_wrapper('phpbb_search_fulltext_native');
+ $class = self::get_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(
@@ -107,6 +87,14 @@ class phpbb_search_native_test extends phpbb_database_test_case
array('f', 'o', 'o'),
),
array(
+ 'f -o -o',
+ 'all',
+ false,
+ null,
+ null,
+ array('f', 'o', 'o'),
+ ),
+ array(
'foo -bar',
'all',
true,
@@ -167,20 +155,4 @@ class phpbb_search_native_test extends phpbb_database_test_case
}
$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/search/postgres_test.php b/tests/search/postgres_test.php
new file mode 100644
index 0000000000..9c77e0c09e
--- /dev/null
+++ b/tests/search/postgres_test.php
@@ -0,0 +1,40 @@
+<?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__) . '/common_test_case.php';
+
+class phpbb_search_postgres_test extends phpbb_search_common_test_case
+{
+ protected $db;
+ protected $search;
+
+ public function getDataSet()
+ {
+ return $this->createXMLDataSet(dirname(__FILE__) . '/../fixtures/empty.xml');
+ }
+
+ protected function setUp()
+ {
+ global $phpbb_root_path, $phpEx, $config, $user, $cache;
+
+ parent::setUp();
+
+ // dbal uses cache
+ $cache = new phpbb_cache_service(new phpbb_cache_driver_null);
+
+ // set config values
+ $config['fulltext_postgres_min_word_len'] = 4;
+ $config['fulltext_postgres_max_word_len'] = 254;
+
+ $this->db = $this->new_dbal();
+ $error = null;
+ $class = self::get_search_wrapper('phpbb_search_fulltext_postgres');
+ $this->search = new $class($error, $phpbb_root_path, $phpEx, null, $config, $this->db, $user);
+ }
+}
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index 75a3c0944b..514619687a 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -141,4 +141,20 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
{
return $matches[1] . strtoupper($matches[2]) . $matches[3];
}
+
+ 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/test_framework/phpbb_search_test_case.php b/tests/test_framework/phpbb_search_test_case.php
new file mode 100644
index 0000000000..418d352c17
--- /dev/null
+++ b/tests/test_framework/phpbb_search_test_case.php
@@ -0,0 +1,29 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2012 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+abstract class phpbb_search_test_case extends phpbb_database_test_case
+{
+ static protected function get_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; }
+ public function get_split_words() { return \$this->split_words; }
+}
+ ";
+ eval($code);
+ }
+ return $wrapped;
+ }
+}