Commit | Line | Data |
---|---|---|
fa5bb5cf TO |
1 | <?php |
2 | ||
fa5bb5cf TO |
3 | /** |
4 | * Class CRM_Core_InnoDBIndexerTest | |
acb109b7 | 5 | * @group headless |
fa5bb5cf TO |
6 | */ |
7 | class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase { | |
00be9182 | 8 | public function tearDown() { |
fa5bb5cf TO |
9 | // May or may not cleanup well if there's a bug in the indexer. |
10 | // This is better than nothing -- and better than duplicating the | |
11 | // cleanup logic. | |
12 | $idx = new CRM_Core_InnoDBIndexer(FALSE, array()); | |
13 | $idx->fixSchemaDifferences(); | |
14 | ||
15 | parent::tearDown(); | |
16 | } | |
17 | ||
00be9182 | 18 | public function testHasDeclaredIndex() { |
fa5bb5cf TO |
19 | $idx = new CRM_Core_InnoDBIndexer(TRUE, array( |
20 | 'civicrm_contact' => array( | |
21 | array('first_name', 'last_name'), | |
21dfd5f5 | 22 | array('foo'), |
fa5bb5cf TO |
23 | ), |
24 | 'civicrm_email' => array( | |
25 | array('whiz'), | |
26 | ), | |
27 | )); | |
28 | ||
29 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name', 'last_name'))); | |
30 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name', 'first_name'))); | |
31 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name'))); // not sure if this is right behavior | |
32 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name'))); // not sure if this is right behavior | |
33 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('foo'))); | |
34 | $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', array('whiz'))); | |
35 | ||
36 | $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('first_name', 'last_name'))); | |
37 | $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('foo'))); | |
38 | $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', array('whiz'))); | |
39 | } | |
40 | ||
41 | /** | |
42 | * When disabled, there is no FTS index, so queries that rely on FTS index fail. | |
43 | */ | |
00be9182 | 44 | public function testDisabled() { |
fa5bb5cf TO |
45 | $idx = new CRM_Core_InnoDBIndexer(FALSE, array( |
46 | 'civicrm_contact' => array( | |
47 | array('first_name', 'last_name'), | |
48 | ), | |
49 | )); | |
50 | $idx->fixSchemaDifferences(); | |
51 | ||
52 | try { | |
53 | CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")'); | |
54 | $this->fail("Missed expected exception"); | |
0db6c3e1 TO |
55 | } |
56 | catch (Exception $e) { | |
fa5bb5cf TO |
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 | */ | |
00be9182 | 64 | public function testEnabled() { |
fa5bb5cf TO |
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 | ||
7fe37828 EM |
80 | /** |
81 | * @return mixed | |
82 | */ | |
00be9182 | 83 | public function supportsFts() { |
fa5bb5cf TO |
84 | return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.6.0', '>='); |
85 | } | |
96025800 | 86 | |
fa5bb5cf | 87 | } |