+ /**
+ * Test search builder style query including custom address fields.
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testAddressCustomFields() {
+ $this->createCustomGroupWithFieldOfType(['extends' => 'Address'], 'int');
+ $individualID = $this->individualCreate();
+ $this->callAPISuccess('Address', 'create', [
+ 'contact_id' => $individualID,
+ 'street_address' => '10 Downing Street',
+ 'location_type_id' => 'Home',
+ $this->getCustomFieldName('int') => 5,
+ ]);
+
+ $queryObject = new CRM_Contact_BAO_Query(
+ [[$this->getCustomFieldName('int') . '-1', '=', 5, 1, 0]],
+ ['contact_type' => 1, 'location' => ['Home' => ['location_type' => 1, $this->getCustomFieldName('int') => 1]]]
+ );
+ $queryObject->query();
+ $tableName = $this->getCustomGroupTable();
+ $fieldName = $this->getCustomFieldColumnName('int');
+
+ $this->assertEquals([], $queryObject->_where[0]);
+ $this->assertEquals($tableName . '.' . $fieldName . ' = 5', implode(', ', $queryObject->_where[1]));
+ $this->assertEquals(1, $queryObject->_whereTables['civicrm_contact']);
+ $this->assertEquals('LEFT JOIN civicrm_address `Home-address` ON (`Home-address`.contact_id = contact_a.id AND `Home-address`.location_type_id = 1)', trim($queryObject->_whereTables['Home-address']));
+ $this->assertEquals("LEFT JOIN {$tableName} ON {$tableName}.entity_id = `Home-address`.id", trim($queryObject->_whereTables[$tableName]));
+ $this->assertEquals([], $queryObject->_qill[0]);
+ $this->assertEquals(['Enter integer here = 5'], $queryObject->_qill[1]);
+ }
+