APIv4 - Properly show deprecated joins in unit tests
authorColeman Watts <coleman@civicrm.org>
Fri, 20 Aug 2021 14:11:34 +0000 (10:11 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 20 Aug 2021 14:11:34 +0000 (10:11 -0400)
Civi/Api4/Query/Api4SelectQuery.php
Civi/Api4/Service/Schema/Joiner.php
tests/phpunit/api/v4/Action/FkJoinTest.php

index 7232d02b3f978c973dc2ad9826a62f3f60aed1e9..6e8cb701e4458bf9c1d73b9cd912ebbd684f6301 100644 (file)
@@ -988,7 +988,7 @@ class Api4SelectQuery {
     try {
       $joinPath = $joiner->autoJoin($this, $pathArray);
     }
-    catch (\Exception $e) {
+    catch (\API_Exception $e) {
       return;
     }
     $lastLink = array_pop($joinPath);
index b09aaaef322373ec092168970cba8af4e6b01481..d64cac920a525a9034fcb51c6cc7f4deb760fa8a 100644 (file)
@@ -106,7 +106,7 @@ class Joiner {
    * @param array $joinPath
    *
    * @return \Civi\Api4\Service\Schema\Joinable\Joinable[]
-   * @throws \Exception
+   * @throws \API_Exception
    */
   protected function getPath(string $baseTable, array $joinPath) {
     $cacheKey = sprintf('%s.%s', $baseTable, implode('.', $joinPath));
@@ -117,7 +117,7 @@ class Joiner {
         $links = $this->schemaMap->getPath($baseTable, $targetAlias);
 
         if (empty($links)) {
-          throw new \Exception(sprintf('Cannot join %s to %s', $baseTable, $targetAlias));
+          throw new \API_Exception(sprintf('Cannot join %s to %s', $baseTable, $targetAlias));
         }
         else {
           $fullPath = array_merge($fullPath, $links);
index d0ed5c87b1b064d37bde1ff25ddc1689e4f2e22c..213726b6e259d4e2c686b969d69e690d646dc32e 100644 (file)
@@ -374,4 +374,22 @@ class FkJoinTest extends UnitTestCase {
     $this->assertEquals('TesterCo', $emailGet['contact_id.employer_id.display_name']);
   }
 
+  public function testDeprecatedJoins() {
+    $message = '';
+    try {
+      \Civi\Api4\Email::get(FALSE)
+        ->addWhere('contact.first_name', '=', 'Peter')
+        ->addWhere('contact.last_name', '=', '')
+        ->addWhere('contact.is_deleted', '=', 0)
+        ->addWhere('contact.is_deceased', '=', 0)
+        ->addWhere('email', '=', '')
+        ->addWhere('is_primary', '=', TRUE)
+        ->setSelect(['contact_id'])->execute();
+    }
+    catch (\Exception $e) {
+      $message = $e->getMessage();
+    }
+    $this->assertStringContainsString("Deprecated join alias 'contact' used in APIv4 get. Should be changed to 'contact_id'", $message);
+  }
+
 }