From b7b81f64316a900d6de308d4b65f89b7b4b58e2f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:16:41 +0200 Subject: [PATCH 1/4] [ticket/11568] Use static calls for static methods PHPBB3-11568 --- tests/functional/auth_test.php | 8 ++++---- tests/functional/browse_test.php | 6 +++--- tests/functional/common_groups_test.php | 4 ++-- tests/functional/posting_test.php | 14 +++++++------- .../test_framework/phpbb_functional_test_case.php | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index a0c909e798..afb4f15fc2 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -17,7 +17,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->login(); // check for logout link - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('LOGOUT_USER', 'admin'), $crawler->filter('.navbar')->text()); } @@ -25,7 +25,7 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case { $this->create_user('anothertestuser'); $this->login('anothertestuser'); - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertContains('anothertestuser', $crawler->filter('.icon-logout')->text()); } @@ -38,11 +38,11 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->add_lang('ucp'); // logout - $crawler = $this->request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); + $crawler = self::request('GET', 'ucp.php?sid=' . $this->sid . '&mode=logout'); $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'); + $crawler = self::request('GET', 'index.php'); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } } diff --git a/tests/functional/browse_test.php b/tests/functional/browse_test.php index 26c18c4c1f..18a2ad9464 100644 --- a/tests/functional/browse_test.php +++ b/tests/functional/browse_test.php @@ -14,19 +14,19 @@ class phpbb_functional_browse_test extends phpbb_functional_test_case { public function test_index() { - $crawler = $this->request('GET', 'index.php'); + $crawler = self::request('GET', 'index.php'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewforum() { - $crawler = $this->request('GET', 'viewforum.php?f=2'); + $crawler = self::request('GET', 'viewforum.php?f=2'); $this->assertGreaterThan(0, $crawler->filter('.topiclist')->count()); } public function test_viewtopic() { - $crawler = $this->request('GET', 'viewtopic.php?t=1'); + $crawler = self::request('GET', 'viewtopic.php?t=1'); $this->assertGreaterThan(0, $crawler->filter('.postbody')->count()); } } diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 6e1f1afdce..7c88ec900d 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -35,10 +35,10 @@ abstract class phpbb_functional_common_groups_test extends phpbb_functional_test $this->add_lang(array('ucp', 'acp/groups')); // Manage Administrators group - $crawler = $this->request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); + $crawler = self::request('GET', $this->get_url() . '&g=5&sid=' . $this->sid); $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); $form['group_colour']->setValue($input); - $crawler = $this->submit($form); + $crawler = self::submit($form); $this->assertContains($this->lang($expected), $crawler->text()); } } diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 5cf7559245..9bcfcc2fda 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -19,17 +19,17 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case // Test creating topic $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); // Test creating a reply $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); - $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + $crawler = self::request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); // 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 = self::request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } @@ -54,7 +54,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + return self::submit_post($posting_url, 'POST_TOPIC', $form_data); } /** @@ -78,7 +78,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case 'post' => true, ), $additional_form_data); - return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + return self::submit_post($posting_url, 'POST_REPLY', $form_data); } /** @@ -93,7 +93,7 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case { $this->add_lang('posting'); - $crawler = $this->request('GET', $posting_url); + $crawler = self::request('GET', $posting_url); $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); $hidden_fields = array( @@ -117,7 +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->request('POST', $posting_url, $form_data); + $crawler = self::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 04a43182ae..a0dceb152b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -344,11 +344,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)); + $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -379,7 +379,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(); @@ -388,7 +388,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)); + $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); From b2be82cd57fd14e354d9e9c06b0324db74b754cf Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:19:19 +0200 Subject: [PATCH 2/4] [ticket/11568] Invert logic for asserting the response PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a0dceb152b..f1d282311f 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -83,11 +83,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @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) + static public function request($method, $path, $form_data = array(), $assert_response_success = true) { $crawler = self::$client->request($method, self::$root_url . $path, $form_data); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } @@ -103,11 +103,11 @@ class phpbb_functional_test_case extends phpbb_test_case * @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) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_success = true) { $crawler = self::$client->submit($form, $values); - if (!$skip_assert_response_success) + if ($assert_response_success) { self::assert_response_success(); } From 09a3877ae4c5bda66f22d89408b589ea8b56f380 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:20:20 +0200 Subject: [PATCH 3/4] [ticket/11568] Add comma at end of array key-value couple PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index f1d282311f..5416125f42 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -202,7 +202,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, ), ))); From 6af5262fcccae3f3e651348a20dbbd8a78e191aa Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 31 May 2013 16:27:52 +0200 Subject: [PATCH 4/4] [ticket/11568] Split status code and html debug assertion into two methods PHPBB3-11568 --- .../phpbb_functional_test_case.php | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 5416125f42..651ab013c7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -80,16 +80,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(), $assert_response_success = true) + 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 ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -100,16 +100,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(), $assert_response_success = true) + static public function submit(Symfony\Component\DomCrawler\Form $form, array $values = array(), $assert_response_html = true) { $crawler = self::$client->submit($form, $values); - if ($assert_response_success) + if ($assert_response_html) { - self::assert_response_success(); + self::assert_response_html(); } return $crawler; @@ -349,7 +349,6 @@ class phpbb_functional_test_case extends phpbb_test_case $form = $crawler->selectButton($this->lang('LOGIN'))->form(); $crawler = self::submit($form, array('username' => $username, 'password' => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -389,7 +388,6 @@ class phpbb_functional_test_case extends phpbb_test_case if (strpos($field, 'password_') === 0) { $crawler = self::submit($form, array('username' => $username, $field => $username . $username)); - $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = self::$cookieJar->all(); @@ -445,23 +443,37 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + /** + * 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('getResponse()->getStatus()); - $content = self::$client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - if (strpos($content, '