1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace florinp\messenger\tests\controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
6
|
|
|
|
7
|
|
|
class main_test extends \phpbb_test_case { |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @var \florinp\messenger\controller\main |
11
|
|
|
*/ |
12
|
|
|
protected $controller; |
13
|
|
|
|
14
|
|
|
public function setUp() { |
15
|
|
|
parent::setUp(); |
16
|
|
|
/** |
17
|
|
|
* @var \phpbb\user $user Mock the user class |
18
|
|
|
*/ |
19
|
|
|
$user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \phpbb\request\request $request |
23
|
|
|
*/ |
24
|
|
|
$request = $this->getMockBuilder('\phpbb\request\request') |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMock(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \florinp\messenger\models\main_model $model |
30
|
|
|
*/ |
31
|
|
|
$model = $this->getMockBuilder('\florinp\messenger\models\main_model') |
32
|
|
|
->disableOriginalConstructor() |
33
|
|
|
->getMock(); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \phpbb\notification\manager $notification_manager |
37
|
|
|
*/ |
38
|
|
|
$notification_manager = $this->getMockBuilder('\phpbb\notification\manager') |
39
|
|
|
->disableOriginalConstructor() |
40
|
|
|
->getMock(); |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \florinp\messenger\libs\emojione $emojione |
44
|
|
|
*/ |
45
|
|
|
$emojione = $this->getMockBuilder('\florinp\messenger\libs\emojione') |
46
|
|
|
->disableOriginalConstructor() |
47
|
|
|
->getMock(); |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var \florinp\messenger\libs\upload $upload |
51
|
|
|
*/ |
52
|
|
|
$upload = $this->getMockBuilder('\florinp\messenger\libs\upload') |
53
|
|
|
->disableOriginalConstructor() |
54
|
|
|
->getMock(); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var \florinp\messenger\libs\download $download |
58
|
|
|
*/ |
59
|
|
|
$download = $this->getMockBuilder('\florinp\messenger\libs\download') |
60
|
|
|
->disableOriginalConstructor() |
61
|
|
|
->getMock(); |
62
|
|
|
|
63
|
|
|
$this->controller = new \florinp\messenger\controller\main( |
64
|
|
|
$request, |
65
|
|
|
$user, |
66
|
|
|
$model, |
67
|
|
|
$notification_manager, |
68
|
|
|
$emojione, |
69
|
|
|
$upload, |
70
|
|
|
$download |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function tearDown() { |
75
|
|
|
$this->controller = null; |
76
|
|
|
parent::tearDown(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function publish_data() { |
80
|
|
|
return array( |
81
|
|
|
array(200, json_encode(array())) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @dataProvider publish_data |
87
|
|
|
*/ |
88
|
|
View Code Duplication |
public function test_publish($status_code, $page_content) { |
|
|
|
|
89
|
|
|
$response = $this->controller->publish(); |
90
|
|
|
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
91
|
|
|
$this->assertEquals($status_code, $response->getStatusCode()); |
92
|
|
|
$this->assertEquals($page_content, $response->getContent()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function load_data() { |
96
|
|
|
return array( |
97
|
|
|
array(200, json_encode(array( |
98
|
|
|
'success' => false, |
99
|
|
|
'error' => 'The request is invalid' |
100
|
|
|
))) |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @dataProvider load_data |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function test_load($status_code, $page_content) { |
|
|
|
|
108
|
|
|
$response = $this->controller->load(); |
109
|
|
|
$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
110
|
|
|
$this->assertEquals($status_code, $response->getStatusCode()); |
111
|
|
|
$this->assertEquals($page_content, $response->getContent()); |
112
|
|
|
} |
113
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.