Merge pull request #14639 from colemanw/i18nCleanup
[civicrm-core.git] / tests / phpunit / CRM / Core / InnoDBIndexerTest.php
... / ...
CommitLineData
1<?php
2
3/**
4 * Class CRM_Core_InnoDBIndexerTest
5 * @group headless
6 */
7class CRM_Core_InnoDBIndexerTest extends CiviUnitTestCase {
8
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
12 // cleanup logic.
13 $idx = new CRM_Core_InnoDBIndexer(FALSE, array());
14 $idx->fixSchemaDifferences();
15
16 parent::tearDown();
17 }
18
19 public 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 // not sure if this is right behavior
33 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('first_name')));
34 // not sure if this is right behavior
35 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('last_name')));
36 $this->assertTrue($idx->hasDeclaredIndex('civicrm_contact', array('foo')));
37 $this->assertFalse($idx->hasDeclaredIndex('civicrm_contact', array('whiz')));
38
39 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('first_name', 'last_name')));
40 $this->assertFalse($idx->hasDeclaredIndex('civicrm_email', array('foo')));
41 $this->assertTrue($idx->hasDeclaredIndex('civicrm_email', array('whiz')));
42 }
43
44 /**
45 * When disabled, there is no FTS index, so queries that rely on FTS index fail.
46 */
47 public function testDisabled() {
48 $idx = new CRM_Core_InnoDBIndexer(FALSE, array(
49 'civicrm_contact' => array(
50 array('first_name', 'last_name'),
51 ),
52 ));
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");
58 }
59 catch (Exception $e) {
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 */
67 public function testEnabled() {
68 if (!$this->supportsFts()) {
69 $this->markTestSkipped("Local installation of InnoDB does not support FTS.");
70 return;
71 }
72
73 $idx = new CRM_Core_InnoDBIndexer(TRUE, array(
74 'civicrm_contact' => array(
75 array('first_name', 'last_name'),
76 ),
77 ));
78 $idx->fixSchemaDifferences();
79
80 CRM_Core_DAO::executeQuery('SELECT id FROM civicrm_contact WHERE MATCH(first_name,last_name) AGAINST ("joe")');
81 }
82
83 /**
84 * @return mixed
85 */
86 public function supportsFts() {
87 return version_compare(CRM_Core_DAO::singleValueQuery('SELECT VERSION()'), '5.6.0', '>=');
88 }
89
90}