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

* ticket/11568:
  [ticket/11568] Add method to get page content
  [ticket/11568] Allow different status codes
  [ticket/11568] Trim the output to allow Tabs before INCLUDE overall_header
  [ticket/11568] Fix common_groups_test.php form handling
  [ticket/11568] Make CookieJar static aswell
  [ticket/11568] Remove manual calls to assert_response_success()
  [ticket/11568] Only use a static version of the client
  [ticket/11568] Any output before the doc type means there was an error
  [ticket/11568] Set client manually so we can increase the cURL timeout
  [ticket/11568] Use Goutte Client to install the board for functional tests

Conflicts:
	tests/test_framework/phpbb_functional_test_case.php
This commit is contained in:
Joas Schilling 2013-05-28 14:51:06 +02:00
commit 6d9888be65
5 changed files with 135 additions and 66 deletions

View file

@ -18,7 +18,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// check for logout link // check for logout link
$crawler = $this->request('GET', 'index.php'); $crawler = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text());
} }
@ -27,7 +26,6 @@ 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 = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
} }
@ -41,12 +39,10 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// logout // logout
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $crawler = $this->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());
// 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 = $this->request('GET', 'index.php');
$this->assert_response_success();
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
} }

View file

@ -15,21 +15,18 @@ 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 = $this->request('GET', 'index.php');
$this->assert_response_success();
$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 = $this->request('GET', 'viewforum.php?f=2');
$this->assert_response_success();
$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 = $this->request('GET', 'viewtopic.php?t=1');
$this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
} }
} }

View file

@ -42,10 +42,9 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
// Manage Administrators group // Manage Administrators group
$crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid);
$this->assert_response_success();
$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->client->submit($form); $crawler = $this->submit($form);
$this->assertContains($this->lang($expected), $crawler->text()); $this->assertContains($this->lang($expected), $crawler->text());
} }
} }

View file

@ -30,7 +30,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
// 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 = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}");
$this->assert_response_success();
$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());
} }
@ -95,7 +94,6 @@ 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 = $this->request('GET', $posting_url);
$this->assert_response_success();
$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(
@ -119,8 +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->client->request('POST', $posting_url, $form_data); $crawler = $this->request('POST', $posting_url, $form_data);
$this->assert_response_success();
$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

@ -12,8 +12,9 @@ require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
class phpbb_functional_test_case extends phpbb_test_case class phpbb_functional_test_case extends phpbb_test_case
{ {
protected $client; static protected $client;
protected $root_url; static protected $cookieJar;
static protected $root_url;
protected $cache = null; protected $cache = null;
protected $db = null; protected $db = null;
@ -39,6 +40,7 @@ class phpbb_functional_test_case extends phpbb_test_case
parent::setUpBeforeClass(); parent::setUpBeforeClass();
self::$config = phpbb_test_case_helpers::get_test_config(); self::$config = phpbb_test_case_helpers::get_test_config();
self::$root_url = self::$config['phpbb_functional_url'];
// Important: this is used both for installation and by // Important: this is used both for installation and by
// test cases for querying the tables. // test cases for querying the tables.
@ -64,12 +66,12 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->bootstrap(); $this->bootstrap();
$this->cookieJar = new CookieJar; self::$cookieJar = new CookieJar;
$this->client = new Goutte\Client(array(), null, $this->cookieJar); self::$client = new Goutte\Client(array(), null, self::$cookieJar);
// Reset the curl handle because it is 0 at this point and not a valid // Reset the curl handle because it is 0 at this point and not a valid
// resource // resource
$this->client->getClient()->getCurlMulti()->reset(true); self::$client->getClient()->getCurlMulti()->reset(true);
$this->root_url = self::$config['phpbb_functional_url'];
// Clear the language array so that things // Clear the language array so that things
// that were added in other tests are gone // that were added in other tests are gone
$this->lang = array(); $this->lang = array();
@ -77,9 +79,55 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->purge_cache(); $this->purge_cache();
} }
public function request($method, $path) /**
* Perform a request to page
*
* @param string $method HTTP Method
* @param string $path Page path, relative from phpBB root path
* @param array $form_data An array of form field values
* @param bool $skip_assert_response_success Should we skip the basic response assertions?
* @return Symfony\Component\DomCrawler\Crawler
*/
static public function request($method, $path, $form_data = array(), $skip_assert_response_success = false)
{ {
return $this->client->request($method, $this->root_url . $path); $crawler = self::$client->request($method, self::$root_url . $path, $form_data);
if (!$skip_assert_response_success)
{
self::assert_response_success();
}
return $crawler;
}
/**
* Submits a form
*
* @param Symfony\Component\DomCrawler\Form $form A Form instance
* @param array $values An array of form field values
* @param bool $skip_assert_response_success Should we skip the basic response assertions?
* @return Symfony\Component\DomCrawler\Crawler
*/
static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $skip_assert_response_success = false)
{
$crawler = self::$client->submit($form, $values);
if (!$skip_assert_response_success)
{
self::assert_response_success();
}
return $crawler;
}
/**
* Get Client Content
*
* @return string HTML page
*/
static public function get_content()
{
return self::$client->getResponse()->getContent();
} }
// bootstrap, called after board is set up // bootstrap, called after board is set up
@ -183,26 +231,73 @@ class phpbb_functional_test_case extends phpbb_test_case
} }
} }
// begin data self::$cookieJar = new CookieJar;
$data = array(); self::$client = new Goutte\Client(array(), null, self::$cookieJar);
// Set client manually so we can increase the cURL timeout
self::$client->setClient(new Guzzle\Http\Client('', array(
Guzzle\Http\Client::DISABLE_REDIRECTS => true,
'curl.options' => array(
CURLOPT_TIMEOUT => 120
),
)));
$data = array_merge($data, self::$config); // Reset the curl handle because it is 0 at this point and not a valid
// resource
$data = array_merge($data, array( self::$client->getClient()->getCurlMulti()->reset(true);
'default_lang' => 'en',
'admin_name' => 'admin',
'admin_pass1' => 'admin',
'admin_pass2' => 'admin',
'board_email' => 'nobody@example.com',
));
$parseURL = parse_url(self::$config['phpbb_functional_url']); $parseURL = parse_url(self::$config['phpbb_functional_url']);
$data = array_merge($data, array( $crawler = self::request('GET', 'install/index.php?mode=install');
self::assertContains('Welcome to Installation', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$crawler = self::submit($form);
self::assertContains('Installation compatibility', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$crawler = self::submit($form);
self::assertContains('Database configuration', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form(array(
// Installer uses 3.0-style dbms name
'dbms' => str_replace('phpbb_db_driver_', '', self::$config['dbms']),
'dbhost' => self::$config['dbhost'],
'dbport' => self::$config['dbport'],
'dbname' => self::$config['dbname'],
'dbuser' => self::$config['dbuser'],
'dbpasswd' => self::$config['dbpasswd'],
'table_prefix' => self::$config['table_prefix'],
));
$crawler = self::submit($form);
self::assertContains('Successful connection', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$crawler = self::submit($form);
self::assertContains('Administrator configuration', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form(array(
'default_lang' => 'en',
'admin_name' => 'admin',
'admin_pass1' => 'adminadmin',
'admin_pass2' => 'adminadmin',
'board_email' => 'nobody@example.com',
));
$crawler = self::submit($form);
self::assertContains('Tests passed', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
$crawler = self::submit($form);
self::assertContains('The configuration file has been written.', $crawler->filter('#main')->text());
file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data(self::$config, self::$config['dbms'], array(), true, true));
$form = $crawler->selectButton('submit')->form();
$crawler = self::submit($form);
self::assertContains('The settings on this page are only necessary to set if you know that you require something different from the default.', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form(array(
'email_enable' => true, 'email_enable' => true,
'smtp_delivery' => true, 'smtp_delivery' => true,
'smtp_host' => 'nxdomain.phpbb.com', 'smtp_host' => 'nxdomain.phpbb.com',
'smtp_auth' => '', 'smtp_auth' => 'PLAIN',
'smtp_user' => 'nxuser', 'smtp_user' => 'nxuser',
'smtp_pass' => 'nxpass', 'smtp_pass' => 'nxpass',
'cookie_secure' => false, 'cookie_secure' => false,
@ -212,28 +307,14 @@ class phpbb_functional_test_case extends phpbb_test_case
'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80, 'server_port' => isset($parseURL['port']) ? (int) $parseURL['port'] : 80,
'script_path' => $parseURL['path'], 'script_path' => $parseURL['path'],
)); ));
// end data
$content = self::do_request('install'); $crawler = self::submit($form);
self::assertNotSame(false, $content); self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text());
self::assertContains('Welcome to Installation', $content); self::assertContains('have been created and populated with some initial data.', $crawler->filter('#main')->text());
$form = $crawler->selectButton('submit')->form();
// Installer uses 3.0-style dbms name $crawler = self::submit($form);
$data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']); self::assertContains('You have successfully installed', $crawler->text());
$content = self::do_request('create_table', $data);
self::assertNotSame(false, $content);
self::assertContains('The database tables used by phpBB', $content);
// 3.0 or 3.1
self::assertContains('have been created and populated with some initial data.', $content);
$content = self::do_request('config_file', $data);
self::assertNotSame(false, $content);
self::assertContains('Configuration file', $content);
file_put_contents($phpbb_root_path . "config.$phpEx", phpbb_create_config_file_data($data, self::$config['dbms'], true, true));
$content = self::do_request('final', $data);
self::assertNotSame(false, $content);
self::assertContains('You have successfully installed', $content);
copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx");
} }
@ -314,7 +395,7 @@ class phpbb_functional_test_case extends phpbb_test_case
'user_lang' => 'en', 'user_lang' => 'en',
'user_timezone' => 0, 'user_timezone' => 0,
'user_dateformat' => '', 'user_dateformat' => '',
'user_password' => phpbb_hash($username), 'user_password' => phpbb_hash($username . $username),
); );
return user_add($user_row); return user_add($user_row);
} }
@ -411,11 +492,11 @@ class phpbb_functional_test_case extends phpbb_test_case
$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->client->submit($form, array('username' => $username, 'password' => $username)); $crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username));
$this->assert_response_success(); $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 = $this->cookieJar->all(); $cookies = self::$cookieJar->all();
// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
foreach ($cookies as $cookie); foreach ($cookies as $cookie);
@ -462,11 +543,11 @@ class phpbb_functional_test_case extends phpbb_test_case
{ {
if (strpos($field, 'password_') === 0) if (strpos($field, 'password_') === 0)
{ {
$crawler = $this->client->submit($form, array('username' => $username, $field => $username)); $crawler = $this->submit($form, array('username' => $username, $field => $username . $username));
$this->assert_response_success(); $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 = $this->cookieJar->all(); $cookies = self::$cookieJar->all();
// The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie
foreach ($cookies as $cookie); foreach ($cookies as $cookie);
@ -539,14 +620,13 @@ class phpbb_functional_test_case extends phpbb_test_case
* *
* @return null * @return null
*/ */
public function assert_response_success() static public function assert_response_success($status_code = 200)
{ {
$this->assertEquals(200, $this->client->getResponse()->getStatus()); self::assertEquals($status_code, self::$client->getResponse()->getStatus());
$content = $this->client->getResponse()->getContent(); $content = self::$client->getResponse()->getContent();
$this->assertNotContains('Fatal error:', $content);
$this->assertNotContains('Notice:', $content); // Any output before the doc type means there was an error
$this->assertNotContains('Warning:', $content); self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
$this->assertNotContains('[phpBB Debug]', $content);
} }
public function assert_filter($crawler, $expr, $msg = null) public function assert_filter($crawler, $expr, $msg = null)