CRM-13312 - CRM_Utils_API_MatchOptionTest
authorTim Otten <totten@civicrm.org>
Tue, 1 Oct 2013 21:49:30 +0000 (23:49 +0200)
committerTim Otten <totten@civicrm.org>
Tue, 1 Oct 2013 21:49:30 +0000 (23:49 +0200)
Make sure that the "noise" records are not touched by other operations. Clean up noise.

See http://forum.civicrm.org/index.php/topic,30133.0.html

----------------------------------------
* CRM-13312: Implement API support for options.match
  http://issues.civicrm.org/jira/browse/CRM-13312

tests/phpunit/CRM/Utils/API/MatchOptionTest.php

index 1f0ef717fcb2cf6ea588fb048e846eedc45d423d..089bb87558aaa76620b23064e8bf22753d12a915 100644 (file)
@@ -6,12 +6,45 @@ require_once 'CiviTest/CiviUnitTestCase.php';
  */
 class CRM_Utils_API_MatchOptionTest extends CiviUnitTestCase {
 
+  /**
+   * @var array
+   */
+  var $noise;
+
   function setUp() {
     parent::setUp();
     $this->assertDBQuery(0, "SELECT count(*) FROM civicrm_contact WHERE first_name='Jeffrey' and last_name='Lebowski'");
 
     // Create noise to ensure we don't accidentally/coincidentally match the first record
-    $this->individualCreate(array('email' => 'ignore1@example.com'));
+    $this->noise['individual'] = $this->individualCreate(array(
+      'email' => 'ignore1@example.com',
+      // 'street_address-1' => 'Irrelevant'
+      'api.Address.create' => array(
+       'location_type_id' => 1,
+        'street_address' => '123 Irrelevant Str',
+        'supplemental_address_1' => 'Room 987',
+      ),
+    ));
+  }
+
+  function tearDown() {
+    $noise = $this->callAPISuccess('Contact', 'get', array(
+      'id' => $this->noise['individual'],
+      'return' => array('email'),
+      'api.Address.get' => 1,
+    ));
+    $this->assertEquals(1, count($noise['values']));
+    foreach ($noise['values'] as $value) {
+      $this->assertEquals('ignore1@example.com', $value['email']);
+      $this->assertEquals(1, count($value['api.Address.get']['values']));
+    }
+    CRM_core_DAO::executeQuery('DELETE FROM civicrm_address WHERE contact_id=%1', array(
+      1 => array($this->noise['individual'], 'Positive')
+    ));
+    $this->callAPISuccess('Contact', 'delete', array(
+      'id' => $this->noise['individual'],
+    ));
+    parent::tearDown();
   }
 
   /**