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] 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
13 changed files with 94 additions and 81 deletions

View File

@@ -85,16 +85,16 @@ class phpbb_functional_test_case extends phpbb_test_case
* @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?
* @param bool $assert_response_html Should we perform standard assertions for a normal html page
* @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);
if (!$skip_assert_response_success)
if ($assert_response_html)
{
self::assert_response_success();
self::assert_response_html();
}
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 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
*/
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);
if (!$skip_assert_response_success)
if ($assert_response_html)
{
self::assert_response_success();
self::assert_response_html();
}
return $crawler;
@@ -237,7 +237,7 @@ class phpbb_functional_test_case extends phpbb_test_case
self::$client->setClient(new Guzzle\Http\Client('', array(
Guzzle\Http\Client::DISABLE_REDIRECTS => true,
'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');
$crawler = $this->request('GET', 'ucp.php');
$crawler = self::request('GET', 'ucp.php');
$this->assertContains($this->lang('LOGIN_EXPLAIN_UCP'), $crawler->filter('html')->text());
$form = $crawler->selectButton($this->lang('LOGIN'))->form();
$crawler = $this->submit($form, array('username' => $username, 'password' => $username . $username));
$this->assert_response_success();
$crawler = self::submit($form, array('username' => $username, 'password' => $username . $username));
$this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text());
$cookies = self::$cookieJar->all();
@@ -493,8 +492,7 @@ class phpbb_functional_test_case extends phpbb_test_case
{
$this->add_lang('ucp');
$crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assert_response_success();
$crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout');
$this->assertContains($this->lang('LOGOUT_REDIRECT'), $crawler->filter('#message')->text());
unset($this->sid);
@@ -515,7 +513,7 @@ class phpbb_functional_test_case extends phpbb_test_case
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());
$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)
{
$crawler = $this->submit($form, array('username' => $username, $field => $username . $username));
$this->assert_response_success();
$crawler = self::submit($form, array('username' => $username, $field => $username . $username));
$this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text());
$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);
}
/*
* 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.
*
* When php decides to die with a fatal error, it still sends 200 OK
* status code. This assertion tries to catch that.
*
* @param int $status_code Expected status code
* @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());
$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)