<commit_before><?php

namespace phpunit\Entity;

use Civi\Test\Api4\UnitTestCase;

/**
 * @group headless
 */
class ContactJoinTest extends UnitTestCase {

  public function setUpHeadless() {
    $relatedTables = array(
      'civicrm_contact',
      'civicrm_address',
      'civicrm_email',
      'civicrm_phone',
      'civicrm_openid',
      'civicrm_im',
      'civicrm_website',
      'civicrm_option_group',
      'civicrm_option_value',
      'civicrm_activity',
      'civicrm_activity_contact',
    );

    $this->cleanup(array('tablesToTruncate' => $relatedTables));
    $this->loadDataSet('SingleContact');

    return parent::setUpHeadless();
  }

  public function testContactJoin() {
    $contact = $this->getReference('test_contact_1');
    foreach (array('Address', 'Email', 'Phone', 'OpenID', 'IM', 'Website') as $entity) {
      $result = civicrm_api4($entity, 'get', array(
        'where' => array(array('contact_id', '=', $contact['id'])),
        'select' => array('contact.display_name', 'contact.id'),
        'limit' => 1,
      ))->first();
      $this->assertEquals($contact['id'], $result['contact']['id']);
      $this->assertEquals($contact['display_name'], $result['contact']['display_name']);
    }
  }
}
<commit_msg>Failing test to demonstrate bug in join logic<commit_after><?php

namespace phpunit\Entity;

use Civi\Test\Api4\UnitTestCase;

/**
 * @group headless
 */
class ContactJoinTest extends UnitTestCase {

  public function setUpHeadless() {
    $relatedTables = array(
      'civicrm_contact',
      'civicrm_address',
      'civicrm_email',
      'civicrm_phone',
      'civicrm_openid',
      'civicrm_im',
      'civicrm_website',
      'civicrm_option_group',
      'civicrm_option_value',
      'civicrm_activity',
      'civicrm_activity_contact',
    );

    $this->cleanup(array('tablesToTruncate' => $relatedTables));
    $this->loadDataSet('SingleContact');

    return parent::setUpHeadless();
  }

  public function testContactJoin() {
    $contact = $this->getReference('test_contact_1');
    foreach (array('Address', 'Email', 'Phone', 'OpenID', 'IM', 'Website') as $entity) {
      $results = civicrm_api4($entity, 'get', array(
        'where' => array(array('contact_id', '=', $contact['id'])),
        'select' => array('contact.display_name', 'contact.id'),
      ));
      foreach ($results as $result) {
        $this->assertEquals($contact['id'], $result['contact']['id']);
        $this->assertEquals($contact['display_name'], $result['contact']['display_name']);
      }
    }
  }
}

{'fraction_non_alphanumeric': 0.1743730407523511, 'fraction_numerical': 0.00274294670846395, 'mean_word_length': 3.7453531598513012, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3617854', 'n_tokens_mistral': 850, 'n_tokens_neox': 836, 'n_words': 134}