X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tests%2Fphpunit%2FCRM%2FContact%2FBAO%2FQueryTest.php;h=f70937de060383ade42d5816644159fcfab697a0;hb=358c4c4179a6b2494b3126bfc33c8b37ee909d49;hp=44f562ad170bacccfa1ac2109d4266de3476f5a2;hpb=8f36c0f58a65099c71347285c127a17aa87ef61a;p=civicrm-core.git diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 44f562ad17..f70937de06 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -1118,4 +1118,61 @@ civicrm_relationship.is_active = 1 AND ]); } + /** + * Test the options are handled for the qill. + */ + public function testQillOptions() { + $qill = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_BAO_Activity', 'activity_type_id', 2, '='); + $this->assertEquals(['=', 'Phone Call'], $qill); + + $qill = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_BAO_Activity', 'priority_id', 2, '='); + $this->assertEquals(['=', 'Normal'], $qill); + } + + /** + * Test tests that a value on 'any entity' with the right metadata will be handled. + * + * @throws \CRM_Core_Exception + */ + public function testGenericWhereHandling() { + $query = new CRM_Contact_BAO_Query([['suffix_id', '=', 2, 0]]); + $this->assertEquals("contact_a.suffix_id = 2", $query->_where[0][0]); + $this->assertEquals('Individual Suffix = Sr.', $query->_qill[0][0]); + $this->assertNotTrue(isset($query->_tables['civicrm_activity'])); + + $query = new CRM_Contact_BAO_Query([['prefix_id', '=', 2, 0]]); + $this->assertEquals('contact_a.prefix_id = 2', $query->_where[0][0]); + $this->assertEquals('Individual Prefix = Ms.', $query->_qill[0][0]); + $this->assertNotTrue(isset($query->_tables['civicrm_activity'])); + + $query = new CRM_Contact_BAO_Query([['gender_id', '=', 2, 0]]); + $this->assertEquals('contact_a.gender_id = 2', $query->_where[0][0]); + $this->assertEquals('Gender = Male', $query->_qill[0][0]); + $this->assertNotTrue(isset($query->_tables['civicrm_activity'])); + + $query = new CRM_Contact_BAO_Query([['communication_style_id', '=', 2, 0]]); + $this->assertEquals('contact_a.communication_style_id = 2', $query->_where[0][0]); + $this->assertEquals('Communication Style = Familiar', $query->_qill[0][0]); + + $query = new CRM_Contact_BAO_Query([['communication_style_id', '=', 2, 0]]); + $this->assertEquals('contact_a.communication_style_id = 2', $query->_where[0][0]); + $this->assertEquals('Communication Style = Familiar', $query->_qill[0][0]); + + $query = new CRM_Contact_BAO_Query([['contact_type', '=', 'Household', 0]]); + $this->assertEquals("contact_a.contact_type = 'Household'", $query->_where[0][0]); + $this->assertEquals('Contact Type = Household', $query->_qill[0][0]); + + $query = new CRM_Contact_BAO_Query([['on_hold', '=', 0, 0]]); + $this->assertEquals('civicrm_email.on_hold = 0', $query->_where[0][0]); + $this->assertEquals('On Hold = 0', $query->_qill[0][0]); + + $query = new CRM_Contact_BAO_Query([['on_hold', '=', 1, 0]]); + $this->assertEquals('civicrm_email.on_hold = 1', $query->_where[0][0]); + $this->assertEquals('On Hold = 1', $query->_qill[0][0]); + + $query = new CRM_Contact_BAO_Query([['world_region', '=', 3, 0]]); + $this->assertEquals('civicrm_worldregion.id = 3', $query->_where[0][0]); + $this->assertEquals('World Region = Middle East and North Africa', $query->_qill[0][0]); + } + }