add test
authorJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 27 Jun 2017 14:18:01 +0000 (19:48 +0530)
committerJitendra Purohit <jitendra@fuzion.co.nz>
Tue, 27 Jun 2017 14:18:01 +0000 (19:48 +0530)
tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php

index 2571ca3cf43c5669246416a2ca417d268bb5b43c..6227a957d2123137126d96d227ab809b984e70fd 100644 (file)
@@ -246,6 +246,35 @@ class CRM_Core_BAO_SchemaHandlerTest extends CiviUnitTestCase {
     $this->assertTrue(empty($missingIndices));
   }
 
+  /**
+   * Check for partial indices
+   */
+  public function testPartialIndices() {
+    CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_prevnext_cache DROP INDEX index_all');
+    //Missing Column `is_selected`.
+    CRM_Core_DAO::executeQuery('CREATE INDEX index_all ON civicrm_prevnext_cache (cacheKey, entity_id1, entity_id2, entity_table)');
+    list($missingIndices, $existingKeyIndices) = CRM_Core_BAO_SchemaHandler::getMissingIndices();
+    $this->assertNotEmpty($existingKeyIndices);
+
+    CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_entity_tag DROP INDEX UI_entity_id_entity_table_tag_id');
+    //Test incorrect Ordering(correct order defined is entity_id and then entity_table, tag_id).
+    CRM_Core_DAO::executeQuery('CREATE INDEX UI_entity_id_entity_table_tag_id ON civicrm_entity_tag (entity_table, entity_id, tag_id)');
+    list($missingIndices, $existingKeyIndices) = CRM_Core_BAO_SchemaHandler::getMissingIndices();
+    $this->assertNotEmpty($existingKeyIndices);
+    $this->assertEquals(array('civicrm_prevnext_cache', 'civicrm_entity_tag'), array_keys($existingKeyIndices));
+
+    //Drop false index and create again.
+    CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_prevnext_cache DROP INDEX index_all');
+    CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_entity_tag DROP INDEX UI_entity_id_entity_table_tag_id');
+    list($missingIndices, $existingKeyIndices) = CRM_Core_BAO_SchemaHandler::getMissingIndices();
+    $this->assertEmpty($existingKeyIndices);
+    CRM_Core_BAO_SchemaHandler::createMissingIndices($missingIndices);
+    //Both vars should be empty now.
+    list($missingIndices, $existingKeyIndices) = CRM_Core_BAO_SchemaHandler::getMissingIndices();
+    $this->assertEmpty($missingIndices);
+    $this->assertEmpty($existingKeyIndices);
+  }
+
   /**
    * Test index signatures are added correctly
    */