addValue('name', uniqid('con')) ->addValue('used_for', 'civicrm_contact') ->addValue('color', '#cccccc') ->execute()->first(); $tagChild = Tag::create(FALSE) ->addValue('name', uniqid('child')) ->addValue('parent_id', $conTag['id']) ->execute()->first(); $tagSubChild = Tag::create(FALSE) ->addValue('name', uniqid('child')) ->addValue('parent_id', $tagChild['id']) ->execute()->first(); $tagSet = Tag::create(FALSE) ->addValue('name', uniqid('set')) ->addValue('used_for', 'civicrm_contact') ->addValue('is_tagset', TRUE) ->execute()->first(); $setChild = Tag::create(FALSE) ->addValue('name', uniqid('child')) ->addValue('parent_id', $tagSet['id']) ->execute()->first(); $contact1 = Contact::create(FALSE) ->execute()->first(); $contact2 = Contact::create(FALSE) ->execute()->first(); EntityTag::create(FALSE) ->addValue('entity_id', $contact1['id']) ->addValue('entity_table', 'civicrm_contact') ->addValue('tag_id', $tagSubChild['id']) ->execute(); EntityTag::create(FALSE) ->addValue('entity_id', $contact2['id']) ->addValue('entity_table', 'civicrm_contact') ->addValue('tag_id', $setChild['id']) ->execute(); $shouldReturnContact1 = Contact::get(FALSE) ->addSelect('id') ->addWhere('tags:name', 'IN', [$conTag['name']]) ->execute(); $this->assertCount(1, $shouldReturnContact1); $this->assertEquals($contact1['id'], $shouldReturnContact1->first()['id']); $shouldReturnContact2 = Contact::get(FALSE) ->addSelect('id') ->addWhere('tags', 'IN', [$setChild['id']]) ->execute(); $this->assertCount(1, $shouldReturnContact2); $this->assertEquals($contact2['id'], $shouldReturnContact2->first()['id']); } }