2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2013 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 "modules/ModuleBuilder/parsers/views/ListLayoutMetaDataParser.php";
39 require_once 'modules/ModuleBuilder/parsers/views/DeployedMetaDataImplementation.php' ;
42 * Check ListLayoutMetaDataParser fills listviewdefs correctly for flex relate custom field to be displayed
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
50 class Bug40969Test extends Sugar_PHPUnit_Framework_TestCase
59 'vname' => 'LBL_OPPORTUNITY_NAME',
61 'dbType' => 'varchar',
64 'date_entered' => array(
65 'name' => 'date_entered',
66 'vname' => 'LBL_DATE_ENTERED',
69 'parent_name' => array(
71 'name' => 'parent_name',
72 'vname' => 'LBL_FLEX_RELATE',
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',
82 'source' => 'custom_fields',
83 'name' => 'parent_id',
84 'vname' => 'LBL_PARENT_ID',
86 'id' => 'Opportunitiesparent_id',
87 'custom_module' => 'Opportunities',
89 'parent_type' => array(
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',
104 public $originalVardefs =
108 'label' => 'LBL_LIST_OPPORTUNITIES_NAME',
112 'dete_entered' => array(
114 'label' => 'LBL_DATE_ENTERED',
119 public function setUp()
122 'group_0' => array('name', 'date_entered', 'parent_name'),
126 public function tearDown()
131 public function testCustomFlexFieldListViewDefs()
133 $methods = array('getFielddefs', 'getOriginalViewdefs', 'getViewdefs');
135 // Mock ListLayoutMetaDataParser Meta Implementation and make it return test values
136 $implementation = $this->getMock('DeployedMetaDataImplementation', $methods, array(), '', false);
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));
142 $metaParser = new Bug40969ListLayoutMetaDataParser($implementation, $this->vardefs);
144 $metaParser->testBug40969();
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']);
159 * Helper class to access protected "_populateFromRequest" method
161 class Bug40969ListLayoutMetaDataParser extends ListLayoutMetaDataParser
164 * @var DeployedMetaDataImplementation
166 public $implementation;
168 public function __construct($implementation)
170 $this->implementation = $implementation;
172 $this->_viewdefs = array_change_key_case($this->implementation->getViewdefs());
173 $this->_fielddefs = $this->implementation->getFielddefs() ;
176 public function testBug40969()
178 return $this->_populateFromRequest();