1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

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
5 changed files with 135 additions and 66 deletions

View File

@@ -12,8 +12,9 @@ require_once __DIR__ . '/../../phpBB/includes/functions_install.php';
class phpbb_functional_test_case extends phpbb_test_case
{
protected $client;
protected $root_url;
static protected $client;
static protected $cookieJar;
static protected $root_url;
protected $cache = null;
protected $db = null;
@@ -39,6 +40,7 @@ class phpbb_functional_test_case extends phpbb_test_case
parent::setUpBeforeClass();
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
// test cases for querying the tables.
@@ -64,12 +66,12 @@ class phpbb_functional_test_case extends phpbb_test_case
$this->bootstrap();
$this->cookieJar = new CookieJar;
$this->client = new Goutte\Client(array(), null, $this->cookieJar);
self::$cookieJar = new 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
// resource
$this->client->getClient()->getCurlMulti()->reset(true);
$this->root_url = self::$config['phpbb_functional_url'];
self::$client->getClient()->getCurlMulti()->reset(true);
// Clear the language array so that things
// that were added in other tests are gone
$this->lang = array();
@@ -77,9 +79,55 @@ class phpbb_functional_test_case extends phpbb_test_case
$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
@@ -183,26 +231,73 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
// begin data
$data = array();
self::$cookieJar = new CookieJar;
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);
$data = array_merge($data, array(
'default_lang' => 'en',
'admin_name' => 'admin',
'admin_pass1' => 'admin',
'admin_pass2' => 'admin',
'board_email' => 'nobody@example.com',
));
// Reset the curl handle because it is 0 at this point and not a valid
// resource
self::$client->getClient()->getCurlMulti()->reset(true);
$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,
'smtp_delivery' => true,
'smtp_host' => 'nxdomain.phpbb.com',
'smtp_auth' => '',
'smtp_auth' => 'PLAIN',
'smtp_user' => 'nxuser',
'smtp_pass' => 'nxpass',
'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,
'script_path' => $parseURL['path'],
));
// end data
$content = self::do_request('install');
self::assertNotSame(false, $content);
self::assertContains('Welcome to Installation', $content);
$crawler = self::submit($form);
self::assertContains('The database tables used by phpBB', $crawler->filter('#main')->text());
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
$data['dbms'] = str_replace('phpbb_db_driver_', '', $data['dbms']);
$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);
$crawler = self::submit($form);
self::assertContains('You have successfully installed', $crawler->text());
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_timezone' => 0,
'user_dateformat' => '',
'user_password' => phpbb_hash($username),
'user_password' => phpbb_hash($username . $username),
);
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());
$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->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
foreach ($cookies as $cookie);
@@ -462,11 +543,11 @@ class phpbb_functional_test_case extends phpbb_test_case
{
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->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
foreach ($cookies as $cookie);
@@ -539,14 +620,13 @@ class phpbb_functional_test_case extends phpbb_test_case
*
* @return null
*/
public function assert_response_success()
static public function assert_response_success($status_code = 200)
{
$this->assertEquals(200, $this->client->getResponse()->getStatus());
$content = $this->client->getResponse()->getContent();
$this->assertNotContains('Fatal error:', $content);
$this->assertNotContains('Notice:', $content);
$this->assertNotContains('Warning:', $content);
$this->assertNotContains('[phpBB Debug]', $content);
self::assertEquals($status_code, self::$client->getResponse()->getStatus());
$content = self::$client->getResponse()->getContent();
// Any output before the doc type means there was an error
self::assertStringStartsWith('<!DOCTYPE', trim($content), 'Output found before DOCTYPE specification.');
}
public function assert_filter($crawler, $expr, $msg = null)