Commit | Line | Data |
---|---|---|
fa5bb5cf TO |
1 | <?php |
2 | ||
3 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
4 | ||
5 | /** | |
6 | * Class CRM_Core_InnoDBIndexerTest | |
7 | */ | |
8 | class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { | |
9 | 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 | |
12 | // cleanup logic. | |
13 | $idx = new CRM_Core_InnoDBIndexer(FALSE, array()); | |
14 | $idx->fixSchemaDifferences(); | |
15 | ||
16 | parent::tearDown(); | |
17 | } | |
18 | ||
19 | function testHasDeclaredIndex() { | |
20 | $idx = new CRM_Core_InnoDBIndexer(TRUE, array( | |
21 | 'civicrm_contact' => array( | |
22 | array('first_name', 'last_name'), | |
23 | array('foo') | |
24 | ), | |
25 | 'civicrm_email' => array( | |
26 | array('whiz'), | |
27 | ), | |
28 | )); | |
29 | ||
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'))); | |
36 | ||
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'))); | |
40 | } | |
41 | ||
42 | /** | |
43 | * When disabled, there is no FTS index, so queries that rely on FTS index fail. | |
44 | */ | |
45 | function testDisabled() { | |
46 | $idx = new CRM_Core_InnoDBIndexer(FALSE, array( | |
47 | 'civicrm_contact' => array( | |
48 | array('first_name', 'last_name'), | |
49 | ), | |
50 | )); | |
51 | $idx->fixSchemaDifferences(); | |
52 | ||
53 | try { | |
54 | CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")'); | |
55 | $this->fail("Missed expected exception"); | |
56 | } catch (Exception $e) { | |
57 | $this->assertTrue(TRUE, 'Received expected exception'); | |
58 | } | |
59 | } | |
60 | ||
61 | /** | |
62 | * When enabled, the FTS index is created, so queries that rely on FTS work. | |
63 | */ | |
64 | function testEnabled() { | |
65 | if (!$this->supportsFts()) { | |
66 | $this->markTestSkipped("Local installation of InnoDB does not support FTS."); | |
67 | return; | |
68 | } | |
69 | ||
70 | $idx = new CRM_Core_InnoDBIndexer(TRUE, array( | |
71 | 'civicrm_contact' => array( | |
72 | array('first_name', 'last_name'), | |
73 | ), | |
74 | )); | |
75 | $idx->fixSchemaDifferences(); | |
76 | ||
77 | CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")'); | |
78 | } | |
79 | ||
80 | function supportsFts() { | |
81 | return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.6.0', '>='); | |
82 | } | |
83 | } |