From 1d3740066f788ed7fb3783614e146807370c98c4 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Wed, 25 Mar 2020 11:05:01 +1100 Subject: [PATCH] [NFC] Add in unit test to ensure that APIv4 Doesn't accept an invalid sort --- .../api/v4/Query/Api4SelectQueryTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/phpunit/api/v4/Query/Api4SelectQueryTest.php b/tests/phpunit/api/v4/Query/Api4SelectQueryTest.php index d82250811a..3a11b5e8b0 100644 --- a/tests/phpunit/api/v4/Query/Api4SelectQueryTest.php +++ b/tests/phpunit/api/v4/Query/Api4SelectQueryTest.php @@ -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) { + } + } + } -- 2.25.1