From ea8011f678a76b372cb9e6c87e710f6810a73c8b Mon Sep 17 00:00:00 2001 From: systopia Date: Wed, 12 Oct 2016 00:55:16 +0100 Subject: [PATCH] started unit tests for new list permission functions --- tests/phpunit/CRM/ACL/ListTest.php | 127 +++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 tests/phpunit/CRM/ACL/ListTest.php diff --git a/tests/phpunit/CRM/ACL/ListTest.php b/tests/phpunit/CRM/ACL/ListTest.php new file mode 100644 index 0000000000..1a3c2cdbbb --- /dev/null +++ b/tests/phpunit/CRM/ACL/ListTest.php @@ -0,0 +1,127 @@ +useTransaction(TRUE); + } + + /** + * general test for the 'view all contacts' permission + */ + public function testViewAllPermission() { + // create test contacts + $contacts = $this->createScenarioA(); + // CRM_Core_Error::debug_log_message(json_encode($contacts)); + + // test WITH permission + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts'); + $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); + // CRM_Core_Error::debug_log_message(json_encode($result)); + $this->assertEqual($result, $contacts, "Contacts should be viewable when 'view all contacts'"); + + + // test WITH explicit permission + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('view all contacts'); + $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::VIEW); + // CRM_Core_Error::debug_log_message(json_encode($result)); + $this->assertEqual($result, $contacts, "Contacts should be viewable when 'view all contacts'"); + + + // test WITHOUT permission + CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); + $this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set"); + } + + + /** + * general test for the 'view all contacts' permission + */ + public function testEditAllPermission() { + // create test contacts + + $contacts = $this->createScenarioA(); + + // test WITH explicit permission + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts'); + $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts, CRM_Core_Permission::EDIT); + $this->assertEqual($result, $contacts, "Contacts should be viewable when 'edit all contacts'"); + + + // test WITHOUT permission + CRM_Core_Config::singleton()->userPermissionClass->permissions = array(); + $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); + $this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set"); + } + + + /** + * general test for the 'view all contacts' permission + */ + public function testViewEditDeleted() { + CRM_Core_Config::singleton()->userPermissionClass->permissions = array('edit all contacts', 'view all contacts'); + $contacts = $this->createScenarioA(); + + + } + + + + + + + + /** + * create test scenario A + */ + protected function createScenarioA() { + // get logged in user + $user_id = $this->createLoggedInUser(); + $this->assertNotEmpty($user_id); + + // create test contacts + $bush_sr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'W.', 'last_name' => 'Bush')); + $bush_jr_id = $this->individualCreate(array('first_name' => 'George', 'middle_name' => 'H. W.', 'last_name' => 'Bush')); + $bush_laura_id = $this->individualCreate(array('first_name' => 'Laura Lane', 'last_name' => 'Bush')); + $bush_brbra_id = $this->individualCreate(array('first_name' => 'Barbara', 'last_name' => 'Bush')); + + // create some relationships + $this->callAPISuccess('Relationship', 'create', array( + 'relationship_type_id' => 1, // CHILD OF + 'contact_id_a' => $bush_sr_id, + 'contact_id_b' => $user_id, + 'is_permission_a_b' => 1, + )); + + $this->callAPISuccess('Relationship', 'create', array( + 'relationship_type_id' => 1, // CHILD OF + 'contact_id_a' => $bush_jr_id, + 'contact_id_b' => $bush_sr_id, + 'is_permission_a_b' => 1, + )); + + // create some relationships + $this->callAPISuccess('Relationship', 'create', array( + 'relationship_type_id' => 1, // CHILD OF + 'contact_id_a' => $bush_brbra_id, + 'contact_id_b' => $bush_jr_id, + 'is_permission_a_b' => 1, + )); + + return array($user_id, $bush_sr_id, $bush_jr_id, $bush_laura_id, $bush_brbra_id); + } + +} -- 2.25.1