Completed
Push — 3.3.x ( 37d736...41194d )
by Erwan
02:32
created

phpbbdirectory_cats_test::get_controller()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 19

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 1
eloc 19
nc 1
nop 0
1
<?php
2
/**
3
*
4
* phpBB Directory extension for the phpBB Forum Software package.
5
*
6
* @copyright (c) 2014 ErnadoO <http://www.phpbb-services.com>
7
* @license GNU General Public License, version 2 (GPL-2.0)
8
*
9
*/
10
11
namespace ernadoo\phpbbdirectory\tests\controller;
12
13
/**
14
* @group controller
15
*/
16
17
class phpbbdirectory_cats_test extends controller_base
18
{
19
	public function getDataSet()
20
	{
21
		return $this->createMySQLXMLDataSet(__DIR__ . '/fixtures/fixture_categories.xml');
22
	}
23
24
	/**
25
	* Setup test environment
26
	*/
27
	public function setUp()
28
	{
29
		parent::setUp();
30
31
		global $phpbb_dispatcher, $phpbb_container;
32
33
		$phpbb_dispatcher = $this->dispatcher;
34
35
		$this->user->data['user_id'] = 2;
36
		$this->user->style['style_path'] = 'prosilver';
37
38
		$this->config['dir_default_order'] = 't d';
39
		$this->config['dir_show'] = 5;
40
	}
41
42 View Code Duplication
	public function get_controller()
43
	{
44
		global $table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch;
45
		global $phpbb_path_helper, $phpbb_extension_manager;
46
47
		$controller = new \ernadoo\phpbbdirectory\controller\categories(
48
			$this->db,
49
			$this->config,
50
			$this->lang,
51
			$this->template,
52
			$this->user,
53
			$this->helper,
54
			$this->request,
55
			$this->auth,
56
			$this->pagination,
57
			$this->core_categorie,
58
			$this->core_link
59
		);
60
		$controller->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch);
61
		$controller->set_path_helper($phpbb_path_helper);
62
		$controller->set_extension_manager($phpbb_extension_manager);
63
64
		return $controller;
65
	}
66
67
	/**
68
	* Test data for the test_display_cat_by_id() function
69
	*
70
	* @return array Array of test data
71
	*/
72
	public function display_cat_by_id_data()
73
	{
74
		return array(
75
			array(1, 1, 301), // old viewable cat
76
		);
77
	}
78
79
	/**
80
	* Test controller display
81
	*
82
	* @dataProvider display_cat_by_id_data
83
	*/
84
	public function test_display_cat_by_id($cat_id, $page, $status_code)
85
	{
86
		$controller = $this->get_controller();
87
88
		$response = $controller->view($cat_id, $page, 0, 0, 0);
0 ignored issues
show
Deprecated Code introduced by
The method ernadoo\phpbbdirectory\c...ller\categories::view() has been deprecated with message: 2.0.0 No longer used since dynamic routing.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
89
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
90
		$this->assertEquals($status_code, $response->getStatusCode());
91
	}
92
93
	/**
94
	 * Test data for the test_display_cat_by_route() function
95
	 *
96
	 * @return array Array of test data
97
	 */
98
	public function display_cat_by_route_data()
99
	{
100
		return array(
101
			array(1, 1, 200, 'view_cat.html'), // viewable cat
102
		);
103
	}
104
105
	/**
106
	 * Test controller display
107
	 *
108
	 * @dataProvider display_cat_by_route_data
109
	 */
110
	public function test_display_cat_by_route($cat_id, $page, $status_code, $page_content)
111
	{
112
		$this->config['dir_default_order'] = 't d';
113
		$this->user->data['user_id'] = 1;
114
115
		$controller = $this->get_controller();
116
117
		$response = $controller->view_route($cat_id, $page, 0, 0, 0);
118
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
119
		$this->assertEquals($status_code, $response->getStatusCode());
120
		$this->assertEquals($page_content, $response->getContent());
121
	}
122
123
	/**
124
	* Test data for the test_display_cat_fails() function
125
	*
126
	* @return array Array of test data
127
	*/
128
	public function display_cat_fails_data()
129
	{
130
		return array(
131
			array(5, 1, 404, 'DIR_ERROR_NO_CATS'),
132
		);
133
	}
134
135
	/**
136
	* Test controller display throws 404 exceptions
137
	*
138
	* @dataProvider display_cat_fails_data
139
	*/
140
	public function test_display_cat_fails($cat_id, $page, $status_code, $page_content)
141
	{
142
		$controller = $this->get_controller();
143
		try
144
		{
145
			$controller->view($cat_id, $page, 0, 0, 0);
0 ignored issues
show
Deprecated Code introduced by
The method ernadoo\phpbbdirectory\c...ller\categories::view() has been deprecated with message: 2.0.0 No longer used since dynamic routing.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
146
			$this->fail('The expected \phpbb\exception\http_exception was not thrown');
147
		}
148
		catch (\phpbb\exception\http_exception $exception)
0 ignored issues
show
Bug introduced by
The class phpbb\exception\http_exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
149
		{
150
			$this->assertEquals($status_code, $exception->getStatusCode());
151
			$this->assertEquals($page_content, $exception->getMessage());
152
		}
153
	}
154
155
	/**
156
	* Test data for the test_category_one_page() function
157
	*
158
	* @return array Array of test data
159
	*/
160
	public function category_one_page_data()
161
	{
162
		return array(
163
			array(3, 'Catégorie 3', 1, 1),
164
		);
165
	}
166
167
	/**
168
	* Test base case scenario
169
	*
170
	* @dataProvider category_one_page_data
171
	*/
172 View Code Duplication
	function test_category_one_page($cat_id, $cat_name, $parent_cat_id, $nb_links)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
173
	{
174
		$controller = $this->get_controller();
175
		$response = $controller->view_route($cat_id);
176
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
177
		$this->assertEquals('200', $response->getStatusCode());
178
	}
179
180
	/**
181
	* Test data for the test_category_no_links() function
182
	*
183
	* @return array Array of test data
184
	*/
185
	public function category_no_links_data()
186
	{
187
		return array(
188
			array(1, 'Catégorie 1', 0),
189
		);
190
	}
191
192
	/**
193
	* Test base case scenario
194
	*
195
	* @dataProvider category_no_links_data
196
	*/
197
	function test_category_no_links($cat_id, $cat_name, $nb_links)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
198
	{
199
		$this->template->expects($this->at(3))
200
			->method('assign_block_vars')
201
			->withConsecutive(
202
			array('no_draw_link')
203
		);
204
205
		$controller = $this->get_controller();
206
		$response = $controller->view_route($cat_id);
207
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
208
		$this->assertEquals('200', $response->getStatusCode());
209
	}
210
211
	/**
212
	* Test data for the test_category_with_pages() function
213
	*
214
	* @return array Array of test data
215
	*/
216
	public function category_with_pages_data()
217
	{
218
		return array(
219
			array(2, 'Catégorie 2', 1, 'Catégorie 1', 6),
220
			array(2, 'Catégorie 2', 1, 'Catégorie 1', 6, 2),
221
		);
222
	}
223
224
	/**
225
	* Test base case scenario
226
	*
227
	* @dataProvider category_with_pages_data
228
	*/
229 View Code Duplication
	public function test_category_with_pages($cat_id, $cat_name, $parent_cat_id, $parent_cat_name, $nb_links, $page = 1, $sort_days = 0)
230
	{
231
		$controller = $this->get_controller();
232
		$response = $controller->view_route($cat_id, $page, $sort_days);
233
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
234
		$this->assertEquals('200', $response->getStatusCode());
235
	}
236
237
	protected function tearDown()
238
	{
239
		parent::tearDown();
240
	}
241
}
242