mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/13867] Amend profile fields manager tests
PHPBB3-13867
This commit is contained in:
parent
84cd7e496b
commit
903185a69c
1 changed files with 72 additions and 44 deletions
|
@ -13,20 +13,23 @@
|
||||||
|
|
||||||
class manager_test extends phpbb_database_test_case
|
class manager_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
|
/** @var \phpbb\config\db_text */
|
||||||
|
protected $config_text;
|
||||||
|
|
||||||
/** @var \phpbb\db\driver\driver_interface */
|
/** @var \phpbb\db\driver\driver_interface */
|
||||||
protected $db;
|
protected $db;
|
||||||
|
|
||||||
/** @var \phpbb\config\db_text */
|
/** @var \phpbb\db\tools\tools */
|
||||||
protected $config_text;
|
protected $db_tools;
|
||||||
|
|
||||||
|
/** @var \phpbb\log\log_interface */
|
||||||
|
protected $log;
|
||||||
|
|
||||||
/** @var \phpbb\profilefields\manager */
|
/** @var \phpbb\profilefields\manager */
|
||||||
protected $manager;
|
protected $manager;
|
||||||
|
|
||||||
/** @var \phpbb\log\log */
|
/** @var string Table prefix */
|
||||||
protected $log;
|
protected $table_prefix;
|
||||||
|
|
||||||
/** @var \phpbb\db\tools */
|
|
||||||
protected $db_tools;
|
|
||||||
|
|
||||||
public function getDataSet()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
|
@ -37,37 +40,53 @@ class manager_test extends phpbb_database_test_case
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
global $phpbb_log;
|
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||||
|
|
||||||
$this->log = $this->prophesize('\phpbb\log\log_interface');
|
$factory = new \phpbb\db\tools\factory();
|
||||||
$phpbb_log = $this->log->reveal();
|
|
||||||
|
|
||||||
$this->db = $this->new_dbal();
|
$this->db = $this->new_dbal();
|
||||||
$this->config_text = $this->prophesize('\phpbb\config\db_text');
|
$this->db_tools = $factory->get($this->db, true);
|
||||||
$this->db_tools = $this->prophesize('\phpbb\db\tools');
|
$this->config_text = new \phpbb\config\db_text($this->db, $table_prefix . 'config_text');
|
||||||
|
$this->table_prefix = $table_prefix;
|
||||||
|
|
||||||
|
$container = new phpbb_mock_container_builder();
|
||||||
|
$dispatcher = new phpbb_mock_event_dispatcher();
|
||||||
|
|
||||||
|
$request = $this->getMock('\phpbb\request\request');
|
||||||
|
$template = $this->getMock('\phpbb\template\template');
|
||||||
|
|
||||||
|
$auth = new \phpbb\auth\auth();
|
||||||
|
$language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx));
|
||||||
|
$collection = new \phpbb\di\service_collection($container);
|
||||||
|
$user = new \phpbb\user($language, '\phpbb\datetime');
|
||||||
|
|
||||||
|
$this->log = new \phpbb\log\log($this->db, $user, $auth, $dispatcher, $phpbb_root_path, 'adm/', $phpEx, $table_prefix . 'log');
|
||||||
|
|
||||||
$this->manager = new \phpbb\profilefields\manager(
|
$this->manager = new \phpbb\profilefields\manager(
|
||||||
$this->prophesize('phpbb\auth\auth')->reveal(),
|
$auth,
|
||||||
|
$this->config_text,
|
||||||
$this->db,
|
$this->db,
|
||||||
$this->db_tools->reveal(),
|
$this->db_tools,
|
||||||
$this->prophesize('\phpbb\event\dispatcher_interface')->reveal(),
|
$dispatcher,
|
||||||
$this->prophesize('\phpbb\request\request')->reveal(),
|
$language,
|
||||||
$this->prophesize('\phpbb\template\template')->reveal(),
|
$this->log,
|
||||||
$this->prophesize('\phpbb\di\service_collection')->reveal(),
|
$request,
|
||||||
$this->prophesize('\phpbb\user')->reveal(),
|
$template,
|
||||||
$this->config_text->reveal(),
|
$collection,
|
||||||
PROFILE_FIELDS_TABLE,
|
$user,
|
||||||
PROFILE_FIELDS_LANG_TABLE,
|
$table_prefix . 'profile_fields',
|
||||||
PROFILE_FIELDS_DATA_TABLE
|
$table_prefix . 'profile_fields_data',
|
||||||
|
$table_prefix . 'profile_fields_lang',
|
||||||
|
$table_prefix . 'profile_lang'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_disable_profilefields()
|
public function test_disable_profilefields()
|
||||||
{
|
{
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', 'pf_1')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', 'pf_1')->shouldBeCalled();
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', 'pf_2')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_DEACTIVATE', 'pf_2')->shouldBeCalled();
|
||||||
|
|
||||||
$this->config_text->set('foo_bar_type.saved', json_encode([1 => 'pf_1', 2 => 'pf_2']))->shouldBeCalled();
|
# $this->config_text->set('foo_bar_type.saved', json_encode([1 => 'pf_1', 2 => 'pf_2']));
|
||||||
|
|
||||||
$this->manager->disable_profilefields('foo_bar_type');
|
$this->manager->disable_profilefields('foo_bar_type');
|
||||||
|
|
||||||
|
@ -76,16 +95,16 @@ class manager_test extends phpbb_database_test_case
|
||||||
WHERE field_active = 1
|
WHERE field_active = 1
|
||||||
AND field_type = 'foo_bar_type'";
|
AND field_type = 'foo_bar_type'";
|
||||||
|
|
||||||
$this->assertSqlResultEquals(false, $sql, 'All profile fields should be disabled');
|
$this->assertSqlResultEquals([], $sql, 'All profile fields should be disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_enable_profilefields()
|
public function test_enable_profilefields()
|
||||||
{
|
{
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_ACTIVATE', 'pf_1')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_ACTIVATE', 'pf_1')->shouldBeCalled();
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_ACTIVATE', 'pf_2')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_ACTIVATE', 'pf_2')->shouldBeCalled();
|
||||||
|
|
||||||
$this->config_text->get('foo_bar_type.saved')->willReturn(json_encode([1 => 'pf_1', 2 => 'pf_2']));
|
# $this->config_text->get('foo_bar_type.saved')->willReturn(json_encode([1 => 'pf_1', 2 => 'pf_2']));
|
||||||
$this->config_text->delete('foo_bar_type.saved')->shouldBeCalled();
|
# $this->config_text->delete('foo_bar_type.saved')->shouldBeCalled();
|
||||||
|
|
||||||
$this->manager->enable_profilefields('foo_bar_type');
|
$this->manager->enable_profilefields('foo_bar_type');
|
||||||
|
|
||||||
|
@ -102,33 +121,42 @@ class manager_test extends phpbb_database_test_case
|
||||||
|
|
||||||
public function test_purge_profilefields()
|
public function test_purge_profilefields()
|
||||||
{
|
{
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_REMOVED', 'pf_1')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_REMOVED', 'pf_1')->shouldBeCalled();
|
||||||
$this->log->add('admin', 'LOG_PROFILE_FIELD_REMOVED', 'pf_2')->shouldBeCalled();
|
# $this->log->add('admin', 'LOG_PROFILE_FIELD_REMOVED', 'pf_2')->shouldBeCalled();
|
||||||
|
|
||||||
$this->config_text->delete('foo_bar_type.saved')->shouldBeCalled();
|
# $this->config_text->delete('foo_bar_type.saved')->shouldBeCalled();
|
||||||
|
|
||||||
$this->db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_pf_1')->shouldBeCalled();
|
# $this->db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_pf_1')->shouldBeCalled();
|
||||||
$this->db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_pf_2')->shouldBeCalled();
|
# $this->db_tools->sql_column_remove(PROFILE_FIELDS_DATA_TABLE, 'pf_pf_2')->shouldBeCalled();
|
||||||
|
|
||||||
$this->manager->enable_profilefields('foo_bar_type');
|
$sql = 'SELECT field_id
|
||||||
|
FROM ' . PROFILE_FIELDS_TABLE . "
|
||||||
|
WHERE field_type = 'foo_bar_type'";
|
||||||
|
$result = $this->db->sql_query($sql);
|
||||||
|
$rowset = $this->db->sql_fetchrowset($result);
|
||||||
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
|
$field_ids = array_map('intval', array_column($rowset, 'field_id'));
|
||||||
|
|
||||||
|
$this->manager->purge_profilefields('foo_bar_type');
|
||||||
|
|
||||||
$sql = 'SELECT field_id
|
$sql = 'SELECT field_id
|
||||||
FROM ' . PROFILE_FIELDS_TABLE . "
|
FROM ' . PROFILE_FIELDS_TABLE . "
|
||||||
WHERE field_type = 'foo_bar_type'";
|
WHERE field_type = 'foo_bar_type'";
|
||||||
|
|
||||||
$this->assertSqlResultEquals(false, $sql, 'All profile fields should be removed');
|
$this->assertSqlResultEquals([], $sql, 'All profile fields should be removed');
|
||||||
|
|
||||||
$sql = 'SELECT field_id
|
$sql = 'SELECT field_id
|
||||||
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
|
||||||
WHERE field_type = 'foo_bar_type'";
|
WHERE field_type = 'foo_bar_type'";
|
||||||
|
|
||||||
$this->assertSqlResultEquals(false, $sql, 'All profile fields lang should be removed');
|
$this->assertSqlResultEquals([], $sql, 'All profile fields lang should be removed');
|
||||||
|
|
||||||
$sql = 'SELECT field_id
|
$sql = 'SELECT lang_name
|
||||||
FROM ' . PROFILE_LANG_TABLE . "
|
FROM ' . PROFILE_LANG_TABLE . '
|
||||||
WHERE field_type = 'foo_bar_type'";
|
WHERE ' . $this->db->sql_in_set('field_id', $field_ids);
|
||||||
|
|
||||||
$this->assertSqlResultEquals(false, $sql, 'All profile fields lang should be removed');
|
$this->assertSqlResultEquals([], $sql, 'All profile fields lang should be removed');
|
||||||
|
|
||||||
$sql = 'SELECT field_id, field_order FROM ' . PROFILE_FIELDS_TABLE;
|
$sql = 'SELECT field_id, field_order FROM ' . PROFILE_FIELDS_TABLE;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue