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 @@
*/
class test_extension_manager_paymenttest extends CRM_Core_Payment {
static $counts = array();
public static $counts = array();
public function install() {
self::$counts['install'] = isset(self::$counts['install']) ? self::$counts['install'] : 0;
......
......@@ -4,6 +4,7 @@
* Class test_extension_manager_reporttest
*/
class test_extension_manager_reporttest extends CRM_Core_Report {
/**
* Class constructor.
*/
......
......@@ -6,6 +6,7 @@ require_once 'CRM/Contact/Form/Search/Custom/Base.php';
* Class test_extension_manager_searchtest
*/
class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
/**
* @param $formValues
*/
......@@ -48,7 +49,8 @@ class test_extension_manager_searchtest extends CRM_Contact_Form_Search_Custom_B
/**
* Get a list of summary data points.
*
* @return mixed; NULL or array with keys:
* @return mixed
* - NULL or array with keys:
* - summary: string
* - total: numeric
*/
......
......@@ -28,7 +28,8 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$contacts = $this->createScenarioPlain();
// 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);
sort($result);
$this->assertEquals($result, $contacts, "Contacts should be viewable when 'view all contacts'");
......@@ -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");
}
/**
* general test for the 'view all contacts' permission
*/
......@@ -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");
}
/**
* Test access related to the 'access deleted contact' permission
*/
......@@ -95,7 +94,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
$this->assertEquals(count($result), count($contacts) - 1, "Only deleted contacts should be excluded");
}
/**
* Test access based on relations
*
......@@ -177,7 +175,6 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
}
}
/**
* Test access based on ACL
*/
......@@ -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].");
}
/**
* Test access with a mix of ACL and relationship
*/
......@@ -285,10 +281,9 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
}
}
/****************************************************
* Scenario Builders *
***************************************************/
/*
* Scenario Builders
*/
/**
* create plain test scenario, no relationships/ACLs
......@@ -322,66 +317,79 @@ class CRM_ACL_ListTest extends CiviUnitTestCase {
// create some relationships
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[1],
'contact_id_b' => $contacts[0],
'is_permission_b_a' => 1,
'is_active' => 1,
));
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[2],
'contact_id_b' => $contacts[1],
'is_permission_b_a' => 1,
'is_active' => 1,
));
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[4],
'contact_id_b' => $contacts[2],
'is_permission_b_a' => 1,
'is_active' => 1,
));
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 4, // SIBLING OF
// SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[5],
'contact_id_b' => $contacts[0],
'is_permission_b_a' => 2, // View
// View
'is_permission_b_a' => 2,
'is_active' => 1,
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[6],
'contact_id_b' => $contacts[5],
'is_permission_b_a' => 1, // Edit
// Edit
'is_permission_b_a' => 1,
'is_active' => 1,
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[7],
'contact_id_b' => $contacts[5],
'is_permission_b_a' => 2, // View
// View
'is_permission_b_a' => 2,
'is_active' => 1,
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 4, // SIBLING OF
// SIBLING OF
'relationship_type_id' => 4,
'contact_id_a' => $contacts[0],
'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,
));
$this->callAPISuccess('Relationship', 'create', array(
'relationship_type_id' => 1, // CHILD OF
// CHILD OF
'relationship_type_id' => 1,
'contact_id_a' => $contacts[9],
'contact_id_b' => $contacts[8],
'is_permission_b_a' => 2, // view
// view
'is_permission_b_a' => 2,
'is_active' => 1,
));
......
......@@ -55,7 +55,6 @@ class CRM_Activity_BAO_ActivityTargetTest extends CiviUnitTestCase {
$this->assertSame($target, array(), 'No targets returned');
}
public function testRetrieveTargetIdsByActivityIdOneID() {
$activity = $this->activityCreate();
......
......@@ -5,6 +5,7 @@
* @group headless
*/
class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
public function setUp() {
parent::setUp();
$this->prepareForACLs();
......@@ -343,7 +344,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL,
'context' => 'home',
'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,
'rowCount' => 0,
'sort' => NULL,
......@@ -513,7 +515,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL,
'context' => 'home',
'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,
'rowCount' => 0,
'sort' => NULL,
......@@ -958,7 +961,7 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'count' => 2,
'earliest' => strtotime('first day of january last year'),
'latest' => strtotime('first day of january this year'),
]
],
],
];
}
......@@ -1040,7 +1043,8 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
'caseId' => NULL,
'context' => 'home',
'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,
'rowCount' => 0,
'sort' => NULL,
......@@ -1239,7 +1243,6 @@ $text
$this->assertEquals(0, $success, "Expected success to be 0");
}
/**
* @param int $phoneType (0=no phone, phone_type option group (1=fixed, 2=mobile)
* @param bool $passPhoneTypeInContactDetails
......
......@@ -116,7 +116,7 @@ class CRM_Activity_Form_SearchTest extends CiviUnitTestCase {
],
[
'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']],
],
......
......@@ -66,7 +66,7 @@ class CRM_Batch_BAO_BatchTest extends CiviUnitTestCase {
]);
$this->contributionCreate([
'contact_id' => $contactId,
'total_amount' => 1,
'total_amount' => 1,
'payment_instrument_id' => 'Credit Card',
'financial_type_id' => 'Member Dues',
'contribution_status_id' => 'Completed',
......
......@@ -41,6 +41,7 @@ require_once 'api/api.php';
* @group headless
*/
class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase {
/**
* Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function
*/
......
......@@ -6,6 +6,7 @@
* @group headless
*/
class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase {
public function setUp() {
parent::setUp();
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
......@@ -41,7 +42,6 @@ class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase {
$this->assertEquals($relTypeID, $xmlProcessor->getCaseManagerRoleId('ForkableCaseType'));
}
/**
* Edit the definition of ForkableCaseType.
*/
......
......@@ -117,13 +117,13 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
$cases = array();
foreach (array(
'empty-defn',
'empty-lists',
'one-item-in-each',
'two-items-in-each',
'forkable-0',
'forkable-1',
) as $key) {
'empty-defn',
'empty-lists',
'one-item-in-each',
'two-items-in-each',
'forkable-0',
'forkable-1',
) as $key) {
$cases[] = array($key, $fixtures[$key]['json'], $fixtures[$key]['xml']);
}
return $cases;
......@@ -187,8 +187,10 @@ class CRM_Case_BAO_CaseTypeTest extends CiviUnitTestCase {
*/
public function normalizeXml($xml) {
return trim(
preg_replace(":\n*<:", "\n<", // tags on new lines
preg_replace("/\n[\n ]+/", "\n", // no leading whitespace
// tags on new lines
preg_replace(":\n*<:", "\n<",
// no leading whitespace
preg_replace("/\n[\n ]+/", "\n",
$xml
)
)
......
......@@ -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);
$this->assertEquals(array(
0 => 'Activity Type = Contribution',
1 => 'Activity Type = Scheduled',
2 => 'Activity Medium = In Person',
0 => 'Activity Type = Contribution',
1 => 'Activity Type = Scheduled',
2 => 'Activity Medium = In Person',
),
$queryObj->_qill[1]
);
......
......@@ -37,18 +37,18 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
*/
protected function setupDefaultAssigneeOptions() {
$options = [
'NONE', 'BY_RELATIONSHIP', 'SPECIFIC_CONTACT', 'USER_CREATING_THE_CASE'
'NONE', 'BY_RELATIONSHIP', 'SPECIFIC_CONTACT', 'USER_CREATING_THE_CASE',
];
CRM_Core_BAO_OptionGroup::ensureOptionGroupExists([
'name' => 'activity_default_assignee'
'name' => 'activity_default_assignee',
]);
foreach ($options as $option) {
$optionValue = CRM_Core_BAO_OptionValue::ensureOptionValueExists([
'option_group_id' => 'activity_default_assignee',
'name' => $option,
'label' => $option
'label' => $option,
]);
$this->defaultAssigneeOptionsValues[$option] = $optionValue['value'];
......@@ -65,19 +65,19 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
'name_a_b' => 'Pupil of',
'name_b_a' => 'Instructor',
'contact_id_a' => $this->contacts['ana'],
'contact_id_b' => $this->contacts['beto']
'contact_id_b' => $this->contacts['beto'],
],
'ana_is_spouse_of_carlos' => [
'type_id' => NULL,
'name_a_b' => 'Spouse of',
'name_b_a' => 'Spouse of',
'contact_id_a' => $this->contacts['ana'],
'contact_id_b' => $this->contacts['carlos']
'contact_id_b' => $this->contacts['carlos'],
],
'unassigned_employee' => [
'type_id' => NULL,
'name_a_b' => 'Employee of',
'name_b_a' => 'Employer'
'name_b_a' => 'Employer',
],
];
......@@ -88,7 +88,7 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
'name_a_b' => $relationship['name_a_b'],
'label_a_b' => $relationship['name_a_b'],
'name_b_a' => $relationship['name_b_a'],
'label_b_a' => $relationship['name_b_a']
'label_b_a' => $relationship['name_b_a'],
]);
if (isset($relationship['contact_id_a'])) {
......@@ -231,7 +231,7 @@ class CRM_Case_XMLProcessor_ProcessTest extends CiviCaseTestCase {
$expectedContact = $assigneeContactId === NULL ? [] : [$assigneeContactId];
$result = $this->callAPISuccess('Activity', 'get', [
'target_contact_id' => $this->activityParams['clientID'],
'return' => ['assignee_contact_id']
'return' => ['assignee_contact_id'],
]);
$activity = CRM_Utils_Array::first($result['values']);
......
......@@ -43,7 +43,6 @@ class CRM_Contact_BAO_ActivitySearchTest extends CiviUnitTestCase {
protected $_params;
protected $test_activity_type_value;
/**
* Test setup for every test.
*
......
......@@ -1550,7 +1550,8 @@ class CRM_Contact_BAO_ContactTest extends CiviUnitTestCase {
$prevTimestamps = $origTimestamps;
foreach ($callbacks as $callbackName => $callback) {
sleep(1); // advance clock by 1 second to ensure timestamps change
// advance clock by 1 second to ensure timestamps change
sleep(1);
$callback($contactId);
$newTimestamps = CRM_Contact_BAO_Contact::getTimestamps($contactId);
......
......@@ -486,7 +486,6 @@ class CRM_Contact_BAO_GroupContactCacheTest extends CiviUnitTestCase {
$this->callAPISuccess('group', 'delete', ['id' => $group2->id]);
}
public function testMultipleGroupWhereClause() {
$returnProperties = array(
'contact_type' => 1,
......
......@@ -192,7 +192,6 @@ class CRM_Contact_BAO_GroupContactTest extends CiviUnitTestCase {
$this->callAPISuccess('Contact', 'delete', array('id' => $childSmartGroupContact));
}
/**
* CRM-19698: Test case for combine contact search in regular and smart group
*/
......
......@@ -94,7 +94,8 @@ class CRM_Contact_BAO_GroupTest extends CiviUnitTestCase {
'name' => uniqid(),
'title' => 'Parent Group B',
'description' => 'Parent Group Two',
'is_active' => 0, // disable
// disable
'is_active' => 0,
));
$group2 = CRM_Contact_BAO_Group::create($params);
......
......@@ -58,8 +58,10 @@ class CRM_Contact_BAO_IndividualTest extends CiviUnitTestCase {
'contact_type' => 'Individual',
'first_name' => 'Ben',
'last_name' => 'Lee',
'prefix_id' => 4, // this is the doctor
'suffix_id' => 2, // and the doctor is a senior
// this is the doctor
'prefix_id' => 4,
// and the doctor is a senior
'suffix_id' => 2,
);
$contact = new CRM_Contact_DAO_Contact();
......
......@@ -78,10 +78,10 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
$contactID = $this->individualCreate();
CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
$this->callAPISuccess('address', 'create', array(
'contact_id' => $contactID,
'city' => 'Cool City',
'location_type_id' => 1,
));
'contact_id' => $contactID,
'city' => 'Cool City',
'location_type_id' => 1,
));
$params = array(
0 => array(
0 => 'city-1',
......@@ -117,10 +117,10 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
$contactID = $this->individualCreate();
CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
$this->callAPISuccess('address', 'create', array(
'contact_id' => $contactID,
'city' => 'Cool City',
'location_type_id' => 1,
));
'contact_id' => $contactID,
'city' => 'Cool City',
'location_type_id' => 1,
));
$params = array(
0 => array(
0 => 'city-1',
......@@ -242,7 +242,6 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
$resultDAO->fetch();
}
/**
* CRM-14263 search builder failure with search profile & address in criteria.
*
......@@ -252,16 +251,18 @@ class CRM_Contact_BAO_QueryTest extends CiviUnitTestCase {
* @dataProvider getSearchProfileData
*
* @param array $params
* @param string $selectClause
* @param string $whereClause
*/
public function testSearchProfilePrimaryCityCRM14263($params, $selectClause, $whereClause) {
$contactID = $this->individualCreate();
CRM_Core_Config::singleton()->defaultSearchProfileID = 1;
$this->callAPISuccess('address', 'create', array(
'contact_id' => $contactID,
'city' => 'Cool CITY',
'street_address' => 'Long STREET',
'location_type_id' => 1,
));
'contact_id' => $contactID,
'city' => 'Cool CITY',
'street_address' => 'Long STREET',
'location_type_id' => 1,
));
$returnProperties = array(
'contact_type' => 1,
'contact_sub_type' => 1,
......@@ -770,7 +771,7 @@ civicrm_relationship.is_active = 1 AND
'avg' => '$ 233.33',
'amount' => '$ 1,400.00',
'count' => 6,
],
],
'cancel' => [
'count' => 2,
'amount' => '$ 100.00',
......@@ -822,13 +823,15 @@ civicrm_relationship.is_active = 1 AND
*/
public function testConvertFormValuesCRM21816() {
$fv = array(
"member_end_date_relative" => "starting_2.month", // next 60 days
// next 60 days
"member_end_date_relative" => "starting_2.month",
"member_end_date_low" => "20180101000000",
"member_end_date_high" => "20180331235959",
"membership_is_current_member" => "1",
"member_is_primary" => "1",
);
$fv_orig = $fv; // $fv is modified by convertFormValues()
// $fv is modified by convertFormValues()
$fv_orig = $fv;
$params = CRM_Contact_BAO_Query::convertFormValues($fv);
// restructure for easier testing
......
......@@ -51,7 +51,7 @@ class CRM_Contact_BAO_RelationshipTest extends CiviUnitTestCase {
$this->quickCleanup([
'civicrm_relationship_type',
'civicrm_relationship',
'civicrm_contact'
'civicrm_contact',
]);
parent::tearDown();
......@@ -120,7 +120,7 @@ class CRM_Contact_BAO_RelationshipTest extends CiviUnitTestCase {
$options = CRM_Contact_BAO_Relationship::buildRelationshipTypeOptions([
'relationship_id' => (string) $relationship['id'],
'contact_id' => $individual['id']
'contact_id' => $individual['id'],
]);
// for this relationship only individual=>organization is possible
......@@ -132,7 +132,7 @@ class CRM_Contact_BAO_RelationshipTest extends CiviUnitTestCase {
$this->assertNotContains($personToPersonReverseType, $options);
$options = CRM_Contact_BAO_Relationship::buildRelationshipTypeOptions([
'contact_id' => $individual['id']
'contact_id' => $individual['id'],
]);
// for this result we only know that "A" must be an individual
......
<?php
/**
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
* +--------------------------------------------------------------------+
* | CiviCRM version 5 |
* +--------------------------------------------------------------------+
* | Copyright CiviCRM LLC (c) 2004-2019 |
* +--------------------------------------------------------------------+
* | This file is a part of CiviCRM. |
* | |
* | CiviCRM is free software; you can copy, modify, and distribute it |
* | under the terms of the GNU Affero General Public License |
* | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
* | |
* | CiviCRM is distributed in the hope that it will be useful, but |
* | WITHOUT ANY WARRANTY; without even the implied warranty of |
* | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
* | See the GNU Affero General Public License for more details. |
* | |
* | You should have received a copy of the GNU Affero General Public |
* | License and the CiviCRM Licensing Exception along |
* | with this program; if not, contact CiviCRM LLC |