]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/modules/ModuleBuilder/parsers/views/Bug40969Test.php
Release 6.5.10
[Github/sugarcrm.git] / tests / modules / ModuleBuilder / parsers / views / Bug40969Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2013 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 "modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php";
39 require_once 'modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php' ;
40
41 /**
42  * Check ListLayoutMetaDataParser fills listviewdefs correctly for flex relate custom field to be displayed
43  * in ListView layout.
44  *
45  * Field should contain:
46  * 'related_fields' key - for data access (entity name)
47  * 'id'                 - for entity id in link
48  * 'dynamic_module'     - for entity module in link
49  */
50 class Bug40969Test extends Sugar_PHPUnit_Framework_TestCase
51 {
52     /**
53      * @var array
54      */
55     protected $vardefs =
56         array(
57             'name'         => array(
58                                   'name'     => 'name',
59                                   'vname'    => 'LBL_OPPORTUNITY_NAME',
60                                   'type'     => 'name',
61                                   'dbType'   => 'varchar',
62                                   'required' => true,
63                               ),
64             'date_entered' => array(
65                                   'name'  => 'date_entered',
66                                   'vname' => 'LBL_DATE_ENTERED',
67                                   'type'  => 'datetime',
68                               ),
69             'parent_name'  => array(
70                                   'source'        => 'non-db',
71                                   'name'          => 'parent_name',
72                                   'vname'         => 'LBL_FLEX_RELATE',
73                                   'type'          => 'parent',
74                                   'options'       => 'parent_type_display',
75                                   'type_name'     => 'parent_type',
76                                   'id_name'       => 'parent_id',
77                                   'parent_type'   => 'record_type_display',
78                                   'id'            => 'Opportunitiesparent_name',
79                                   'custom_module' => 'Opportunities',
80                               ),
81             'parent_id'    => array(
82                                   'source'        => 'custom_fields',
83                                   'name'          => 'parent_id',
84                                   'vname'         => 'LBL_PARENT_ID',
85                                   'type'          => 'id',
86                                   'id'            => 'Opportunitiesparent_id',
87                                   'custom_module' => 'Opportunities',
88                               ),
89             'parent_type'  => array(
90                                   'required'      => false,
91                                   'source'        => 'custom_fields',
92                                   'name'          => 'parent_type',
93                                   'vname'         => 'LBL_PARENT_TYPE',
94                                   'type'          => 'parent_type',
95                                   'dbType'        => 'varchar',
96                                   'id'            => 'Opportunitiesparent_type',
97                                   'custom_module' => 'Opportunities',
98                               ),
99         );
100
101     /**
102      * @var array
103      */
104     public $originalVardefs =
105         array(
106             'name'         => array(
107                                   'width'   => 30,
108                                   'label'   => 'LBL_LIST_OPPORTUNITIES_NAME',
109                                   'link'    => true,
110                                   'default' => true,
111                               ),
112             'dete_entered' => array(
113                                   'width'   => 10,
114                                   'label'   => 'LBL_DATE_ENTERED',
115                                   'default' => true,
116                               ),
117         );
118
119     public function setUp()
120     {
121         $_POST = array(
122                      'group_0' => array('name', 'date_entered', 'parent_name'),
123                  );
124     }
125
126     public function tearDown()
127     {
128         $_POST = array();
129     }
130
131     public function testCustomFlexFieldListViewDefs()
132     {
133         $methods = array('getFielddefs', 'getOriginalViewdefs', 'getViewdefs');
134
135         // Mock ListLayoutMetaDataParser Meta Implementation and make it return test values
136         $implementation = $this->getMock('DeployedMetaDataImplementation', $methods, array(), '', false);
137
138         $implementation->expects($this->any())->method('getFielddefs')->will($this->returnValue($this->vardefs));
139         $implementation->expects($this->any())->method('getOriginalViewdefs')->will($this->returnValue($this->originalVardefs));
140         $implementation->expects($this->any())->method('getViewdefs')->will($this->returnValue($this->originalVardefs));
141
142         $metaParser =  new Bug40969ListLayoutMetaDataParser($implementation, $this->vardefs);
143
144         $metaParser->testBug40969();
145
146         // Assert Flex Relate field contain required listview defs to be correctly displayed
147         $this->assertArrayHasKey('parent_name', $metaParser->_viewdefs);
148         $this->assertArrayHasKey('dynamic_module', $metaParser->_viewdefs['parent_name']);
149         $this->assertArrayHasKey('id', $metaParser->_viewdefs['parent_name']);
150         $this->assertArrayHasKey('link', $metaParser->_viewdefs['parent_name']);
151         $this->assertTrue($metaParser->_viewdefs['parent_name']['link']);
152         $this->assertArrayHasKey('related_fields', $metaParser->_viewdefs['parent_name']);
153         $this->assertEquals(array('parent_id', 'parent_type'), $metaParser->_viewdefs['parent_name']['related_fields']);
154     }
155
156 }
157
158 /**
159  * Helper class to access protected "_populateFromRequest" method
160  */
161 class Bug40969ListLayoutMetaDataParser extends ListLayoutMetaDataParser
162 {
163     /**
164      * @var DeployedMetaDataImplementation
165      */
166     public $implementation;
167
168     public function __construct($implementation)
169     {
170         $this->implementation = $implementation;
171
172         $this->_viewdefs = array_change_key_case($this->implementation->getViewdefs());
173         $this->_fielddefs = $this->implementation->getFielddefs() ;
174     }
175
176     public function testBug40969()
177     {
178         return $this->_populateFromRequest();
179     }
180
181 }