aboutsummaryrefslogtreecommitdiffstats
path: root/tests/functional
diff options
context:
space:
mode:
Diffstat (limited to 'tests/functional')
-rw-r--r--tests/functional/acp_permissions_test.php128
-rw-r--r--tests/functional/auth_test.php11
-rw-r--r--tests/functional/extension_controller_test.php151
-rw-r--r--tests/functional/fileupload_form_test.php74
-rw-r--r--tests/functional/fileupload_remote_test.php72
-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/controller.php35
-rw-r--r--tests/functional/fixtures/ext/foo/bar/ext.php6
-rw-r--r--tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html3
-rw-r--r--tests/functional/fixtures/files/empty.png0
-rw-r--r--tests/functional/fixtures/files/illegal-extension.bifbin0 -> 519 bytes
-rw-r--r--tests/functional/fixtures/files/too-large.pngbin0 -> 284717 bytes
-rw-r--r--tests/functional/fixtures/files/valid.jpgbin0 -> 554 bytes
-rw-r--r--tests/functional/memberlist_test.php43
15 files changed, 544 insertions, 0 deletions
diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php
new file mode 100644
index 0000000000..f7fd44fc89
--- /dev/null
+++ b/tests/functional/acp_permissions_test.php
@@ -0,0 +1,128 @@
+<?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_acp_permissions_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+
+ $this->login();
+ $this->admin_login();
+ $this->add_lang('acp/permissions');
+ }
+
+ public function test_permissions_tab()
+ {
+ // Permissions tab
+ // XXX hardcoded id
+ $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid);
+ $this->assert_response_success();
+ // these language strings are html
+ $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
+ }
+
+ public function test_select_user()
+ {
+ // User permissions
+ $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent());
+
+ // Select admin
+ $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
+ $data = array('username[0]' => 'admin');
+ $form->setValues($data);
+ $crawler = $this->client->submit($form);
+ $this->assert_response_success();
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+ }
+
+ public function permissions_data()
+ {
+ return array(
+ // description
+ // permission type
+ // permission name
+ // mode
+ // object name
+ // object id
+ array(
+ 'user permission',
+ 'u_',
+ 'u_hideonline',
+ 'setting_user_global',
+ 'user_id',
+ 2,
+ ),
+ array(
+ 'moderator permission',
+ 'm_',
+ 'm_ban',
+ 'setting_mod_global',
+ 'group_id',
+ 4,
+ ),
+ /* Admin does not work yet, probably because founder can do everything
+ array(
+ 'admin permission',
+ 'a_',
+ 'a_forum',
+ 'setting_admin_global',
+ 'group_id',
+ 5,
+ ),
+ */
+ );
+ }
+
+ /**
+ * @dataProvider permissions_data
+ */
+ public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id)
+ {
+ // Get the form
+ $crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
+
+ // XXX globals for phpbb_auth, refactor it later
+ global $db, $cache;
+ $db = $this->get_db();
+ $cache = new phpbb_mock_null_cache;
+
+ $auth = new phpbb_auth;
+ // XXX hardcoded id
+ $user_data = $auth->obtain_user_data(2);
+ $auth->acl($user_data);
+ $this->assertEquals(1, $auth->acl_get($permission));
+
+ // Set u_hideonline to never
+ $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form();
+ // initially it should be a yes
+ $values = $form->getValues();
+ $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]);
+ // set to never
+ $data = array("setting[$object_id][0][$permission]" => '0');
+ $form->setValues($data);
+ $crawler = $this->client->submit($form);
+ $this->assert_response_success();
+ $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text());
+
+ // check acl again
+ $auth = new phpbb_auth;
+ // XXX hardcoded id
+ $user_data = $auth->obtain_user_data(2);
+ $auth->acl($user_data);
+ $this->assertEquals(0, $auth->acl_get($permission));
+ }
+}
diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php
index 662b1bd38b..f92a4a2210 100644
--- a/tests/functional/auth_test.php
+++ b/tests/functional/auth_test.php
@@ -49,4 +49,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->assert_response_success();
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
}
+
+ public function test_acp_login()
+ {
+ $this->login();
+ $this->admin_login();
+
+ // check that we are logged in
+ $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
+ }
}
diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php
new file mode 100644
index 0000000000..f28b321942
--- /dev/null
+++ b/tests/functional/extension_controller_test.php
@@ -0,0 +1,151 @@
+<?php
+/**
+*
+* @package testing
+* @copyright (c) 2011 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @group functional
+*/
+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
+ */
+ static public function setUpBeforeClass()
+ {
+ global $phpbb_root_path;
+ parent::setUpBeforeClass();
+
+ $directories = array(
+ $phpbb_root_path . 'ext/foo/bar/',
+ $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)
+ {
+ if (!is_dir($dir))
+ {
+ mkdir($dir, 0777, true);
+ }
+ }
+
+ 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 (self::$fixtures as $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()
+ {
+ parent::setUp();
+
+ $this->phpbb_extension_manager = $this->get_extension_manager();
+
+ $this->purge_cache();
+ }
+
+ /**
+ * Check a controller for extension foo/bar.
+ */
+ public function test_foo_bar()
+ {
+ $this->phpbb_extension_manager->enable('foo/bar');
+ $crawler = $this->request('GET', 'app.php?controller=foo/bar');
+ $this->assert_response_success();
+ $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
+ $this->phpbb_extension_manager->purge('foo/bar');
+ }
+
+ /**
+ * Check the output of a controller using the template system
+ */
+ public function test_controller_with_template()
+ {
+ $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 calling a controller without a required
+ * argument.
+ */
+ public function test_missing_argument()
+ {
+ $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 status code resulting from an exception thrown by a controller
+ */
+ public function test_exception_should_result_in_500_status_code()
+ {
+ $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/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_disabled_or_404()
+ {
+ $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/fileupload_form_test.php b/tests/functional/fileupload_form_test.php
new file mode 100644
index 0000000000..b663c89e95
--- /dev/null
+++ b/tests/functional/fileupload_form_test.php
@@ -0,0 +1,74 @@
+<?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_fileupload_form_test extends phpbb_functional_test_case
+{
+ private $path;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->path = __DIR__ . '/fixtures/files/';
+ $this->add_lang('posting');
+ $this->login();
+ }
+
+ private function upload_file($filename, $mimetype)
+ {
+ $file = array(
+ 'tmp_name' => $this->path . $filename,
+ 'name' => $filename,
+ 'type' => $mimetype,
+ 'size' => filesize($this->path . $filename),
+ 'error' => UPLOAD_ERR_OK,
+ );
+
+ $crawler = $this->client->request(
+ 'POST',
+ 'posting.php?mode=reply&f=2&t=1&sid=' . $this->sid,
+ array('add_file' => $this->lang('ADD_FILE')),
+ array('fileupload' => $file)
+ );
+
+ return $crawler;
+ }
+
+ public function test_empty_file()
+ {
+ $this->markTestIncomplete('Test fails intermittently.');
+ $crawler = $this->upload_file('empty.png', 'image/png');
+ $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text());
+ }
+
+ public function test_invalid_extension()
+ {
+ $crawler = $this->upload_file('illegal-extension.bif', 'application/octet-stream');
+ $this->assertEquals($this->lang('DISALLOWED_EXTENSION', 'bif'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_too_large()
+ {
+ $this->markTestIncomplete('Functional tests use an admin account which ignores maximum upload size.');
+ $crawler = $this->upload_file('too-large.png', 'image/png');
+ $this->assertEquals($this->lang('WRONG_FILESIZE', '256', 'KiB'), $crawler->filter('p.error')->text());
+ }
+
+ public function test_valid_file()
+ {
+ $this->markTestIncomplete('Test fails intermittently.');
+ $crawler = $this->upload_file('valid.jpg', 'image/jpeg');
+ $this->assert_response_success();
+ // ensure there was no error message rendered
+ $this->assertNotContains('<h2>' . $this->lang('INFORMATION') . '</h2>', $this->client->getResponse()->getContent());
+ $this->assertContains($this->lang('POSTED_ATTACHMENTS'), $crawler->filter('#postform h3')->eq(1)->text());
+ }
+}
diff --git a/tests/functional/fileupload_remote_test.php b/tests/functional/fileupload_remote_test.php
new file mode 100644
index 0000000000..0deb79acf6
--- /dev/null
+++ b/tests/functional/fileupload_remote_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
+ *
+ */
+
+/**
+ * @group functional
+ */
+class phpbb_functional_fileupload_remote_test extends phpbb_functional_test_case
+{
+ public function setUp()
+ {
+ parent::setUp();
+ // Only doing this within the functional framework because we need a
+ // URL
+
+ // Global $config required by unique_id
+ // Global $user required by fileupload::remote_upload
+ global $config, $user;
+
+ if (!is_array($config))
+ {
+ $config = array();
+ }
+
+ $config['rand_seed'] = '';
+ $config['rand_seed_last_update'] = time() + 600;
+
+ $user = new phpbb_mock_user();
+ $user->lang = new phpbb_mock_lang();
+ }
+
+ public function tearDown()
+ {
+ global $config, $user;
+ $user = null;
+ $config = array();
+ }
+
+ public function test_invalid_extension()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload('http://example.com/image.gif');
+ $this->assertEquals('URL_INVALID', $file->error[0]);
+ }
+
+ public function test_non_existant()
+ {
+ $upload = new fileupload('', array('jpg'), 100);
+ $file = $upload->remote_upload('http://example.com/image.jpg');
+ $this->assertEquals('EMPTY_REMOTE_DATA', $file->error[0]);
+ }
+
+ public function test_successful_upload()
+ {
+ $upload = new fileupload('', array('gif'), 1000);
+ $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals(0, sizeof($file->error));
+ $this->assertTrue(file_exists($file->filename));
+ }
+
+ public function test_too_large()
+ {
+ $upload = new fileupload('', array('gif'), 100);
+ $file = $upload->remote_upload($this->root_url . 'styles/prosilver/theme/images/forum_read.gif');
+ $this->assertEquals('WRONG_FILESIZE', $file->error[0]);
+ }
+}
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/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
new file mode 100644
index 0000000000..74359d51ab
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/ext.php
@@ -0,0 +1,6 @@
+<?php
+
+class phpbb_ext_foo_bar_ext extends phpbb_extension_base
+{
+
+}
diff --git a/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
new file mode 100644
index 0000000000..8fb6994d3d
--- /dev/null
+++ b/tests/functional/fixtures/ext/foo/bar/styles/prosilver/template/foo_bar_body.html
@@ -0,0 +1,3 @@
+<!-- INCLUDE overall_header.html -->
+<div id="content">{A_VARIABLE}</div>
+<!-- INCLUDE overall_footer.html -->
diff --git a/tests/functional/fixtures/files/empty.png b/tests/functional/fixtures/files/empty.png
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/functional/fixtures/files/empty.png
diff --git a/tests/functional/fixtures/files/illegal-extension.bif b/tests/functional/fixtures/files/illegal-extension.bif
new file mode 100644
index 0000000000..3cd5038e38
--- /dev/null
+++ b/tests/functional/fixtures/files/illegal-extension.bif
Binary files differ
diff --git a/tests/functional/fixtures/files/too-large.png b/tests/functional/fixtures/files/too-large.png
new file mode 100644
index 0000000000..ed4b0abd80
--- /dev/null
+++ b/tests/functional/fixtures/files/too-large.png
Binary files differ
diff --git a/tests/functional/fixtures/files/valid.jpg b/tests/functional/fixtures/files/valid.jpg
new file mode 100644
index 0000000000..95a87ddbdf
--- /dev/null
+++ b/tests/functional/fixtures/files/valid.jpg
Binary files differ
diff --git a/tests/functional/memberlist_test.php b/tests/functional/memberlist_test.php
new file mode 100644
index 0000000000..879bee2f0e
--- /dev/null
+++ b/tests/functional/memberlist_test.php
@@ -0,0 +1,43 @@
+<?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_memberlist_test extends phpbb_functional_test_case
+{
+ public function test_memberlist()
+ {
+ $this->create_user('memberlist-test-user');
+ // logs in as admin
+ $this->login();
+ $crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains('memberlist-test-user', $crawler->text());
+
+ // restrict by first character
+ $crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains('memberlist-test-user', $crawler->text());
+
+ // make sure results for wrong character are not returned
+ $crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertNotContains('memberlist-test-user', $crawler->text());
+ }
+
+ public function test_viewprofile()
+ {
+ $this->login();
+ // XXX hardcoded user id
+ $crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
+ $this->assert_response_success();
+ $this->assertContains('admin', $crawler->filter('h2')->text());
+ }
+}