aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/functional/auth_test.php4
-rw-r--r--tests/functional/browse_test.php3
-rw-r--r--tests/functional/common_groups_test.php3
-rw-r--r--tests/functional/posting_test.php5
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php182
5 files changed, 133 insertions, 64 deletions
diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php
index f92a4a2210..8359bbe8ea 100644
--- a/tests/functional/auth_test.php
+++ b/tests/functional/auth_test.php
@@ -18,7 +18,6 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// check for logout link
$crawler = $this->request('GET', 'index.php');
- $this->assert_response_success();
$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->login('anothertestuser');
$crawler = $this->request('GET', 'index.php');
- $this->assert_response_success();
$this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text());
}
@@ -41,12 +39,10 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case
// 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());
// look for a register link, which should be visible only when logged out
$crawler = $this->request('GET', 'index.php');
- $this->assert_response_success();
$this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text());
}
diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php
index b5748059c6..26c18c4c1f 100644
--- a/tests/functional/browse_test.php
+++ b/tests/functional/browse_test.php
@@ -15,21 +15,18 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case
public function test_index()
{
$crawler = $this->request('GET', 'index.php');
- $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
}
public function test_viewforum()
{
$crawler = $this->request('GET', 'viewforum.php?f=2');
- $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.topiclist')->count());
}
public function test_viewtopic()
{
$crawler = $this->request('GET', 'viewtopic.php?t=1');
- $this->assert_response_success();
$this->assertGreaterThan(0, $crawler->filter('.postbody')->count());
}
}
diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php
index cc6afa54b9..0f376f2705 100644
--- a/tests/functional/common_groups_test.php
+++ b/tests/functional/common_groups_test.php
@@ -42,10 +42,9 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test
// Manage Administrators group
$crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid);
- $this->assert_response_success();
$form = $crawler->selectButton($this->lang('SUBMIT'))->form();
$form['group_colour']->setValue($input);
- $crawler = $this->client->submit($form);
+ $crawler = $this->submit($form);
$this->assertContains($this->lang($expected), $crawler->text());
}
}
diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php
index d05207edf0..5cf7559245 100644
--- a/tests/functional/posting_test.php
+++ b/tests/functional/posting_test.php
@@ -30,7 +30,6 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case
// 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}");
- $this->assert_response_success();
$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');
$crawler = $this->request('GET', $posting_url);
- $this->assert_response_success();
$this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text());
$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
// 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.
- $crawler = $this->client->request('POST', $posting_url, $form_data);
- $this->assert_response_success();
+ $crawler = $this->request('POST', $posting_url, $form_data);
$this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text());
$url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri();
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 660234f3ed..42d38255f7 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -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)
+ {
+ $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 $this->client->request($method, $this->root_url . $path);
+ 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);
+ // Reset the curl handle because it is 0 at this point and not a valid
+ // resource
+ self::$client->getClient()->getCurlMulti()->reset(true);
- $data = array_merge($data, array(
+ $parseURL = parse_url(self::$config['phpbb_functional_url']);
+
+ $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' => 'admin',
- 'admin_pass2' => 'admin',
+ 'admin_pass1' => 'adminadmin',
+ 'admin_pass2' => 'adminadmin',
'board_email' => 'nobody@example.com',
));
- $parseURL = parse_url(self::$config['phpbb_functional_url']);
+ $crawler = self::submit($form);
+ self::assertContains('Tests passed', $crawler->filter('#main')->text());
+ $form = $crawler->selectButton('submit')->form();
- $data = array_merge($data, array(
+ $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);
-
- // 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('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();
+
+ $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)