aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework/phpbb_functional_test_case.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2013-05-31 16:45:06 +0200
committerJoas Schilling <nickvergessen@gmx.de>2013-05-31 16:45:06 +0200
commit8c4670eeb1264e2535021e400d2cf7e2c2028010 (patch)
tree9c1a92f4f2711f09c9816ffde93c05b25e0c7ce5 /tests/test_framework/phpbb_functional_test_case.php
parent5c046b9493d05981264c18b304d217fc75eda9e2 (diff)
parent6af5262fcccae3f3e651348a20dbbd8a78e191aa (diff)
downloadforums-8c4670eeb1264e2535021e400d2cf7e2c2028010.tar
forums-8c4670eeb1264e2535021e400d2cf7e2c2028010.tar.gz
forums-8c4670eeb1264e2535021e400d2cf7e2c2028010.tar.bz2
forums-8c4670eeb1264e2535021e400d2cf7e2c2028010.tar.xz
forums-8c4670eeb1264e2535021e400d2cf7e2c2028010.zip
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
Diffstat (limited to 'tests/test_framework/phpbb_functional_test_case.php')
-rw-r--r--tests/test_framework/phpbb_functional_test_case.php61
1 files changed, 36 insertions, 25 deletions
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php
index 92f777c4d7..67c6a4fb5f 100644
--- a/tests/test_framework/phpbb_functional_test_case.php
+++ b/tests/test_framework/phpbb_functional_test_case.php
@@ -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)