Commit 39b959db authored by Seamus Lee's avatar Seamus Lee

Update Unit test styling to cover the future coder version

parent 068fdda3
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
class test_extension_manager_paymenttest extends CRM_Core_Payment { class test_extension_manager_paymenttest extends CRM_Core_Payment {
static $counts = array(); public static $counts = array();
public function install() { public function install() {
self::$counts['install'] = isset(self::$counts['install']) ? self::$counts['install'] : 0; self::$counts['install'] = isset(self::$counts['install']) ? self::$counts['install'] : 0;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Class test_extension_manager_reporttest * Class test_extension_manager_reporttest
*/ */
class test_extension_manager_reporttest extends CRM_Core_Report { class test_extension_manager_reporttest extends CRM_Core_Report {
/** /**
* Class constructor. * Class constructor.
*/ */
......
...@@ -6,6 +6,7 @@ require_once 'CRM/Contact/Form/Search/Custom/Base.php'; ...@@ -6,6 +6,7 @@ require_once 'CRM/Contact/Form/Search/Custom/Base.php';
* Class test_extension_manager_searchtest * Class test_extension_manager_searchtest
*/ */
class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface { class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
/** /**
* @param $formValues * @param $formValues
*/ */
...@@ -48,7 +49,8 @@ class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_B ...@@ -48,7 +49,8 @@ class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_B
/** /**
* Get a list of summary data points. * Get a list of summary data points.
* *
* @return mixed; NULL or array with keys: * @return mixed
* - NULL or array with keys:
* - summary: string * - summary: string
* - total: numeric * - total: numeric
*/ */
......
...@@ -28,7 +28,8 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -28,7 +28,8 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$contacts = $this->createScenarioPlain(); $contacts = $this->createScenarioPlain();
// test WITH all permissions // test WITH all permissions
CRM_Core_Config::singleton()->userPermissionClass->permissions = NULL; // NULL means 'all permissions' in UnitTests environment // NULL means 'all permissions' in UnitTests environment
CRM_Core_Config::singleton()->userPermissionClass->permissions = NULL;
$result = CRM_Contact_BAO_Contact_Permission::allowList($contacts); $result = CRM_Contact_BAO_Contact_Permission::allowList($contacts);
sort($result); sort($result);
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'"); $this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'");
...@@ -52,7 +53,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -52,7 +53,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set"); $this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set");
} }
/** /**
* general test for the 'view all contacts' permission * general test for the 'view all contacts' permission
*/ */
...@@ -73,7 +73,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -73,7 +73,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set"); $this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set");
} }
/** /**
* Test access related to the 'access deleted contact' permission * Test access related to the 'access deleted contact' permission
*/ */
...@@ -95,7 +94,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -95,7 +94,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$this->assertEquals(count($result), count($contacts) - 1, "Only deleted contacts should be excluded"); $this->assertEquals(count($result), count($contacts) - 1, "Only deleted contacts should be excluded");
} }
/** /**
* Test access based on relations * Test access based on relations
* *
...@@ -177,7 +175,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -177,7 +175,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
} }
} }
/** /**
* Test access based on ACL * Test access based on ACL
*/ */
...@@ -202,7 +199,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -202,7 +199,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$this->assertContains($contacts[4], $result, "User[0] should NOT have an ACL permission on contact[4]."); $this->assertContains($contacts[4], $result, "User[0] should NOT have an ACL permission on contact[4].");
} }
/** /**
* Test access with a mix of ACL and relationship * Test access with a mix of ACL and relationship
*/ */
...@@ -285,10 +281,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -285,10 +281,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
} }
} }
/*
/**************************************************** * Scenario Builders
* Scenario Builders * */
***************************************************/
/** /**
* create plain test scenario, no relationships/ACLs * create plain test scenario, no relationships/ACLs
...@@ -322,66 +317,79 @@ class CRM_ACL_ListTest extends CiviUnitTestCase { ...@@ -322,66 +317,79 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
// create some relationships // create some relationships
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[1], 'contact_id_a' => $contacts[1],
'contact_id_b' => $contacts[0], 'contact_id_b' => $contacts[0],
'is_permission_b_a' => 1, 'is_permission_b_a' => 1,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[2], 'contact_id_a' => $contacts[2],
'contact_id_b' => $contacts[1], 'contact_id_b' => $contacts[1],
'is_permission_b_a' => 1, 'is_permission_b_a' => 1,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[4], 'contact_id_a' => $contacts[4],
'contact_id_b' => $contacts[2], 'contact_id_b' => $contacts[2],
'is_permission_b_a' => 1, 'is_permission_b_a' => 1,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 4, // SIBLING OF // SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[5], 'contact_id_a' => $contacts[5],
'contact_id_b' => $contacts[0], 'contact_id_b' => $contacts[0],
'is_permission_b_a' => 2, // View // View
'is_permission_b_a' => 2,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[6], 'contact_id_a' => $contacts[6],
'contact_id_b' => $contacts[5], 'contact_id_b' => $contacts[5],
'is_permission_b_a' => 1, // Edit // Edit
'is_permission_b_a' => 1,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[7], 'contact_id_a' => $contacts[7],
'contact_id_b' => $contacts[5], 'contact_id_b' => $contacts[5],
'is_permission_b_a' => 2, // View // View
'is_permission_b_a' => 2,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 4, // SIBLING OF // SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[0], 'contact_id_a' => $contacts[0],
'contact_id_b' => $contacts[8], 'contact_id_b' => $contacts[8],
'is_permission_a_b' => 1, // edit (as a_b) // edit (as a_b)
'is_permission_a_b' => 1,
'is_active' => 1, 'is_active' => 1,
)); ));
$this->callAPISuccess('Relationship', 'create', array( $this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF // CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[9], 'contact_id_a' => $contacts[9],
'contact_id_b' => $contacts[8], 'contact_id_b' => $contacts[8],
'is_permission_b_a' => 2, // view // view
'is_permission_b_a' => 2,
'is_active' => 1, 'is_active' => 1,
)); ));
......
...@@ -55,7 +55,6 @@ class CRM_Activity_BAO_ActivityTargetTest extends CiviUnitTestCase { ...@@ -55,7 +55,6 @@ class CRM_Activity_BAO_ActivityTargetTest extends CiviUnitTestCase {
$this->assertSame($target, array(), 'No targets returned'); $this->assertSame($target, array(), 'No targets returned');
} }
public function testRetrieveTargetIdsByActivityIdOneID() { public function testRetrieveTargetIdsByActivityIdOneID() {
$activity = $this->activityCreate(); $activity = $this->activityCreate();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* @group headless * @group headless
*/ */
class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
$this->prepareForACLs(); $this->prepareForACLs();
...@@ -343,7 +344,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ...@@ -343,7 +344,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL, 'caseId' => NULL,
'context' => 'home', 'context' => 'home',
'activity_type_id' => NULL, 'activity_type_id' => NULL,
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'), // for dashlet the Scheduled status is set by default // for dashlet the Scheduled status is set by default
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
'offset' => 0, 'offset' => 0,
'rowCount' => 0, 'rowCount' => 0,
'sort' => NULL, 'sort' => NULL,
...@@ -513,7 +515,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ...@@ -513,7 +515,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL, 'caseId' => NULL,
'context' => 'home', 'context' => 'home',
'activity_type_id' => NULL, 'activity_type_id' => NULL,
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'), // for dashlet the Scheduled status is set by default // for dashlet the Scheduled status is set by default
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
'offset' => 0, 'offset' => 0,
'rowCount' => 0, 'rowCount' => 0,
'sort' => NULL, 'sort' => NULL,
...@@ -958,7 +961,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ...@@ -958,7 +961,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'count' => 2, 'count' => 2,
'earliest' => strtotime('first day of january last year'), 'earliest' => strtotime('first day of january last year'),
'latest' => strtotime('first day of january this year'), 'latest' => strtotime('first day of january this year'),
] ],
], ],
]; ];
} }
...@@ -1040,7 +1043,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase { ...@@ -1040,7 +1043,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL, 'caseId' => NULL,
'context' => 'home', 'context' => 'home',
'activity_type_id' => NULL, 'activity_type_id' => NULL,
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'), // for dashlet the Scheduled status is set by default // for dashlet the Scheduled status is set by default
'activity_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled'),
'offset' => 0, 'offset' => 0,
'rowCount' => 0, 'rowCount' => 0,
'sort' => NULL, 'sort' => NULL,
...@@ -1239,7 +1243,6 @@ $text ...@@ -1239,7 +1243,6 @@ $text
$this->assertEquals(0, $success, "Expected success to be 0"); $this->assertEquals(0, $success, "Expected success to be 0");
} }
/** /**
* @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile) * @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile)
* @param bool $passPhoneTypeInContactDetails * @param bool $passPhoneTypeInContactDetails
......
...@@ -116,7 +116,7 @@ class CRM_Activity_Form_SearchTest extends CiviUnitTestCase { ...@@ -116,7 +116,7 @@ class CRM_Activity_Form_SearchTest extends CiviUnitTestCase {
], ],
[ [
'search_criteria' => [ 'search_criteria' => [
['activity_status_id', '=', ['IN' => ['1', '2']], 0, 0] ['activity_status_id', '=', ['IN' => ['1', '2']], 0, 0],
], ],
'expected_qill' => [['Activity Status In Scheduled, Completed']], 'expected_qill' => [['Activity Status In Scheduled, Completed']],
], ],
......
...@@ -66,7 +66,7 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase { ...@@ -66,7 +66,7 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase {
]); ]);
$this->contributionCreate([ $this->contributionCreate([
'contact_id' => $contactId, 'contact_id' => $contactId,
'total_amount' => 1, 'total_amount' => 1,
'payment_instrument_id' => 'Credit Card', 'payment_instrument_id' => 'Credit Card',
'financial_type_id' => 'Member Dues', 'financial_type_id' => 'Member Dues',
'contribution_status_id' => 'Completed', 'contribution_status_id' => 'Completed',
......
...@@ -41,6 +41,7 @@ require_once 'api/api.php'; ...@@ -41,6 +41,7 @@ require_once 'api/api.php';
* @group headless * @group headless
*/ */
class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase { class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase {
/** /**
* Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function * Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function
*/ */
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* @group headless * @group headless
*/ */
class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase { class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile(); CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
...@@ -41,7 +42,6 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase { ...@@ -41,7 +42,6 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase {
$this->assertEquals($relTypeID, $xmlProcessor->getCaseManagerRoleId('ForkableCaseType')); $this->assertEquals($relTypeID, $xmlProcessor->getCaseManagerRoleId('ForkableCaseType'));
} }
/** /**
* Edit the definition of ForkableCaseType. * Edit the definition of ForkableCaseType.
*/ */
......
...@@ -117,13 +117,13 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { ...@@ -117,13 +117,13 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
$cases = array(); $cases = array();
foreach (array( foreach (array(
'empty-defn', 'empty-defn',
'empty-lists', 'empty-lists',
'one-item-in-each', 'one-item-in-each',
'two-items-in-each', 'two-items-in-each',
'forkable-0', 'forkable-0',
'forkable-1', 'forkable-1',
) as $key) { ) as $key) {
$cases[] = array($key, $fixtures[$key]['json'], $fixtures[$key]['xml']); $cases[] = array($key, $fixtures[$key]['json'], $fixtures[$key]['xml']);
} }
return $cases; return $cases;
...@@ -187,8 +187,10 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase { ...@@ -187,8 +187,10 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
*/ */
public function normalizeXml($xml) { public function normalizeXml($xml) {
return trim( return trim(
preg_replace(":\n*<:", "\n<", // tags on new lines // tags on new lines
preg_replace("/\n[\n ]+/", "\n", // no leading whitespace preg_replace(":\n*<:", "\n<",
// no leading whitespace
preg_replace("/\n[\n ]+/", "\n",
$xml $xml
) )
) )
......
...@@ -59,9 +59,9 @@ class CRM_Case_BAO_QueryTest extends CiviUnitTestCase { ...@@ -59,9 +59,9 @@ class CRM_Case_BAO_QueryTest extends CiviUnitTestCase {
$queryObj = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE); $queryObj = new CRM_Contact_BAO_Query($params, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CASE);
$this->assertEquals(array( $this->assertEquals(array(
0 => 'Activity Type = Contribution', 0 => 'Activity Type = Contribution',
1 => 'Activity Type = Scheduled', 1 => 'Activity Type = Scheduled',
2 => 'Activity Medium = In Person', 2 => 'Activity Medium = In Person',
), ),
$queryObj->_qill[1] $queryObj->_qill[1]
); );
......
...@@ -37,18 +37,18 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase { ...@@ -37,18 +37,18 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
*/ */
protected function setupDefaultAssigneeOptions() { protected function setupDefaultAssigneeOptions() {
$options = [ $options = [
'NONE', 'BY_RELATIONSHIP', 'SPECIFIC_CONTACT', 'USER_CREATING_THE_CASE' 'NONE', 'BY_RELATIONSHIP', 'SPECIFIC_CONTACT', 'USER_CREATING_THE_CASE',
]; ];
CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([ CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([
'name' => 'activity_default_assignee' 'name' => 'activity_default_assignee',
]); ]);
foreach ($options as $option) { foreach ($options as $option) {
$optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists([ $optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists([
'option_group_id' => 'activity_default_assignee', 'option_group_id' => 'activity_default_assignee',
'name' => $option, 'name' => $option,
'label' => $option 'label' => $option,
]); ]);
$this->defaultAssigneeOptionsValues[$option] = $optionValue['value']; $this->defaultAssigneeOptionsValues[$option] = $optionValue['value'];
...@@ -65,19 +65,19 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase { ...@@ -65,19 +65,19 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
'name_a_b' => 'Pupil of', 'name_a_b' => 'Pupil of',
'name_b_a' => 'Instructor', 'name_b_a' => 'Instructor',
'contact_id_a' => $this->contacts['ana'], 'contact_id_a' => $this->contacts['ana'],
'contact_id_b' => $this->contacts['beto'] 'contact_id_b' => $this->contacts['beto'],
], ],
'ana_is_spouse_of_carlos' => [ 'ana_is_spouse_of_carlos' => [
'type_id' => NULL, 'type_id' => NULL,
'name_a_b' => 'Spouse of', 'name_a_b' => 'Spouse of',
'name_b_a' => 'Spouse of', 'name_b_a' => 'Spouse of',
'contact_id_a' => $this->contacts['ana'], 'contact_id_a' => $this->contacts['ana'],
'contact_id_b' => $this->contacts['carlos'] 'contact_id_b' => $this->contacts['carlos'],
], ],
'unassigned_employee' => [ 'unassigned_employee' => [
'type_id' => NULL, 'type_id' => NULL,
'name_a_b' => 'Employee of', 'name_a_b' => 'Employee of',
'name_b_a' => 'Employer' 'name_b_a' => 'Employer',
], ],
]; ];
...@@ -88,7 +88,7 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase { ...@@ -88,7 +88,7 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
'name_a_b' => $relationship['name_a_b'], 'name_a_b' => $relationship['name_a_b'],
'label_a_b' => $relationship['name_a_b'], 'label_a_b' => $relationship['name_a_b'],
'name_b_a' => $relationship['name_b_a'], 'name_b_a' => $relationship['name_b_a'],
'label_b_a' => $relationship['name_b_a'] 'label_b_a' => $relationship['name_b_a'],
]);