Completed
Push — 3.3.x ( 8ae6a3...6c48f9 )
by Erwan
05:50
created

phpbbdirectory_base_test   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 132
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 24
loc 132
rs 10

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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_base_test extends controller_base
18
{
19
	public function getDataSet()
20
	{
21
		return $this->createXMLDataSet(__DIR__ . '/fixtures/fixture_base.xml');
22
	}
23
24
	/**
25
	* Setup test environment
26
	*/
27
	public function setUp()
28
	{
29
		parent::setUp();
30
31
		$this->user->style['style_path'] 	= 'prosilver';
32
		$this->config['dir_recent_block']	= 1;
33
		$this->config['dir_recent_rows']	= 1;
34
		$this->config['dir_recent_columns'] = 3;
35
		$this->config['dir_recent_exclude'] = '';
36
	}
37
38
	public function get_controller($user_id = 1)
39
	{
40
		global $table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch;
41
		global $phpEx, $phpbb_root_path;
42
43
		$this->user->data['user_id']		= $user_id;
44
		$this->user->data['is_registered']	= ($this->user->data['user_id'] != ANONYMOUS && ($this->user->data['user_type'] == USER_NORMAL || $this->user->data['user_type'] == USER_FOUNDER)) ? true : false;
45
46
		$controller = new \ernadoo\phpbbdirectory\controller\categories(
47
			$this->db,
48
			$this->config,
49
			$this->lang,
50
			$this->template,
51
			$this->user,
52
			$this->helper,
53
			$this->request,
54
			$this->auth,
55
			$this->pagination,
56
			$this->core_categorie,
57
			$this->core_link
58
		);
59
		$controller->set_tables($table_categories, $tables_comments, $tables_links, $tables_votes, $tables_watch);
60
		$controller->set_path_helper($this->phpbb_path_helper);
61
		$controller->set_extension_manager($this->phpbb_extension_manager);
62
63
		return $controller;
64
	}
65
66
	/**
67
	* Test data for the test_display_base() function
68
	*
69
	* @return array Array of test data
70
	*/
71
	public function display_base_data()
72
	{
73
		return array(
74
			array(200, 'body.html'),
75
		);
76
	}
77
78
	/**
79
	* Test controller display
80
	*
81
	* @dataProvider display_base_data
82
	*/
83
	public function test_display_base($status_code, $page_content)
84
	{
85
		$controller = $this->get_controller();
86
		$response = $controller->base();
87
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
88
		$this->assertEquals($status_code, $response->getStatusCode());
89
		$this->assertEquals($page_content, $response->getContent());
90
	}
91
92
	/**
93
	* Test base case scenario
94
	*
95
	*/
96
	public function test_for_root_categories()
97
	{
98
		$assign_block_vars = 2;
99
100
		$this->template->expects($this->exactly(2))
101
		->method('assign_vars')
102
		->withConsecutive(
103
			array(
104
				array( // navlinks
105
					'S_PHPBB_DIRECTORY'	=> true,
106
				),
107
			),
108
			array(
109
				array(
110
					'S_AUTH_ADD'		=> null,
111
					'S_AUTH_SEARCH'		=> null,
112
					'S_HAS_SUBCAT'		=> true,
113
					'S_ROOT'			=> true,
114
115
					'U_MAKE_SEARCH'		=> 'ernadoo_phpbbdirectory_search_controller',
116
				)
117
			)
118
		);
119
120
		$controller = $this->get_controller();
121
122
		$this->template->expects($this->exactly(7))
123
		->method('assign_block_vars')
124
		->withConsecutive(
125
			array('cat'),
126
			array('cat.subcat'),
127
			array('block'),
128
			array('block.row'),
129
			array('block.row.col', array(
130
				'UC_THUMBNAIL'            => '<a href="" onclick="window.open(\'ernadoo_phpbbdirectory_view_controller\'); return false;"><img src="" title="phpbb-services" alt="phpbb-services" /></a>',
131
				'NAME'                    => 'phpbb-services',
132
				'USER'                    => '<a href="phpBB/memberlist.php?mode=viewprofile&amp;u=2" class="username"></a>',
133
				'TIME'                    => '',
134
				'CAT'                     => 'Catégorie 2',
135
				'COUNT'					  => 0,
136
				'COMMENT'                 => 1,
137
138
				'U_CAT'                   => $this->helper->route('ernadoo_phpbbdirectory_dynamic_route_2'),
139
				'U_COMMENT'               => $this->helper->route('ernadoo_phpbbdirectory_comment_view_controller'),
140
141
				'L_DIR_SEARCH_NB_CLICKS'	=> 'DIR_SEARCH_NB_CLICKS',
142
				'L_DIR_SEARCH_NB_COMMS'		=> 'DIR_SEARCH_NB_COMMS',
143
				)
144
			),
145
			array('block.row.col'),
146
			array('block.row.col2')
147
		);
148
149
		$response = $controller->base();
150
		$this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
151
		$this->assertEquals('200', $response->getStatusCode());
152
	}
153
154
	protected function tearDown()
155
	{
156
		parent::tearDown();
157
	}
158
}
159