Skip to content

Commit

Permalink
dev/core#2073 Memory leak fix
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Sep 29, 2020
1 parent 4fc8726 commit d4d6659
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 44 deletions.
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Contact/SelectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,15 @@ public function testContactIDQuery() {
*/
public function testSelectorQueryOnNonASCIIlocationType() {
$contactID = $this->individualCreate();
$locationType = $this->locationTypeCreate([
$locationTypeID = $this->locationTypeCreate([
'name' => 'Non ASCII Location Type',
'display_name' => 'Дом Location type',
'vcard_name' => 'Non ASCII Location Type',
'is_active' => 1,
]);
$this->callAPISuccess('Email', 'create', [
'contact_id' => $contactID,
'location_type_id' => $locationType->id,
'location_type_id' => $locationTypeID,
'email' => 'test@test.com',
]);

Expand All @@ -470,7 +470,7 @@ public function testSelectorQueryOnNonASCIIlocationType() {
['email' => ['IS NOT NULL' => 1]],
[
[
0 => 'email-' . $locationType->id,
0 => 'email-' . $locationTypeID,
1 => 'IS NOT NULL',
2 => NULL,
3 => 1,
Expand All @@ -483,7 +483,7 @@ public function testSelectorQueryOnNonASCIIlocationType() {
'sort_name' => 1,
'location' => [
'Non ASCII Location Type' => [
'location_type' => $locationType->id,
'location_type' => $locationTypeID,
'email' => 1,
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,7 @@ public function locationTypeCreate($params = NULL) {
// clear getfields cache
CRM_Core_PseudoConstant::flush();
$this->callAPISuccess('phone', 'getfields', ['version' => 3, 'cache_clear' => 1]);
return $locationType;
return $locationType->id;
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/phpunit/api/v3/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class api_v3_AddressTest extends CiviUnitTestCase {
protected $_contactID;
protected $_locationType;
protected $_locationTypeID;
protected $_params;

protected $_entity;
Expand All @@ -32,12 +32,12 @@ public function setUp() {
parent::setUp();

$this->_contactID = $this->organizationCreate();
$this->_locationType = $this->locationTypeCreate();
$this->_locationTypeID = $this->locationTypeCreate();
CRM_Core_PseudoConstant::flush();

$this->_params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'street_name' => 'Ambachtstraat',
'street_number' => '23',
'street_address' => 'Ambachtstraat 23',
Expand All @@ -49,7 +49,7 @@ public function setUp() {
}

public function tearDown() {
$this->locationTypeDelete($this->_locationType->id);
$this->locationTypeDelete($this->_locationTypeID);
$this->contactDelete($this->_contactID);
$this->quickCleanup(['civicrm_address', 'civicrm_relationship']);
parent::tearDown();
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testCreateAddressParsing($version) {
$params = [
'street_parsing' => 1,
'street_address' => '54A Excelsior Ave. Apt 1C',
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'contact_id' => $this->_contactID,
];
$subfile = "AddressParse";
Expand Down Expand Up @@ -256,7 +256,7 @@ public function testDeleteAddress($version) {
$this->_apiversion = $version;
//check there are no address to start with
$get = $this->callAPISuccess('address', 'get', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(0, $get['count'], 'Contact already exists ');

Expand All @@ -266,7 +266,7 @@ public function testDeleteAddress($version) {
$result = $this->callAPIAndDocument('address', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$get = $this->callAPISuccess('address', 'get', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted In line ' . __LINE__);
}
Expand Down Expand Up @@ -434,7 +434,7 @@ public function testCreateAddressPrimaryHandlingChangeExisting($version) {
public function testCreateDuplicateLocationTypes() {
$address1 = $this->callAPISuccess('address', 'create', $this->_params);
$address2 = $this->callAPISuccess('address', 'create', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'street_address' => '1600 Pensilvania Avenue',
'city' => 'Washington DC',
'is_primary' => 0,
Expand All @@ -443,7 +443,7 @@ public function testCreateDuplicateLocationTypes() {
]);
$check = $this->callAPISuccess('address', 'getcount', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(2, $check);
$this->callAPISuccess('address', 'delete', ['id' => $address1['id']]);
Expand All @@ -454,7 +454,7 @@ public function testGetWithJoin() {
$cid = $this->individualCreate([
'api.Address.create' => [
'street_address' => __FUNCTION__,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
],
]);
$result = $this->callAPISuccess('address', 'getsingle', [
Expand Down
54 changes: 27 additions & 27 deletions tests/phpunit/api/v3/EmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
class api_v3_EmailTest extends CiviUnitTestCase {
protected $_contactID;
protected $_locationType;
protected $locationType2;
protected $_locationTypeID;
protected $locationType2ID;
protected $_entity;
protected $_params;

Expand All @@ -27,16 +27,16 @@ public function setUp() {
$this->useTransaction(TRUE);

$this->_contactID = $this->organizationCreate(NULL);
$this->_locationType = $this->locationTypeCreate(NULL);
$this->locationType2 = $this->locationTypeCreate([
$this->_locationTypeID = $this->locationTypeCreate();
$this->locationType2ID = $this->locationTypeCreate([
'name' => 'New Location Type 2',
'vcard_name' => 'New Location Type 2',
'description' => 'Another Location Type',
'is_active' => 1,
]);
$this->_params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => 'api@a-team.com',
'is_primary' => 1,

Expand All @@ -57,7 +57,7 @@ public function testCreateEmail($version) {
$params = $this->_params;
//check there are no emails to start with
$get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted.');

Expand Down Expand Up @@ -167,15 +167,15 @@ public function testDeleteEmail($version) {
$this->_apiversion = $version;
$params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => 'api@a-team.com',
'is_primary' => 1,

//TODO email_type_id
];
//check there are no emails to start with
$get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(0, $get['count'], 'email already exists');

Expand All @@ -185,7 +185,7 @@ public function testDeleteEmail($version) {
$result = $this->callAPIAndDocument('email', 'delete', ['id' => $create['id']], __FUNCTION__, __FILE__);
$this->assertEquals(1, $result['count']);
$get = $this->callAPISuccess('email', 'get', [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(0, $get['count'], 'Contact not successfully deleted');
}
Expand All @@ -209,27 +209,27 @@ public function testReplaceEmail($version) {
'contact_id' => $this->_contactID,
'values' => [
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-1@example.com',
'is_primary' => 1,
],
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-2@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-3@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
'email' => '2-1@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
'email' => '2-2@example.com',
'is_primary' => 0,
],
Expand All @@ -247,7 +247,7 @@ public function testReplaceEmail($version) {
// replace the subset of emails in location #1, but preserve location #2
$replace2Params = [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'values' => [
[
'email' => '1-4@example.com',
Expand All @@ -261,14 +261,14 @@ public function testReplaceEmail($version) {
// check emails at location #1 -- all three replaced by one
$get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);
$this->assertEquals(1, $get['count'], 'Incorrect email count');

// check emails at location #2 -- preserve the original two
$get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
]);

$this->assertEquals(2, $get['count'], 'Incorrect email count');
Expand Down Expand Up @@ -314,27 +314,27 @@ public function testReplaceEmailsInChain($version) {
'api.email.replace' => [
'values' => [
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-1@example.com',
'is_primary' => 1,
],
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-2@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-3@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
'email' => '2-1@example.com',
'is_primary' => 0,
],
[
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
'email' => '2-2@example.com',
'is_primary' => 0,
],
Expand All @@ -354,7 +354,7 @@ public function testReplaceEmailsInChain($version) {
$getReplace2Params = [
'id' => $this->_contactID,
'api.email.replace' => [
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'values' => [
[
'email' => '1-4@example.com',
Expand All @@ -370,15 +370,15 @@ public function testReplaceEmailsInChain($version) {
// check emails at location #1 -- all three replaced by one
$get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);

$this->assertEquals(1, $get['count'], 'Incorrect email count');

// check emails at location #2 -- preserve the original two
$get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->locationType2->id,
'location_type_id' => $this->locationType2ID,
]);
$this->assertEquals(2, $get['count'], 'Incorrect email count');
}
Expand All @@ -402,7 +402,7 @@ public function testReplaceEmailWithId($version) {
'contact_id' => $this->_contactID,
'values' => [
[
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
'email' => '1-1@example.com',
'is_primary' => 1,
'on_hold' => 1,
Expand Down Expand Up @@ -431,7 +431,7 @@ public function testReplaceEmailWithId($version) {
// ensure the 'email' was updated while other fields were preserved
$get = $this->callAPISuccess('email', 'get', [
'contact_id' => $this->_contactID,
'location_type_id' => $this->_locationType->id,
'location_type_id' => $this->_locationTypeID,
]);

$this->assertEquals(1, $get['count'], 'Incorrect email count at ' . __LINE__);
Expand Down
3 changes: 1 addition & 2 deletions tests/phpunit/api/v3/PhoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function setUp() {
$this->useTransaction();

$this->_contactID = $this->organizationCreate();
$loc = $this->locationTypeCreate();
$this->_locationType = $loc->id;
$this->_locationType = $this->locationTypeCreate();
CRM_Core_PseudoConstant::flush();
$this->_params = [
'contact_id' => $this->_contactID,
Expand Down

0 comments on commit d4d6659

Please sign in to comment.