forked from phpbb-extensions/boardrules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_controller_test.php
More file actions
116 lines (105 loc) · 3.2 KB
/
main_controller_test.php
File metadata and controls
116 lines (105 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
*
* Board Rules extension for the phpBB Forum Software package.
*
* @copyright (c) 2014 phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace phpbb\boardrules\tests\controller;
class main_controller_test extends \phpbb_test_case
{
/**
* Test data for the test_display() function
*
* @return array Array of test data
*/
public function display_data()
{
return array(
'A rule' => array(
200,
'@phpbb_boardrules/boardrules_controller.html',
[
'get_left_id' => 1,
'get_right_id' => 2,
'get_anchor' => '',
'get_title' => 'title',
'get_message_for_display' => 'content',
]
),
'A category' => array(
200,
'@phpbb_boardrules/boardrules_controller.html',
[
'get_left_id' => 1,
'get_right_id' => 6,
'get_anchor' => '',
'get_title' => 'title',
'get_message_for_display' => 'content',
],
),
);
}
/**
* Test controller display
*
* @dataProvider display_data
*/
public function test_display($status_code, $page_content, $rule_data)
{
global $config, $user, $phpbb_root_path, $phpEx;
// Global vars called upon during execution
$config = new \phpbb\config\config(array('boardrules_enable' => 1));
$lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx);
$lang = new \phpbb\language\language($lang_loader);
$user = new \phpbb\user($lang, '\phpbb\datetime');
$entity = $this->getMockBuilder('\phpbb\boardrules\entity\rule')
->disableOriginalConstructor()
->getMock();
foreach ($rule_data as $method => $return_value)
{
$entity->method($method)->willReturn($return_value);
}
// Mock the rule operator and return an empty array for get_rules method
$rule_operator = $this->getMockBuilder('\phpbb\boardrules\operators\rule')
->disableOriginalConstructor()
->getMock();
$rule_operator->expects(self::at(0))
->method('get_rules')
->willReturn(array());
$rule_operator->expects(self::at(1))
->method('get_rules')
->willReturn([$entity]);
// Mock the controller helper and return render response object
$controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
->disableOriginalConstructor()
->getMock();
$controller_helper->expects(self::once())
->method('render')
->willReturnCallback(function ($template_file, $page_title = '', $status_code = 200, $display_online_list = false) {
return new \Symfony\Component\HttpFoundation\Response($template_file, $status_code);
});
// Mock the template
$template = $this->getMockBuilder('\phpbb\template\template')
->getMock();
/** @var \phpbb\controller\helper $controller_helper */
/** @var \phpbb\boardrules\operators\rule $rule_operator */
/** @var \phpbb\template\template $template */
$controller = new \phpbb\boardrules\controller\main_controller(
$config,
$controller_helper,
$lang,
$rule_operator,
$template,
$user,
$phpbb_root_path,
$phpEx
);
$response = $controller->display();
self::assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
self::assertEquals($status_code, $response->getStatusCode());
self::assertEquals($page_content, $response->getContent());
}
}