1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-30 21:40:43 +02:00

[ticket/16902] Extend test

PHPBB3-16902
This commit is contained in:
rxu
2021-10-31 18:50:35 +07:00
parent e7c81cd1a6
commit 015c9313a7
2 changed files with 166 additions and 16 deletions

View File

@@ -1437,4 +1437,112 @@ class phpbb_functional_test_case extends phpbb_test_case
return $file_form_data;
}
/**
* Get HTML of the crawler
* See https://symfony.com/doc/current/components/dom_crawler.html#component-dom-crawler-dumping
*
* @param Symfony\Component\DomCrawler\Crawler $crawler Crawler instance
* @param string $url Request URL
*
* @return array Hidden form fields array
*/
protected function dump_crawler($crawler)
{
if (!$crawler)
{
return;
}
$html = '';
foreach ($crawler as $domElement)
{
$html .= $domElement->ownerDocument->saveHTML($domElement);
}
return $html;
}
/**
* Get username of currently logged in user
*
* @return string|bool username if logged in, false otherwise
*/
protected function get_logged_in_user()
{
$username_logged_in = false;
$crawler = self::request('GET', 'index.php');
$is_logged_in = strpos($crawler->filter('div[class="navbar"]')->text(), 'Login') === false;
if ($is_logged_in)
{
$username_logged_in = $crawler->filter('li[id="username_logged_in"] > div > a > span')->text();
}
return $username_logged_in;
}
/**
* Disable posting flood control
*/
protected function disable_flood_interval()
{
$relogin_back = false;
$logged_in_username = $this->get_logged_in_user();
if ($logged_in_username && $logged_in_username !== 'admin')
{
$this->logout();
$relogin_back = true;
}
if (!$logged_in_username || $relogin_back)
{
$this->login();
$this->admin_login();
}
$this->add_lang('acp/common');
$crawler = self::request('GET', 'adm/index.php?i=acp_board&mode=post&sid=' . $this->sid);
$form = $crawler->selectButton('submit')->form([
'config[flood_interval]' => 0,
]);
$crawler = self::submit($form);
$this->assertContainsLang('CONFIG_UPDATED', $crawler->text());
// Get logged out back or get logged in in user back if needed
if (!$logged_in_username)
{
$this->logout();
}
if ($relogin_back)
{
$this->logout();
$this->login($logged_in_username);
}
}
/**
* Check if a user exists by username(s) or user_id(s)
*
* @param array &$user_id_ary The user ids to check or empty if usernames used
* @param array &$username_ary The usernames to check or empty if user ids used
*
* @return bool Returns true if a user exists, false otherwise
*/
protected function user_exists($username, $user_id = null)
{
global $db;
$db = $this->get_db();
if (!function_exists('utf_clean_string'))
{
require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php');
}
if (!function_exists('user_get_id_name'))
{
require_once(__DIR__ . '/../../phpBB/includes/functions_user.php');
}
return user_get_id_name($user_id, $username) ? false : true;
}
}