From 5dcf028cf0791956be0a8cb5f8ea82d3cd91080a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:12:32 +0200 Subject: [PATCH 01/10] [ticket/11568] Use Goutte Client to install the board for functional tests PHPBB3-11568 --- .../phpbb_functional_test_case.php | 144 +++++++++++++----- 1 file changed, 105 insertions(+), 39 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b1352b247e..cd3133f3a0 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -17,6 +17,9 @@ class phpbb_functional_test_case extends phpbb_test_case protected $client; protected $root_url; + static protected $static_client; + static protected $static_root_url; + protected $cache = null; protected $db = null; @@ -77,6 +80,11 @@ class phpbb_functional_test_case extends phpbb_test_case return $this->client->request($method, $this->root_url . $path); } + static public function static_request($method, $path) + { + return self::$static_client->request($method, self::$static_root_url . $path); + } + // bootstrap, called after board is set up // once per test case class // test cases can override this @@ -148,28 +156,78 @@ class phpbb_functional_test_case extends phpbb_test_case } } - // begin data - $data = array(); + $cookieJar = new CookieJar; + self::$static_client = new Goutte\Client(array(), null, $cookieJar); - $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::$static_client->getClient()->getCurlMulti()->reset(true); + self::$static_root_url = self::$config['phpbb_functional_url']; $parseURL = parse_url(self::$config['phpbb_functional_url']); - $data = array_merge($data, array( - 'email_enable' => false, - 'smtp_delivery' => false, - 'smtp_host' => '', - 'smtp_auth' => '', - 'smtp_user' => '', - 'smtp_pass' => '', + $crawler = self::static_request('GET', 'install/index.php?mode=install'); + self::static_assert_response_success(); + self::assertContains('Welcome to Installation', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Successful connection', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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_email1' => 'nobody@example.com', + 'board_email2' => 'nobody@example.com', + )); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('Tests passed', $crawler->filter('#main')->text()); + $form = $crawler->selectButton('submit')->form(); + + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + 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::$static_client->submit($form); + self::static_assert_response_success(); + 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' => 'PLAIN', + 'smtp_user' => 'nxuser', + 'smtp_pass' => 'nxpass', 'cookie_secure' => false, 'force_server_vars' => false, 'server_protocol' => $parseURL['scheme'] . '://', @@ -177,26 +235,16 @@ 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::$static_client->submit($form); + self::static_assert_response_success(); + 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(); - $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'], array(), true, true)); - - $content = self::do_request('final', $data); - self::assertNotSame(false, $content); - self::assertContains('You have successfully installed', $content); + $crawler = self::$static_client->submit($form); + self::static_assert_response_success(); + self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -270,7 +318,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); } @@ -283,7 +331,7 @@ 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->client->submit($form, array('username' => $username, 'password' => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_REDIRECT'), $crawler->filter('html')->text()); @@ -323,7 +371,7 @@ 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->client->submit($form, array('username' => $username, $field => $username . $username)); $this->assert_response_success(); $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); @@ -397,4 +445,22 @@ class phpbb_functional_test_case extends phpbb_test_case $this->assertNotContains('Warning:', $content); $this->assertNotContains('[phpBB Debug]', $content); } + + /** + * 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. + * + * @return null + */ + static public function static_assert_response_success() + { + self::assertEquals(200, self::$static_client->getResponse()->getStatus()); + $content = self::$static_client->getResponse()->getContent(); + self::assertNotContains('Fatal error:', $content); + self::assertNotContains('Notice:', $content); + //@todo: self::assertNotContains('Warning:', $content); + self::assertNotContains('[phpBB Debug]', $content); + } } From a3e5efc63483f06c6d66296adbd0538d59a05a21 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 21:16:49 +0200 Subject: [PATCH 02/10] [ticket/11568] Set client manually so we can increase the cURL timeout PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index cd3133f3a0..b622c6e284 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -158,6 +158,13 @@ class phpbb_functional_test_case extends phpbb_test_case $cookieJar = new CookieJar; self::$static_client = new Goutte\Client(array(), null, $cookieJar); + // Set client manually so we can increase the cURL timeout + self::$static_client->setClient(new Guzzle\Http\Client('', array( + Guzzle\Http\Client::DISABLE_REDIRECTS => true, + 'curl.options' => array( + CURLOPT_TIMEOUT => 120 + ), + ))); // Reset the curl handle because it is 0 at this point and not a valid // resource From f25389f94a46bb63d8688be9eef699de9853b4fc Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 26 May 2013 23:57:50 +0200 Subject: [PATCH 03/10] [ticket/11568] Any output before the doc type means there was an error Change is needed to allow "Warning:" in the HTML body PHPBB3-11568 --- .../test_framework/phpbb_functional_test_case.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b622c6e284..8a386d1db7 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -447,10 +447,9 @@ class phpbb_functional_test_case extends phpbb_test_case { $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); + + // Any output before the doc type means there was an error + $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); $content = self::$static_client->getResponse()->getContent(); - self::assertNotContains('Fatal error:', $content); - self::assertNotContains('Notice:', $content); - //@todo: self::assertNotContains('Warning:', $content); - self::assertNotContains('[phpBB Debug]', $content); + + // Any output before the doc type means there was an error + self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:09:44 +0200 Subject: [PATCH 04/10] [ticket/11568] Only use a static version of the client PHPBB3-11568 --- .../phpbb_functional_test_case.php | 119 +++++++++--------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8a386d1db7..0d122604fd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -14,11 +14,8 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { - protected $client; - protected $root_url; - - static protected $static_client; - static protected $static_root_url; + static protected $client; + static protected $root_url; protected $cache = null; protected $db = null; @@ -43,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']; if (!isset(self::$config['phpbb_functional_url'])) { @@ -63,11 +61,11 @@ 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::$client = new Goutte\Client(array(), null, $this->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(); @@ -75,14 +73,45 @@ 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; } - static public function static_request($method, $path) + /** + * 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) { - return self::$static_client->request($method, self::$static_root_url . $path); + $crawler = self::$client->submit($form, $values); + + if (!$skip_assert_response_success) + { + self::assert_response_success(); + } + + return $crawler; } // bootstrap, called after board is set up @@ -157,9 +186,9 @@ class phpbb_functional_test_case extends phpbb_test_case } $cookieJar = new CookieJar; - self::$static_client = new Goutte\Client(array(), null, $cookieJar); + self::$client = new Goutte\Client(array(), null, $cookieJar); // Set client manually so we can increase the cURL timeout - self::$static_client->setClient(new Guzzle\Http\Client('', array( + self::$client->setClient(new Guzzle\Http\Client('', array( Guzzle\Http\Client::DISABLE_REDIRECTS => true, 'curl.options' => array( CURLOPT_TIMEOUT => 120 @@ -168,23 +197,19 @@ class phpbb_functional_test_case extends phpbb_test_case // Reset the curl handle because it is 0 at this point and not a valid // resource - self::$static_client->getClient()->getCurlMulti()->reset(true); - self::$static_root_url = self::$config['phpbb_functional_url']; + self::$client->getClient()->getCurlMulti()->reset(true); $parseURL = parse_url(self::$config['phpbb_functional_url']); - $crawler = self::static_request('GET', 'install/index.php?mode=install'); - self::static_assert_response_success(); + $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::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Installation compatibility', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $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 @@ -197,13 +222,11 @@ class phpbb_functional_test_case extends phpbb_test_case 'table_prefix' => self::$config['table_prefix'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Successful connection', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Administrator configuration', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(array( 'default_lang' => 'en', @@ -214,19 +237,16 @@ class phpbb_functional_test_case extends phpbb_test_case 'board_email2' => 'nobody@example.com', )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('Tests passed', $crawler->filter('#main')->text()); $form = $crawler->selectButton('submit')->form(); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $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::$static_client->submit($form); - self::static_assert_response_success(); + $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, @@ -243,14 +263,12 @@ class phpbb_functional_test_case extends phpbb_test_case 'script_path' => $parseURL['path'], )); - $crawler = self::$static_client->submit($form); - self::static_assert_response_success(); + $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::$static_client->submit($form); - self::static_assert_response_success(); + $crawler = self::submit($form); self::assertContains('You have successfully installed', $crawler->text()); copy($phpbb_root_path . "config.$phpEx", $phpbb_root_path . "config_test.$phpEx"); } @@ -338,7 +356,7 @@ 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 . $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()); @@ -378,7 +396,7 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $crawler = $this->client->submit($form, array('username' => $username, $field => $username . $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()); @@ -443,29 +461,12 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - public function assert_response_success() + static public function assert_response_success() { - $this->assertEquals(200, $this->client->getResponse()->getStatus()); - $content = $this->client->getResponse()->getContent(); + self::assertEquals(200, self::$client->getResponse()->getStatus()); + $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - $this->assertEquals(0, strpos($content, 'getResponse()->getStatus()); - $content = self::$static_client->getResponse()->getContent(); - - // Any output before the doc type means there was an error - self::assertEquals(0, strpos($content, ' Date: Mon, 27 May 2013 22:12:50 +0200 Subject: [PATCH 05/10] [ticket/11568] Remove manual calls to assert_response_success() PHPBB3-11568 --- tests/functional/auth_test.php | 4 ---- tests/functional/browse_test.php | 3 --- tests/functional/posting_test.php | 5 +---- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 662b1bd38b..a0c909e798 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/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(); From da98866c24572031b2deda4e8a50cac07efdef5d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:25:25 +0200 Subject: [PATCH 06/10] [ticket/11568] Make CookieJar static aswell PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 0d122604fd..1725a45e38 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -15,6 +15,7 @@ require_once __DIR__ . '/../../phpBB/includes/cache.php'; class phpbb_functional_test_case extends phpbb_test_case { static protected $client; + static protected $cookieJar; static protected $root_url; protected $cache = null; @@ -60,8 +61,8 @@ class phpbb_functional_test_case extends phpbb_test_case $this->bootstrap(); - $this->cookieJar = new CookieJar; - self::$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 self::$client->getClient()->getCurlMulti()->reset(true); @@ -185,8 +186,8 @@ class phpbb_functional_test_case extends phpbb_test_case } } - $cookieJar = new CookieJar; - self::$client = new Goutte\Client(array(), null, $cookieJar); + 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, @@ -360,7 +361,7 @@ class phpbb_functional_test_case extends phpbb_test_case $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); @@ -400,7 +401,7 @@ class phpbb_functional_test_case extends phpbb_test_case $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); From 9be57ec076eb1c819c6a6a51c4f2ba9f3e3c915d Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 27 May 2013 22:33:48 +0200 Subject: [PATCH 07/10] [ticket/11568] Fix common_groups_test.php form handling PHPBB3-11568 --- tests/functional/common_groups_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/functional/common_groups_test.php b/tests/functional/common_groups_test.php index 7ccd78421e..6e1f1afdce 100644 --- a/tests/functional/common_groups_test.php +++ b/tests/functional/common_groups_test.php @@ -36,10 +36,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()); } } From 3d6620f0db5dbbf9b1f59ec865854a1dcd2e3179 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:10:27 +0200 Subject: [PATCH 08/10] [ticket/11568] Trim the output to allow Tabs before INCLUDE overall_header 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 1725a45e38..4ebe1d2d17 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -468,6 +468,6 @@ class phpbb_functional_test_case extends phpbb_test_case $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error - self::assertStringStartsWith(' Date: Tue, 28 May 2013 14:38:28 +0200 Subject: [PATCH 09/10] [ticket/11568] Allow different status codes PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 4ebe1d2d17..e87f53caed 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -462,9 +462,9 @@ class phpbb_functional_test_case extends phpbb_test_case * * @return null */ - static public function assert_response_success() + static public function assert_response_success($status_code = 200) { - self::assertEquals(200, self::$client->getResponse()->getStatus()); + self::assertEquals($status_code, self::$client->getResponse()->getStatus()); $content = self::$client->getResponse()->getContent(); // Any output before the doc type means there was an error From e84fb0c6cacdd4da2542bb94e5994d1962930ca4 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 28 May 2013 14:47:24 +0200 Subject: [PATCH 10/10] [ticket/11568] Add method to get page content PHPBB3-11568 --- tests/test_framework/phpbb_functional_test_case.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e87f53caed..63cbeb515a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -115,6 +115,16 @@ class phpbb_functional_test_case extends phpbb_test_case 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 // once per test case class // test cases can override this