Merge pull request #15948 from eileenmcnaughton/export_test
[civicrm-core.git] / tests / phpunit / CRM / Core / InnoDBIndexerTest.php
CommitLineData
fa5bb5cf
TO
1<?php
2
fa5bb5cf
TO
3/**
4 * Class CRM_Core_InnoDBIndexerTest
acb109b7 5 * @group headless
fa5bb5cf
TO
6 */
7class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase {
39b959db 8
00be9182 9 public function tearDown() {
fa5bb5cf
TO
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.
9099cab3 13 $idx = new CRM_Core_InnoDBIndexer(FALSE, []);
fa5bb5cf
TO
14 $idx->fixSchemaDifferences();
15
16 parent::tearDown();
17 }
18
00be9182 19 public function testHasDeclaredIndex() {
9099cab3
CW
20 $idx = new CRM_Core_InnoDBIndexer(TRUE, [
21 'civicrm_contact' => [
22 ['first_name', 'last_name'],
23 ['foo'],
24 ],
25 'civicrm_email' => [
26 ['whiz'],
27 ],
28 ]);
fa5bb5cf 29
9099cab3
CW
30 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name', 'last_name']));
31 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['last_name', 'first_name']));
39b959db 32 // not sure if this is right behavior
9099cab3 33 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', ['first_name']));
39b959db 34 // not sure if this is right behavior
9099cab3
CW
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']));
fa5bb5cf 38
9099cab3
CW
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']));
fa5bb5cf
TO
42 }
43
44 /**
45 * When disabled, there is no FTS index, so queries that rely on FTS index fail.
46 */
00be9182 47 public function testDisabled() {
9099cab3
CW
48 $idx = new CRM_Core_InnoDBIndexer(FALSE, [
49 'civicrm_contact' => [
50 ['first_name', 'last_name'],
51 ],
52 ]);
fa5bb5cf
TO
53 $idx->fixSchemaDifferences();
54
55 try {
56 CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
57 $this->fail("Missed expected exception");
0db6c3e1
TO
58 }
59 catch (Exception $e) {
fa5bb5cf
TO
60 $this->assertTrue(TRUE, 'Received expected exception');
61 }
62 }
63
64 /**
65 * When enabled, the FTS index is created, so queries that rely on FTS work.
66 */
00be9182 67 public function testEnabled() {
fa5bb5cf
TO
68 if (!$this->supportsFts()) {
69 $this->markTestSkipped("Local installation of InnoDB does not support FTS.");
70 return;
71 }
72
9099cab3
CW
73 $idx = new CRM_Core_InnoDBIndexer(TRUE, [
74 'civicrm_contact' => [
75 ['first_name', 'last_name'],
76 ],
77 ]);
fa5bb5cf
TO
78 $idx->fixSchemaDifferences();
79
80 CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
81 }
82
7fe37828
EM
83 /**
84 * @return mixed
85 */
00be9182 86 public function supportsFts() {
fa5bb5cf
TO
87 return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.6.0', '>=');
88 }
96025800 89
fa5bb5cf 90}