diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-05-14 22:51:10 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-05-14 22:51:10 +0200 |
commit | ac8e8a156a771cabcd73859f1c2235c89257e76b (patch) | |
tree | 2477c191d1c1c600e7e35a80a0304b72e48d421a /tests | |
parent | 45e014d35d755363224a8a84dd9bb51299a6f107 (diff) | |
download | forums-ac8e8a156a771cabcd73859f1c2235c89257e76b.tar forums-ac8e8a156a771cabcd73859f1c2235c89257e76b.tar.gz forums-ac8e8a156a771cabcd73859f1c2235c89257e76b.tar.bz2 forums-ac8e8a156a771cabcd73859f1c2235c89257e76b.tar.xz forums-ac8e8a156a771cabcd73859f1c2235c89257e76b.zip |
[ticket/11544] Add admin_login() method to 3.0 functional test case
This method is needed in order to be able to properly test acp functions.
PHPBB3-11544
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_framework/phpbb_functional_test_case.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 83c931f924..b1352b247e 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -299,6 +299,50 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login($username = 'admin') + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $crawler = $this->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(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); + + $cookies = $this->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); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) |