From: larssandergreen Date: Sun, 2 Oct 2022 17:33:34 +0000 (-0600) Subject: add tests, handle nots X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0cff04bd1442e5476bf15bd4114aac54c45c9e8e;p=civicrm-core.git add tests, handle nots --- diff --git a/Civi/Api4/Utils/FormattingUtil.php b/Civi/Api4/Utils/FormattingUtil.php index 7b66db6f73..788a5b73b7 100644 --- a/Civi/Api4/Utils/FormattingUtil.php +++ b/Civi/Api4/Utils/FormattingUtil.php @@ -161,11 +161,11 @@ class FormattingUtil { $operator = ($operator === '=' || $operator === 'LIKE') ? 'BETWEEN' : 'NOT BETWEEN'; if (is_null($dateFrom) && !is_null($dateTo)) { - $operator = '<='; + $operator = ($operator === 'BETWEEN') ? '<=' : '>='; return self::formatDateValue($format, $dateTo); } elseif (!is_null($dateFrom) && is_null($dateTo)) { - $operator = '>='; + $operator = ($operator === 'BETWEEN') ? '>=' : '<='; return self::formatDateValue($format, $dateFrom); } else { diff --git a/tests/phpunit/api/v4/Action/DateTest.php b/tests/phpunit/api/v4/Action/DateTest.php index b58a59ad06..e61a22313e 100644 --- a/tests/phpunit/api/v4/Action/DateTest.php +++ b/tests/phpunit/api/v4/Action/DateTest.php @@ -197,6 +197,48 @@ class DateTest extends Api4TestBase implements TransactionalInterface { ->addWhere('id', '=', $c1) ->execute(); $this->assertCount(2, $contact); + + // Find contributions To end of previous calendar year + $contact = \Civi\Api4\Contact::get() + ->addSelect('id', 'contribution.total_amount') + ->setJoin([ + ['Contribution AS contribution', FALSE, NULL, ['contribution.receive_date', '=', '"earlier.year"']], + ]) + ->addWhere('id', '=', $c1) + ->execute(); + $this->assertCount(2, $contact); + + // Find contributions not To end of previous calendar year + $contact = \Civi\Api4\Contact::get() + ->addSelect('id', 'contribution.total_amount') + ->setJoin([ + ['Contribution AS contribution', FALSE, NULL, ['contribution.receive_date', '!=', '"earlier.year"']], + ]) + ->addWhere('id', '=', $c1) + ->execute(); + $this->assertCount(1, $contact); + $this->assertEquals(6, $contact[0]['contribution.total_amount']); + + // Find contributions From start of current calendar year + $contact = \Civi\Api4\Contact::get() + ->addSelect('id', 'contribution.total_amount') + ->setJoin([ + ['Contribution AS contribution', FALSE, NULL, ['contribution.receive_date', '=', '"greater.year"']], + ]) + ->addWhere('id', '=', $c1) + ->execute(); + $this->assertCount(1, $contact); + $this->assertEquals(6, $contact[0]['contribution.total_amount']); + + // Find contributions not From start of current calendar year + $contact = \Civi\Api4\Contact::get() + ->addSelect('id', 'contribution.total_amount') + ->setJoin([ + ['Contribution AS contribution', FALSE, NULL, ['contribution.receive_date', '!=', '"greater.year"']], + ]) + ->addWhere('id', '=', $c1) + ->execute(); + $this->assertCount(2, $contact); } }