Merge branch 'ticket/11568' into ticket/11568-develop

* ticket/11568:
  [ticket/11568] Split status code and html debug assertion into two methods
  [ticket/11568] Add comma at end of array key-value couple
  [ticket/11568] Invert logic for asserting the response
  [ticket/11568] Use static calls for static methods

Conflicts:
	tests/test_framework/phpbb_functional_test_case.php
This commit is contained in:
Joas Schilling 2013-05-31 16:45:06 +02:00
commit 8c4670eeb1
13 changed files with 94 additions and 81 deletions

View file

@ -25,7 +25,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
{ {
// Permissions tab // Permissions tab
// XXX hardcoded id // XXX hardcoded id
$crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=16&sid=' . $this->sid);
// these language strings are html // these language strings are html
$this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content()); $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->get_content());
} }
@ -33,14 +33,14 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
public function test_select_user() public function test_select_user()
{ {
// User permissions // User permissions
$crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
$this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content()); $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->get_content());
// Select admin // Select admin
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$data = array('username[0]' => 'admin'); $data = array('username[0]' => 'admin');
$form->setValues($data); $form->setValues($data);
$crawler = $this->submit($form); $crawler = self::submit($form);
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
} }
@ -88,7 +88,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id) public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id)
{ {
// Get the form // 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); $crawler = self::request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid);
$this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text());
// XXX globals for phpbb_auth, refactor it later // XXX globals for phpbb_auth, refactor it later
@ -110,7 +110,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case
// set to never // set to never
$data = array("setting[$object_id][0][$permission]" => '0'); $data = array("setting[$object_id][0][$permission]" => '0');
$form->setValues($data); $form->setValues($data);
$crawler = $this->submit($form); $crawler = self::submit($form);
$this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text());
// check acl again // check acl again

View file

@ -17,7 +17,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->login(); $this->login();
// check for logout link // check for logout link
$crawler = $this->request('GET', 'index.php'); $crawler = self::request('GET', 'index.php');
$this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
} }
@ -25,7 +25,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
{ {
$this->create_user('anothertestuser'); $this->create_user('anothertestuser');
$this->login('anothertestuser'); $this->login('anothertestuser');
$crawler = $this->request('GET', 'index.php'); $crawler = self::request('GET', 'index.php');
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
} }
@ -38,11 +38,11 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->add_lang('ucp'); $this->add_lang('ucp');
// logout // logout
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
// look for a register link, which should be visible only when logged out // look for a register link, which should be visible only when logged out
$crawler = $this->request('GET', 'index.php'); $crawler = self::request('GET', 'index.php');
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
} }
@ -52,7 +52,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
$this->admin_login(); $this->admin_login();
// check that we are logged in // check that we are logged in
$crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
$this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text());
} }
} }

View file

@ -14,19 +14,19 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
{ {
public function test_index() public function test_index()
{ {
$crawler = $this->request('GET', 'index.php'); $crawler = self::request('GET', 'index.php');
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
} }
public function test_viewforum() public function test_viewforum()
{ {
$crawler = $this->request('GET', 'viewforum.php?f=2'); $crawler = self::request('GET', 'viewforum.php?f=2');
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
} }
public function test_viewtopic() public function test_viewtopic()
{ {
$crawler = $this->request('GET', 'viewtopic.php?t=1'); $crawler = self::request('GET', 'viewtopic.php?t=1');
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
} }
} }

View file

@ -41,10 +41,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
$this->add_lang(array('ucp', 'acp/groups')); $this->add_lang(array('ucp', 'acp/groups'));
// Manage Administrators group // Manage Administrators group
$crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid);
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['group_colour']->setValue($input); $form['group_colour']->setValue($input);
$crawler = $this->submit($form); $crawler = self::submit($form);
$this->assertContains($this->lang($expected), $crawler->text()); $this->assertContains($this->lang($expected), $crawler->text());
} }
} }

View file

@ -109,7 +109,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
public function test_list() public function test_list()
{ {
$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
$this->assertCount(1, $crawler->filter('.ext_enabled')); $this->assertCount(1, $crawler->filter('.ext_enabled'));
$this->assertCount(5, $crawler->filter('.ext_disabled')); $this->assertCount(5, $crawler->filter('.ext_disabled'));
@ -131,7 +131,7 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
public function test_details() public function test_details()
{ {
$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid);
$validation = array( $validation = array(
'DISPLAY_NAME' => 'phpBB Foo Extension', 'DISPLAY_NAME' => 'phpBB Foo Extension',
@ -174,46 +174,46 @@ class phpbb_functional_extension_acp_test extends phpbb_functional_test_case
public function test_enable_pre() public function test_enable_pre()
{ {
// Foo is already enabled (redirect to list) // 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); $crawler = self::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_NAME', $crawler->filter('html')->text());
$this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
$this->assertContainsLang('EXTENSION_ACTIONS', $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); $crawler = self::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()); $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text());
} }
public function test_disable_pre() public function test_disable_pre()
{ {
// Moo is not enabled (redirect to list) // 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); $crawler = self::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_NAME', $crawler->filter('html')->text());
$this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text());
$this->assertContainsLang('EXTENSION_ACTIONS', $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); $crawler = self::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()); $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text());
} }
public function test_purge_pre() public function test_purge_pre()
{ {
// test2 is not available (error) // 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); $crawler = self::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()); $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); $crawler = self::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()); $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text());
} }
public function test_actions() 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); $crawler = self::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()); $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); $crawler = self::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()); $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); $crawler = self::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()); $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text());
} }
} }

View file

@ -6,6 +6,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
* *
*/ */
require_once dirname(__FILE__) . '/../../phpBB/includes/db/db_tools.php';
/** /**
* @group functional * @group functional
@ -90,7 +91,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
public function test_foo_bar() public function test_foo_bar()
{ {
$this->phpbb_extension_manager->enable('foo/bar'); $this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'app.php?controller=foo/bar'); $crawler = self::request('GET', 'app.php?controller=foo/bar', array(), false);
self::assert_response_status_code();
$this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text()); $this->assertContains("foo/bar controller handle() method", $crawler->filter('body')->text());
$this->phpbb_extension_manager->purge('foo/bar'); $this->phpbb_extension_manager->purge('foo/bar');
} }
@ -101,7 +103,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
public function test_controller_with_template() public function test_controller_with_template()
{ {
$this->phpbb_extension_manager->enable('foo/bar'); $this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'app.php?controller=foo/template'); $crawler = self::request('GET', 'app.php?controller=foo/template');
$this->assertContains("I am a variable", $crawler->filter('#content')->text()); $this->assertContains("I am a variable", $crawler->filter('#content')->text());
$this->phpbb_extension_manager->purge('foo/bar'); $this->phpbb_extension_manager->purge('foo/bar');
} }
@ -113,8 +115,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
public function test_missing_argument() public function test_missing_argument()
{ {
$this->phpbb_extension_manager->enable('foo/bar'); $this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'app.php?controller=foo/baz', array(), true); $crawler = self::request('GET', 'app.php?controller=foo/baz', array(), false);
$this->assert_response_success(500); $this->assert_response_html(500);
$this->assertContains('Missing value for argument #1: test in class phpbb_ext_foo_bar_controller:baz', $crawler->filter('body')->text()); $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'); $this->phpbb_extension_manager->purge('foo/bar');
} }
@ -125,8 +127,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
public function test_exception_should_result_in_500_status_code() public function test_exception_should_result_in_500_status_code()
{ {
$this->phpbb_extension_manager->enable('foo/bar'); $this->phpbb_extension_manager->enable('foo/bar');
$crawler = $this->request('GET', 'app.php?controller=foo/exception', array(), true); $crawler = self::request('GET', 'app.php?controller=foo/exception', array(), false);
$this->assert_response_success(500); $this->assert_response_html(500);
$this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text()); $this->assertContains('Exception thrown from foo/exception route', $crawler->filter('body')->text());
$this->phpbb_extension_manager->purge('foo/bar'); $this->phpbb_extension_manager->purge('foo/bar');
} }
@ -142,8 +144,8 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
*/ */
public function test_error_ext_disabled_or_404() public function test_error_ext_disabled_or_404()
{ {
$crawler = $this->request('GET', 'app.php?controller=does/not/exist', array(), true); $crawler = self::request('GET', 'app.php?controller=does/not/exist', array(), false);
$this->assert_response_success(404); $this->assert_response_html(404);
$this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text()); $this->assertContains('No route found for "GET /does/not/exist"', $crawler->filter('body')->text());
} }
} }

View file

@ -99,13 +99,13 @@ class phpbb_functional_extension_permission_lang_test extends phpbb_functional_t
$this->phpbb_extension_manager->enable('foo/bar'); $this->phpbb_extension_manager->enable('foo/bar');
// User permissions // User permissions
$crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid);
// Select admin // Select admin
$form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$data = array('username[0]' => 'admin'); $data = array('username[0]' => 'admin');
$form->setValues($data); $form->setValues($data);
$crawler = $this->submit($form); $crawler = self::submit($form);
// language from language/en/acp/permissions_phpbb.php // language from language/en/acp/permissions_phpbb.php
$this->assertContains('Can attach files', $crawler->filter('body')->text()); $this->assertContains('Can attach files', $crawler->filter('body')->text());

View file

@ -16,7 +16,7 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case
{ {
global $config; global $config;
$this->add_lang('ucp'); $this->add_lang('ucp');
$crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); $crawler = self::request('GET', 'ucp.php?mode=sendpassword');
$this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text()); $this->assertEquals($this->lang('SEND_PASSWORD'), $crawler->filter('h2')->text());
} }
@ -25,18 +25,18 @@ class phpbb_functional_forgot_password_test extends phpbb_functional_test_case
$this->login(); $this->login();
$this->admin_login(); $this->admin_login();
$this->add_lang('ucp'); $this->add_lang('ucp');
$crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security'); $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid . '&i=acp_board&mode=security');
$form = $crawler->selectButton('Submit')->form(); $form = $crawler->selectButton('Submit')->form();
$values = $form->getValues(); $values = $form->getValues();
$values["config[allow_password_reset]"] = 0; $values["config[allow_password_reset]"] = 0;
$form->setValues($values); $form->setValues($values);
$crawler = $this->submit($form); $crawler = self::submit($form);
$this->logout(); $this->logout();
$crawler = $this->request('GET', 'ucp.php?mode=sendpassword'); $crawler = self::request('GET', 'ucp.php?mode=sendpassword');
$this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text()); $this->assertContains($this->lang('UCP_PASSWORD_RESET_DISABLED', '', ''), $crawler->text());
} }

View file

@ -17,15 +17,15 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case
$this->create_user('memberlist-test-user'); $this->create_user('memberlist-test-user');
// logs in as admin // logs in as admin
$this->login(); $this->login();
$crawler = $this->request('GET', 'memberlist.php?sid=' . $this->sid); $crawler = self::request('GET', 'memberlist.php?sid=' . $this->sid);
$this->assertContains('memberlist-test-user', $crawler->text()); $this->assertContains('memberlist-test-user', $crawler->text());
// restrict by first character // restrict by first character
$crawler = $this->request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid); $crawler = self::request('GET', 'memberlist.php?first_char=m&sid=' . $this->sid);
$this->assertContains('memberlist-test-user', $crawler->text()); $this->assertContains('memberlist-test-user', $crawler->text());
// make sure results for wrong character are not returned // make sure results for wrong character are not returned
$crawler = $this->request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid); $crawler = self::request('GET', 'memberlist.php?first_char=a&sid=' . $this->sid);
$this->assertNotContains('memberlist-test-user', $crawler->text()); $this->assertNotContains('memberlist-test-user', $crawler->text());
} }
@ -33,13 +33,13 @@ class phpbb_functional_memberlist_test extends phpbb_functional_test_case
{ {
$this->login(); $this->login();
// XXX hardcoded user id // XXX hardcoded user id
$crawler = $this->request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid); $crawler = self::request('GET', 'memberlist.php?mode=viewprofile&u=2&sid=' . $this->sid);
$this->assertContains('admin', $crawler->filter('h2')->text()); $this->assertContains('admin', $crawler->filter('h2')->text());
} }
protected function get_memberlist_leaders_table_crawler() protected function get_memberlist_leaders_table_crawler()
{ {
$crawler = $this->request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid); $crawler = self::request('GET', 'memberlist.php?mode=leaders&sid=' . $this->sid);
return $crawler->filter('.forumbg-table'); return $crawler->filter('.forumbg-table');
} }

View file

@ -75,7 +75,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
public function test_extensions_list() public function test_extensions_list()
{ {
$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);
$this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text()); $this->assertContains($this->lang('EXTENSIONS_EXPLAIN'), $crawler->filter('#main')->text());
$this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text()); $this->assertContains('phpBB 3.1 Extension Testing', $crawler->filter('#main')->text());
$this->assertContains('Details', $crawler->filter('#main')->text()); $this->assertContains('Details', $crawler->filter('#main')->text());
@ -83,7 +83,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
public function test_extensions_details() public function test_extensions_details()
{ {
$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo%2Fbar&sid=' . $this->sid);
// Test whether the details are displayed // Test whether the details are displayed
$this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text()); $this->assertContains($this->lang('CLEAN_NAME'), $crawler->filter('#main')->text());
@ -99,7 +99,7 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
public function test_extensions_details_notexists() public function test_extensions_details_notexists()
{ {
$crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=not%2Fexists&sid=' . $this->sid);
// Error message because the files do not exist // Error message because the files do not exist
$this->assertContains('The required file does not exist:', $crawler->filter('#main')->text()); $this->assertContains('The required file does not exist:', $crawler->filter('#main')->text());

View file

@ -40,7 +40,7 @@ class phpbb_functional_notification_test extends phpbb_functional_test_case
public function test_user_subscriptions($checkbox_name, $expected_status) public function test_user_subscriptions($checkbox_name, $expected_status)
{ {
$this->login(); $this->login();
$crawler = $this->request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options'); $crawler = self::request('GET', 'ucp.php?i=ucp_notifications&mode=notification_options');
$cplist = $crawler->filter('.table1'); $cplist = $crawler->filter('.table1');
if ($expected_status) if ($expected_status)

View file

@ -19,17 +19,17 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
// Test creating topic // Test creating topic
$post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.');
$crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text());
// Test creating a reply // Test creating a reply
$post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.');
$crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}");
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
// Test quoting a message // Test quoting a message
$crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $crawler = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
$this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text());
} }
@ -54,7 +54,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
'post' => true, 'post' => true,
), $additional_form_data); ), $additional_form_data);
return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); return self::submit_post($posting_url, 'POST_TOPIC', $form_data);
} }
/** /**
@ -78,7 +78,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
'post' => true, 'post' => true,
), $additional_form_data); ), $additional_form_data);
return $this->submit_post($posting_url, 'POST_REPLY', $form_data); return self::submit_post($posting_url, 'POST_REPLY', $form_data);
} }
/** /**
@ -93,7 +93,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
{ {
$this->add_lang('posting'); $this->add_lang('posting');
$crawler = $this->request('GET', $posting_url); $crawler = self::request('GET', $posting_url);
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
$hidden_fields = array( $hidden_fields = array(
@ -117,7 +117,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
// I use a request because the form submission method does not allow you to send data that is not // 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) // 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. // Instead, I send it as a request with the submit button "post" set to true.
$crawler = $this->request('POST', $posting_url, $form_data); $crawler = self::request('POST', $posting_url, $form_data);
$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
$url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();

View file

@ -85,16 +85,16 @@ class phpbb_functional_test_case extends phpbb_test_case
* @param string $method HTTP Method * @param string $method HTTP Method
* @param string $path Page path, relative from phpBB root path * @param string $path Page path, relative from phpBB root path
* @param array $form_data An array of form field values * @param array $form_data An array of form field values
* @param bool $skip_assert_response_success Should we skip the basic response assertions? * @param bool $assert_response_html Should we perform standard assertions for a normal html page
* @return Symfony\Component\DomCrawler\Crawler * @return Symfony\Component\DomCrawler\Crawler
*/ */
static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false) static public function request($method, $path, $form_data = array(), $assert_response_html = true)
{ {
$crawler = self::$client->request($method, self::$root_url . $path, $form_data); $crawler = self::$client->request($method, self::$root_url . $path, $form_data);
if (!$skip_assert_response_success) if ($assert_response_html)
{ {
self::assert_response_success(); self::assert_response_html();
} }
return $crawler; return $crawler;
@ -105,16 +105,16 @@ class phpbb_functional_test_case extends phpbb_test_case
* *
* @param Symfony\Component\DomCrawler\Form $form A Form instance * @param Symfony\Component\DomCrawler\Form $form A Form instance
* @param array $values An array of form field values * @param array $values An array of form field values
* @param bool $skip_assert_response_success Should we skip the basic response assertions? * @param bool $assert_response_html Should we perform standard assertions for a normal html page
* @return Symfony\Component\DomCrawler\Crawler * @return Symfony\Component\DomCrawler\Crawler
*/ */
static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false) static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true)
{ {
$crawler = self::$client->submit($form, $values); $crawler = self::$client->submit($form, $values);
if (!$skip_assert_response_success) if ($assert_response_html)
{ {
self::assert_response_success(); self::assert_response_html();
} }
return $crawler; return $crawler;
@ -237,7 +237,7 @@ class phpbb_functional_test_case extends phpbb_test_case
self::$client->setClient(new Guzzle\Http\Client('', array( self::$client->setClient(new Guzzle\Http\Client('', array(
Guzzle\Http\Client::DISABLE_REDIRECTS => true, Guzzle\Http\Client::DISABLE_REDIRECTS => true,
'curl.options' => array( 'curl.options' => array(
CURLOPT_TIMEOUT => 120 CURLOPT_TIMEOUT => 120,
), ),
))); )));
@ -469,12 +469,11 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
$this->add_lang('ucp'); $this->add_lang('ucp');
$crawler = $this->request('GET', 'ucp.php'); $crawler = self::request('GET', 'ucp.php');
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text()); $this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('LOGIN'))->form(); $form = $crawler->selectButton($this->lang('LOGIN'))->form();
$crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username)); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username));
$this->assert_response_success();
$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
$cookies = self::$cookieJar->all(); $cookies = self::$cookieJar->all();
@ -493,8 +492,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
$this->add_lang('ucp'); $this->add_lang('ucp');
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text()); $this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
unset($this->sid); unset($this->sid);
@ -515,7 +513,7 @@ class phpbb_functional_test_case extends phpbb_test_case
return; return;
} }
$crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); $crawler = self::request('GET', 'adm/index.php?sid=' . $this->sid);
$this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('LOGIN'))->form(); $form = $crawler->selectButton($this->lang('LOGIN'))->form();
@ -524,8 +522,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
if (strpos($field, 'password_') === 0) if (strpos($field, 'password_') === 0)
{ {
$crawler = $this->submit($form, array('username' => $username, $field => $username . $username)); $crawler = self::submit($form, array('username' => $username, $field => $username . $username));
$this->assert_response_success();
$this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text());
$cookies = self::$cookieJar->all(); $cookies = self::$cookieJar->all();
@ -593,24 +590,38 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message);
} }
/*
* Perform some basic assertions for the page
*
* Checks for debug/error output before the actual page content and the status code
*
* @param mixed $status_code Expected status code, false to disable check
* @return null
*/
static public function assert_response_html($status_code = 200)
{
if ($status_code !== false)
{
self::assert_response_status_code($status_code);
}
// Any output before the doc type means there was an error
$content = self::$client->getResponse()->getContent();
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
}
/** /**
* Heuristic function to check that the response is success. * Heuristic function to check that the response is success.
* *
* When php decides to die with a fatal error, it still sends 200 OK * When php decides to die with a fatal error, it still sends 200 OK
* status code. This assertion tries to catch that. * status code. This assertion tries to catch that.
* *
* @param int $status_code Expected status code
* @return null * @return null
*/ */
static public function assert_response_success($status_code = 200) static public function assert_response_status_code($status_code = 200)
{ {
self::assertEquals($status_code, self::$client->getResponse()->getStatus()); self::assertEquals($status_code, self::$client->getResponse()->getStatus());
$content = self::$client->getResponse()->getContent();
// Any output before the doc type means there was an error
if (strpos($content, '<!DOCTYPE') !== false)
{
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
}
} }
public function assert_filter($crawler, $expr, $msg = null) public function assert_filter($crawler, $expr, $msg = null)