[NFC] Add in unit test to ensure that APIv4 Doesn't accept an invalid sort
authorSeamus Lee <seamuslee001@gmail.com>
Wed, 25 Mar 2020 00:05:01 +0000 (11:05 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sat, 28 Mar 2020 01:07:38 +0000 (12:07 +1100)
tests/phpunit/api/v4/Query/Api4SelectQueryTest.php

index d82250811a9598588dd7ed67a48da4da7ec6d979..3a11b5e8b0a51ff7f6b3fd93edac11cdd8d372f5 100644 (file)
@@ -109,4 +109,27 @@ class Api4SelectQueryTest extends UnitTestCase {
     $this->assertCount(2, $result['phones']);
   }
 
+  public function testInvaidSort() {
+    $api = \Civi\API\Request::create('Contact', 'get', ['version' => 4, 'checkPermissions' => FALSE]);
+    $query = new Api4SelectQuery($api);
+    $query->select[] = 'id';
+    $query->select[] = 'first_name';
+    $query->select[] = 'phones.phone';
+    $query->where[] = ['first_name', '=', 'Phoney'];
+    $query->orderBy = ['first_name' => 'sleep(1)'];
+    try {
+      $results = $query->run();
+      $this->fail('An Exception Should have been raised');
+    }
+    catch (\API_Exception $e) {
+    }
+    $query->orderBy = ['sleep(1)', 'ASC'];
+    try {
+      $results = $query->run();
+      $this->fail('An Exception Should have been raised');
+    }
+    catch (\API_Exception $e) {
+    }
+  }
+
 }