Forked from Kobedinho/custom_readonly_fields_logic.php
Last active
January 12, 2017 22:13
-
-
Save betobaz/214ccc2646d724b06ffab4cea2e4deb0 to your computer and use it in GitHub Desktop.
SugarCRM: Dependencies with Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Documentation.- http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.7/Architecture/Sugar_Logic/Dependency_Actions/ | |
$dependencies['Meetings']['readonly_fields'] = array( | |
'hooks' => array("edit"), // values : "edit", "view", "save" and "all" | |
'trigger' => 'equal($status,"Held")', //Optional, the trigger for the dependency. Defaults to 'true'. | |
'triggerFields' => array('status'), // The list of fields to watch for change events. When changed, the trigger expressions will be recalculated. | |
'onload' => true, // Whether or not to trigger the dependencies when the page is loaded. | |
//Actions is a list of actions to fire when the trigger is true | |
// You could list multiple fields here each in their own array under 'actions' | |
'actions' => array( | |
array( | |
'name' => 'ReadOnly', // actions: ReadOnly, SetOptions, SetPanelVisibility, SetRequired, SetValue, SetVisibility | |
//The parameters passed in will depend on the action type set in 'name' | |
'params' => array( | |
'target' => 'status', | |
'value' => 'true', | |
), | |
), | |
), | |
// The list of dependencies to execute when the trigger expression is false | |
'notActions' => array( | |
), | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MeetingsDependenciesTest extends Sugar_PHPUnit_Framework_TestCase | |
{ | |
private $moduleName = 'Meetings'; | |
public function setUp() | |
{ | |
$this->view = new SugarView(); | |
$this->view->module = $this->moduleName; | |
$defs = $this->view->getMetaDataFile('edit'); | |
$this->dependencies = DependencyManager::getDependenciesForView($defs, 'EditView', $this->moduleName); | |
} | |
public function testDebeDependencias() | |
{ | |
$this->assertCount(1, $this->dependencies); | |
} | |
public function testDebeDeTenerDependenciaEstado() | |
{ | |
$dependencia = $this->dependencies[0]->getDefinition(); | |
$this->assertEquals("MeetingsEditView_readonly_fields", $dependencia['name']); | |
$this->assertEquals(['all'], $dependencia['hooks']); | |
$this->assertEquals('true', $dependencia['trigger']); | |
$this->assertEquals(['status'], $dependencia['triggerFields']); | |
$this->assertTrue($dependencia['onload']); | |
$this->assertCount(1, $dependencia['actions']); | |
$action = $dependencia['actions'][0]; | |
$this->assertEquals('ReadOnly', $action['action']); | |
$this->assertCount(3, $action['params']); | |
$this->assertEquals([ | |
'target' => 'status', | |
'value' => 'true', | |
], $action['params']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment