0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-02-21 20:56:08 +00:00
salesagility_SuiteCRM/tests/unit/phpunit/modules/ACLActions/ACLActionTest.php
j.dang 4a381d962a Replace explicit bean instantiations in files 101 - 110
- File: '... /tests/unit/phpunit/modules/ACLActions/ACLActionTest.php'

   - Replaced 4 occurrence(s) of 'new ACLAction()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/ProjectTask/ProjectTaskTest.php'

   - Replaced 19 occurrence(s) of 'new ProjectTask()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/Alerts/AlertTest.php'

   - Replaced 1 occurrence(s) of 'new User()'

   - Replaced 2 occurrence(s) of 'new Alert()'

- File: '... /tests/unit/phpunit/modules/ACLRoles/ACLRoleTest.php'

   - Replaced 10 occurrence(s) of 'new ACLRole()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/jjwg_Markers/jjwg_MarkersTest.php'

   - Replaced 5 occurrence(s) of 'new jjwg_Markers()'

- File: '... /tests/unit/phpunit/modules/Tasks/TaskTest.php'

   - Replaced 12 occurrence(s) of 'new Task()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/CampaignLog/CampaignLogTest.php'

   - Replaced 4 occurrence(s) of 'new CampaignLog()'

   - Replaced 1 occurrence(s) of 'new User()'

- File: '... /tests/unit/phpunit/modules/UserPreferences/UserPreferenceTest.php'

   - Replaced 5 occurrence(s) of 'new User()'

   - Replaced 2 occurrence(s) of 'new UserPreference()'

- File: '... /tests/unit/phpunit/modules/Favorites/FavoritesTest.php'

   - Replaced 4 occurrence(s) of 'new Favorites()'

- File: '... /tests/unit/phpunit/modules/AOR_Scheduled_Reports/AOR_Scheduled_ReportsTest.php'

   - Replaced 1 occurrence(s) of 'new User()'

   - Replaced 1 occurrence(s) of 'new AOR_Report()'

   - Replaced 5 occurrence(s) of 'new AOR_Scheduled_Reports()'
2020-01-22 13:50:56 +00:00

239 lines
9.5 KiB
PHP

<?php /** @noinspection ALL */
use SuiteCRM\Test\SuitePHPUnitFrameworkTestCase;
class ACLActionTest extends SuitePHPUnitFrameworkTestCase
{
public function setUp()
{
parent::setUp();
global $current_user;
get_sugar_config_defaults();
$current_user = BeanFactory::newBean('Users');
}
public function tearDown()
{
parent::tearDown();
}
public function testACLAction()
{
self::markTestIncomplete('environment dependency');
$_POST['foo'] = 'bar123ase';
// Execute the constructor and check for the Object type and type attribute
$aclAction = BeanFactory::newBean('ACLActions');
$this->assertInstanceOf('ACLAction', $aclAction);
$this->assertInstanceOf('SugarBean', $aclAction);
$this->assertAttributeEquals('ACLActions', 'module_dir', $aclAction);
$this->assertAttributeEquals('ACLAction', 'object_name', $aclAction);
$this->assertAttributeEquals('acl_actions', 'table_name', $aclAction);
$this->assertAttributeEquals(true, 'new_schema', $aclAction);
$this->assertAttributeEquals(true, 'disable_custom_fields', $aclAction);
}
public function testaddActions()
{
self::markTestIncomplete('environment dependency');
//take count of actions initially and then after method execution and test if action count increases
$action_count = count(ACLAction::getDefaultActions());
ACLAction::addActions('Test');
$actual = ACLAction::getDefaultActions();
$this->assertGreaterThan($action_count, count($actual));
}
public function testremoveActions()
{
//take count of actions initially and then after method execution and test if action count decreases
$action_count = count(ACLAction::getDefaultActions());
ACLAction::removeActions('Test');
$actual = ACLAction::getDefaultActions();
$this->assertLessThanOrEqual($action_count, count($actual), 'actual count was: ' . count($actual));
}
public function testAccessName()
{
$this->assertFalse(ACLAction::AccessName('')); //test with invalid value
$this->assertEquals('All', ACLAction::AccessName(90)); //test with a valid value
}
public function testgetDefaultActions()
{
global $beanList;
$actual = ACLAction::getDefaultActions();
$this->assertTrue(is_array($actual)); //verify that it returns an array
foreach ($actual as $acl) {
$this->assertInstanceOf('ACLAction', $acl);
}
$actual = ACLAction::getDefaultActions('module', 'list');
$this->assertTrue(is_array($actual)); //verify that it returns an array
foreach ($actual as $acl) {
$this->assertInstanceOf('ACLAction', $acl);
$this->assertEquals('list', $acl->name);
}
}
public function testgetUserActions()
{
self::markTestIncomplete('Need to implement: verify that all three results returned are different.');
// $result1 = ACLAction::getUserActions('1');
// $result2 = ACLAction::getUserActions('1', false, 'Accounts');
// $result3 = ACLAction::getUserActions('1', false, 'Accounts', 'list');
//verify that all three results returned are different
//$this->assertNotSame($result1, $result2);
//$this->assertNotSame($result1, $result3);
//$this->assertNotSame($result2, $result3);
}
public function testhasAccess()
{
$this->assertFalse(ACLAction::hasAccess()); //check with defaults
$this->assertTrue(ACLAction::hasAccess(false, false, 90)); //access All with is owner false
$this->assertTrue(ACLAction::hasAccess(true, true, 90)); //access All with is owner true
$this->assertFalse(ACLAction::hasAccess(false, false, -98));// check access disabled
$this->assertFalse(ACLAction::hasAccess(true, true, 89)); //check access enabled
$this->assertTrue(ACLAction::hasAccess(true, true, 75)); //check owner access with is owner true
$this->assertFalse(ACLAction::hasAccess(false, true, 75)); //check owner access with is owner false
}
public function testuserNeedsSecurityGroup()
{
$this->assertFalse(ACLAction::userNeedsSecurityGroup('1', '', ''));//test with empty module and action
$this->assertFalse(ACLAction::userNeedsSecurityGroup('1', 'Accounts',
'list')); //test with valid module and action
}
public function testuserHasAccess()
{
self::markTestIncomplete('Need to fix checking user access. Hint: session is a system state perhaps its failing because the user session');
// Test with empty module and action
$this->assertFalse(ACLAction::userHasAccess('', '', ''));
// Test with empty user and valid module and action
$this->assertTrue(ACLAction::userHasAccess('', 'Accounts',
'list'));
// Test with valid User, module and action
$this->assertTrue(ACLAction::userHasAccess('1', 'Accounts', 'list'));
// Test with valid User, module and action
$this->assertTrue(ACLAction::userHasAccess('1', 'SecurityGroups',
'list'));
// Test with valid User, module and action
$this->assertTrue(ACLAction::userHasAccess('1', 'Users', 'list'));
}
public function testgetUserAccessLevel()
{
self::markTestIncomplete('Need to fix checking user access. Hint: session is a system state perhaps its failing because the user session');
//tes for accoounts module with two different actions
$this->assertEquals(90, ACLAction::getUserAccessLevel('1', 'Accounts', 'list'));
$this->assertEquals(89, ACLAction::getUserAccessLevel('1', 'Accounts', 'access'));
//tes for users module with two different actions
$this->assertEquals(90, ACLAction::getUserAccessLevel('1', 'Users', 'list'));
$this->assertEquals(89, ACLAction::getUserAccessLevel('1', 'Users', 'access'));
}
public function testuserNeedsOwnership()
{
self::markTestIncomplete('Need to fix checking user access. Hint: session is a system state perhaps its failing because the user session');
//test with invalid values
$this->assertFalse(ACLAction::userNeedsOwnership('', '', ''));
//test with valid values for different module and action combination
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Accounts', 'list'));
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Accounts', 'delete'));
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Users', 'delete'));
$this->assertFalse(ACLAction::userNeedsOwnership('1', 'Users', 'list'));
}
public function testsetupCategoriesMatrix()
{
//preset required data
$categories = array();
$categories['Accounts']['module']['list'][] = 'list';
$categories['Accounts']['module']['edit'][] = 'edit';
$names_expected = array('list' => 'List', 'edit' => 'Edit');
$categories_expected = array(
'Accounts' => array(
'module' => array(
'list' => array(
'list',
'accessColor' => false,
'accessName' => false,
'accessLabel' => false,
'accessOptions' => array(
90 => 'All',
80 => 'Group',
75 => 'Owner',
0 => 'Not Set',
-99 => 'None'
)
),
'edit' => array(
'edit',
'accessColor' => false,
'accessName' => false,
'accessLabel' => false,
'accessOptions' => array(
90 => 'All',
80 => 'Group',
75 => 'Owner',
0 => 'Not Set',
-99 => 'None'
)
),
),
),
);
//execute the method and verify that it retunrs expected results
$result = ACLAction::setupCategoriesMatrix($categories);
$this->assertSame($names_expected, $result);
$this->assertSame($categories, $categories_expected);
}
public function testtoArray()
{
$aclAction = BeanFactory::newBean('ACLActions');
//wihout any fields set
$expected = array('id' => null, 'aclaccess' => null);
$actual = $aclAction->toArray();
$this->assertSame($expected, $actual);
//with fileds pre populated
$aclAction->populateFromRow(array('id' => '1234', 'aclaccess' => '9999'));
$expected = array('id' => '1234', 'aclaccess' => '9999');
$actual = $aclAction->toArray();
$this->assertSame($expected, $actual);
}
public function testfromArray()
{
$aclAction = BeanFactory::newBean('ACLActions');
$arr = array('id' => '1234', 'name' => 'test');
//execute the method and verify that it retunrs expected results
$aclAction->fromArray($arr);
$this->assertSame($aclAction->id, '1234');
$this->assertSame($aclAction->name, 'test');
}
public function testclearSessionCache()
{
$aclAction = BeanFactory::newBean('ACLActions');
//execute the method and verify that it unsets the session cache
$aclAction->clearSessionCache();
$this->assertFalse(isset($_SESSION['ACL']));
}
}