mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-30 21:40:43 +02:00
Merge branch '3.2.x' into 3.3.x
This commit is contained in:
31
tests/profilefields/fixtures/manager.xml
Normal file
31
tests/profilefields/fixtures/manager.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<dataset>
|
||||
<table name="phpbb_profile_fields">
|
||||
<column>field_id</column>
|
||||
<column>field_ident</column>
|
||||
<column>field_active</column>
|
||||
<column>field_type</column>
|
||||
<column>field_order</column>
|
||||
<row>
|
||||
<value>1</value>
|
||||
<value>pf_1</value>
|
||||
<value>1</value>
|
||||
<value>foo_bar_type</value>
|
||||
<value>1</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>2</value>
|
||||
<value>pf_2</value>
|
||||
<value>1</value>
|
||||
<value>foo_bar_type</value>
|
||||
<value>2</value>
|
||||
</row>
|
||||
<row>
|
||||
<value>3</value>
|
||||
<value>pf_3</value>
|
||||
<value>1</value>
|
||||
<value>other_type</value>
|
||||
<value>3</value>
|
||||
</row>
|
||||
</table>
|
||||
</dataset>
|
178
tests/profilefields/manager_test.php
Normal file
178
tests/profilefields/manager_test.php
Normal file
@@ -0,0 +1,178 @@
|
||||
<?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 manager_test extends phpbb_database_test_case
|
||||
{
|
||||
/** @var \phpbb\config\db_text */
|
||||
protected $config_text;
|
||||
|
||||
/** @var \phpbb\db\driver\driver_interface */
|
||||
protected $db;
|
||||
|
||||
/** @var \phpbb\db\tools\tools */
|
||||
protected $db_tools;
|
||||
|
||||
/** @var \phpbb\log\log_interface */
|
||||
protected $log;
|
||||
|
||||
/** @var \phpbb\profilefields\manager */
|
||||
protected $manager;
|
||||
|
||||
/** @var string Table prefix */
|
||||
protected $table_prefix;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/manager.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
global $phpbb_root_path, $phpEx, $table_prefix;
|
||||
|
||||
$this->db = $this->new_dbal();
|
||||
$this->db_tools = $this->getMock('\phpbb\db\tools\tools', [], [$this->db]);
|
||||
$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(
|
||||
$auth,
|
||||
$this->config_text,
|
||||
$this->db,
|
||||
$this->db_tools,
|
||||
$dispatcher,
|
||||
$language,
|
||||
$this->log,
|
||||
$request,
|
||||
$template,
|
||||
$collection,
|
||||
$user,
|
||||
$table_prefix . 'profile_fields',
|
||||
$table_prefix . 'profile_fields_data',
|
||||
$table_prefix . 'profile_fields_lang',
|
||||
$table_prefix . 'profile_lang'
|
||||
);
|
||||
}
|
||||
|
||||
public function test_disable_profilefields()
|
||||
{
|
||||
// Disable the profile field type
|
||||
$this->manager->disable_profilefields('foo_bar_type');
|
||||
|
||||
$sql = 'SELECT field_id, field_ident
|
||||
FROM ' . $this->table_prefix . "profile_fields
|
||||
WHERE field_active = 1
|
||||
AND field_type = 'foo_bar_type'";
|
||||
$this->assertSqlResultEquals([], $sql, 'All profile fields should be disabled');
|
||||
|
||||
// Test that the config entry exists
|
||||
$saved = $this->config_text->get('foo_bar_type.saved');
|
||||
$saved = (array) json_decode($saved, true);
|
||||
$this->assertEquals([
|
||||
1 => 'pf_1',
|
||||
2 => 'pf_2',
|
||||
], $saved, 'All disable profile fields should be saved');
|
||||
}
|
||||
|
||||
public function test_enable_profilefields()
|
||||
{
|
||||
// Enable the profile field type
|
||||
$this->manager->enable_profilefields('foo_bar_type');
|
||||
|
||||
$sql = 'SELECT field_id
|
||||
FROM ' . $this->table_prefix . "profile_fields
|
||||
WHERE field_active = 1
|
||||
AND field_type = 'foo_bar_type'
|
||||
ORDER BY field_id ASC";
|
||||
$this->assertSqlResultEquals([
|
||||
['field_id' => '1'],
|
||||
['field_id' => '2'],
|
||||
], $sql, 'All profile fields should be enabled');
|
||||
|
||||
// Test that the config entry was removed
|
||||
$saved = $this->config_text->get('foo_bar_type.saved');
|
||||
$this->assertEquals($saved, null, 'All disable profile fields should be removed');
|
||||
}
|
||||
|
||||
public function test_purge_profilefields()
|
||||
{
|
||||
$this->db_tools
|
||||
->expects($this->exactly(2))
|
||||
->method('sql_column_remove')
|
||||
->with(
|
||||
$this->table_prefix . 'profile_fields_data',
|
||||
$this->stringStartsWith('pf_')
|
||||
);
|
||||
|
||||
// Get the field identifiers
|
||||
$sql = 'SELECT field_id
|
||||
FROM ' . $this->table_prefix . "profile_fields
|
||||
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'));
|
||||
|
||||
// Purge the profile field type
|
||||
$this->manager->purge_profilefields('foo_bar_type');
|
||||
|
||||
// Test all the profile field tables
|
||||
$sql = 'SELECT field_id
|
||||
FROM ' . $this->table_prefix . "profile_fields
|
||||
WHERE field_type = 'foo_bar_type'";
|
||||
$this->assertSqlResultEquals([], $sql, 'All profile fields should be removed');
|
||||
|
||||
$sql = 'SELECT field_id
|
||||
FROM ' . $this->table_prefix . "profile_fields_lang
|
||||
WHERE field_type = 'foo_bar_type'";
|
||||
$this->assertSqlResultEquals([], $sql, 'All profile fields lang should be removed');
|
||||
|
||||
$sql = 'SELECT lang_name
|
||||
FROM ' . $this->table_prefix . 'profile_lang
|
||||
WHERE ' . $this->db->sql_in_set('field_id', $field_ids);
|
||||
$this->assertSqlResultEquals([], $sql, 'All profile fields lang should be removed');
|
||||
|
||||
$sql = 'SELECT field_id, field_order
|
||||
FROM ' . $this->table_prefix . 'profile_fields
|
||||
ORDER BY field_id ASC';
|
||||
$this->assertSqlResultEquals([
|
||||
[
|
||||
'field_id' => '3',
|
||||
'field_order' => '1'
|
||||
]
|
||||
], $sql, 'Profile fields order should be recalculated, starting by 1');
|
||||
|
||||
// Test that the config entry was removed
|
||||
$saved = $this->config_text->get('foo_bar_type.saved');
|
||||
$this->assertEquals($saved, null, 'All disable profile fields should be removed');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user