Skip to content
Snippets Groups Projects
Commit 12a8b146 authored by colemanw's avatar colemanw
Browse files

APIv4 - Properly show deprecated joins in unit tests

parent fc6f9f21
No related branches found
No related tags found
No related merge requests found
......@@ -988,7 +988,7 @@ class Api4SelectQuery {
try {
$joinPath = $joiner->autoJoin($this, $pathArray);
}
catch (\Exception $e) {
catch (\API_Exception $e) {
return;
}
$lastLink = array_pop($joinPath);
......
......@@ -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);
......
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment