Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(TB Filter Text) added test, added some comments re cs/ci
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Jul 21, 2021
1 parent 288d564 commit ea5dee0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
24 changes: 20 additions & 4 deletions tests/tine20/Addressbook/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,31 @@ public function testUpdateContactWithMissingPostalcode()
$this->assertTrue(48143 == $updatedContact->adr_two_postalcode || is_null($updatedContact->adr_two_postalcode));
}

/**
* try to get a contact
*/
public function testSearchContactCS()
{
$this->objects['initialContact']->adr_one_street = 'caseSensitivityIsVerySensitive';
$contact = $this->_addContact();
$this->assertEquals($this->objects['initialContact']->adr_one_street, $contact->adr_one_street);

$this->assertSame(1, $this->_instance->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Addressbook_Model_Contact::class, [
['field' => 'adr_one_street', 'operator' => 'contains', 'value' => 'isverys']
]))->count(), 'ci search did not work');
$this->assertSame(0, $this->_instance->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Addressbook_Model_Contact::class, [
['field' => 'adr_one_street', 'operator' => 'contains', 'value' => 'isverys']
], '', [Tinebase_Model_Filter_Text::CASE_SENSITIVE => true]))->count(), 'cs search did not work');
$this->assertSame(1, $this->_instance->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Addressbook_Model_Contact::class, [
['field' => 'adr_one_street', 'operator' => 'contains', 'value' => 'IsVeryS']
], '', [Tinebase_Model_Filter_Text::CASE_SENSITIVE => true]))->count(), 'cs search did not work');
}

public function testSearchContactWithBackslash()
{
$this->objects['initialContact']->adr_one_street = '\\\\';
$this->objects['initialContact']->adr_two_street = 'test\\hola\\*uijuiui';
$contact = $this->_addContact();

$this->assertEquals($this->objects['initialContact']->adr_two_street, $contact->adr_two_street);

$this->assertSame(1, $this->_instance->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Expand Down
28 changes: 16 additions & 12 deletions tine20/Tinebase/Model/Filter/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
class Tinebase_Model_Filter_Text extends Tinebase_Model_Filter_Abstract
{
const CASE_SENSITIVE = 'caseSensitive';

/**
* @var array list of allowed operators
*/
Expand Down Expand Up @@ -63,12 +65,12 @@ class Tinebase_Model_Filter_Text extends Tinebase_Model_Filter_Abstract
public function __construct($_fieldOrData, $_operator = NULL, $_value = NULL, array $_options = array())
{
$_options = isset($_fieldOrData['options']) ? $_fieldOrData['options'] : $_options;
if (isset($_options['caseSensitive']) && $_options['caseSensitive']) {
if (isset($_options[self::CASE_SENSITIVE]) && $_options[self::CASE_SENSITIVE]) {
$this->_caseSensitive = true;
}
if (isset($_options['binary']) && $_options['binary']) {
$this->_binary = true;
if (!isset($_options['caseSensitive'])) {
if (!isset($_options[self::CASE_SENSITIVE])) {
$this->_caseSensitive = true;
}
}
Expand All @@ -85,7 +87,7 @@ protected function _setOpSqlMap()
return;
}

// TODO fixme
// TODO fixme move CS here
// if ($this->_caseSensitive) {}
// it seems as of mysql8 this might become an option
// 'sqlop' => ' LIKE _utf8mb4 ? COLLATE utf8mb4_unicode_cs? or something'
Expand Down Expand Up @@ -121,15 +123,17 @@ public function appendFilterSql($_select, $_backend)
{
// quote field identifier, set action and replace wildcards
$field = $this->_getQuotedFieldName($_backend);
if (($db = Tinebase_Core::getDb()) instanceof Zend_Db_Adapter_Pdo_Mysql) {
if (!$this->_binary && $this->_caseSensitive) {
$field = 'BINARY ' . $field;
} elseif ($this->_binary && !$this->_caseSensitive) {
if ($db->getConfig()['charset'] === 'utf8') {
$field .= ' COLLATE utf8_unicode_ci';
} else {
$field .= ' COLLATE utf8mb4_unicode_ci';
}

// TODO fix me: this should be moved to the static part of the query, the search condition.
// TODO fix me: that might improve performance quiet a bit, remove this, do it in _setOpSqlMap
$db = Tinebase_Core::getDb();
if (!$this->_binary && $this->_caseSensitive) {
$field = 'BINARY ' . $field;
} elseif ($this->_binary && !$this->_caseSensitive) {
if ($db->getConfig()['charset'] === 'utf8') {
$field .= ' COLLATE utf8_unicode_ci';
} else {
$field .= ' COLLATE utf8mb4_unicode_ci';
}
}

Expand Down

0 comments on commit ea5dee0

Please sign in to comment.