CRM_Utils_QueryFormatterTest - Improve legibility of examples.
authorTim Otten <totten@civicrm.org>
Tue, 28 Jun 2016 22:30:34 +0000 (15:30 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 28 Jun 2016 22:30:34 +0000 (15:30 -0700)
tests/phpunit/CRM/Utils/QueryFormatterTest.php

index cb3f897f7fd1b061c207f6a591bf48934564a08a..b055b4439529eab66817cb939035d808e1af396f 100644 (file)
@@ -15,224 +15,65 @@ class CRM_Utils_QueryFormatterTest extends CiviUnitTestCase {
     // Array(0=>$inputText, 1=>$language, 2=>$options, 3=>$expectedText).
     $cases = array();
 
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      '%someone@example.com%',
-    );
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      'someone@example.com',
-    );
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_PHRASE,
-      '"someone@example.com"',
-    );
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-      '"*someone@example.com*"',
-    );
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-      '*someone* *example*',
-      // Hmm, this seems suspicious... drops ".com".
-    );
-    $cases[] = array(
-      'someone@example.com',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
-      'someone* example*',
-      // Hmm, this seems suspicious... is `example` a distinct word in mysql lexer?
-    );
+    $cases[] = array('someone@example.com', 'like', 'simple', '%someone@example.com%');
+    $cases[] = array('someone@example.com', 'like', 'phrase', '%someone@example.com%');
+    $cases[] = array('someone@example.com', 'like', 'wildphrase', '%someone@example.com%');
+    $cases[] = array('someone@example.com', 'like', 'wildwords', '%someone@example.com%');
+    $cases[] = array('someone@example.com', 'like', 'wildwords-suffix', '%someone@example.com%');
 
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      '%first second%',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_PHRASE,
-      '%first second%',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-      '%first second%',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-      '%first%second%',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
-      '%first%second%',
-    );
+    $cases[] = array('someone@example.com', 'fts', 'simple', 'someone@example.com');
+    $cases[] = array('someone@example.com', 'fts', 'phrase', '"someone@example.com"');
+    $cases[] = array('someone@example.com', 'fts', 'wildphrase', '"*someone@example.com*"');
+    $cases[] = array('someone@example.com', 'fts', 'wildwords', '*someone* *example*'); // (1)
+    $cases[] = array('someone@example.com', 'fts', 'wildwords-suffix', 'someone* example*'); // (1)
 
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      'first second',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_PHRASE,
-      '"first second"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-      '"*first second*"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-      '*first* *second*',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
-      'first* second*',
-    );
+    $cases[] = array('someone@example.com', 'ftsbool', 'simple', '+someone +example'); // (1)
+    $cases[] = array('someone@example.com', 'ftsbool', 'phrase', '+"someone@example.com"');
+    $cases[] = array('someone@example.com', 'ftsbool', 'wildphrase', '+"*someone@example.com*"');
+    $cases[] = array('someone@example.com', 'ftsbool', 'wildwords', '+*someone* +*example*'); // (1)
+    $cases[] = array('someone@example.com', 'ftsbool', 'wildwords-suffix', '+someone* +example*'); // (1)
 
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      '+first +second',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-      CRM_Utils_QueryFormatter::MODE_PHRASE,
-      '+"first second"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-      CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-      '+"*first second*"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-      '+*first* +*second*',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
-      '+first* +second*',
-    );
+    // Note: The examples marked with (1) are suspicious cases where
 
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SOLR,
-      CRM_Utils_QueryFormatter::MODE_NONE,
-      'first second',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SOLR,
-      CRM_Utils_QueryFormatter::MODE_PHRASE,
-      '"first second"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SOLR,
-      CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-      '"*first second*"',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SOLR,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-      '*first* *second*',
-    );
-    $cases[] = array(
-      'first second',
-      CRM_Utils_QueryFormatter::LANG_SOLR,
-      CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
-      'first* second*',
-    );
+    $cases[] = array('first second', 'like', 'simple', '%first second%');
+    $cases[] = array('first second', 'like', 'phrase', '%first second%');
+    $cases[] = array('first second', 'like', 'wildphrase', '%first second%');
+    $cases[] = array('first second', 'like', 'wildwords', '%first%second%');
+    $cases[] = array('first second', 'like', 'wildwords-suffix', '%first%second%');
+
+    $cases[] = array('first second', 'fts', 'simple', 'first second');
+    $cases[] = array('first second', 'fts', 'phrase', '"first second"');
+    $cases[] = array('first second', 'fts', 'wildphrase', '"*first second*"');
+    $cases[] = array('first second', 'fts', 'wildwords', '*first* *second*');
+    $cases[] = array('first second', 'fts', 'wildwords-suffix', 'first* second*');
+
+    $cases[] = array('first second', 'ftsbool', 'simple', '+first +second');
+    $cases[] = array('first second', 'ftsbool', 'phrase', '+"first second"');
+    $cases[] = array('first second', 'ftsbool', 'wildphrase', '+"*first second*"');
+    $cases[] = array('first second', 'ftsbool', 'wildwords', '+*first* +*second*');
+    $cases[] = array('first second', 'ftsbool', 'wildwords-suffix', '+first* +second*');
+
+    $cases[] = array('first second', 'solr', 'simple', 'first second');
+    $cases[] = array('first second', 'solr', 'phrase', '"first second"');
+    $cases[] = array('first second', 'solr', 'wildphrase', '"*first second*"');
+    $cases[] = array('first second', 'solr', 'wildwords', '*first* *second*');
+    $cases[] = array('first second', 'solr', 'wildwords-suffix', 'first* second*');
 
     // If user supplies wildcards, then ignore mode.
     foreach (array(
-               CRM_Utils_QueryFormatter::MODE_NONE,
-               CRM_Utils_QueryFormatter::MODE_WILDPHRASE,
-               CRM_Utils_QueryFormatter::MODE_WILDWORDS,
-               CRM_Utils_QueryFormatter::MODE_WILDWORDS_SUFFIX,
+               'simple',
+               'wildphrase',
+               'wildwords',
+               'wildwords-suffix',
              ) as $mode) {
-      $cases[] = array(
-        'first% second',
-        CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-        $mode,
-        'first% second',
-      );
-      $cases[] = array(
-        'first% second',
-        CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-        $mode,
-        'first* second',
-      );
-      $cases[] = array(
-        'first% second',
-        CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-        $mode,
-        '+first* +second',
-      );
-      $cases[] = array(
-        'first% second',
-        CRM_Utils_QueryFormatter::LANG_SOLR,
-        $mode,
-        'first* second',
-      );
-      $cases[] = array(
-        'first second%',
-        CRM_Utils_QueryFormatter::LANG_SQL_LIKE,
-        $mode,
-        'first second%',
-      );
-      $cases[] = array(
-        'first second%',
-        CRM_Utils_QueryFormatter::LANG_SQL_FTS,
-        $mode,
-        'first second*',
-      );
-      $cases[] = array(
-        'first second%',
-        CRM_Utils_QueryFormatter::LANG_SQL_FTSBOOL,
-        $mode,
-        '+first +second*',
-      );
-      $cases[] = array(
-        'first second%',
-        CRM_Utils_QueryFormatter::LANG_SOLR,
-        $mode,
-        'first second*',
-      );
+      $cases[] = array('first% second', 'like', $mode, 'first% second');
+      $cases[] = array('first% second', 'fts', $mode, 'first* second');
+      $cases[] = array('first% second', 'ftsbool', $mode, '+first* +second');
+      $cases[] = array('first% second', 'solr', $mode, 'first* second');
+      $cases[] = array('first second%', 'like', $mode, 'first second%');
+      $cases[] = array('first second%', 'fts', $mode, 'first second*');
+      $cases[] = array('first second%', 'ftsbool', $mode, '+first +second*');
+      $cases[] = array('first second%', 'solr', $mode, 'first second*');
     }
 
     return $cases;