Skip to content

Commit

Permalink
Update Unit test styling to cover the future coder version
Browse files Browse the repository at this point in the history
  • Loading branch information
seamuslee001 committed Apr 7, 2019
1 parent 068fdda commit 39b959d
Show file tree
Hide file tree
Showing 219 changed files with 2,237 additions and 1,883 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Class test_extension_manager_reporttest
*/
class test_extension_manager_reporttest extends CRM_Core_Report {

/**
* Class constructor.
*/
Expand Down
4 changes: 3 additions & 1 deletion tests/extensions/test.extension.manager.searchtest/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* 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
*/
Expand Down Expand Up @@ -48,7 +49,8 @@ public function buildForm(&$form) {
/**
* 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
*/
Expand Down
60 changes: 34 additions & 26 deletions tests/phpunit/CRM/ACL/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function testViewAllPermission() {
$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'");
Expand All @@ -52,7 +53,6 @@ public function testViewAllPermission() {
$this->assertEmpty($result, "Contacts should NOT be viewable when 'view all contacts' is not set");
}


/**
* general test for the 'view all contacts' permission
*/
Expand All @@ -73,7 +73,6 @@ public function testEditAllPermission() {
$this->assertEmpty($result, "Contacts should NOT be viewable when 'edit all contacts' is not set");
}


/**
* Test access related to the 'access deleted contact' permission
*/
Expand All @@ -95,7 +94,6 @@ public function testViewEditDeleted() {
$this->assertEquals(count($result), count($contacts) - 1, "Only deleted contacts should be excluded");
}


/**
* Test access based on relations
*
Expand Down Expand Up @@ -177,7 +175,6 @@ public function testPermissionByRelation() {
}
}


/**
* Test access based on ACL
*/
Expand All @@ -202,7 +199,6 @@ public function testPermissionByACL() {
$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
*/
Expand Down Expand Up @@ -285,10 +281,9 @@ public function testPermissionCompare() {
}
}


/****************************************************
* Scenario Builders *
***************************************************/
/*
* Scenario Builders
*/

/**
* create plain test scenario, no relationships/ACLs
Expand Down Expand Up @@ -322,66 +317,79 @@ protected function createScenarioRelations() {

// 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,
));

Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/CRM/Activity/BAO/ActivityTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function testRetrieveTargetIdsByActivityIdZeroID() {
$this->assertSame($target, array(), 'No targets returned');
}


public function testRetrieveTargetIdsByActivityIdOneID() {
$activity = $this->activityCreate();

Expand Down
13 changes: 8 additions & 5 deletions tests/phpunit/CRM/Activity/BAO/ActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @group headless
*/
class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {

public function setUp() {
parent::setUp();
$this->prepareForACLs();
Expand Down Expand Up @@ -343,7 +344,8 @@ public function testGetActivitiesCountforNonAdminDashboard() {
'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,
Expand Down Expand Up @@ -513,7 +515,8 @@ public function testGetActivitiesforNonAdminDashboard() {
'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,
Expand Down Expand Up @@ -958,7 +961,7 @@ public function getActivityDateData() {
'count' => 2,
'earliest' => strtotime('first day of january last year'),
'latest' => strtotime('first day of january this year'),
]
],
],
];
}
Expand Down Expand Up @@ -1040,7 +1043,8 @@ protected function setUpForActivityDashboardTests() {
'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,
Expand Down Expand Up @@ -1239,7 +1243,6 @@ public function testSendSMSMobileInToProviderParamWithDoNotSMS() {
$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
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Activity/Form/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function getSearchCriteria() {
],
[
'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']],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Batch/BAO/BatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testGetBatchFinancialItems() {
]);
$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',
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CRM/Bridge/OG/DrupalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
* @group headless
*/
class CRM_Bridge_OG_DrupalTest extends CiviUnitTestCase {

/**
* Test that one (ane only one) role (option value) is deleted by the updateCiviACLRole function
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Case/BAO/CaseTypeForkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @group headless
*/
class CRM_Case_BAO_CaseTypeForkTest extends CiviCaseTestCase {

public function setUp() {
parent::setUp();
CRM_Core_ManagedEntities::singleton(TRUE)->reconcile();
Expand Down Expand Up @@ -41,7 +42,6 @@ public function testManagerContact() {
$this->assertEquals($relTypeID, $xmlProcessor->getCaseManagerRoleId('ForkableCaseType'));
}


/**
* Edit the definition of ForkableCaseType.
*/
Expand Down
20 changes: 11 additions & 9 deletions tests/phpunit/CRM/Case/BAO/CaseTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public function definitionProvider() {

$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;
Expand Down Expand Up @@ -187,8 +187,10 @@ public function testRoundtrip_JsonToXmlToJson($fixtureName, $inputJson, $ignore)
*/
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
)
)
Expand Down
6 changes: 3 additions & 3 deletions tests/phpunit/CRM/Case/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public function testWhereClauseSingle() {

$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]
);
Expand Down
Loading

0 comments on commit 39b959d

Please sign in to comment.