forked from phpbb-extensions/phpbb-ext-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_test.php.twig
More file actions
77 lines (68 loc) · 2.81 KB
/
main_test.php.twig
File metadata and controls
77 lines (68 loc) · 2.81 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
<?php
/**
*
* {{ EXTENSION.extension_display_name }}. An extension for the phpBB Forum Software package.
*
* @copyright (c) {{ "now"|date("Y") ~ (AUTHORS.0.author_name ? ', ' ~ AUTHORS.0.author_name) ~ (AUTHORS.0.author_homepage ? ', ' ~ AUTHORS.0.author_homepage) }}
* @license GNU General Public License, version 2 (GPL-2.0)
*
*/
namespace {{ EXTENSION.vendor_name }}\{{ EXTENSION.extension_name }}\tests\controller;
class main_test extends \phpbb_test_case
{
/**
* Dataset for the test_handle() test
*/
public function handle_data()
{
return [
[200, '@{{ EXTENSION.vendor_name|lower }}_{{ EXTENSION.extension_name|lower }}/{{ EXTENSION.extension_name|lower }}_body.html'],
];
}
/**
* A simple test that creates the controller class, and
* checks that its handle() method is working as expected.
*
* Note the dataProvider is required in this docblock to
* define the data set method this test will be using (above).
*
* @dataProvider handle_data
*/
public function test_handle($status_code, $page_content)
{
// Mocks are dummy implementations that provide the API of components we depend on //
/** @var \phpbb\template\template $template Mock the template class */
$template = $this->getMockBuilder('\phpbb\template\template')
->disableOriginalConstructor()
->getMock();
/** @var {{ LANGUAGE.class }}|\PHPUnit\Framework\MockObject\MockObject ${{ LANGUAGE.object }} Mock the {{ LANGUAGE.object }} class */
${{ LANGUAGE.object }} = $this->getMockBuilder('{{ LANGUAGE.class }}')
->disableOriginalConstructor()
->getMock();
// Set {{ LANGUAGE.object }}->lang() to return any arguments sent to it
${{ LANGUAGE.object }}->expects(self::any())
->method('lang')
->will(self::returnArgument(0));
/** @var \phpbb\controller\helper|\PHPUnit\Framework\MockObject\MockObject $controller_helper Mock the controller helper class */
$controller_helper = $this->getMockBuilder('\phpbb\controller\helper')
->disableOriginalConstructor()
->getMock();
// Set the expected output of the controller_helper->render() method
$controller_helper->expects($this->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);
});
// Instantiate the controller
$controller = new \{{ EXTENSION.vendor_name }}\{{ EXTENSION.extension_name }}\controller\main_controller(
new \phpbb\config\config([]),
$controller_helper,
$template,
${{ LANGUAGE.object }}
);
$response = $controller->handle('test');
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals($status_code, $response->getStatusCode());
$this->assertEquals($page_content, $response->getContent());
}
}