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

ViewFactoryTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 74
rs 10
c 1
b 0
f 1
1
<?php
2
3
4
5
class ViewFactoryTest extends PHPUnit_Framework_TestCase{
6
7
	public function testloadView(){
8
		error_reporting(E_ERROR | E_WARNING | E_PARSE);
9
		
10
		//check with invalid input. must return sugaview instance
11
		$view = ViewFactory::loadView('default','');
12
		$this->assertInstanceOf('SugarView',$view);
13
		
14
		//check with a valid module without a specific view, must return sugarview instance
15
		$view = ViewFactory::loadView('default','Users');
16
		$this->assertInstanceOf('SugarView',$view);
17
		
18
		//check with a valid module and specific view, must reutern speciifc view instance
19
		$view = ViewFactory::loadView('list','Users');
20
		$this->assertInstanceOf('UsersViewList',$view);		
21
		
22
	}
23
24
	public function test_loadConfig(){
25
		//check with a invalid module, method must not change the view options.
26
		$view = ViewFactory::loadView('default','');
27
		$options = $view->options;
28
		ViewFactory::_loadConfig($view, 'default');
29
		$this->assertSame($options,$view->options);
30
		
31
		
32
		//check with a valid module which does not implement it's own view config. method must not change the view options.
33
		 $view = ViewFactory::loadView('detail','Users');
34
		 $options = $view->options;
35
		 ViewFactory::_loadConfig($view, 'detail');
36
		 $this->assertSame($options,$view->options);
37
		 
38
		
39
		//check with a valid module which implement it's own view config. method still must not change the view options because it needs.
40
		$view = ViewFactory::loadView('area_detail_map','jjwg_Areas');
41
		$view->module = 'jjwg_Areas';
42
		$options = $view->options;
43
		ViewFactory::_loadConfig($view, 'area_detail_map');
44
		$this->assertSame($options,$view->options);		
45
		
46
		
47
	}
48
49
	public function test_buildFromFile(){
50
51
		//checck with valid values and test if it returns correct view instance
52
		$type = 'list';
53
		$target_module = 'Users';
54
		$bean = Null;
55
		$view = ViewFactory::_buildFromFile('modules/' . $target_module . '/views/view.'.$type.'.php', $bean, array(), $type, $target_module);
56
		$this->assertInstanceOf('UsersViewList',$view);
57
		
58
		//checck with valid values and test if it returns correct view instance
59
		$type = 'detail';
60
		$target_module = 'Users';
61
		$bean = Null;
62
		$view = ViewFactory::_buildFromFile('modules/' . $target_module . '/views/view.'.$type.'.php', $bean, array(), $type, $target_module);
63
		$this->assertInstanceOf('UsersViewDetail',$view);
64
		
65
	}
66
67
	public function test_buildClass(){
68
69
		//checck with valid values and test if it returns correct view instance
70
		$view = ViewFactory::_buildClass('UsersViewList', Null, array());
71
		$this->assertInstanceOf('UsersViewList',$view);		
72
		
73
		//checck with valid values and test if it returns correct view instance
74
		$view = ViewFactory::_buildClass('UsersViewDetail', Null, array());
75
		$this->assertInstanceOf('UsersViewDetail',$view);
76
				
77
	}
78
}
79
?>
80