Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

BugTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 239
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 15
lcom 1
cbo 2
dl 0
loc 239
rs 10
c 1
b 0
f 1
1
<?php
2
3
4
class BugTest extends PHPUnit_Framework_TestCase {
5
6
	
7
	public function testBug() 
8
	{
9
		//execute the contructor and check for the Object type and  attributes
10
		$bug = new Bug();
11
		$this->assertInstanceOf('Bug',$bug);
12
		$this->assertInstanceOf('SugarBean',$bug);
13
			
14
		$this->assertAttributeEquals('Bugs', 'module_dir', $bug);
15
		$this->assertAttributeEquals('Bug', 'object_name', $bug);
16
		$this->assertAttributeEquals('bugs', 'table_name', $bug);
17
		$this->assertAttributeEquals('accounts_bugs', 'rel_account_table', $bug);
18
		$this->assertAttributeEquals('contacts_bugs', 'rel_contact_table', $bug);
19
		$this->assertAttributeEquals('cases_bugs', 'rel_case_table', $bug);
20
		$this->assertAttributeEquals(true, 'new_schema', $bug);
21
		
22
	}
23
24
	
25
	public function testget_summary_text()
26
	{
27
		error_reporting(E_ERROR | E_PARSE);
28
		
29
		$bug = new Bug();
30
		
31
		//test without setting name
32
		$this->assertEquals(Null,$bug->get_summary_text());
33
		
34
		//test with name set//test with name set
35
		$bug->name = "test";
36
		$this->assertEquals('test',$bug->get_summary_text());
37
		
38
	}
39
40
	public function testcreate_list_query()
41
	{		
42
		$bug = new Bug();
43
		
44
		//test with empty string params
45
		$expected = "SELECT \n                               bugs.*\n\n                                ,users.user_name as assigned_user_name, releases.id release_id, releases.name release_name FROM bugs 				LEFT JOIN releases ON bugs.found_in_release=releases.id\n								LEFT JOIN users\n                                ON bugs.assigned_user_id=users.id  where  bugs.deleted=0  ORDER BY bugs.name";
46
		$actual = $bug->create_list_query('','');
47
		$this->assertSame($expected,$actual);
48
	
49
	
50
		//test with valid string params
51
		$expected = "SELECT \n                               bugs.*\n\n                                ,users.user_name as assigned_user_name, releases.id release_id, releases.name release_name FROM bugs 				LEFT JOIN releases ON bugs.found_in_release=releases.id\n								LEFT JOIN users\n                                ON bugs.assigned_user_id=users.id  where bugs.name=\"\" AND  bugs.deleted=0  ORDER BY releases.id";
52
		$actual = $bug->create_list_query('releases.id','bugs.name=""');
53
		$this->assertSame($expected,$actual);
54
		
55
	}
56
57
	public function testcreate_export_query()
58
	{
59
		$bug = new Bug();
60
		
61
		//test with empty string params
62
		$expected = "SELECT\n                                bugs.*,\n                                r1.name found_in_release_name,\n                                r2.name fixed_in_release_name,\n                                users.user_name assigned_user_name FROM bugs 				LEFT JOIN releases r1 ON bugs.found_in_release = r1.id\n								LEFT JOIN releases r2 ON bugs.fixed_in_release = r2.id\n								LEFT JOIN users\n                                ON bugs.assigned_user_id=users.id where   bugs.deleted=0\n                 ORDER BY bugs.bug_number";		
63
		$actual = $bug->create_export_query('','');
64
		$this->assertSame($expected,$actual);
65
66
		
67
		//test with valid string params
68
		$expected = "SELECT\n                                bugs.*,\n                                r1.name found_in_release_name,\n                                r2.name fixed_in_release_name,\n                                users.user_name assigned_user_name FROM bugs 				LEFT JOIN releases r1 ON bugs.found_in_release = r1.id\n								LEFT JOIN releases r2 ON bugs.fixed_in_release = r2.id\n								LEFT JOIN users\n                                ON bugs.assigned_user_id=users.id where bugs.name=\"\" AND   bugs.deleted=0\n                 ORDER BY releases.id";
69
		$actual = $bug->create_export_query('releases.id','bugs.name=""');
70
		$this->assertSame($expected,$actual);
71
		
72
		
73
		
74
	}
75
	
76
	public function testfill_in_additional_list_fields()
77
	{
78
		$bug = new Bug();
79
80
		//execute the method and test if it works and does not throws an exception.
81
		try {
82
			$bug->fill_in_additional_list_fields();
83
			$this->assertTrue(true);
84
		}
85
		catch (Exception $e) {
86
			$this->fail();
87
		}
88
89
	
90
	}
91
92
	public function testfill_in_additional_detail_fields()
93
	{   
94
95
		$bug = new Bug();
96
		$bug->assigned_user_id = 1;
97
		$bug->created_by = 1;
98
		$bug->modified_user_id = 1;
99
				
100
		//test with attributes preset and verify attributes are set accordingly
101
		$bug->fill_in_additional_detail_fields();
102
		
103
		$this->assertEquals("Administrator", $bug->assigned_user_name);
104
		$this->assertEquals("Administrator", $bug->created_by_name); 
105
		$this->assertEquals("Administrator", $bug->modified_by_name); 
106
		
107
	}
108
109
110
	public function testset_release() 
111
	{
112
		
113
		$bug = new Bug();
114
		$bug->found_in_release = "1";
115
		
116
		$bug->set_release();
117
		
118
		$this->assertEquals("",$bug->release_name);		
119
		
120
	}
121
122
	
123
	public function testset_fixed_in_release() 
124
	{
125
126
		$bug = new Bug();
127
		$bug->found_in_release = "1";
128
		
129
		$bug->set_release();
130
		
131
		$this->assertEquals("",$bug->fixed_in_release_name);	
132
	}
133
	
134
	
135
	public function testget_list_view_data()
136
	{
137
		$bug = new Bug();
138
		
139
		//execute the method and verify that it retunrs expected results
140
		$expected = array(
141
			"DELETED"=>0,
142
			"NAME"=>"<em>blank</em>",
143
			"PRIORITY"=>"",
144
			"STATUS"=>"",
145
			"TYPE"=>"",
146
			"RELEASE"=> NULL,
147
			"BUG_NUMBER" => NULL,
148
			"ENCODED_NAME"=>NULL
149
		);
150
		
151
		$actual = $bug->get_list_view_data();
152
		$this->assertSame($expected,$actual);
153
				
154
	}
155
156
157
	public function testbuild_generic_where_clause () 
158
	{
159
		$bug = new Bug();
160
		
161
		//execute with blank parameters
162
		$expected = "bugs.name like '%'";
163
		$actual = $bug->build_generic_where_clause ("");
164
		$this->assertSame($expected,$actual);
165
		
166
		
167
		//execute with numeric parameter
168
		$expected = "bugs.name like '1%' or bugs.bug_number like '1%'";
169
		$actual = $bug->build_generic_where_clause(1);
170
		$this->assertSame($expected,$actual);
171
				
172
	}
173
174
	
175
	public function testset_notification_body()
176
	{
177
		$bug = new Bug();
178
		
179
		$bug->name = "test";
180
		$bug->type = "Defect";
181
		$bug->priority = "Urgent";
182
		$bug->status = "New";
183
		$bug->resolution = "Accepted";
184
		$bug->bug_number ="1";
185
186
		//test with attributes preset and verify template variables are set accordingly
187
		$result = $bug->set_notification_body(new Sugar_Smarty(), $bug);
188
		
189
		$this->assertEquals($bug->name ,$result->_tpl_vars['BUG_SUBJECT']);
190
		$this->assertEquals($bug->type ,$result->_tpl_vars['BUG_TYPE']);
191
		$this->assertEquals($bug->priority ,$result->_tpl_vars['BUG_PRIORITY']);
192
		$this->assertEquals($bug->status ,$result->_tpl_vars['BUG_STATUS']);
193
		$this->assertEquals($bug->resolution ,$result->_tpl_vars['BUG_RESOLUTION']);
194
		$this->assertEquals($bug->bug_number ,$result->_tpl_vars['BUG_BUG_NUMBER']);
195
		
196
	}
197
	
198
	public function testbean_implements()
199
	{
200
		$bug = new Bug();
201
		$this->assertEquals(false, $bug->bean_implements('')); //test with blank value
202
		$this->assertEquals(false, $bug->bean_implements('test')); //test with invalid value
203
		$this->assertEquals(true, $bug->bean_implements('ACL')); //test with valid value
204
	}
205
	
206
	public function testsave()
207
	{
208
		$bug = new Bug();
209
		
210
		$bug->name = "test";
211
		$bug->bug_number ="1";
212
		$bug->type = "Defect";
213
		$bug->priority = "Urgent";
214
		$bug->status = "New";
215
		$bug->resolution = "Accepted";
216
		
217
		$bug->save();
218
		 
219
		 
220
		//test for record ID to verify that record is saved
221
		$this->assertTrue(isset($bug->id));
222
		$this->assertEquals(36, strlen($bug->id));
223
		 
224
		 
225
		//mark the record as deleted and verify that this record cannot be retrieved anymore.
226
		$bug->mark_deleted($bug->id);
227
		$result = $bug->retrieve($bug->id);
228
		$this->assertEquals(null,$result);
229
		
230
	}
231
232
233
	public function testgetReleaseDropDown()
234
	{
235
		$result = getReleaseDropDown();
236
		
237
		//execute the method and verify it returns an array
238
		$this->assertTrue(is_array($result));
239
	}
240
	
241
	
242
}
243
244
245
246
247
?>