From 1debf77ab45732fe6abe274a661ea055f1cc3686 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 17 Sep 2018 12:46:46 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B0931:=20DBSearch=20AddCondition=20updated?= =?UTF-8?q?=20for=20tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobjectsearch.class.php | 5 ++ test/core/DBSearchCommitTest.php | 93 ++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 test/core/DBSearchCommitTest.php diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index 27e5f6436..50f674758 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -480,6 +480,11 @@ class DBObjectSearch extends DBSearch $oNewCondition = Expression::FromOQL($sOQLCondition); break; + case 'MATCHES': + $oRightExpr = new ScalarExpression($value); + $oNewCondition = new MatchExpression($oField, $oRightExpr); + break; + case 'Contains': case 'Begins with': case 'Finishes with': diff --git a/test/core/DBSearchCommitTest.php b/test/core/DBSearchCommitTest.php new file mode 100644 index 000000000..267b723a6 --- /dev/null +++ b/test/core/DBSearchCommitTest.php @@ -0,0 +1,93 @@ + + *
  • MakeGroupByQuery
  • + * + * + * @runTestsInSeparateProcesses + * @preserveGlobalState disabled + * @backupGlobals disabled + */ +class DBSearchCommitTest extends ItopDataTestCase +{ + // Need database COMMIT in order to create the FULLTEXT INDEX of MySQL + const USE_TRANSACTION = false; + + /** + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MissingQueryArgument + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException + * @throws \Exception + */ + public function testAttributeTagSet() + { + // Create a tag + $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'UNIT First'); + $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'UNIT Second'); + //Use it + $oTicket = $this->CreateTicket(1); + $oTicket->Set(TAG_ATTCODE, 'tag1'); + $oTicket->DBWrite(); + + $oSearch = DBSearch::FromOQL("SELECT UserRequest"); + $oSearch->AddCondition(TAG_ATTCODE, 'tag1', 'MATCHES'); + $oSet = new \DBObjectSet($oSearch); + static::assertEquals(1, $oSet->Count()); + + + $oTicket->Set(TAG_ATTCODE, 'tag1 tag2'); + $oTicket->DBWrite(); + + $oSet = new \DBObjectSet($oSearch); + static::assertEquals(1, $oSet->Count()); + } + + /** + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MissingQueryArgument + * @throws \MySQLException + * @throws \MySQLHasGoneAwayException + * @throws \OQLException + * @throws \Exception + */ + public function testAttributeTagSet2() + { + // Create a tag + $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag1', 'UNIT First'); + $this->CreateTagData(TAG_CLASS, TAG_ATTCODE, 'tag2', 'UNIT Second'); + //Use it + $oTicket = $this->CreateTicket(1); + $oTicket->Set(TAG_ATTCODE, 'tag1'); + $oTicket->DBWrite(); + + $oSearch = DBSearch::FromOQL("SELECT UserRequest"); + $oSearch->AddCondition(TAG_ATTCODE, 'tag1'); + $oSet = new \DBObjectSet($oSearch); + static::assertEquals(1, $oSet->Count()); + + + $oTicket->Set(TAG_ATTCODE, 'tag1 tag2'); + $oTicket->DBWrite(); + + $oSet = new \DBObjectSet($oSearch); + static::assertEquals(0, $oSet->Count()); + } + +}