[NFC] [TEST] cleanup, more use of return in AddressTest
authorEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 17 Jun 2021 06:35:36 +0000 (18:35 +1200)
committerEileen McNaughton <emcnaughton@wikimedia.org>
Thu, 17 Jun 2021 06:38:02 +0000 (18:38 +1200)
tests/phpunit/api/v3/AddressTest.php

index 3f7ed4f873a63ec41fe80ddf41d1118f6afaf69a..59f7028109748a6e5452f95e45b19c9714beab25 100644 (file)
@@ -244,7 +244,7 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     unset($params['is_primary']);
     $params['id'] = $result['id'];
     $this->callAPISuccess('Address', 'create', $params);
-    $result = $this->callAPISuccess('Address', 'get', ['contact_id' => $params['contact_id']]);
+    $result = $this->callAPISuccess('Address', 'get', ['contact_id' => $params['contact_id'], 'return' => 'is_primary']);
     $this->assertEquals(1, $result['count']);
     $this->assertEquals(1, $result['values'][$result['id']]['is_primary']);
     $this->getAndCheck($params, $result['id'], 'address');
@@ -289,9 +289,9 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $params = [
       'contact_id' => $this->_contactID,
       'street_name' => $address['values'][$address['id']]['street_name'],
+      'return' => ['location_type_id', 'is_primary', 'street_address'],
     ];
     $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__);
-    $this->callAPISuccess('Address', 'delete', ['id' => $result['id']]);
     $this->assertEquals($address['values'][$address['id']]['location_type_id'], $result['values'][$address['id']]['location_type_id']);
     $this->assertEquals($address['values'][$address['id']]['is_primary'], $result['values'][$address['id']]['is_primary']);
     $this->assertEquals($address['values'][$address['id']]['street_address'], $result['values'][$address['id']]['street_address']);
@@ -307,10 +307,10 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $this->callAPISuccess('address', 'create', $this->_params);
     $params = [
       'contact_id' => $this->_contactID,
+      'return' => 'location_type_id',
     ];
-    $address = $this->callAPISuccess('Address', 'getsingle', ($params));
+    $address = $this->callAPISuccessGetSingle('Address', ($params));
     $this->assertEquals($address['location_type_id'], $this->_params['location_type_id']);
-    $this->callAPISuccess('address', 'delete', ['id' => $address['id']]);
   }
 
   /**
@@ -323,18 +323,18 @@ class api_v3_AddressTest extends CiviUnitTestCase {
     $create = $this->callAPISuccess('address', 'create', $this->_params);
     $this->callAPISuccess('address', 'create', array_merge($this->_params, ['street_address' => 'yzy']));
     $subfile = "AddressSort";
-    $description = "Demonstrates Use of sort filter.";
+    $description = 'Demonstrates Use of sort filter.';
     $params = [
       'options' => [
         'sort' => 'street_address DESC',
         'limit' => 2,
       ],
       'sequential' => 1,
+      'return' => 'street_address',
     ];
     $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(2, $result['count']);
     $this->assertEquals('Ambachtstraat 23', $result['values'][1]['street_address']);
-    $this->callAPISuccess('address', 'delete', ['id' => $create['id']]);
   }
 
   /**
@@ -345,16 +345,16 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   public function testGetAddressLikeSuccess($version) {
     $this->_apiversion = $version;
     $this->callAPISuccess('address', 'create', $this->_params);
-    $subfile = "AddressLike";
-    $description = "Demonstrates Use of Like.";
+    $subfile = 'AddressLike';
+    $description = 'Demonstrates Use of Like.';
     $params = [
       'street_address' => ['LIKE' => '%mb%'],
       'sequential' => 1,
+      'return' => 'street_address',
     ];
     $result = $this->callAPIAndDocument('Address', 'Get', $params, __FUNCTION__, __FILE__, $description, $subfile);
     $this->assertEquals(1, $result['count']);
     $this->assertEquals('Ambachtstraat 23', $result['values'][0]['street_address']);
-    $this->callAPISuccess('address', 'delete', ['id' => $result['id']]);
   }
 
   /**
@@ -364,14 +364,13 @@ class api_v3_AddressTest extends CiviUnitTestCase {
    */
   public function testGetAddressLikeFail($version) {
     $this->_apiversion = $version;
-    $create = $this->callAPISuccess('address', 'create', $this->_params);
+    $this->callAPISuccess('address', 'create', $this->_params);
     $params = [
       'street_address' => ['LIKE' => "'%xy%'"],
       'sequential' => 1,
     ];
-    $result = $this->callAPISuccess('Address', 'Get', ($params));
+    $result = $this->callAPISuccessGetCount('Address', $params, 0);
     $this->assertEquals(0, $result['count']);
-    $this->callAPISuccess('address', 'delete', ['id' => $create['id']]);
   }
 
   /**
@@ -392,7 +391,6 @@ class api_v3_AddressTest extends CiviUnitTestCase {
 
     $this->customFieldDelete($ids['custom_field_id']);
     $this->customGroupDelete($ids['custom_group_id']);
-    $this->callAPISuccess('address', 'delete', ['id' => $result['id']]);
   }
 
   /**
@@ -599,13 +597,13 @@ class api_v3_AddressTest extends CiviUnitTestCase {
   public function testGetOptionsAbbr() {
     $result = $this->callAPISuccess('Address', 'getoptions', [
       'field' => 'country_id',
-      'context' => "abbreviate",
+      'context' => 'abbreviate',
     ]);
     $this->assertContains('US', $result['values']);
     $this->assertNotContains('United States', $result['values']);
     $result = $this->callAPISuccess('Address', 'getoptions', [
       'field' => 'state_province_id',
-      'context' => "abbreviate",
+      'context' => 'abbreviate',
     ]);
     $this->assertContains('AL', $result['values']);
     $this->assertNotContains('Alabama', $result['values']);