From: Jitendra Purohit Date: Tue, 27 Jun 2017 14:18:01 +0000 (+0530) Subject: add test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d7367cefbb28ead6b6305addf133f24f6e381125;p=civicrm-core.git add test --- diff --git a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php index 2571ca3cf4..6227a957d2 100644 --- a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php +++ b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php @@ -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 */