1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

Merge branch 'master' into ticket/12629

This commit is contained in:
Marc Alexander
2018-10-26 10:16:04 +02:00
committed by GitHub
114 changed files with 1902 additions and 967 deletions

View File

@@ -21,9 +21,6 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
/** @var \phpbb\db\driver\driver_interface */
protected $db;
/** @var \phpbb\filesystem\filesystem */
protected $filesystem;
/** @var \phpbb\attachment\resync */
protected $resync;
@@ -47,22 +44,11 @@ class phpbb_attachment_delete_test extends \phpbb_database_test_case
$cache = $this->createMock('\phpbb\cache\driver\driver_interface');
$this->config = new \phpbb\config\config(array());
$this->db = $this->new_dbal();
$db_mock = $this->createMock('\phpbb\db\driver\driver_interface');
$this->resync = new \phpbb\attachment\resync($this->db);
$this->filesystem = $this->createMock('\phpbb\filesystem\filesystem', array('remove', 'exists'));
$this->filesystem->expects($this->any())
->method('remove')
->willReturn(false);
$this->filesystem->expects($this->any())
$this->storage = $this->createMock('\phpbb\storage\storage');
$this->storage->expects($this->any())
->method('exists')
->willReturn(true);
$adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($adapter);
$this->storage = new \phpbb\storage\storage($db_mock, $cache, $adapter_factory_mock, '', '');
$this->dispatcher = new \phpbb_mock_event_dispatcher();
$this->attachment_delete = new \phpbb\attachment\delete($this->config, $this->db, $this->dispatcher, $this->resync, $this->storage);
}

View File

@@ -86,9 +86,7 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
));
$config = $this->config;
$this->db = $this->new_dbal();
$db_mock = $this->createMock('\phpbb\db\driver\driver_interface');
$this->cache = new \phpbb\cache\service(new \phpbb\cache\driver\dummy(), $this->config, $this->db, $phpbb_root_path, $phpEx);
$cache_mock = $this->createMock('\phpbb\cache\driver\driver_interface');
$this->request = $this->createMock('\phpbb\request\request');
$this->filesystem = new \phpbb\filesystem\filesystem();
@@ -105,13 +103,10 @@ class phpbb_attachment_upload_test extends \phpbb_database_test_case
$this->mimetype_guesser = new \phpbb\mimetype\guesser($guessers);
$this->plupload = new \phpbb\plupload\plupload($phpbb_root_path, $this->config, $this->request, new \phpbb\user($this->language, '\phpbb\datetime'), $this->php_ini, $this->mimetype_guesser);
$adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($adapter);
$this->storage = new \phpbb\storage\storage($db_mock, $cache_mock, $adapter_factory_mock, '', '');
$this->storage = $this->createMock('\phpbb\storage\storage');
$this->storage->expects($this->any())
->method('free_space')
->willReturn(1024*1024); // 1gb
$factory_mock = $this->getMockBuilder('\phpbb\files\factory')
->disableOriginalConstructor()

View File

@@ -30,25 +30,16 @@ class phpbb_avatar_manager_test extends \phpbb_database_test_case
global $phpbb_root_path, $phpEx;
// Mock phpbb_container
$cache = $this->createMock('\phpbb\cache\driver\driver_interface');
$phpbb_container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
$phpbb_container->expects($this->any())
->method('get')
->will($this->returnArgument(0));
$filesystem = new \phpbb\filesystem\filesystem();
$adapter = new \phpbb\storage\adapter\local($filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$adapter->configure(['path' => 'images/avatars/upload']);
$db = $this->createMock('\phpbb\db\driver\driver_interface');
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($adapter);
$storage = new \phpbb\storage\storage($db, $cache, $adapter_factory_mock, '', '');
$storage = $this->createMock('\phpbb\storage\storage');
// Prepare dependencies for avatar manager and driver
$this->config = new \phpbb\config\config(array());
$cache = $this->createMock('\phpbb\cache\driver\driver_interface');
$path_helper = new \phpbb\path_helper(
new \phpbb\symfony_request(
new phpbb_mock_request()

View File

@@ -49,10 +49,27 @@ class phpbb_cache_apcu_driver_test extends phpbb_cache_common_test_case
protected function setUp()
{
global $phpbb_container, $phpbb_root_path;
parent::setUp();
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');
$this->driver = new \phpbb\cache\driver\apcu;
$this->driver->purge();
}
public function test_purge()
{
/* add a cache entry which does not match our key */
$foreign_key = 'test_' . $this->driver->key_prefix . 'test';
$this->assertSame(true, apcu_store($foreign_key, 0, 600));
$this->assertSame(true, apcu_exists($foreign_key));
parent::test_purge();
$this->assertSame(true, apcu_exists($foreign_key));
}
}

View File

@@ -94,6 +94,9 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
'auth.provider_collection',
$provider_collection
);
$phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens');
$phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states');
$phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts');
parent::setUp();
}

View File

@@ -28,18 +28,20 @@ class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case
public function data_add_profile_field()
{
return array(
array('bool', 'profilefields.type.bool',
array('profilefields.type.bool',
array(
'field_ident' => 'bool',
'lang_name' => 'bool',
'lang_options[0]' => 'foo',
'lang_options[1]' => 'bar',
),
array(),
),
array('dropdown', 'profilefields.type.dropdown',
array('profilefields.type.dropdown',
array(
'field_ident' => 'dropdown',
'lang_name' => 'dropdown',
'lang_options' => "foo\nbar\nbar\nfoo",
),
array(),
),
);
}
@@ -47,13 +49,12 @@ class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case
/**
* @dataProvider data_add_profile_field
*/
public function test_add_profile_field($name, $type, $page1_settings, $page2_settings)
public function test_add_profile_field($type, $page1_settings)
{
// Custom profile fields page
$crawler = self::request('GET', 'adm/index.php?i=acp_profile&mode=profile&sid=' . $this->sid);
// these language strings are html
$form = $crawler->selectButton('Create new field')->form(array(
'field_ident' => $name,
'field_type' => $type,
));
$crawler = self::submit($form);
@@ -63,7 +64,7 @@ class phpbb_functional_acp_profile_field_test extends phpbb_functional_test_case
$crawler = self::submit($form);
// Fill form for profile field specific options
$form = $crawler->selectButton('Save')->form($page2_settings);
$form = $crawler->selectButton('Save')->form();
$crawler= self::submit($form);
$this->assertContainsLang('ADDED_PROFILE_FIELD', $crawler->text());

View File

@@ -82,6 +82,10 @@ class phpbb_functions_user_delete_test extends phpbb_database_test_case
$phpbb_container->set('auth.provider.oauth.service.google', $oauth_provider_google);
$phpbb_container->set('auth.provider_collection', $provider_collection);
$phpbb_container->set('notification_manager', $notification_manager);
$phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens');
$phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states');
$phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts');
}
public function test_user_delete()

View File

@@ -49,6 +49,9 @@ class phpbb_functions_user_delete_user_test extends phpbb_database_test_case
'auth.provider_collection',
$provider_collection
);
$phpbb_container->setParameter('tables.auth_provider_oauth_token_storage', 'phpbb_oauth_tokens');
$phpbb_container->setParameter('tables.auth_provider_oauth_states', 'phpbb_oauth_states');
$phpbb_container->setParameter('tables.auth_provider_oauth_account_assoc', 'phpbb_oauth_accounts');
}
public function first_last_post_data()

View File

@@ -21,6 +21,7 @@ class phpbb_mock_container_builder implements ContainerInterface
public function __construct()
{
$this->setParameter('debug.load_time', false);
$this->setParameter('session.log_errors', false);
}
/**

View File

@@ -56,7 +56,6 @@ abstract class phpbb_notification_submit_post_base extends phpbb_database_test_c
// Database
$this->db = $this->new_dbal();
$db = $this->db;
$db_mock = $this->createMock('\phpbb\db\driver\driver_interface');
// Auth
$auth = $this->createMock('\phpbb\auth\auth');

View File

@@ -87,21 +87,12 @@ class phpbb_privmsgs_delete_user_pms_test extends phpbb_database_test_case
{
global $db, $phpbb_container, $phpbb_root_path;
$cache = $this->createMock('\phpbb\cache\driver\driver_interface');
$db = $this->new_dbal();
$db_mock = $this->createMock('\phpbb\db\driver\driver_interface');
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('notification_manager', new phpbb_mock_notification_manager());
$adapter = new \phpbb\storage\adapter\local(new \phpbb\filesystem\filesystem(), new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$adapter->configure(['path' => 'files']);
$adapter_factory_mock = $this->createMock('\phpbb\storage\adapter_factory');
$adapter_factory_mock->expects($this->any())
->method('get')
->willReturn($adapter);
$storage = new \phpbb\storage\storage($db_mock, $cache, $adapter_factory_mock, '', '');
$storage = $this->createMock('\phpbb\storage\storage');
// Works as a workaround for tests
$phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\attachment\resync($db), $storage));

View File

@@ -20,16 +20,6 @@ class phpbb_type_cast_helper_test extends phpbb_test_case
$this->type_cast_helper = new \phpbb\request\type_cast_helper();
}
public function test_addslashes_recursively()
{
$data = array('some"string' => array('that"' => 'really"', 'needs"' => '"escaping'));
$expected = array('some\\"string' => array('that\\"' => 'really\\"', 'needs\\"' => '\\"escaping'));
$this->type_cast_helper->addslashes_recursively($data);
$this->assertEquals($expected, $data);
}
public function test_simple_recursive_set_var()
{
$data = 'eviL<3';

View File

@@ -108,7 +108,7 @@ class phpbb_security_redirect_test extends phpbb_security_test_base
if ($expected_error !== false)
{
$this->setExpectedTriggerError(E_USER_ERROR, $user->lang[$expected_error]);
$this->setExpectedTriggerError(E_USER_WARNING, $user->lang[$expected_error]);
}
$result = redirect($test, true, $disable_cd_check);

View File

@@ -0,0 +1,136 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
class phpbb_storage_adapter_local_subfolders_test extends phpbb_test_case
{
protected $adapter;
protected $path;
protected $filesystem;
public function setUp()
{
parent::setUp();
$this->filesystem = new \phpbb\filesystem\filesystem();
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
$this->adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$this->adapter->configure(['path' => 'test_path', 'subfolders' => true]);
$this->path = $phpbb_root_path . 'test_path/';
mkdir($this->path);
}
public function tearDown()
{
$this->adapter = null;
rmdir($this->path);
}
public function test_put_contents()
{
$this->adapter->put_contents('file.txt', 'abc');
$this->assertTrue(file_exists($this->path . '3d/8e/file.txt'));
$this->assertEquals(file_get_contents($this->path . '3d/8e/file.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
}
public function test_get_contents()
{
mkdir($this->path . '3d/8e', 0777, true);
file_put_contents($this->path . '3d/8e/file.txt', 'abc');
$this->assertEquals($this->adapter->get_contents('file.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
}
public function test_exists()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
$this->assertTrue($this->adapter->exists('file.txt'));
$this->assertFalse($this->adapter->exists('3d/8e/file.txt'));
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
}
public function test_delete_file()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
$this->assertTrue(file_exists($this->path . '3d/8e/file.txt'));
$this->adapter->delete('file.txt');
$this->assertFalse(file_exists($this->path . '3d/8e/file.txt'));
$this->assertFalse(file_exists($this->path . '3d'));
}
public function test_rename()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
$this->adapter->rename('file.txt', 'file2.txt');
$this->assertFalse(file_exists($this->path . '3d/8e/file.txt'));
$this->assertTrue(file_exists($this->path . '27/36/file2.txt'));
$this->assertFalse(file_exists($this->path . '3d'));
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
}
public function test_copy()
{
mkdir($this->path . '3d/8e', 0777, true);
file_put_contents($this->path . '3d/8e/file.txt', 'abc');
$this->adapter->copy('file.txt', 'file2.txt');
$this->assertEquals(file_get_contents($this->path . '3d/8e/file.txt'), 'abc');
$this->assertEquals(file_get_contents($this->path . '27/36/file2.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
}
public function test_read_stream()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
$stream = $this->adapter->read_stream('file.txt');
$this->assertTrue(is_resource($stream));
fclose($stream);
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
}
public function test_write_stream()
{
file_put_contents($this->path . 'file.txt', 'abc');
$stream = fopen($this->path . 'file.txt', 'rb');
$this->adapter->write_stream('file2.txt', $stream);
fclose($stream);
$this->assertEquals(file_get_contents($this->path . '27/36/file2.txt'), 'abc');
unlink($this->path . 'file.txt');
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
}
}

View File

@@ -27,7 +27,7 @@
$phpbb_root_path = getcwd() . DIRECTORY_SEPARATOR;
$this->adapter = new \phpbb\storage\adapter\local($this->filesystem, new \FastImageSize\FastImageSize(), new \phpbb\mimetype\guesser(array(new \phpbb\mimetype\extension_guesser)), $phpbb_root_path);
$this->adapter->configure(['path' => 'test_path', 'depth' => 2]);
$this->adapter->configure(['path' => 'test_path', 'subfolders' => false]);
$this->path = $phpbb_root_path . 'test_path/';
mkdir($this->path);
@@ -42,82 +42,61 @@
public function test_put_contents()
{
$this->adapter->put_contents('file.txt', 'abc');
$this->assertTrue(file_exists($this->path . '3d/8e/file.txt'));
$this->assertEquals(file_get_contents($this->path . '3d/8e/file.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
$this->assertTrue(file_exists($this->path . 'file.txt'));
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
unlink($this->path . 'file.txt');
}
public function test_get_contents()
{
mkdir($this->path . '3d/8e', 0777, true);
file_put_contents($this->path . '3d/8e/file.txt', 'abc');
file_put_contents($this->path . 'file.txt', 'abc');
$this->assertEquals($this->adapter->get_contents('file.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
unlink($this->path . 'file.txt');
}
public function test_exists()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
touch($this->path . 'file.txt');
$this->assertTrue($this->adapter->exists('file.txt'));
$this->assertFalse($this->adapter->exists('3d/8e/file.txt'));
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
$this->assertFalse($this->adapter->exists('noexist.txt'));
unlink($this->path . 'file.txt');
}
public function test_delete_file()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
$this->assertTrue(file_exists($this->path . '3d/8e/file.txt'));
touch($this->path . 'file.txt');
$this->assertTrue(file_exists($this->path . 'file.txt'));
$this->adapter->delete('file.txt');
$this->assertFalse(file_exists($this->path . '3d/8e/file.txt'));
$this->assertFalse(file_exists($this->path . '3d'));
$this->assertFalse(file_exists($this->path . 'file.txt'));
}
public function test_rename()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
touch($this->path . 'file.txt');
$this->adapter->rename('file.txt', 'file2.txt');
$this->assertFalse(file_exists($this->path . '3d/8e/file.txt'));
$this->assertTrue(file_exists($this->path . '27/36/file2.txt'));
$this->assertFalse(file_exists($this->path . '3d'));
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
$this->assertFalse(file_exists($this->path . 'file.txt'));
$this->assertTrue(file_exists($this->path . 'file2.txt'));
$this->assertFalse(file_exists($this->path . 'file.txt'));
unlink($this->path . 'file2.txt');
}
public function test_copy()
{
mkdir($this->path . '3d/8e', 0777, true);
file_put_contents($this->path . '3d/8e/file.txt', 'abc');
file_put_contents($this->path . 'file.txt', 'abc');
$this->adapter->copy('file.txt', 'file2.txt');
$this->assertEquals(file_get_contents($this->path . '3d/8e/file.txt'), 'abc');
$this->assertEquals(file_get_contents($this->path . '27/36/file2.txt'), 'abc');
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
$this->assertEquals(file_get_contents($this->path . 'file.txt'), 'abc');
$this->assertEquals(file_get_contents($this->path . 'file2.txt'), 'abc');
unlink($this->path . 'file.txt');
unlink($this->path . 'file2.txt');
}
public function test_read_stream()
{
mkdir($this->path . '3d/8e', 0777, true);
touch($this->path . '3d/8e/file.txt');
touch($this->path . 'file.txt');
$stream = $this->adapter->read_stream('file.txt');
$this->assertTrue(is_resource($stream));
fclose($stream);
unlink($this->path . '3d/8e/file.txt');
rmdir($this->path . '3d/8e');
rmdir($this->path . '3d');
unlink($this->path . 'file.txt');
}
public function test_write_stream()
@@ -126,11 +105,9 @@
$stream = fopen($this->path . 'file.txt', 'rb');
$this->adapter->write_stream('file2.txt', $stream);
fclose($stream);
$this->assertEquals(file_get_contents($this->path . '27/36/file2.txt'), 'abc');
$this->assertEquals(file_get_contents($this->path . 'file2.txt'), 'abc');
unlink($this->path . 'file.txt');
unlink($this->path . '27/36/file2.txt');
rmdir($this->path . '27/36');
rmdir($this->path . '27');
unlink($this->path . 'file2.txt');
}
}

View File

@@ -364,7 +364,7 @@ class phpbb_template_template_test extends phpbb_template_template_test_case
array(),
array(),
array(),
"Value'\n1 O'Clock\nValue\\x27\n1\\x20O\\x27Clock",
"Value'\n1 O'Clock\nValue\\u0027\n1\\u0020O\\u0027Clock",
array('VARIABLE' => "Value'", '1_VARIABLE' => "1 O'Clock"),
),
array(

View File

@@ -1241,10 +1241,6 @@ class phpbb_functional_test_case extends phpbb_test_case
}
}
// Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened)
// is not at least 2 seconds before submission, cancel the form
$form_data['lastclick'] = 0;
// 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.

View File

@@ -192,6 +192,13 @@ class phpbb_ui_test_case extends phpbb_test_case
}
}
$install_config_file = $phpbb_root_path . 'store/install_config.php';
if (file_exists($install_config_file))
{
unlink($install_config_file);
}
$container_builder = new \phpbb\di\container_builder($phpbb_root_path, $phpEx);
$container = $container_builder
->with_environment('installer')
@@ -205,11 +212,14 @@ class phpbb_ui_test_case extends phpbb_test_case
],
'cache.driver.class' => 'phpbb\cache\driver\file'
])
->with_config(new \phpbb\config_php_file($phpbb_root_path, $phpEx))
->without_compiled_container()
->get_container();
$container->register('installer.install_finish.notify_user')->setSynthetic(true);
$container->set('installer.install_finish.notify_user', new phpbb_mock_null_installer_task());
$container->register('installer.install_finish.install_extensions')->setSynthetic(true);
$container->set('installer.install_finish.install_extensions', new phpbb_mock_null_installer_task());
$container->compile();
$language = $container->get('language');
@@ -414,6 +424,12 @@ class phpbb_ui_test_case extends phpbb_test_case
{
if (!$this->cache)
{
global $phpbb_container, $phpbb_root_path;
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->setParameter('core.environment', PHPBB_ENVIRONMENT);
$phpbb_container->setParameter('core.cache_dir', $phpbb_root_path . 'cache/' . PHPBB_ENVIRONMENT . '/');
$this->cache = new \phpbb\cache\driver\file;
}
@@ -665,4 +681,37 @@ class phpbb_ui_test_case extends phpbb_test_case
$this->getDriver()->takeScreenshot($screenshot);
}
/**
* Wait for AJAX. Should be called after an AJAX action is made.
*
* @param string $framework javascript frameworks jquery|prototype|dojo
* @throws \Facebook\WebDriver\Exception\NoSuchElementException
* @throws \Facebook\WebDriver\Exception\TimeOutException
*/
public function waitForAjax($framework = 'jquery')
{
switch ($framework)
{
case 'jquery':
$code = 'return jQuery.active;';
break;
case 'prototype':
$code = 'return Ajax.activeRequestCount;';
break;
case 'dojo':
$code = 'return dojo.io.XMLHTTPTransport.inFlight.length;';
break;
default:
throw new \RuntimeException('Unsupported framework');
break;
}
// wait for at most 30s, retry every 2000ms (2s)
$driver = $this->getDriver();
$driver->wait(30, 2000)->until(
function () use ($driver, $code) {
return !$driver->executeScript($code);
}
);
}
}