Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticket/634] Increase code coverage #635

Merged
merged 2 commits into from
Jun 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tests/mock/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ public function assign_block_vars($row, $values)
$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;
}
}

Expand Down Expand Up @@ -63,4 +68,9 @@ public function delete_var($key)
{
unset($this->data[$key]);
}

public function get_row($row)
{
return $this->data[$row];
}
}
48 changes: 45 additions & 3 deletions tests/unit/acp/move_module_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -91,6 +102,11 @@ public function setUp()
));
$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(
Expand Down Expand Up @@ -377,6 +393,32 @@ public function test_can_add_module($module_class, $column, $expected)
{
$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)
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/acp/portal_module_test.php
Original file line number Diff line number Diff line change
@@ -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']);
}
}
1 change: 0 additions & 1 deletion tests/unit/functions/check_file_src_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
1 change: 0 additions & 1 deletion tests/unit/functions/fetch_news_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
1 change: 0 additions & 1 deletion tests/unit/functions/functions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/functions/get_user_groups_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/functions/simple_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/modules/calendar_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
176 changes: 176 additions & 0 deletions tests/unit/modules/welcome_test.php
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 0 additions & 1 deletion tests/unit/portal/fetch_posts_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down