From 45fd2cc6c232b1fdc18d276a9a31456d005255ef Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 28 Jun 2016 15:30:34 -0700 Subject: [PATCH] CRM_Utils_QueryFormatterTest - Improve legibility of examples. --- .../phpunit/CRM/Utils/QueryFormatterTest.php | 261 ++++-------------- 1 file changed, 51 insertions(+), 210 deletions(-) diff --git a/tests/phpunit/CRM/Utils/QueryFormatterTest.php b/tests/phpunit/CRM/Utils/QueryFormatterTest.php index cb3f897f7f..b055b44395 100644 --- a/tests/phpunit/CRM/Utils/QueryFormatterTest.php +++ b/tests/phpunit/CRM/Utils/QueryFormatterTest.php @@ -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; -- 2.25.1