]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/include/MVC/View/SugarViewTest.php
Release 6.4.1
[Github/sugarcrm.git] / tests / include / MVC / View / SugarViewTest.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
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.
12  * 
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
16  * details.
17  * 
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
21  * 02110-1301 USA.
22  * 
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.
25  * 
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.
29  * 
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  ********************************************************************************/
36
37  
38 require_once 'include/MVC/View/SugarView.php';
39
40 class SugarViewTest extends Sugar_PHPUnit_Framework_TestCase
41 {
42     public function setUp()
43     {
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');
47     }
48     
49     public function tearDown()
50     {
51         unset($GLOBALS['mod_strings']);
52         unset($GLOBALS['app_strings']);
53     }
54     
55     public function testGetModuleTab()
56     {
57         $_REQUEST['module_tab'] = 'ADMIN';
58         $moduleTab = $this->_view->getModuleTab();
59         $this->assertEquals('ADMIN', $moduleTab, 'Module Tab names are not equal from request');
60     }
61
62     public function testGetMetaDataFile()
63     {
64         // backup custom file if it already exists
65         if(file_exists('custom/modules/Contacts/metadata/listviewdefs.php')){
66             copy('custom/modules/Contacts/metadata/listviewdefs.php', 'custom/modules/Contacts/metadata/listviewdefs.php.bak');
67             unlink('custom/modules/Contacts/metadata/listviewdefs.php');
68         }
69         $this->_view->module = 'Contacts';
70         $this->_view->type = 'list';
71         $metaDataFile = $this->_view->getMetaDataFile();
72         $this->assertEquals('modules/Contacts/metadata/listviewdefs.php', $metaDataFile, 'Did not load the correct metadata file');
73
74         //test custom file
75         if(!file_exists('custom/modules/Contacts/metadata/')){
76             sugar_mkdir('custom/modules/Contacts/metadata/', null, true);
77         }
78         $customFile = 'custom/modules/Contacts/metadata/listviewdefs.php';
79         if(!file_exists($customFile))
80         {
81             sugar_file_put_contents($customFile, array());
82             $customMetaDataFile = $this->_view->getMetaDataFile();
83             $this->assertEquals($customFile, $customMetaDataFile, 'Did not load the correct custom metadata file');
84             unlink($customFile);
85         }
86         // Restore custom file if we backed it up
87         if(file_exists('custom/modules/Contacts/metadata/listviewdefs.php.bak')){
88             rename('custom/modules/Contacts/metadata/listviewdefs.php.bak', 'custom/modules/Contacts/metadata/listviewdefs.php');
89         }
90     }
91     
92     public function testInit()
93     {
94         $bean = new SugarBean;
95         $view_object_map = array('foo'=>'bar');
96         $GLOBALS['action'] = 'barbar';
97         $GLOBALS['module'] = 'foofoo';
98         
99         $this->_view->init($bean,$view_object_map);
100         
101         $this->assertInstanceOf('SugarBean',$this->_view->bean);
102         $this->assertEquals($view_object_map,$this->_view->view_object_map);
103         $this->assertEquals($GLOBALS['action'],$this->_view->action);
104         $this->assertEquals($GLOBALS['module'],$this->_view->module);
105         $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
106     }
107     
108     public function testInitNoParameters()
109     {
110         $GLOBALS['action'] = 'barbar';
111         $GLOBALS['module'] = 'foofoo';
112         
113         $this->_view->init();
114         
115         $this->assertNull($this->_view->bean);
116         $this->assertEquals(array(),$this->_view->view_object_map);
117         $this->assertEquals($GLOBALS['action'],$this->_view->action);
118         $this->assertEquals($GLOBALS['module'],$this->_view->module);
119         $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
120     }
121     
122     public function testInitSmarty()
123     {
124         $this->_view->initSmarty();
125         
126         $this->assertInstanceOf('Sugar_Smarty',$this->_view->ss);
127         $this->assertEquals($this->_view->ss->get_template_vars('MOD'),$GLOBALS['mod_strings']);
128         $this->assertEquals($this->_view->ss->get_template_vars('APP'),$GLOBALS['app_strings']);
129     }
130     
131     /**
132      * @outputBuffering enabled
133      */
134     public function testDisplayErrors()
135     {
136         $this->_view->errors = array('error1','error2');
137         $this->_view->suppressDisplayErrors = true;
138         
139         $this->assertEquals(
140             '<span class="error">error1</span><br><span class="error">error2</span><br>',
141             $this->_view->displayErrors()
142             );
143     }
144     
145     /**
146      * @outputBuffering enabled
147      */
148     public function testDisplayErrorsDoNotSupressOutput()
149     {
150         $this->_view->errors = array('error1','error2');
151         $this->_view->suppressDisplayErrors = false;
152         
153         $this->assertEmpty($this->_view->displayErrors());
154     }
155     
156     public function testGetBrowserTitle()
157     {
158         $viewMock = $this->getMock('SugarViewTestMock',array('_getModuleTitleParams'));
159         $viewMock->expects($this->any())
160                  ->method('_getModuleTitleParams')
161                  ->will($this->returnValue(array('foo','bar')));
162         
163         $this->assertEquals(
164             "bar &raquo; foo &raquo; {$GLOBALS['app_strings']['LBL_BROWSER_TITLE']}",
165             $viewMock->getBrowserTitle()
166             );
167     }
168     
169     public function testGetBrowserTitleUserLogin()
170     {
171         $this->_view->module = 'Users';
172         $this->_view->action = 'Login';
173         
174         $this->assertEquals(
175             "{$GLOBALS['app_strings']['LBL_BROWSER_TITLE']}",
176             $this->_view->getBrowserTitle()
177             );
178     }
179     
180     public function testGetBreadCrumbSymbolForLTRTheme()
181     {
182         $theme = SugarTestThemeUtilities::createAnonymousTheme();
183         SugarThemeRegistry::set($theme);
184         
185         $this->assertEquals(
186             "<span class='pointer'>&raquo;</span>",
187             $this->_view->getBreadCrumbSymbol()
188             );
189     }
190     
191     public function testGetBreadCrumbSymbolForRTLTheme()
192     {
193         $theme = SugarTestThemeUtilities::createAnonymousRTLTheme();
194         SugarThemeRegistry::set($theme);
195         
196         $this->assertEquals(
197             "<span class='pointer'>&laquo;</span>",
198             $this->_view->getBreadCrumbSymbol()
199             );
200     }
201 }
202
203 class SugarViewTestMock extends SugarView
204 {
205     public function getModuleTab()
206     {
207         return parent::_getModuleTab();
208     }
209     
210     public function initSmarty()
211     {
212         return parent::_initSmarty();
213     }
214 }