CRM-18517 add merge test for when conflict encountered
authoreileen <emcnaughton@wikimedia.org>
Fri, 13 May 2016 04:26:23 +0000 (16:26 +1200)
committereileen <emcnaughton@wikimedia.org>
Mon, 16 May 2016 22:59:26 +0000 (10:59 +1200)
This test relies on the code loop being fixed

CRM/Core/BAO/PrevNextCache.php
tests/phpunit/api/v3/JobTest.php

index f76ec2f94370e79f8a0ad2bf3414683272c7c564..a78e0f3c592990aefd25bc5a4eddd601f019561a 100644 (file)
@@ -215,8 +215,6 @@ WHERE  cacheKey     = %3 AND
    *   Should we return rows that have already been idenfified as having a conflict.
    *   When this is TRUE you should be careful you do not set up a loop.
    *
-   * @param array $select
-   *
    * @return array
    */
   public static function retrieve($cacheKey, $join = NULL, $whereClause = NULL, $offset = 0, $rowCount = 0, $select = array(), $orderByClause = '', $includeConflicts = TRUE) {
index 7f993c4753617e23e3651a5716c5d0fb1d294d83..4b741316b3c43aea2e76f9f498a99706d516ad8a 100644 (file)
@@ -298,11 +298,126 @@ class api_v3_JobTest extends CiviUnitTestCase {
 
   /**
    * Test the batch merge function.
+   *
+   * We are just checking it returns without error here.
    */
   public function testBatchMerge() {
     $this->callAPISuccess('Job', 'process_batch_merge', array());
   }
 
+  /**
+   * Test the batch merge function actually works!
+   *
+   * @dataProvider getMergeSets
+   *
+   * @param $dataSet
+   */
+  public function testBatchMergeWorks($dataSet) {
+    foreach ($dataSet['contacts'] as $params) {
+      $this->callAPISuccess('Contact', 'create', $params);
+    }
+
+    $result = $this->callAPISuccess('Job', 'process_batch_merge', array());
+    $this->assertEquals($dataSet['skipped'], count($result['values']['skipped']), 'Failed to skip the right number:' . $dataSet['skipped']);
+    $this->assertEquals($dataSet['merged'], count($result['values']['merged']));
+    $result = $this->callAPISuccess('Contact', 'get', array('contact_sub_type' => 'Student', 'sequential' => 1));
+    $this->assertEquals(count($dataSet['expected']), $result['count']);
+    foreach ($dataSet['expected'] as $index => $contact) {
+      foreach ($contact as $key => $value) {
+        $this->assertEquals($value, $result['values'][$index][$key]);
+      }
+    }
+  }
+
+  /**
+   * Get data for batch merge.
+   */
+  public function getMergeSets() {
+    $data = array(
+      array(
+        array(
+          'contacts' => array(
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'contact_sub_type' => 'Student',
+              'api.Address.create' => array(
+                'street_address' => 'big house',
+                'location_type_id' => 'Home',
+              ),
+            ),
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'contact_sub_type' => 'Student',
+            ),
+          ),
+          'skipped' => 0,
+          'merged' => 1,
+          'expected' => array(
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+            ),
+          ),
+        ),
+      ),
+      array(
+        array(
+          'contacts' => array(
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'contact_sub_type' => 'Student',
+              'api.Address.create' => array(
+                'street_address' => 'big house',
+                'location_type_id' => 'Home',
+              ),
+            ),
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'contact_sub_type' => 'Student',
+              'api.Address.create' => array(
+                'street_address' => 'bigger house',
+                'location_type_id' => 'Home',
+              ),
+            ),
+          ),
+          'skipped' => 1,
+          'merged' => 0,
+          'expected' => array(
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'street_address' => 'big house',
+            ),
+            array(
+              'first_name' => 'Michael',
+              'last_name' => 'Jackson',
+              'email' => 'michael@neverland.com',
+              'contact_type' => 'Individual',
+              'street_address' => 'bigger house',
+            ),
+          ),
+        ),
+      ),
+    );
+    return $data;
+  }
+
   /**
    * @param $op
    * @param string $objectName