Merge pull request #23101 from MegaphoneJon/core-1836-js
[civicrm-core.git] / tests / phpunit / api / v4 / Entity / ParticipantTest.php
index 5140c184a3f0d08d69479ec9649dd7dcaa096bd4..3de8b5bb4016f0876ca8d48b596d9837e05a1c7e 100644 (file)
@@ -27,7 +27,7 @@ use api\v4\UnitTestCase;
  */
 class ParticipantTest extends UnitTestCase {
 
-  public function setUp() {
+  public function setUp(): void {
     parent::setUp();
     $cleanup_params = [
       'tablesToTruncate' => [
@@ -47,7 +47,7 @@ class ParticipantTest extends UnitTestCase {
     $whereDescription = 'Criteria for selecting Participants';
 
     $this->assertEquals(TRUE, $getParams['checkPermissions']['default']);
-    $this->assertContains($whereDescription, $getParams['where']['description']);
+    $this->assertStringContainsString($whereDescription, $getParams['where']['description']);
   }
 
   public function testGet() {
@@ -180,6 +180,29 @@ class ParticipantTest extends UnitTestCase {
       $otherParticipantResult->offsetExists($firstParticipantId),
       'excluded wrong record');
 
+    // check syntax for date-range
+
+    $getParticipantsById = function($wheres = []) {
+      return Participant::get(FALSE)
+        ->setWhere($wheres)
+        ->execute()
+        ->indexBy('id');
+    };
+
+    $thisYearParticipants = $getParticipantsById([['register_date', '=', 'this.year']]);
+    $this->assertFalse(isset($thisYearParticipants[$firstParticipantId]));
+
+    $otherYearParticipants = $getParticipantsById([['register_date', '!=', 'this.year']]);
+    $this->assertTrue(isset($otherYearParticipants[$firstParticipantId]));
+
+    Participant::update()->setCheckPermissions(FALSE)
+      ->addWhere('id', '=', $firstParticipantId)
+      ->addValue('register_date', 'now')
+      ->execute();
+
+    $thisYearParticipants = $getParticipantsById([['register_date', '=', 'this.year']]);
+    $this->assertTrue(isset($thisYearParticipants[$firstParticipantId]));
+
     // retrieve a participant record and update some records
     $patchRecord = [
       'source' => "not " . $firstResult['source'],