2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
38 require_once 'include/MVC/View/SugarView.php';
40 class SugarViewTest extends Sugar_PHPUnit_Framework_TestCase
42 public function setUp()
44 $this->_view = new SugarViewTestMock();
45 $GLOBALS['app_strings'] = return_application_language($GLOBALS['current_language']);
46 $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Users');
49 public function tearDown()
51 unset($GLOBALS['mod_strings']);
52 unset($GLOBALS['app_strings']);
55 public function testGetModuleTab()
57 $_REQUEST['module_tab'] = 'ADMIN';
58 $moduleTab = $this->_view->getModuleTab();
59 $this->assertEquals('ADMIN', $moduleTab, 'Module Tab names are not equal from request');
62 public function testGetMetaDataFile()
64 $this->_view->module = 'Contacts';
65 $this->_view->type = 'list';
66 $metaDataFile = $this->_view->getMetaDataFile();
67 $this->assertEquals('modules/Contacts/metadata/listviewdefs.php', $metaDataFile, 'Did not load the correct metadata file');
70 sugar_mkdir('custom/modules/Contacts/metadata/', null, true);
71 $customFile = 'custom/modules/Contacts/metadata/listviewdefs.php';
72 if(!file_exists($customFile))
74 sugar_file_put_contents($customFile, array());
75 $customMetaDataFile = $this->_view->getMetaDataFile();
76 $this->assertEquals($customFile, $customMetaDataFile, 'Did not load the correct custom metadata file');
81 public function testInit()
83 $bean = new SugarBean;
84 $view_object_map = array('foo'=>'bar');
85 $GLOBALS['action'] = 'barbar';
86 $GLOBALS['module'] = 'foofoo';
88 $this->_view->init($bean,$view_object_map);
90 $this->assertInstanceOf('SugarBean',$this->_view->bean);
91 $this->assertEquals($view_object_map,$this->_view->view_object_map);
92 $this->assertEquals($GLOBALS['action'],$this->_view->action);
93 $this->assertEquals($GLOBALS['module'],$this->_view->module);
94 $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
97 public function testInitNoParameters()
99 $GLOBALS['action'] = 'barbar';
100 $GLOBALS['module'] = 'foofoo';
102 $this->_view->init();
104 $this->assertNull($this->_view->bean);
105 $this->assertEquals(array(),$this->_view->view_object_map);
106 $this->assertEquals($GLOBALS['action'],$this->_view->action);
107 $this->assertEquals($GLOBALS['module'],$this->_view->module);
108 $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
111 public function testInitSmarty()
113 $this->_view->initSmarty();
115 $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
116 $this->assertEquals($this->_view->ss->get_template_vars('MOD'),$GLOBALS['mod_strings']);
117 $this->assertEquals($this->_view->ss->get_template_vars('APP'),$GLOBALS['app_strings']);
121 * @outputBuffering enabled
123 public function testDisplayErrors()
125 $this->_view->errors = array('error1','error2');
126 $this->_view->suppressDisplayErrors = true;
129 '<span class="error">error1</span><br><span class="error">error2</span><br>',
130 $this->_view->displayErrors()
135 * @outputBuffering enabled
137 public function testDisplayErrorsDoNotSupressOutput()
139 $this->_view->errors = array('error1','error2');
140 $this->_view->suppressDisplayErrors = false;
142 $this->assertEmpty($this->_view->displayErrors());
145 public function testGetBrowserTitle()
147 $viewMock = $this->getMock('SugarViewTestMock',array('_getModuleTitleParams'));
148 $viewMock->expects($this->any())
149 ->method('_getModuleTitleParams')
150 ->will($this->returnValue(array('foo','bar')));
153 "bar » foo » {$GLOBALS['app_strings']['LBL_BROWSER_TITLE']}",
154 $viewMock->getBrowserTitle()
158 public function testGetBrowserTitleUserLogin()
160 $this->_view->module = 'Users';
161 $this->_view->action = 'Login';
164 "{$GLOBALS['app_strings']['LBL_BROWSER_TITLE']}",
165 $this->_view->getBrowserTitle()
169 public function testGetBreadCrumbSymbolForLTRTheme()
171 $theme = SugarTestThemeUtilities::createAnonymousTheme();
172 SugarThemeRegistry::set($theme);
175 "<span class='pointer'>»</span>",
176 $this->_view->getBreadCrumbSymbol()
180 public function testGetBreadCrumbSymbolForRTLTheme()
182 $theme = SugarTestThemeUtilities::createAnonymousRTLTheme();
183 SugarThemeRegistry::set($theme);
186 "<span class='pointer'>«</span>",
187 $this->_view->getBreadCrumbSymbol()
192 class SugarViewTestMock extends SugarView
194 public function getModuleTab()
196 return parent::_getModuleTab();
199 public function initSmarty()
201 return parent::_initSmarty();