3 require_once 'CiviTest/CiviUnitTestCase.php';
6 * Class CRM_Core_InnoDBIndexerTest
8 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, array());
14 $idx->fixSchemaDifferences();
19 public function testHasDeclaredIndex() {
20 $idx = new CRM_Core_InnoDBIndexer(TRUE, array(
21 'civicrm_contact' => array(
22 array('first_name', 'last_name'),
25 'civicrm_email' => array(
30 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name', 'last_name')));
31 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name', 'first_name')));
32 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name'))); // not sure if this is right behavior
33 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name'))); // not sure if this is right behavior
34 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('foo')));
35 $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', array('whiz')));
37 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('first_name', 'last_name')));
38 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('foo')));
39 $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', array('whiz')));
43 * When disabled, there is no FTS index, so queries that rely on FTS index fail.
45 public function testDisabled() {
46 $idx = new CRM_Core_InnoDBIndexer(FALSE, array(
47 'civicrm_contact' => array(
48 array('first_name', 'last_name'),
51 $idx->fixSchemaDifferences();
54 CRM_Core_DAO
::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
55 $this->fail("Missed expected exception");
57 catch (Exception
$e) {
58 $this->assertTrue(TRUE, 'Received expected exception');
63 * When enabled, the FTS index is created, so queries that rely on FTS work.
65 public function testEnabled() {
66 if (!$this->supportsFts()) {
67 $this->markTestSkipped("Local installation of InnoDB does not support FTS.");
71 $idx = new CRM_Core_InnoDBIndexer(TRUE, array(
72 'civicrm_contact' => array(
73 array('first_name', 'last_name'),
76 $idx->fixSchemaDifferences();
78 CRM_Core_DAO
::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
81 public function supportsFts() {
82 return version_compare(CRM_Core_DAO
::singleValueQuery('SELECT VERSION()'), '5.6.0', '>=');