Merge pull request #635 from marc1706/ticket/634
[ticket/634] Increase code coverage
This commit is contained in:
@@ -29,10 +29,15 @@ class template
|
||||
$this->data[$row] = array();
|
||||
}
|
||||
|
||||
$index = (sizeof($this->data[$row])) ? sizeof($this->data[$row]) : 0;
|
||||
foreach ($values as $key => $column)
|
||||
{
|
||||
$this->test_case->assertArrayNotHasKey($key, $this->data[$row]);
|
||||
$this->data[$row][$key] = $column;
|
||||
if (!isset($this->data[$row][$index]))
|
||||
{
|
||||
$this->data[$row][$index] = array();
|
||||
}
|
||||
$this->data[$row][$index][$key] = $column;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,4 +68,9 @@ class template
|
||||
{
|
||||
unset($this->data[$key]);
|
||||
}
|
||||
|
||||
public function get_row($row)
|
||||
{
|
||||
return $this->data[$row];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
|
||||
namespace board3\portal\portal\modules;
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../acp/portal_module.php');
|
||||
|
||||
class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
static public $redirected = false;
|
||||
@@ -31,12 +28,26 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
/** @var \board3\portal\includes\helper */
|
||||
protected $portal_helper;
|
||||
|
||||
/** @var \board3\portal\acp\portal_module */
|
||||
protected $portal_module;
|
||||
|
||||
/** @var \board3\portal\tests\mock\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb_mock_request */
|
||||
protected $request;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
global $db, $cache, $phpbb_root_path, $phpEx, $user, $phpbb_container, $request, $template, $table_prefix;
|
||||
global $phpbb_dispatcher;
|
||||
|
||||
$user = new \board3\portal\tests\mock\user();
|
||||
$template = new \board3\portal\tests\mock\template($this);
|
||||
$this->template = $template;
|
||||
$request = new \phpbb_mock_request;
|
||||
$this->request = $request;
|
||||
$phpbb_container = new \phpbb_mock_container_builder();
|
||||
// Mock module service collection
|
||||
$config = new \phpbb\config\config(array());
|
||||
@@ -91,6 +102,11 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
));
|
||||
$this->database_handler = new \board3\portal\portal\modules\database_handler($db);
|
||||
$this->constraints_handler = new \board3\portal\portal\modules\constraints_handler($this->portal_columns, $user);
|
||||
$phpbb_dispatcher = $this->getMock('\phpbb\event\dispatcher', array('trigger_event'), array($phpbb_container));
|
||||
$phpbb_dispatcher->expects($this->any())
|
||||
->method('trigger_event')
|
||||
->with($this->anything())
|
||||
->will($this->returnArgument(1));
|
||||
|
||||
$path_helper = new \phpbb\path_helper(
|
||||
new \phpbb\symfony_request(
|
||||
@@ -377,6 +393,32 @@ class phpbb_acp_move_module_test extends \board3\portal\tests\testframework\data
|
||||
{
|
||||
$this->assertSame($expected, $this->constraints_handler->can_add_module($this->portal_helper->get_module($module_class), $column));
|
||||
}
|
||||
|
||||
public function test_main_wrong_mode()
|
||||
{
|
||||
$this->setExpectedTriggerError(E_USER_ERROR, 'NO_MODE');
|
||||
$this->portal_module->main(5, 'foobar');
|
||||
}
|
||||
|
||||
public function test_main_config()
|
||||
{
|
||||
$this->portal_module->main(5, 'config');
|
||||
$this->template->assert_equals(array(), 'options');
|
||||
$options = $this->template->get_row('options');
|
||||
$this->assertNotEmpty($this->template->get_row('options'));
|
||||
$this->assertEquals(true, in_array('board3_show_all_pages', $options[9]));
|
||||
}
|
||||
|
||||
public function test_main_invalid_submit()
|
||||
{
|
||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||
$this->portal_module->main(5, 'config');
|
||||
$this->template->assert_equals(array(), 'options');
|
||||
$options = $this->template->get_row('options');
|
||||
$this->assertNotEmpty($this->template->get_row('options'));
|
||||
$this->assertEquals(true, in_array('board3_show_all_pages', $options[9]));
|
||||
$this->template->assert_same(true, 'S_ERROR');
|
||||
}
|
||||
}
|
||||
|
||||
function redirect($url)
|
||||
|
||||
23
tests/unit/acp/portal_module_test.php
Normal file
23
tests/unit/acp/portal_module_test.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2014 Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\portal\modules;
|
||||
|
||||
use board3\portal\acp\portal_info;
|
||||
|
||||
class phpbb_acp_portal_module_test extends \board3\portal\tests\testframework\test_case
|
||||
{
|
||||
public function test_portal_info()
|
||||
{
|
||||
$portal_info = new portal_info();
|
||||
$module_info = $portal_info->module();
|
||||
$this->assertArrayHasKey('filename', $module_info);
|
||||
$this->assertSame('\board3\portal\acp\portal_module', $module_info['filename']);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php');
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_content.php');
|
||||
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
|
||||
class phpbb_unit_functions_get_user_groups_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
public function getDataSet()
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
|
||||
class phpbb_functions_simple_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_ap_validate()
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
namespace board3\portal\modules;
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
|
||||
class phpbb_unit_modules_calendar_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $path_helper;
|
||||
|
||||
176
tests/unit/modules/welcome_test.php
Normal file
176
tests/unit/modules/welcome_test.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) Board3 Group ( www.board3.de )
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
namespace board3\portal\modules;
|
||||
|
||||
class phpbb_unit_modules_welcome_test extends \board3\portal\tests\testframework\database_test_case
|
||||
{
|
||||
protected $path_helper;
|
||||
|
||||
/** @var \board3\portal\modules\welcome */
|
||||
protected $welcome;
|
||||
|
||||
/** @var \phpbb\config\config */
|
||||
protected $config;
|
||||
|
||||
/** @var \board3\portal\tests\mock\template */
|
||||
protected $template;
|
||||
|
||||
/** @var \phpbb_mock_request */
|
||||
protected $request;
|
||||
|
||||
protected $expected_config = array();
|
||||
protected $expected_portal_config = array();
|
||||
|
||||
static public $form_key_valid = false;
|
||||
|
||||
public function getDataSet()
|
||||
{
|
||||
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/configs.xml');
|
||||
}
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
global $cache, $phpbb_root_path, $phpEx, $phpbb_dispatcher, $request;
|
||||
|
||||
$this->config = new \phpbb\config\config(array());
|
||||
$this->request = new \phpbb_mock_request();
|
||||
$request = $this->request;
|
||||
$this->template = new \board3\portal\tests\mock\template($this);
|
||||
$this->user = new \phpbb\user('\phpbb\datetime');
|
||||
$cache = $this->getMock('\phpbb\cache\cache', array('destroy', 'sql_exists', 'get', 'put', 'sql_load'));
|
||||
$cache->expects($this->any())
|
||||
->method('destroy')
|
||||
->with($this->equalTo('portal_config'));
|
||||
$cache->expects($this->any())
|
||||
->method('get')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
$cache->expects($this->any())
|
||||
->method('sql_exists')
|
||||
->with($this->anything());
|
||||
$cache->expects($this->any())
|
||||
->method('sql_exists')
|
||||
->with($this->anything())
|
||||
->will($this->returnValue(false));
|
||||
$cache->expects($this->any())
|
||||
->method('put')
|
||||
->with($this->anything());
|
||||
$phpbb_dispatcher = $this->getMockBuilder('\phpbb\event\dispatcher')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$phpbb_dispatcher->expects($this->any())
|
||||
->method('trigger_event')
|
||||
->with($this->anything())
|
||||
->will($this->returnArgument(1));
|
||||
|
||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, $phpbb_root_path, $phpEx);
|
||||
\set_config('foobar', 0, false, $this->config);
|
||||
$this->config->delete('foobar');
|
||||
}
|
||||
|
||||
public function test_get_template_center()
|
||||
{
|
||||
\set_portal_config('board3_welcome_message_' . 5, 'Welcome to my Community!');
|
||||
$this->config['board3_welcome_message_uid_' . 5] = '';
|
||||
$this->config['board3_welcome_message_bitfield_' . 5] = '';
|
||||
$return = $this->welcome->get_template_center(5);
|
||||
$this->assertEquals('welcome_center.html', $return);
|
||||
$this->template->assert_same('Welcome to my Community!', 'PORTAL_WELCOME_MSG');
|
||||
}
|
||||
|
||||
public function test_get_template_acp()
|
||||
{
|
||||
$acp_template = $this->welcome->get_template_acp(5);
|
||||
$this->assertNotEmpty($acp_template);
|
||||
$this->assertArrayHasKey('board3_welcome_message_5', $acp_template['vars']);
|
||||
}
|
||||
|
||||
public function test_install()
|
||||
{
|
||||
$this->assertTrue($this->welcome->install(1));
|
||||
|
||||
foreach ($this->config as $key => $value)
|
||||
{
|
||||
$this->expected_config[$key] = $value;
|
||||
}
|
||||
|
||||
$portal_config = obtain_portal_config();
|
||||
|
||||
foreach ($portal_config as $key => $value)
|
||||
{
|
||||
$this->expected_portal_config[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dependsOn test_install
|
||||
*/
|
||||
public function test_uninstall()
|
||||
{
|
||||
$this->assertNotEmpty($this->welcome->uninstall(1, $this->db));
|
||||
|
||||
foreach ($this->expected_config as $key => $value)
|
||||
{
|
||||
$this->assertFalse(isset($this->config[$key]));
|
||||
}
|
||||
|
||||
$portal_config = obtain_portal_config();
|
||||
|
||||
foreach ($this->expected_config as $key => $value)
|
||||
{
|
||||
$this->assertFalse(isset($portal_config[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
public function test_update_welcome()
|
||||
{
|
||||
$this->welcome->update_welcome('foobar', 5);
|
||||
$this->template->assert_same(true, 'S_EDIT');
|
||||
$this->request->overwrite('preview', true, \phpbb\request\request_interface::POST);
|
||||
$this->request->overwrite('welcome_message', 'foobar101');
|
||||
$this->welcome->update_welcome('foobar', 5);
|
||||
$this->template->assert_same(true, 'S_PREVIEW');
|
||||
$this->template->assert_same('foobar101', 'PREVIEW_TEXT');
|
||||
|
||||
$this->request = new \phpbb_mock_request();
|
||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', '');
|
||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||
self::$form_key_valid = true;
|
||||
$this->request->overwrite('welcome_message', 'foobar101');
|
||||
$this->welcome->update_welcome('foobar', 5);
|
||||
self::$form_key_valid = false;
|
||||
}
|
||||
|
||||
public function test_update_welcome_invalid_form_key()
|
||||
{
|
||||
$this->request = new \phpbb_mock_request();
|
||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', '');
|
||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||
$this->request->overwrite('welcome_message', 'foobar101');
|
||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||
$this->welcome->update_welcome('foobar', 5);
|
||||
}
|
||||
|
||||
public function test_update_welcome_empty_message()
|
||||
{
|
||||
$this->request = new \phpbb_mock_request();
|
||||
$this->welcome = new \board3\portal\modules\welcome($this->config, $this->request, $this->template, $this->user, '', '');
|
||||
$this->request->overwrite('submit', true, \phpbb\request\request_interface::POST);
|
||||
$this->request->overwrite('welcome_message', '');
|
||||
$this->setExpectedTriggerError(E_USER_WARNING);
|
||||
$this->welcome->update_welcome('foobar', 5);
|
||||
}
|
||||
}
|
||||
|
||||
function check_form_key($value)
|
||||
{
|
||||
return phpbb_unit_modules_welcome_test::$form_key_valid;
|
||||
}
|
||||
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions_acp.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/functions.php');
|
||||
require_once(dirname(__FILE__) . '/../../../../../../includes/utf/utf_tools.php');
|
||||
|
||||
Reference in New Issue
Block a user