4 * Class CRM_Core_InnoDBIndexerTest
7 class CRM_Core_InnoDBIndexerTest
extends CiviUnitTestCase
{
9 public function tearDown() {
10 // May or may not cleanup well if there's a bug in the indexer.
11 // This is better than nothing -- and better than duplicating the
13 $idx = new CRM_Core_InnoDBIndexer(FALSE, []);
14 $idx->fixSchemaDifferences();
19 public function testHasDeclaredIndex() {
20 $idx = new CRM_Core_InnoDBIndexer(TRUE, [
21 'civicrm_contact' => [
22 ['first_name', 'last_name'],
30 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name', 'last_name']));
31 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name', 'first_name']));
32 // not sure if this is right behavior
33 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name']));
34 // not sure if this is right behavior
35 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name']));
36 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['foo']));
37 $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', ['whiz']));
39 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['first_name', 'last_name']));
40 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', ['foo']));
41 $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', ['whiz']));
45 * When disabled, there is no FTS index, so queries that rely on FTS index fail.
47 public function testDisabled() {
48 $idx = new CRM_Core_InnoDBIndexer(FALSE, [
49 'civicrm_contact' => [
50 ['first_name', 'last_name'],
53 $idx->fixSchemaDifferences();
56 CRM_Core_DAO
::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
57 $this->fail("Missed expected exception");
59 catch (Exception
$e) {
60 $this->assertTrue(TRUE, 'Received expected exception');
65 * When enabled, the FTS index is created, so queries that rely on FTS work.
67 public function testEnabled() {
68 if (!$this->supportsFts()) {
69 $this->markTestSkipped("Local installation of InnoDB does not support FTS.");
73 $idx = new CRM_Core_InnoDBIndexer(TRUE, [
74 'civicrm_contact' => [
75 ['first_name', 'last_name'],
78 $idx->fixSchemaDifferences();
80 CRM_Core_DAO
::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
86 public function supportsFts() {
87 return version_compare(CRM_Core_DAO
::singleValueQuery('SELECT VERSION()'), '5.6.0', '>=');