[ticket/13867] Add tests

PHPBB3-13867
This commit is contained in:
Tristan Darricau 2016-12-30 15:13:47 +01:00 committed by mrgoldy
parent b1e1ee7d55
commit b3f3886cd9
5 changed files with 174 additions and 1 deletions

View file

@ -783,6 +783,10 @@ class acp_profile
$s_one_need_edit = true;
}
if (!isset($this->type_collection[$row['field_type']]))
{
continue;
}
$profile_field = $this->type_collection[$row['field_type']];
$field_block = array(

View file

@ -665,7 +665,7 @@ class manager
* @param bool $active True to limit output to active profile fields, false for all
* @return array Array with profile field ids as keys and idents as values
*/
private function list_profilefields($profilefield_type_name, $active=false)
private function list_profilefields($profilefield_type_name, $active = false)
{
// Get list of profile fields affected by this operation, if any
$profile_fields = array();

View 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>

View file

@ -0,0 +1,137 @@
<?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\db\driver\driver_interface */
protected $db;
/** @var \phpbb\config\db_text */
protected $config_text;
/** @var \phpbb\profilefields\manager */
protected $manager;
/** @var \phpbb\log\log_interface */
protected $log;
/** @var \phpbb\db\tools */
protected $db_tools;
public function getDataSet()
{
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/manager.xml');
}
public function setUp()
{
parent::setUp();
global $phpbb_log;
$this->log = $this->prophesize('\phpbb\log\log_interface');
$phpbb_log = $this->log->reveal();
$this->db = $this->new_dbal();
$this->config_text = $this->prophesize('\phpbb\config\db_text');
$this->db_tools = $this->prophesize('\phpbb\db\tools');
$this->manager = new \phpbb\profilefields\manager(
$this->prophesize('phpbb\auth\auth')->reveal(),
$this->db,
$this->db_tools->reveal(),
$this->prophesize('\phpbb\event\dispatcher_interface')->reveal(),
$this->prophesize('\phpbb\request\request')->reveal(),
$this->prophesize('\phpbb\template\template')->reveal(),
$this->prophesize('\phpbb\di\service_collection')->reveal(),
$this->prophesize('\phpbb\user')->reveal(),
$this->config_text->reveal(),
PROFILE_FIELDS_TABLE,
PROFILE_FIELDS_LANG_TABLE,
PROFILE_FIELDS_DATA_TABLE
);
}
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_2')->shouldBeCalled();
$this->config_text->set('foo_bar_type.saved', json_encode([1 => 'pf_1', 2 => 'pf_2']))->shouldBeCalled();
$this->manager->disable_profilefields('foo_bar_type');
$sql = 'SELECT field_id, field_ident
FROM ' . PROFILE_FIELDS_TABLE . "
WHERE field_active = 1
AND field_type = 'foo_bar_type'";
$this->assertSqlResultEquals(false, $sql, 'All profile fields should be disabled');
}
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_2')->shouldBeCalled();
$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->manager->enable_profilefields('foo_bar_type');
$sql = 'SELECT field_id
FROM ' . PROFILE_FIELDS_TABLE . "
WHERE field_active = 1
AND field_type = 'foo_bar_type'";
$this->assertSqlResultEquals([
['field_id' => '1'],
['field_id' => '2'],
], $sql, 'All profile fields should be enabled');
}
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_2')->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_2')->shouldBeCalled();
$this->manager->enable_profilefields('foo_bar_type');
$sql = 'SELECT field_id
FROM ' . PROFILE_FIELDS_TABLE . "
WHERE field_type = 'foo_bar_type'";
$this->assertSqlResultEquals(false, $sql, 'All profile fields should be removed');
$sql = 'SELECT field_id
FROM ' . PROFILE_FIELDS_LANG_TABLE . "
WHERE field_type = 'foo_bar_type'";
$this->assertSqlResultEquals(false, $sql, 'All profile fields lang should be removed');
$sql = 'SELECT field_id
FROM ' . PROFILE_LANG_TABLE . "
WHERE field_type = 'foo_bar_type'";
$this->assertSqlResultEquals(false, $sql, 'All profile fields lang should be removed');
$sql = 'SELECT field_id, field_order FROM ' . PROFILE_FIELDS_TABLE;
$this->assertSqlResultEquals([['field_id' => '3', 'field_order' => '1'],], $sql, 'Profile fields order should be recalculated, starting by 1');
}
}

View file

@ -27,6 +27,7 @@ class phpbb_test_case extends PHPUnit_Framework_TestCase
'PHP_Token_Stream_CachingFactory' => array('cache'),
'phpbb_database_test_case' => array('already_connected', 'last_post_timestamp'),
'Prophecy\Doubler\NameGenerator' => array('counter'),
);
}